1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 | if (process.env.NODE_ENV === 'development') {
|
6 | var preact = require('preact');
|
7 | var options = preact.options;
|
8 | var oldVnodeOption = options.vnode;
|
9 |
|
10 | options.vnode = function (vnode) {
|
11 | var nodeName = vnode.nodeName,
|
12 | attributes = vnode.attributes,
|
13 | children = vnode.children;
|
14 |
|
15 |
|
16 | if (nodeName === void 0) {
|
17 | console.error('Undefined component passed to preact.h()\n' + serializeVNode(vnode));
|
18 | }
|
19 |
|
20 | if (attributes && attributes.ref !== void 0 && typeof attributes.ref !== 'function' && !('$$typeof' in vnode)
|
21 | ) {
|
22 | throw new Error('Component\'s "ref" property should be a function,' + (' but [' + typeof attributes.ref + '] passed\n') + serializeVNode(vnode));
|
23 | }
|
24 |
|
25 | {
|
26 | var keys = {};
|
27 |
|
28 | inspectChildren(children, function (deepChild) {
|
29 | if (!deepChild || deepChild.key == null) return;
|
30 |
|
31 |
|
32 | var key = deepChild.key + '';
|
33 |
|
34 | if (keys.hasOwnProperty(key)) {
|
35 | console.error('Following component has two or more children with the ' + 'same "key" attribute. This may cause glitches and misbehavior ' + 'in rendering process. Component: \n\n' + serializeVNode(vnode));
|
36 |
|
37 |
|
38 | return true;
|
39 | }
|
40 |
|
41 | keys[key] = true;
|
42 | });
|
43 | }
|
44 |
|
45 | if (oldVnodeOption) oldVnodeOption.call(this, vnode);
|
46 | };
|
47 |
|
48 | try {
|
49 | var oldRender = preact.render;
|
50 | preact.render = function (vnode, parent, merge) {
|
51 | if (parent == null && merge == null) {
|
52 |
|
53 | console.error('The "containerNode" or "replaceNode" is not defined in the render method. ' + 'Component: \n\n' + serializeVNode(vnode));
|
54 | } else if (parent == merge) {
|
55 |
|
56 |
|
57 | console.error('The "containerNode" and "replaceNode" are the same in render method, ' + 'when the "replaceNode" DOM node is expected to be a child of "containerNode". ' + 'docs-ref: https://preactjs.com/guide/api-reference#-preact-render-. Component: \n\n' + serializeVNode(vnode));
|
58 | }
|
59 | return oldRender(vnode, parent, merge);
|
60 | };
|
61 | } catch (e) {}
|
62 |
|
63 | var inspectChildren = function inspectChildren(children, inspect) {
|
64 | if (!Array.isArray(children)) {
|
65 | children = [children];
|
66 | }
|
67 | return children.some(function (child, i) {
|
68 | if (Array.isArray(child)) {
|
69 | return inspectChildren(child, inspect);
|
70 | }
|
71 |
|
72 | return inspect(child, i);
|
73 | });
|
74 | };
|
75 |
|
76 | var serializeVNode = function serializeVNode(_ref) {
|
77 | var nodeName = _ref.nodeName,
|
78 | attributes = _ref.attributes,
|
79 | children = _ref.children;
|
80 |
|
81 | if (typeof nodeName === 'function') {
|
82 | nodeName = nodeName.name || nodeName.displayName;
|
83 | }
|
84 |
|
85 | var props = '';
|
86 | if (attributes) {
|
87 | for (var attr in attributes) {
|
88 | if (attributes.hasOwnProperty(attr) && attr !== 'children') {
|
89 | var value = attributes[attr];
|
90 |
|
91 |
|
92 | if (typeof value === 'function') {
|
93 | value = 'function ' + (value.displayName || value.name) + '() {}';
|
94 | }
|
95 | if (Object(value) === value && !value.toString) {
|
96 | value = Object.prototype.toString.call(value);
|
97 | } else {
|
98 | value = value + '';
|
99 | }
|
100 |
|
101 | props += ' ' + attr + '=' + JSON.stringify(value);
|
102 | }
|
103 | }
|
104 | }
|
105 |
|
106 | return '<' + nodeName + props + (children && children.length ? '>..</' + nodeName + '>' : ' />');
|
107 | };
|
108 |
|
109 | require('preact/devtools');
|
110 | }
|
111 |
|
112 |
|
\ | No newline at end of file |