preact
Version:
Fast 4kb React-compatible Virtual DOM library.
3 lines (2 loc) • 10.2 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=[],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}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 w=o.prototype.setState;function g(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())),w.call(this,n,e)};var k=/^(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)$/,E=o.prototype.forceUpdate;function M(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)),E.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,w=y?{useEffect:new WeakMap,useLayoutEffect:new WeakMap,lazyPropTypes:new WeakMap}:null,E=[];n.__e=function(n,t,r,i){var c=o&&o.error===n&&o;c&&(c.done=!0);try{if(t&&t.__c&&"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}"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,c,s,u,l=n.type;if(r=!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"+M(n)+"\n\n"+d(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)+" = "+M(l)+";\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(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"+M(n)+"\n\n"+d(n));if("string"==typeof n.type)for(var f in n.props)if("o"===f[0]&&"n"===f[1]&&"function"!=typeof n.props[f]&&null!=n.props[f])throw new Error("Component's \""+f+'" property should be a function, but got ['+typeof n.props[f]+"] instead\n"+M(n)+"\n\n"+d(n));if("function"==typeof n.type&&n.type.propTypes){if("Lazy"===n.type.displayName&&w&&!w.lazyPropTypes.has(n.type)){var p="PropTypes are not supported on lazy(). Use propTypes on the wrapped component itself. ";try{var h=n.type();w.lazyPropTypes.set(n.type,!0),console.warn(p+"Component wrapped in lazy() is "+a(h))}catch(n){console.warn(p+"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);e=n.type.propTypes,c=y,s=a(n),u=function(){return d(n)},Object.keys(e).forEach(function(n){var o;try{o=e[n](c,n,s,"prop",null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(n){o=n}o&&!(o.message in t)&&(t[o.message]=!0,console.error("Failed prop type: "+o.message+"\n"+u()))})}i&&i(n)};var _,T=0;n.__r=function(n){u&&u(n),r=!0;var e=n.__c;if(e===_?T++:T=1,T>=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));_=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 O=function(n,e){return{get:function(){var o="get"+n+e;E&&E.indexOf(o)<0&&(E.push(o),console.warn("getting vnode."+n+" is deprecated, "+e))},set:function(){var o="set"+n+e;E&&E.indexOf(o)<0&&(E.push(o),console.warn("setting vnode."+n+" is not allowed, "+e))}}},I={nodeName:O("nodeName","use vnode.type"),attributes:O("attributes","use vnode.props"),children:O("children","use vnode.props.children")},j=Object.create({},I);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__=j,s&&s(n)},n.diffed=function(n){var e,o=n.type,t=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=0),"string"==typeof o&&(g(o)||"p"===o||"a"===o||"button"===o)){var i=b(t);if(""!==i&&g(o))"table"===o&&"td"!==i&&g(i)?console.error("Improper nesting of table. Your <table> should not have a table-node parent."+M(n)+"\n\n"+d(n)):"thead"!==o&&"tfoot"!==o&&"tbody"!==o||"table"===i?"tr"===o&&"thead"!==i&&"tfoot"!==i&&"tbody"!==i?console.error("Improper nesting of table. Your <tr> should have a <thead/tbody/tfoot> parent."+M(n)+"\n\n"+d(n)):"td"===o&&"tr"!==i?console.error("Improper nesting of table. Your <td> should have a <tr> parent."+M(n)+"\n\n"+d(n)):"th"===o&&"tr"!==i&&console.error("Improper nesting of table. Your <th> should have a <tr>."+M(n)+"\n\n"+d(n)):console.error("Improper nesting of table. Your <thead/tbody/tfoot> should have a <table> parent."+M(n)+"\n\n"+d(n));else if("p"===o){var s=m(n).filter(function(n){return k.test(n)});s.length&&console.error("Improper nesting of paragraph. Your <p> should not have "+s.join(", ")+" as child-elements."+M(n)+"\n\n"+d(n))}else"a"!==o&&"button"!==o||-1!==m(n).indexOf(o)&&console.error("Improper nesting of interactive content. Your <"+o+"> should not have other "+("a"===o?"anchor":"button")+" tags as child-elements."+M(n)+"\n\n"+d(n))}if(r=!1,c&&c(n),null!=n.__k)for(var u=[],l=0;l<n.__k.length;l++){var f=n.__k[l];if(f&&null!=f.key){var p=f.key;if(-1!==u.indexOf(p)){console.error('Following component has two or more children with the same key attribute: "'+p+'". This may cause glitches and misbehavior in rendering process. Component: \n\n'+M(n)+"\n\n"+d(n));break}u.push(p)}}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 w=0;w<y.__H.length;w++)if((e=y.__H[w])!=e){var E=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 "+E+" 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