Skip to content

Commit 2ec86fa

Browse files
committed
feat(fragment): Add Fragment function
1 parent d7a1b59 commit 2ec86fa

File tree

7 files changed

+1962
-1798
lines changed

7 files changed

+1962
-1798
lines changed

package-lock.json

Lines changed: 1946 additions & 1787 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@
4141
"eslint-config-prettier": "^9.0.0",
4242
"eslint-plugin-prettier": "^5.2.1",
4343
"prettier": "^3.3.3",
44-
"typescript": "^5.6.2"
44+
"typescript": "^5.7.0"
4545
}
4646
}

src/jsx-runtime.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import type { ShadowHostElement } from "./types.js";
22
import { PLUSNEW_ELEMENT_TYPE } from "./types.js";
33

4-
export { PLUSNEW_FRAGMENT_TYPE as Fragment } from "./types.js"
4+
export { Fragment } from "./types.js";
55

66
export function jsx(
77
type: string,
88
props: object,
99
...children: (() => ShadowHostElement)[]
1010
): ShadowHostElement {
1111
return {
12-
// This tag allows us to uniquely identify this as a React Element
12+
// This tag allows us to uniquely identify this as a JSX Element
1313
$$typeof: PLUSNEW_ELEMENT_TYPE,
1414

1515
// Built-in properties that belong on the element

src/reconciler/component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ShadowComponentElement, ShadowElement } from "../types.js";
1+
import { type ShadowComponentElement, type ShadowElement, PLUSNEW_ELEMENT_TYPE} from "../types.js";
22
import type { Reconciler } from "./index.js";
33
import { remove } from "./util.js";
44

@@ -8,6 +8,7 @@ export function isComponentElement(
88
return (
99
typeof shadowElement === "object" &&
1010
"$$typeof" in shadowElement &&
11+
shadowElement.$$typeof === PLUSNEW_ELEMENT_TYPE &&
1112
typeof shadowElement.type === "function"
1213
);
1314
}

src/reconciler/fragment.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import { PLUSNEW_FRAGMENT_TYPE, type ShadowFragmentElement, type ShadowElement } from "../types.js";
1+
import { PLUSNEW_ELEMENT_TYPE, Fragment, type ShadowElement, ShadowComponentElement, ShadowHostElement } from "../types.js";
22
import type { Reconciler } from "./index.js";
33
import { arrayReconcileWithoutSorting, remove } from "./util.js";
44

55

66
export function isFragmentElement(
77
shadowElement: ShadowElement,
8-
): shadowElement is ShadowFragmentElement {
8+
): shadowElement is ShadowHostElement {
99
return (
1010
typeof shadowElement === "object" &&
1111
"$$typeof" in shadowElement &&
12-
shadowElement.type === PLUSNEW_FRAGMENT_TYPE
12+
shadowElement.$$typeof === PLUSNEW_ELEMENT_TYPE &&
13+
shadowElement.type === Fragment
1314
);
1415
}
1516

src/reconciler/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ export function reconcile(
2727
shadowElement: ShadowElement,
2828
): Node | null {
2929
for (const reconciler of [
30+
fragmentReconcile,
3031
hostReconcile,
3132
componentReconcile,
32-
fragmentReconcile,
3333
textReconcile,
3434
arrayReconcile,
3535
falseReconcile,

src/types.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import type { Reconciler } from "./reconciler/index.js";
22

33
export const PLUSNEW_ELEMENT_TYPE = Symbol("plusnew-element-type");
4-
export const PLUSNEW_FRAGMENT_TYPE = Symbol("plusnew-fragment-type");
4+
5+
export function Fragment(props: { children: ShadowElement }) {
6+
return props.children
7+
}
58

69
// type Expect<T extends true> = T;
710

@@ -123,8 +126,8 @@ export type ShadowComponentElement = {
123126
};
124127

125128
export type ShadowFragmentElement = {
126-
$$typeof: typeof PLUSNEW_ELEMENT_TYPE;
127-
type: typeof PLUSNEW_FRAGMENT_TYPE;
129+
$$typeof: typeof PLUSNEW_ELEMENT_TYPE
130+
type: typeof Fragment;
128131
props: any;
129132
children: (() => ShadowElement)[];
130133
};

0 commit comments

Comments
 (0)