-
-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathindex.js
77 lines (69 loc) · 1.76 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { options, Fragment } from 'preact';
/** @typedef {import('preact').VNode} VNode */
let vnodeId = 0;
/**
* @fileoverview
* This file exports various methods that implement Babel's "automatic" JSX runtime API:
* - jsx(type, props, key)
* - jsxs(type, props, key)
* - jsxDEV(type, props, key, __source, __self)
*
* The implementation of createVNode here is optimized for performance.
* Benchmarks: https://esbench.com/bench/5f6b54a0b4632100a7dcd2b3
*/
/**
* JSX.Element factory used by Babel's {runtime:"automatic"} JSX transform
* @param {VNode['type']} type
* @param {VNode['props']} props
* @param {VNode['key']} [key]
* @param {string} [__self]
* @param {string} [__source]
*/
function createVNode(type, props, key, __self, __source) {
// We'll want to preserve `ref` in props to get rid of the need for
// forwardRef components in the future, but that should happen via
// a separate PR.
let normalizedProps = {},
ref,
i;
for (i in props) {
if (i == 'ref') {
ref = props[i];
} else {
normalizedProps[i] = props[i];
}
}
const vnode = {
type,
props: normalizedProps,
key,
ref,
_children: null,
_parent: null,
_depth: 0,
_dom: null,
_nextDom: undefined,
_component: null,
_hydrating: null,
constructor: undefined,
_original: --vnodeId,
__source,
__self
};
// If a Component VNode, check for and apply defaultProps.
// Note: `type` is often a String, and can be `undefined` in development.
if (typeof type === 'function' && (ref = type.defaultProps)) {
for (i in ref)
if (typeof normalizedProps[i] === 'undefined') {
normalizedProps[i] = ref[i];
}
}
if (options.vnode) options.vnode(vnode);
return vnode;
}
export {
createVNode as jsx,
createVNode as jsxs,
createVNode as jsxDEV,
Fragment
};