Skip to content

Commit ce16370

Browse files
committed
[fix] JSX Creator bug between SnabbDOM 3 & Parcel 2
related with parcel-bundler/parcel#7739
1 parent cd1f523 commit ce16370

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web-cell",
3-
"version": "3.0.0-alpha.0",
3+
"version": "3.0.0-alpha.1",
44
"description": "Web Components engine based on VDOM, JSX, MobX & TypeScript",
55
"keywords": [
66
"web",
@@ -48,7 +48,7 @@
4848
"core-js": "^3.21.1",
4949
"element-internals-polyfill": "^0.1.54",
5050
"eslint": "^8.9.0",
51-
"eslint-config-prettier": "^8.3.0",
51+
"eslint-config-prettier": "^8.4.0",
5252
"husky": "^7.0.4",
5353
"jest": "^27.5.1",
5454
"jsdom": "^19.0.0",

source/renderer.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import {
1010
On,
1111
VNodeData,
1212
VNode,
13-
JsxVNodeChild,
13+
JsxVNodeChildren,
1414
Fragment,
15-
jsx,
15+
vnode,
16+
h,
1617
init,
1718
attributesModule,
1819
propsModule,
@@ -107,14 +108,36 @@ function splitProps(tagName: string, raw: VDOMData) {
107108
export function createCell(
108109
tag: ComponentTag,
109110
props: VDOMData = {},
110-
...defaultSlot: JsxVNodeChild[]
111+
...children: JsxVNodeChildren[]
111112
) {
113+
var defaultSlot: (VNode | string)[] = children
114+
.flat()
115+
.filter(node => node != null && node !== false && node !== '')
116+
.map(node =>
117+
typeof node === 'boolean' ||
118+
typeof node === 'number' ||
119+
typeof node === 'string'
120+
? vnode(
121+
undefined,
122+
undefined,
123+
undefined,
124+
String(node),
125+
undefined
126+
)
127+
: node
128+
);
129+
if (defaultSlot.length === 1 && typeof defaultSlot[0] !== 'string') {
130+
const [{ sel, text }] = defaultSlot;
131+
132+
if (!sel && text) defaultSlot = [text];
133+
}
134+
112135
if (isHTMLElementClass(tag)) tag = tagNameOf(tag);
113136
else if (tag === Fragment)
114137
return Fragment({ key: props?.key }, ...defaultSlot);
115138
else if (typeof tag === 'function') return tag({ ...props, defaultSlot });
116139

117-
return jsx(tag, splitProps(tag, props), defaultSlot);
140+
return h(tag, splitProps(tag, props), defaultSlot);
118141
}
119142

120143
export function renderToStaticMarkup(tree: VNode) {

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,10 +2294,10 @@ escodegen@^2.0.0:
22942294
optionalDependencies:
22952295
source-map "~0.6.1"
22962296

2297-
eslint-config-prettier@^8.3.0:
2298-
version "8.3.0"
2299-
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.3.0.tgz#f7471b20b6fe8a9a9254cc684454202886a2dd7a"
2300-
integrity sha512-BgZuLUSeKzvlL/VUjx/Yb787VQ26RU3gGjA3iiFvdsp/2bMfVIWUVP7tjxtjS0e+HP409cPlPvNkQloz8C91ew==
2297+
eslint-config-prettier@^8.4.0:
2298+
version "8.4.0"
2299+
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.4.0.tgz#8e6d17c7436649e98c4c2189868562921ef563de"
2300+
integrity sha512-CFotdUcMY18nGRo5KGsnNxpznzhkopOcOo0InID+sgQssPrzjvsyKZPvOgymTFeHrFuC3Tzdf2YndhXtULK9Iw==
23012301

23022302
eslint-scope@^5.1.1:
23032303
version "5.1.1"

0 commit comments

Comments
 (0)