-
-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jsx/dom): Intrinsic elements can now also be safely Evaluated mul…
…tiple times for the same element
- Loading branch information
Showing
3 changed files
with
34 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,16 @@ | ||
import type { Props, JSXNode } from '../base' | ||
import { normalizeIntrinsicElementProps } from '../utils' | ||
|
||
const JSXNodeCompatPrototype = { | ||
type: { | ||
get(this: { tag: string | Function }): string | Function { | ||
return this.tag | ||
}, | ||
}, | ||
ref: { | ||
get(this: { props?: { ref: unknown } }): unknown { | ||
return this.props?.ref | ||
}, | ||
}, | ||
} | ||
import { newJSXNode } from './utils' | ||
|
||
export const jsxDEV = (tag: string | Function, props: Props, key?: string): JSXNode => { | ||
if (typeof tag === 'string') { | ||
normalizeIntrinsicElementProps(props) | ||
} | ||
return Object.defineProperties( | ||
{ | ||
tag, | ||
props, | ||
key, | ||
}, | ||
JSXNodeCompatPrototype | ||
) as JSXNode | ||
return newJSXNode({ | ||
tag, | ||
props, | ||
key, | ||
}) | ||
} | ||
|
||
export const Fragment = (props: Record<string, unknown>): JSXNode => jsxDEV('', props, undefined) |
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 |
---|---|---|
@@ -1,7 +1,24 @@ | ||
import type { Props, JSXNode } from '../base' | ||
import { DOM_INTERNAL_TAG } from '../constants' | ||
|
||
export const setInternalTagFlag = (fn: Function): Function => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
;(fn as any)[DOM_INTERNAL_TAG] = true | ||
return fn | ||
} | ||
|
||
const JSXNodeCompatPrototype = { | ||
type: { | ||
get(this: { tag: string | Function }): string | Function { | ||
return this.tag | ||
}, | ||
}, | ||
ref: { | ||
get(this: { props?: { ref: unknown } }): unknown { | ||
return this.props?.ref | ||
}, | ||
}, | ||
} | ||
|
||
export const newJSXNode = (obj: { tag: string | Function; props?: Props; key?: string }): JSXNode => | ||
Object.defineProperties(obj, JSXNodeCompatPrototype) as JSXNode |