UNPKG

preact

Version:

Fast 4kb React-compatible Virtual DOM library.

3 lines (2 loc) • 10.2 kB
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=[],c=[],s=new WeakMap,u=new WeakMap;function l(){return i.length>0?i[i.length-1]:null}var f=!0;function d(n){for(var e=[n],o=n;null!=(o=s.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+")":f&&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."),f=!1,n+"\n"},"")}function p(){var o=n.__b,t=n.diffed,r=n.vnode,a=n.__r,l=n.__e,f=function(n,e,o){i.length=Math.min(i.length,n[0]+e),c.length=Math.min(c.length,n[1]+o)};n.diffed=function(n){var e=u.get(n);e&&(u.delete(n),f(e,0,0)),t&&t(n)},n.__b=function(n){"function"==typeof n.type&&(u.set(n,[i.length,c.length]),n.type!=e&&i.push(n)),o&&o(n)},n.__e=function(n,e,o,t){var r=u.get(e);r&&f(r,+(i[r[0]]==e),+(c[r[1]]==e));try{l(n,e,o,t)}catch(n){throw r&&(u.delete(e),f(r,0,0)),n}},n.vnode=function(n){s.set(n,c.length>0?c[c.length-1]:null),r&&r(n)},n.__r=function(n){(function(n){return"function"==typeof n.type&&n.type!=e})(n)&&c.push(n),a&&a(n)}}function h(){var n=l();return n?d(n):null}function v(n){return n!=n}var y=["ref"],m="function"==typeof WeakMap;function b(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,b(n))}else n&&"string"==typeof n.type&&e.push(n.type)}),e):e}function w(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:"":w(n.__):n.type:""}var g=o.prototype.setState;function k(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'+d(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)$/,M=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 c=e.children;return"<"+o+t+(c&&c.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'+d(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'+d(this.__v)),M.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"+d(n))},function(){p();var o,r=!1,i=n.__b,c=n.diffed,s=n.vnode,u=n.__r,l=n.__e,f=n.__,h=n.__h,g=m?{useEffect:new WeakMap,useLayoutEffect:new WeakMap,lazyPropTypes:new WeakMap}:null,M=[];n.__e=function(n,t,r,i){var c=o&&o.error===n&&o;c&&(c.done=!0);try{if(t&&t.__c&&n&&"function"==typeof n.then){var s=n;n=new Error("Missing Suspense. The throwing component was: "+a(t));for(var u=t;u;u=u.__)if(u.__c&&u.__c.__c){n=s;break}if(n instanceof Error)throw n}(i=i||{}).componentStack=d(t),l(n,t,r,i)}catch(n){var f=o={error:n,vnode:c&&n===c.error?c.vnode:t};throw queueMicrotask(function(){if(!f.done){var n=function(n){for(var o=n;o&&("function"!=typeof o.type||o.type==e);)o=o.__;return o||n}(f.vnode);console.error("An error occurred in the <"+a(n)+"> component, and no error boundary handled it.\n\n"+d(n))}o==f&&(o=void 0)}),n}n&&"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+");")}f&&f(n,e)},n.__b=function(n){o=void 0;var e=n.type;if(r=!0,void 0===e)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"+d(n));if(null!=e&&"object"==typeof e){if(void 0!==e.__k&&void 0!==e.__e)throw new Error("Invalid type passed to createElement(): "+e+"\n\nDid you accidentally pass a JSX literal as JSX twice?\n\n let My"+a(n)+" = "+_(e)+";\n let vnode = <My"+a(n)+" />;\n\nThis usually happens when you export a JSX literal and not the component.\n\n"+d(n));throw new Error("Invalid type passed to createElement(): "+(Array.isArray(e)?"array":e))}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"+d(n));if("string"==typeof n.type)for(var c in n.props)if("o"===c[0]&&"n"===c[1]&&"function"!=typeof n.props[c]&&null!=n.props[c])throw new Error("Component's \""+c+'" property should be a function, but got ['+typeof n.props[c]+"] instead\n"+_(n)+"\n\n"+d(n));if("function"==typeof n.type&&n.type.propTypes){if("Lazy"===n.type.displayName&&g&&!g.lazyPropTypes.has(n.type)){var s="PropTypes are not supported on lazy(). Use propTypes on the wrapped component itself. ";try{var u=n.type();g.lazyPropTypes.set(n.type,!0),console.warn(s+"Component wrapped in lazy() is "+a(u))}catch(n){console.warn(s+"We will log the wrapped component's name once it is loaded.")}}var l=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,y);!function(e,o,r,a,i){Object.keys(e).forEach(function(r){var i;try{i=e[r](o,r,a,"prop",null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(n){i=n}i&&!(i.message in t)&&(t[i.message]=!0,console.error("Failed prop type: "+i.message+"\n"+d(n)))})}(n.type.propTypes,l,0,a(n))}i&&i(n)};var T,O=0;n.__r=function(n){u&&u(n),r=!0;var e=n.__c;if(e===T?O++:O=1,O>=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));T=e},n.__h=function(n,e,o){if(!n||!r)throw new Error("Hook can only be invoked from render methods.");h&&h(n,e,o)};var I=function(n,e){return{get:function(){var o="get"+n+e;M&&M.indexOf(o)<0&&(M.push(o),console.warn("getting vnode."+n+" is deprecated, "+e))},set:function(){var o="set"+n+e;M&&M.indexOf(o)<0&&(M.push(o),console.warn("setting vnode."+n+" is not allowed, "+e))}}},j={nodeName:I("nodeName","use vnode.type"),attributes:I("attributes","use vnode.props"),children:I("children","use vnode.props.children")},S=Object.create({},j);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__=S,s&&s(n)},n.diffed=function(n){var e=n.type,o=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"+d(n))}}),n.__c===T&&(O=0),"string"==typeof e&&(k(e)||"p"===e||"a"===e||"button"===e)){var t=w(o);if(""!==t&&k(e))"table"===e&&"td"!==t&&k(t)?console.error("Improper nesting of table. Your <table> should not have a table-node parent."+_(n)+"\n\n"+d(n)):"thead"!==e&&"tfoot"!==e&&"tbody"!==e||"table"===t?"tr"===e&&"thead"!==t&&"tfoot"!==t&&"tbody"!==t?console.error("Improper nesting of table. Your <tr> should have a <thead/tbody/tfoot> parent."+_(n)+"\n\n"+d(n)):"td"===e&&"tr"!==t?console.error("Improper nesting of table. Your <td> should have a <tr> parent."+_(n)+"\n\n"+d(n)):"th"===e&&"tr"!==t&&console.error("Improper nesting of table. Your <th> should have a <tr>."+_(n)+"\n\n"+d(n)):console.error("Improper nesting of table. Your <thead/tbody/tfoot> should have a <table> parent."+_(n)+"\n\n"+d(n));else if("p"===e){var i=b(n).filter(function(n){return E.test(n)});i.length&&console.error("Improper nesting of paragraph. Your <p> should not have "+i.join(", ")+" as child-elements."+_(n)+"\n\n"+d(n))}else"a"!==e&&"button"!==e||-1!==b(n).indexOf(e)&&console.error("Improper nesting of interactive content. Your <"+e+"> should not have other "+("a"===e?"anchor":"button")+" tags as child-elements."+_(n)+"\n\n"+d(n))}if(r=!1,c&&c(n),null!=n.__k)for(var s=[],u=0;u<n.__k.length;u++){var l=n.__k[u];if(l&&null!=l.key){var f=l.key;if(-1!==s.indexOf(f)){console.error('Following component has two or more children with the same key attribute: "'+f+'". This may cause glitches and misbehavior in rendering process. Component: \n\n'+_(n)+"\n\n"+d(n));break}s.push(f)}}if(null!=n.__c&&null!=n.__c.__H){var p=n.__c.__H.__;if(p)for(var h=0;h<p.length;h+=1){var y=p[h];if(y.__H)for(var m=0;m<y.__H.length;m++)if(v(y.__H[m])){var g=a(n);console.warn("Invalid argument passed to hook. Hooks should not be called with NaN in the dependency array. Hook index "+h+" in component "+g+" was called with NaN.")}}}}}();export{h as captureOwnerStack,l as getCurrentVNode,a as getDisplayName,d as getOwnerStack,r as resetPropWarnings,p as setupComponentStack}; //# sourceMappingURL=debug.mjs.map