-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f2fda3
commit 2181325
Showing
5 changed files
with
169 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { UNDEFINED } from './constants'; | ||
|
||
export const TYPE_TEXT = 1 << 0; | ||
export const TYPE_ELEMENT = 1 << 1; | ||
export const TYPE_CLASS = 1 << 2; | ||
export const TYPE_FUNCTION = 1 << 3; | ||
export const TYPE_INVALID = 1 << 6; | ||
export const TYPE_COMPONENT = TYPE_CLASS | TYPE_FUNCTION; | ||
|
||
export const MODE_SVG = 1 << 4; | ||
export const MODE_MATH = 1 << 5; | ||
const INHERITED_MODES = MODE_MATH | MODE_SVG; | ||
|
||
/** | ||
* | ||
* @param {VNode} vnode | ||
* @param {Internal | null} parentInternal | ||
* @returns {Internal} | ||
*/ | ||
export function createInternal(vnode, parentInternal) { | ||
let flags = parentInternal ? parentInternal.flags & INHERITED_MODES : 0, | ||
type = vnode.type; | ||
|
||
if (vnode.constructor !== UNDEFINED) { | ||
flags |= TYPE_INVALID; | ||
} else if (typeof vnode == 'string' || type == null) { | ||
// type = null; | ||
flags |= TYPE_TEXT; | ||
} else { | ||
// flags = typeof type === 'function' ? COMPONENT_NODE : ELEMENT_NODE; | ||
flags |= | ||
typeof type == 'function' | ||
? type.prototype && type.prototype.render | ||
? TYPE_CLASS | ||
: TYPE_FUNCTION | ||
: TYPE_ELEMENT; | ||
|
||
if (flags & TYPE_ELEMENT && type === 'svg') { | ||
flags |= MODE_SVG; | ||
} else if ( | ||
parentInternal && | ||
parentInternal.flags & MODE_SVG && | ||
parentInternal.type === 'foreignObject' | ||
) { | ||
flags &= ~MODE_SVG; | ||
} else if (flags & TYPE_ELEMENT && type === 'math') { | ||
flags |= MODE_MATH; | ||
} | ||
} | ||
|
||
return { | ||
type, | ||
props: vnode.props, | ||
key: vnode.key, | ||
ref: vnode.ref, | ||
data: | ||
flags & TYPE_COMPONENT | ||
? { _commitCallbacks: [], _context: null, _stateCallbacks: [] } | ||
: null, | ||
flags, | ||
// @ts-expect-error | ||
vnode, | ||
// TODO: rerender | ||
_children: null, | ||
_parent: parentInternal, | ||
_vnodeId: vnode._original, | ||
_component: null, | ||
_depth: parentInternal ? parentInternal._depth + 1 : 0 | ||
}; | ||
} |