preact
Version:
Fast 4kb React-compatible Virtual DOM library.
3 lines (2 loc) • 9.52 kB
JavaScript
import{options as n,Fragment as e,Component as o}from"preact";import"preact/devtools";var t={};function r(){t={}}function a(n){return n.type===e?"Fragment":"function"==typeof n.type?n.type.displayName||n.type.name:"string"==typeof n.type?n.type:"#text"}var i=[],s=[],c=new WeakMap;function l(){return i.length>0?i[i.length-1]:null}var u=!0;function f(n){return"function"==typeof n.type&&n.type!=e}function p(n){for(var e=[n],o=n;null!=(o=c.get(o));)e.push(o);return e.reduce(function(n,e){n+=" in "+a(e);var o=e.__source;return o?n+=" (at "+o.fileName+":"+o.lineNumber+")":u&&console.warn("Add @babel/plugin-transform-react-jsx-source to get a more detailed component stack. Note that you should not add it to production builds of your App for bundle size reasons."),u=!1,n+"\n"},"")}function d(){var e=n.__b,o=n.diffed,t=n.__,r=n.vnode,a=n.__r;n.diffed=function(n){f(n)&&s.pop(),i.pop(),o&&o(n)},n.__b=function(n){f(n)&&i.push(n),e&&e(n)},n.__=function(n,e){s=[],t&&t(n,e)},n.vnode=function(n){c.set(n,s.length>0?s[s.length-1]:null),r&&r(n)},n.__r=function(n){f(n)&&s.push(n),a&&a(n)}}function h(){var n=l();return n?p(n):null}var v=["ref"],y="function"==typeof WeakMap;function m(n){var e=[];return n.__k?(n.__k.forEach(function(n){if(n&&"function"==typeof n.type){if(n.props.__P)return;e.push.apply(e,m(n))}else n&&"string"==typeof n.type&&e.push(n.type)}),e):e}function b(n){return n?"function"==typeof n.type?n.props.__P?n.props.__P.localName||"":null==n.__?null!=n.__e&&null!=n.__e.parentNode?n.__e.parentNode.localName:"":b(n.__):n.type:""}var g=o.prototype.setState;function w(n){return"table"===n||"tfoot"===n||"tbody"===n||"thead"===n||"td"===n||"tr"===n||"th"===n}o.prototype.setState=function(n,e){return null==this.__v&&null==this.state&&console.warn('Calling "this.setState" inside the constructor of a component is a no-op and might be a bug in your application. Instead, set "this.state = {}" directly.\n\n'+p(l())),g.call(this,n,e)};var E=/^(address|article|aside|blockquote|details|div|dl|fieldset|figcaption|figure|footer|form|h1|h2|h3|h4|h5|h6|header|hgroup|hr|main|menu|nav|ol|p|pre|search|section|table|ul)$/,k=o.prototype.forceUpdate;function _(n){var e=n.props,o=a(n),t="";for(var r in e)if(e.hasOwnProperty(r)&&"children"!==r){var i=e[r];"function"==typeof i&&(i="function "+(i.displayName||i.name)+"() {}"),i=Object(i)!==i||i.toString?i+"":Object.prototype.toString.call(i),t+=" "+r+"="+JSON.stringify(i)}var s=e.children;return"<"+o+t+(s&&s.length?">..</"+o+">":" />")}o.prototype.forceUpdate=function(n){return null==this.__v?console.warn('Calling "this.forceUpdate" inside the constructor of a component is a no-op and might be a bug in your application.\n\n'+p(l())):null==this.__P&&console.warn('Can\'t call "this.forceUpdate" on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.\n\n'+p(this.__v)),k.call(this,n)},n.__m=function(n,e){var o=n.type,t=e.map(function(n){return n&&n.localName}).filter(Boolean);console.error('Expected a DOM node of type "'+o+'" but found "'+t.join(", ")+"\" as available DOM-node(s), this is caused by the SSR'd HTML containing different DOM-nodes compared to the hydrated one.\n\n"+p(n))},function(){d();var e=!1,o=n.__b,r=n.diffed,i=n.vnode,s=n.__r,c=n.__e,l=n.__,u=n.__h,f=y?{useEffect:new WeakMap,useLayoutEffect:new WeakMap,lazyPropTypes:new WeakMap}:null,h=[];n.__e=function(n,e,o,t){if(e&&e.__c&&"function"==typeof n.then){var r=n;n=new Error("Missing Suspense. The throwing component was: "+a(e));for(var i=e;i;i=i.__)if(i.__c&&i.__c.__c){n=r;break}if(n instanceof Error)throw n}(t=t||{}).componentStack=p(e),c(n,e,o,t),"function"!=typeof n.then&&console.error(n)},n.__=function(n,e){if(!e)throw new Error("Undefined parent passed to render(), this is the second argument.\nCheck if the element is available in the DOM/has the correct id.");var o;switch(e.nodeType){case 1:case 11:case 9:o=!0;break;default:o=!1}if(!o){var t=a(n);throw new Error("Expected a valid HTML node as a second argument to render.\tReceived "+e+" instead: render(<"+t+" />, "+e+");")}l&&l(n,e)},n.__b=function(n){var r,i,s,c,l=n.type;if(e=!0,void 0===l)throw new Error("Undefined component passed to createElement()\n\nYou likely forgot to export your component or might have mixed up default and named imports"+_(n)+"\n\n"+p(n));if(null!=l&&"object"==typeof l){if(void 0!==l.__k&&void 0!==l.__e)throw new Error("Invalid type passed to createElement(): "+l+"\n\nDid you accidentally pass a JSX literal as JSX twice?\n\n let My"+a(n)+" = "+_(l)+";\n let vnode = <My"+a(n)+" />;\n\nThis usually happens when you export a JSX literal and not the component.\n\n"+p(n));throw new Error("Invalid type passed to createElement(): "+(Array.isArray(l)?"array":l))}if(void 0!==n.ref&&"function"!=typeof n.ref&&"object"!=typeof n.ref&&!("$$typeof"in n))throw new Error('Component\'s "ref" property should be a function, or an object created by createRef(), but got ['+typeof n.ref+"] instead\n"+_(n)+"\n\n"+p(n));if("string"==typeof n.type)for(var u in n.props)if("o"===u[0]&&"n"===u[1]&&"function"!=typeof n.props[u]&&null!=n.props[u])throw new Error("Component's \""+u+'" property should be a function, but got ['+typeof n.props[u]+"] instead\n"+_(n)+"\n\n"+p(n));if("function"==typeof n.type&&n.type.propTypes){if("Lazy"===n.type.displayName&&f&&!f.lazyPropTypes.has(n.type)){var d="PropTypes are not supported on lazy(). Use propTypes on the wrapped component itself. ";try{var h=n.type();f.lazyPropTypes.set(n.type,!0),console.warn(d+"Component wrapped in lazy() is "+a(h))}catch(n){console.warn(d+"We will log the wrapped component's name once it is loaded.")}}var y=function(n,e){if(null==n)return{};var o={};for(var t in n)if({}.hasOwnProperty.call(n,t)){if(-1!==e.indexOf(t))continue;o[t]=n[t]}return o}(n.props,v);r=n.type.propTypes,i=y,s=a(n),c=function(){return p(n)},Object.keys(r).forEach(function(n){var e;try{e=r[n](i,n,s,"prop",null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(n){e=n}e&&!(e.message in t)&&(t[e.message]=!0,console.error("Failed prop type: "+e.message+"\n"+c()))})}o&&o(n)};var g,k=0;n.__r=function(n){s&&s(n),e=!0;var o=n.__c;if(o===g?k++:k=1,k>=25)throw new Error("Too many re-renders. This is limited to prevent an infinite loop which may lock up your browser. The component causing this is: "+a(n));g=o},n.__h=function(n,o,t){if(!n||!e)throw new Error("Hook can only be invoked from render methods.");u&&u(n,o,t)};var T=function(n,e){return{get:function(){var o="get"+n+e;h&&h.indexOf(o)<0&&(h.push(o),console.warn("getting vnode."+n+" is deprecated, "+e))},set:function(){var o="set"+n+e;h&&h.indexOf(o)<0&&(h.push(o),console.warn("setting vnode."+n+" is not allowed, "+e))}}},O={nodeName:T("nodeName","use vnode.type"),attributes:T("attributes","use vnode.props"),children:T("children","use vnode.props.children")},I=Object.create({},O);n.vnode=function(n){var e=n.props;if(null!==n.type&&null!=e&&("__source"in e||"__self"in e)){var o=n.props={};for(var t in e){var r=e[t];"__source"===t?n.__source=r:"__self"===t?n.__self=r:o[t]=r}}n.__proto__=I,i&&i(n)},n.diffed=function(n){var o,t=n.type,i=n.__;if(n.__k&&n.__k.forEach(function(e){if("object"==typeof e&&e&&void 0===e.type){var o=Object.keys(e).join(",");throw new Error("Objects are not valid as a child. Encountered an object with the keys {"+o+"}.\n\n"+p(n))}}),n.__c===g&&(k=0),"string"==typeof t&&(w(t)||"p"===t||"a"===t||"button"===t)){var s=b(i);if(""!==s&&w(t))"table"===t&&"td"!==s&&w(s)?console.error("Improper nesting of table. Your <table> should not have a table-node parent."+_(n)+"\n\n"+p(n)):"thead"!==t&&"tfoot"!==t&&"tbody"!==t||"table"===s?"tr"===t&&"thead"!==s&&"tfoot"!==s&&"tbody"!==s?console.error("Improper nesting of table. Your <tr> should have a <thead/tbody/tfoot> parent."+_(n)+"\n\n"+p(n)):"td"===t&&"tr"!==s?console.error("Improper nesting of table. Your <td> should have a <tr> parent."+_(n)+"\n\n"+p(n)):"th"===t&&"tr"!==s&&console.error("Improper nesting of table. Your <th> should have a <tr>."+_(n)+"\n\n"+p(n)):console.error("Improper nesting of table. Your <thead/tbody/tfoot> should have a <table> parent."+_(n)+"\n\n"+p(n));else if("p"===t){var c=m(n).filter(function(n){return E.test(n)});c.length&&console.error("Improper nesting of paragraph. Your <p> should not have "+c.join(", ")+" as child-elements."+_(n)+"\n\n"+p(n))}else"a"!==t&&"button"!==t||-1!==m(n).indexOf(t)&&console.error("Improper nesting of interactive content. Your <"+t+"> should not have other "+("a"===t?"anchor":"button")+" tags as child-elements."+_(n)+"\n\n"+p(n))}if(e=!1,r&&r(n),null!=n.__k)for(var l=[],u=0;u<n.__k.length;u++){var f=n.__k[u];if(f&&null!=f.key){var d=f.key;if(-1!==l.indexOf(d)){console.error('Following component has two or more children with the same key attribute: "'+d+'". This may cause glitches and misbehavior in rendering process. Component: \n\n'+_(n)+"\n\n"+p(n));break}l.push(d)}}if(null!=n.__c&&null!=n.__c.__H){var h=n.__c.__H.__;if(h)for(var v=0;v<h.length;v+=1){var y=h[v];if(y.__H)for(var T=0;T<y.__H.length;T++)if((o=y.__H[T])!=o){var O=a(n);console.warn("Invalid argument passed to hook. Hooks should not be called with NaN in the dependency array. Hook index "+v+" in component "+O+" was called with NaN.")}}}}}();export{h as captureOwnerStack,l as getCurrentVNode,a as getDisplayName,p as getOwnerStack,r as resetPropWarnings,d as setupComponentStack};
//# sourceMappingURL=debug.mjs.map