babel-plugin-jsx-dom-expressions 0.36.0-beta.0 → 0.36.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -10
- package/index.js +107 -103
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -38,29 +38,33 @@ const view = ({ item }) => {
|
|
|
38
38
|
Compiles to:
|
|
39
39
|
|
|
40
40
|
```jsx
|
|
41
|
-
import {
|
|
41
|
+
import { template as _$template } from "dom";
|
|
42
|
+
import { delegateEvents as _$delegateEvents } from "dom";
|
|
43
|
+
import { className as _$className } from "dom";
|
|
42
44
|
import { effect as _$effect } from "dom";
|
|
45
|
+
import { insert as _$insert } from "dom";
|
|
43
46
|
|
|
44
|
-
const _tmpl$ =
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
const _tmpl$ = /*#__PURE__*/_$template(`<tr><td class="col-md-1"></td><td class="col-md-4"><a></a></td><td class="col-md-1"><a><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td><td class="col-md-6"></td></tr>`, 16);
|
|
48
|
+
const view = ({
|
|
49
|
+
item
|
|
50
|
+
}) => {
|
|
48
51
|
const itemId = item.id;
|
|
49
|
-
return (
|
|
50
|
-
const _el$ = _tmpl$.
|
|
52
|
+
return (() => {
|
|
53
|
+
const _el$ = _tmpl$.cloneNode(true),
|
|
51
54
|
_el$2 = _el$.firstChild,
|
|
52
55
|
_el$3 = _el$2.nextSibling,
|
|
53
56
|
_el$4 = _el$3.firstChild,
|
|
54
57
|
_el$5 = _el$3.nextSibling,
|
|
55
58
|
_el$6 = _el$5.firstChild;
|
|
56
|
-
_$effect(() => (_el$.className = itemId === selected() ? "danger" : ""));
|
|
57
59
|
_$insert(_el$2, itemId);
|
|
58
|
-
_el$4
|
|
60
|
+
_el$4.$$click = e => select(item, e);
|
|
59
61
|
_$insert(_el$4, () => item.label);
|
|
60
|
-
_el$6
|
|
62
|
+
_el$6.$$click = e => del(item, e);
|
|
63
|
+
_$effect(() => _$className(_el$, itemId === selected() ? "danger" : ""));
|
|
61
64
|
return _el$;
|
|
62
65
|
})();
|
|
63
66
|
};
|
|
67
|
+
_$delegateEvents(["click"]);
|
|
64
68
|
```
|
|
65
69
|
|
|
66
70
|
The use of cloneNode improves repeat insert performance and precompilation reduces the number of references to the minimal traversal path. This is a basic example which doesn't leverage event delegation or any of the more advanced features described below.
|
package/index.js
CHANGED
|
@@ -76,15 +76,38 @@ const Aliases = /*#__PURE__*/ Object.assign(Object.create(null), {
|
|
|
76
76
|
className: "class",
|
|
77
77
|
htmlFor: "for"
|
|
78
78
|
});
|
|
79
|
+
|
|
79
80
|
const PropAliases = /*#__PURE__*/ Object.assign(Object.create(null), {
|
|
80
81
|
class: "className",
|
|
81
|
-
formnovalidate:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
formnovalidate: {
|
|
83
|
+
$: "formNoValidate",
|
|
84
|
+
BUTTON: 1,
|
|
85
|
+
INPUT: 1
|
|
86
|
+
},
|
|
87
|
+
ismap: {
|
|
88
|
+
$: "isMap",
|
|
89
|
+
IMG: 1
|
|
90
|
+
},
|
|
91
|
+
nomodule: {
|
|
92
|
+
$: "noModule",
|
|
93
|
+
SCRIPT: 1
|
|
94
|
+
},
|
|
95
|
+
playsinline: {
|
|
96
|
+
$: "playsInline",
|
|
97
|
+
VIDEO: 1
|
|
98
|
+
},
|
|
99
|
+
readonly: {
|
|
100
|
+
$: "readOnly",
|
|
101
|
+
INPUT: 1,
|
|
102
|
+
TEXTAREA: 1
|
|
103
|
+
}
|
|
86
104
|
});
|
|
87
105
|
|
|
106
|
+
function getPropAlias(prop, tagName) {
|
|
107
|
+
const a = PropAliases[prop];
|
|
108
|
+
return typeof a === "object" ? (a[tagName] ? a["$"] : undefined) : a;
|
|
109
|
+
}
|
|
110
|
+
|
|
88
111
|
// list of Element events that will be delegated
|
|
89
112
|
const DelegatedEvents = /*#__PURE__*/ new Set([
|
|
90
113
|
"beforeinput",
|
|
@@ -261,7 +284,7 @@ function registerImportMethod(path, name, moduleName) {
|
|
|
261
284
|
// the cloning is required to play well with babel-preset-env which is
|
|
262
285
|
// transpiling import as we add them and using the same identifier causes
|
|
263
286
|
// problems with the multiple identifiers of the same thing
|
|
264
|
-
return t__namespace.
|
|
287
|
+
return t__namespace.cloneNode(iden);
|
|
265
288
|
}
|
|
266
289
|
}
|
|
267
290
|
|
|
@@ -585,7 +608,7 @@ function transformElement$3(path, info) {
|
|
|
585
608
|
isCustomElement = tagName.indexOf("-") > -1,
|
|
586
609
|
results = {
|
|
587
610
|
template: `<${tagName}`,
|
|
588
|
-
|
|
611
|
+
declarations: [],
|
|
589
612
|
exprs: [],
|
|
590
613
|
dynamics: [],
|
|
591
614
|
postExprs: [],
|
|
@@ -638,7 +661,7 @@ function transformElement$3(path, info) {
|
|
|
638
661
|
return results;
|
|
639
662
|
}
|
|
640
663
|
|
|
641
|
-
function setAttr$2(path, elem, name, value, { isSVG, dynamic, prevId, isCE }) {
|
|
664
|
+
function setAttr$2(path, elem, name, value, { isSVG, dynamic, prevId, isCE, tagName }) {
|
|
642
665
|
// pull out namespace
|
|
643
666
|
const config = getConfig(path);
|
|
644
667
|
let parts, namespace;
|
|
@@ -698,7 +721,7 @@ function setAttr$2(path, elem, name, value, { isSVG, dynamic, prevId, isCE }) {
|
|
|
698
721
|
|
|
699
722
|
const isChildProp = ChildProperties.has(name);
|
|
700
723
|
const isProp = Properties.has(name);
|
|
701
|
-
const alias =
|
|
724
|
+
const alias = getPropAlias(name, tagName.toUpperCase());
|
|
702
725
|
if (namespace !== "attr" && (isChildProp || (!isSVG && isProp) || isCE || namespace === "prop")) {
|
|
703
726
|
if (isCE && !isChildProp && !isProp && namespace !== "prop") name = toPropertyName(name);
|
|
704
727
|
return t__namespace.assignmentExpression(
|
|
@@ -1144,6 +1167,7 @@ function transformAttributes$2(path, results) {
|
|
|
1144
1167
|
t__namespace.arrowFunctionExpression(
|
|
1145
1168
|
[],
|
|
1146
1169
|
setAttr$2(path, elem, key, value.expression, {
|
|
1170
|
+
tagName,
|
|
1147
1171
|
isSVG,
|
|
1148
1172
|
isCE
|
|
1149
1173
|
})
|
|
@@ -1157,14 +1181,14 @@ function transformAttributes$2(path, results) {
|
|
|
1157
1181
|
nextElem = attribute.scope.generateUidIdentifier("el$");
|
|
1158
1182
|
children = t__namespace.JSXText(" ");
|
|
1159
1183
|
children.extra = { raw: " ", rawValue: " " };
|
|
1160
|
-
results.
|
|
1184
|
+
results.declarations.push(
|
|
1161
1185
|
t__namespace.variableDeclarator(nextElem, t__namespace.memberExpression(elem, t__namespace.identifier("firstChild")))
|
|
1162
1186
|
);
|
|
1163
1187
|
}
|
|
1164
|
-
results.dynamics.push({ elem: nextElem, key, value: value.expression, isSVG, isCE });
|
|
1188
|
+
results.dynamics.push({ elem: nextElem, key, value: value.expression, isSVG, isCE, tagName });
|
|
1165
1189
|
} else {
|
|
1166
1190
|
results.exprs.push(
|
|
1167
|
-
t__namespace.expressionStatement(setAttr$2(attribute, elem, key, value.expression, { isSVG, isCE }))
|
|
1191
|
+
t__namespace.expressionStatement(setAttr$2(attribute, elem, key, value.expression, { isSVG, isCE, tagName }))
|
|
1168
1192
|
);
|
|
1169
1193
|
}
|
|
1170
1194
|
} else {
|
|
@@ -1176,7 +1200,7 @@ function transformAttributes$2(path, results) {
|
|
|
1176
1200
|
key = Aliases[key] || key;
|
|
1177
1201
|
if (value && ChildProperties.has(key)) {
|
|
1178
1202
|
results.exprs.push(
|
|
1179
|
-
t__namespace.expressionStatement(setAttr$2(attribute, elem, key, value, { isSVG, isCE }))
|
|
1203
|
+
t__namespace.expressionStatement(setAttr$2(attribute, elem, key, value, { isSVG, isCE, tagName }))
|
|
1180
1204
|
);
|
|
1181
1205
|
} else {
|
|
1182
1206
|
!isSVG && (key = key.toLowerCase());
|
|
@@ -1258,7 +1282,7 @@ function transformChildren$2(path, results, config) {
|
|
|
1258
1282
|
t__namespace.identifier(tempPath),
|
|
1259
1283
|
t__namespace.identifier(i === 0 ? "firstChild" : "nextSibling")
|
|
1260
1284
|
);
|
|
1261
|
-
results.
|
|
1285
|
+
results.declarations.push(
|
|
1262
1286
|
t__namespace.variableDeclarator(
|
|
1263
1287
|
child.id,
|
|
1264
1288
|
config.hydratable && tagName === "html"
|
|
@@ -1266,7 +1290,7 @@ function transformChildren$2(path, results, config) {
|
|
|
1266
1290
|
: walk
|
|
1267
1291
|
)
|
|
1268
1292
|
);
|
|
1269
|
-
results.
|
|
1293
|
+
results.declarations.push(...child.declarations);
|
|
1270
1294
|
results.exprs.push(...child.exprs);
|
|
1271
1295
|
results.dynamics.push(...child.dynamics);
|
|
1272
1296
|
results.postExprs.push(...child.postExprs);
|
|
@@ -1326,7 +1350,7 @@ function createPlaceholder(path, results, tempPath, i, char) {
|
|
|
1326
1350
|
results.template += `<!${char}>`;
|
|
1327
1351
|
if (config.hydratable && char === "/") {
|
|
1328
1352
|
contentId = path.scope.generateUidIdentifier("co$");
|
|
1329
|
-
results.
|
|
1353
|
+
results.declarations.push(
|
|
1330
1354
|
t__namespace.variableDeclarator(
|
|
1331
1355
|
t__namespace.arrayPattern([exprId, contentId]),
|
|
1332
1356
|
t__namespace.callExpression(
|
|
@@ -1336,7 +1360,7 @@ function createPlaceholder(path, results, tempPath, i, char) {
|
|
|
1336
1360
|
)
|
|
1337
1361
|
);
|
|
1338
1362
|
} else
|
|
1339
|
-
results.
|
|
1363
|
+
results.declarations.push(
|
|
1340
1364
|
t__namespace.variableDeclarator(
|
|
1341
1365
|
exprId,
|
|
1342
1366
|
t__namespace.memberExpression(
|
|
@@ -1602,8 +1626,8 @@ function registerTemplate(path, results) {
|
|
|
1602
1626
|
])
|
|
1603
1627
|
);
|
|
1604
1628
|
}
|
|
1605
|
-
results.
|
|
1606
|
-
results.decl = t__namespace.variableDeclaration("const", results.
|
|
1629
|
+
results.declarations.unshift(decl);
|
|
1630
|
+
results.decl = t__namespace.variableDeclaration("const", results.declarations);
|
|
1607
1631
|
}
|
|
1608
1632
|
|
|
1609
1633
|
function wrapDynamics$1(path, dynamics) {
|
|
@@ -1632,6 +1656,7 @@ function wrapDynamics$1(path, dynamics) {
|
|
|
1632
1656
|
setAttr$2(path, dynamics[0].elem, dynamics[0].key, dynamics[0].value, {
|
|
1633
1657
|
isSVG: dynamics[0].isSVG,
|
|
1634
1658
|
isCE: dynamics[0].isCE,
|
|
1659
|
+
tagName: dynamics[0].tagName,
|
|
1635
1660
|
dynamic: true,
|
|
1636
1661
|
prevId: prevValue
|
|
1637
1662
|
})
|
|
@@ -1639,17 +1664,17 @@ function wrapDynamics$1(path, dynamics) {
|
|
|
1639
1664
|
])
|
|
1640
1665
|
);
|
|
1641
1666
|
}
|
|
1642
|
-
const
|
|
1667
|
+
const declarations = [],
|
|
1643
1668
|
statements = [],
|
|
1644
1669
|
identifiers = [],
|
|
1645
1670
|
prevId = t__namespace.identifier("_p$");
|
|
1646
|
-
dynamics.forEach(({ elem, key, value, isSVG, isCE }) => {
|
|
1671
|
+
dynamics.forEach(({ elem, key, value, isSVG, isCE, tagName }) => {
|
|
1647
1672
|
const identifier = path.scope.generateUidIdentifier("v$");
|
|
1648
1673
|
if (key.startsWith("class:") && !t__namespace.isBooleanLiteral(value) && !t__namespace.isUnaryExpression(value)) {
|
|
1649
1674
|
value = t__namespace.unaryExpression("!", t__namespace.unaryExpression("!", value));
|
|
1650
1675
|
}
|
|
1651
1676
|
identifiers.push(identifier);
|
|
1652
|
-
|
|
1677
|
+
declarations.push(t__namespace.variableDeclarator(identifier, value));
|
|
1653
1678
|
if (key === "classList" || key === "style") {
|
|
1654
1679
|
const prev = t__namespace.memberExpression(prevId, identifier);
|
|
1655
1680
|
statements.push(
|
|
@@ -1657,7 +1682,7 @@ function wrapDynamics$1(path, dynamics) {
|
|
|
1657
1682
|
t__namespace.assignmentExpression(
|
|
1658
1683
|
"=",
|
|
1659
1684
|
prev,
|
|
1660
|
-
setAttr$2(path, elem, key, identifier, { isSVG, isCE, dynamic: true, prevId: prev })
|
|
1685
|
+
setAttr$2(path, elem, key, identifier, { isSVG, isCE, tagName, dynamic: true, prevId: prev })
|
|
1661
1686
|
)
|
|
1662
1687
|
)
|
|
1663
1688
|
);
|
|
@@ -1672,7 +1697,7 @@ function wrapDynamics$1(path, dynamics) {
|
|
|
1672
1697
|
elem,
|
|
1673
1698
|
key,
|
|
1674
1699
|
t__namespace.assignmentExpression("=", t__namespace.memberExpression(prevId, identifier), identifier),
|
|
1675
|
-
{ isSVG, isCE, dynamic: true }
|
|
1700
|
+
{ isSVG, isCE, tagName, dynamic: true }
|
|
1676
1701
|
)
|
|
1677
1702
|
)
|
|
1678
1703
|
)
|
|
@@ -1685,7 +1710,7 @@ function wrapDynamics$1(path, dynamics) {
|
|
|
1685
1710
|
t__namespace.arrowFunctionExpression(
|
|
1686
1711
|
[prevId],
|
|
1687
1712
|
t__namespace.blockStatement([
|
|
1688
|
-
t__namespace.variableDeclaration("const",
|
|
1713
|
+
t__namespace.variableDeclaration("const", declarations),
|
|
1689
1714
|
...statements,
|
|
1690
1715
|
t__namespace.returnStatement(prevId)
|
|
1691
1716
|
])
|
|
@@ -1786,7 +1811,7 @@ function transformElement$2(path, info) {
|
|
|
1786
1811
|
results = {
|
|
1787
1812
|
template: [`<${tagName}`],
|
|
1788
1813
|
templateValues: [],
|
|
1789
|
-
|
|
1814
|
+
declarations: [],
|
|
1790
1815
|
exprs: [],
|
|
1791
1816
|
dynamics: [],
|
|
1792
1817
|
tagName,
|
|
@@ -2310,57 +2335,6 @@ function createElement(path, { topLevel, hydratable }) {
|
|
|
2310
2335
|
if (props.length > 1 || dynamicSpread) {
|
|
2311
2336
|
props = [t__namespace.callExpression(registerImportMethod(path, "mergeProps"), props)];
|
|
2312
2337
|
}
|
|
2313
|
-
|
|
2314
|
-
// transformed = t.arrowFunctionExpression(
|
|
2315
|
-
// [],
|
|
2316
|
-
// t.objectExpression(
|
|
2317
|
-
// attributes.reduce((memo, attribute) => {
|
|
2318
|
-
// const node = attribute.node;
|
|
2319
|
-
|
|
2320
|
-
// if (t.isJSXSpreadAttribute(node)) {
|
|
2321
|
-
// const expr = node.argument;
|
|
2322
|
-
// memo.push(t.spreadElement(expr));
|
|
2323
|
-
// return memo;
|
|
2324
|
-
// }
|
|
2325
|
-
// let value = node.value,
|
|
2326
|
-
// key = t.isJSXNamespacedName(node.name)
|
|
2327
|
-
// ? `${node.name.namespace.name}:${node.name.name.name}`
|
|
2328
|
-
// : node.name.name,
|
|
2329
|
-
// reservedNameSpace =
|
|
2330
|
-
// t.isJSXNamespacedName(node.name) && reservedNameSpaces.has(node.name.namespace.name);
|
|
2331
|
-
// if (
|
|
2332
|
-
// ((t.isJSXNamespacedName(node.name) && reservedNameSpace) || ChildProperties.has(key)) &&
|
|
2333
|
-
// !t.isJSXExpressionContainer(value)
|
|
2334
|
-
// ) {
|
|
2335
|
-
// node.value = value = t.JSXExpressionContainer(value || t.JSXEmptyExpression());
|
|
2336
|
-
// }
|
|
2337
|
-
|
|
2338
|
-
// if (
|
|
2339
|
-
// t.isJSXExpressionContainer(value) &&
|
|
2340
|
-
// (reservedNameSpace ||
|
|
2341
|
-
// ChildProperties.has(key) ||
|
|
2342
|
-
// !(t.isStringLiteral(value.expression) || t.isNumericLiteral(value.expression)))
|
|
2343
|
-
// ) {
|
|
2344
|
-
// if (
|
|
2345
|
-
// key === "ref" ||
|
|
2346
|
-
// key.startsWith("use:") ||
|
|
2347
|
-
// key.startsWith("prop:") ||
|
|
2348
|
-
// key.startsWith("on")
|
|
2349
|
-
// )
|
|
2350
|
-
// return memo;
|
|
2351
|
-
|
|
2352
|
-
// memo.push(t.objectProperty(t.stringLiteral(key), value.expression));
|
|
2353
|
-
// } else {
|
|
2354
|
-
// if (key === "$ServerOnly") return memo;
|
|
2355
|
-
// if (t.isJSXExpressionContainer(value)) value = value.expression;
|
|
2356
|
-
// memo.push(
|
|
2357
|
-
// t.objectProperty(t.stringLiteral(key), value ? value : t.booleanLiteral(true))
|
|
2358
|
-
// );
|
|
2359
|
-
// }
|
|
2360
|
-
// return memo;
|
|
2361
|
-
// }, [])
|
|
2362
|
-
// )
|
|
2363
|
-
// );
|
|
2364
2338
|
}
|
|
2365
2339
|
|
|
2366
2340
|
const exprs = [
|
|
@@ -2387,7 +2361,7 @@ function transformElement$1(path, info) {
|
|
|
2387
2361
|
let tagName = getTagName(path.node),
|
|
2388
2362
|
results = {
|
|
2389
2363
|
id: path.scope.generateUidIdentifier("el$"),
|
|
2390
|
-
|
|
2364
|
+
declarations: [],
|
|
2391
2365
|
exprs: [],
|
|
2392
2366
|
dynamics: [],
|
|
2393
2367
|
postExprs: [],
|
|
@@ -2395,7 +2369,7 @@ function transformElement$1(path, info) {
|
|
|
2395
2369
|
renderer: "universal"
|
|
2396
2370
|
};
|
|
2397
2371
|
|
|
2398
|
-
results.
|
|
2372
|
+
results.declarations.push(
|
|
2399
2373
|
t__namespace.variableDeclarator(
|
|
2400
2374
|
results.id,
|
|
2401
2375
|
t__namespace.callExpression(
|
|
@@ -2611,7 +2585,7 @@ function transformChildren(path, results) {
|
|
|
2611
2585
|
getRendererConfig(path, "universal").moduleName
|
|
2612
2586
|
);
|
|
2613
2587
|
if (multi) {
|
|
2614
|
-
results.
|
|
2588
|
+
results.declarations.push(
|
|
2615
2589
|
t__namespace.variableDeclarator(
|
|
2616
2590
|
child.id,
|
|
2617
2591
|
t__namespace.callExpression(createTextNode, [
|
|
@@ -2625,7 +2599,7 @@ function transformChildren(path, results) {
|
|
|
2625
2599
|
]);
|
|
2626
2600
|
}
|
|
2627
2601
|
appends.push(t__namespace.expressionStatement(t__namespace.callExpression(insertNode, [results.id, insert])));
|
|
2628
|
-
results.
|
|
2602
|
+
results.declarations.push(...child.declarations);
|
|
2629
2603
|
results.exprs.push(...child.exprs);
|
|
2630
2604
|
results.dynamics.push(...child.dynamics);
|
|
2631
2605
|
} else if (child.exprs.length) {
|
|
@@ -2749,7 +2723,7 @@ function processSpreads(path, attributes, { elem, hasChildren, wrapConditionals
|
|
|
2749
2723
|
function createTemplate(path, result, wrap) {
|
|
2750
2724
|
const config = getConfig(path);
|
|
2751
2725
|
if (result.id) {
|
|
2752
|
-
result.decl = t__namespace.variableDeclaration("const", result.
|
|
2726
|
+
result.decl = t__namespace.variableDeclaration("const", result.declarations);
|
|
2753
2727
|
if (
|
|
2754
2728
|
!(result.exprs.length || result.dynamics.length || result.postExprs.length) &&
|
|
2755
2729
|
result.decl.declarations.length === 1
|
|
@@ -2799,14 +2773,14 @@ function wrapDynamics(path, dynamics) {
|
|
|
2799
2773
|
])
|
|
2800
2774
|
);
|
|
2801
2775
|
}
|
|
2802
|
-
const
|
|
2776
|
+
const declarations = [],
|
|
2803
2777
|
statements = [],
|
|
2804
2778
|
identifiers = [],
|
|
2805
2779
|
prevId = t__namespace.identifier("_p$");
|
|
2806
2780
|
dynamics.forEach(({ elem, key, value }) => {
|
|
2807
2781
|
const identifier = path.scope.generateUidIdentifier("v$");
|
|
2808
2782
|
identifiers.push(identifier);
|
|
2809
|
-
|
|
2783
|
+
declarations.push(t__namespace.variableDeclarator(identifier, value));
|
|
2810
2784
|
const prev = t__namespace.memberExpression(prevId, identifier);
|
|
2811
2785
|
statements.push(
|
|
2812
2786
|
t__namespace.expressionStatement(
|
|
@@ -2830,7 +2804,7 @@ function wrapDynamics(path, dynamics) {
|
|
|
2830
2804
|
t__namespace.arrowFunctionExpression(
|
|
2831
2805
|
[prevId],
|
|
2832
2806
|
t__namespace.blockStatement([
|
|
2833
|
-
t__namespace.variableDeclaration("const",
|
|
2807
|
+
t__namespace.variableDeclaration("const", declarations),
|
|
2834
2808
|
...statements,
|
|
2835
2809
|
t__namespace.returnStatement(prevId)
|
|
2836
2810
|
])
|
|
@@ -2890,7 +2864,8 @@ function transformComponent(path) {
|
|
|
2890
2864
|
: node.argument
|
|
2891
2865
|
);
|
|
2892
2866
|
} else {
|
|
2893
|
-
|
|
2867
|
+
// handle weird babel bug around HTML entities
|
|
2868
|
+
const value = (t__namespace.isStringLiteral(node.value) ? t__namespace.stringLiteral(node.value.value): node.value) || t__namespace.booleanLiteral(true),
|
|
2894
2869
|
id = convertJSXIdentifier(node.name),
|
|
2895
2870
|
key = id.name;
|
|
2896
2871
|
if (hasChildren && key === "children") return;
|
|
@@ -3032,11 +3007,15 @@ function transformComponentChildren(children, config) {
|
|
|
3032
3007
|
const filteredChildren = filterChildren(children);
|
|
3033
3008
|
if (!filteredChildren.length) return;
|
|
3034
3009
|
let dynamic = false;
|
|
3010
|
+
let pathNodes = [];
|
|
3035
3011
|
|
|
3036
3012
|
let transformedChildren = filteredChildren.reduce((memo, path) => {
|
|
3037
3013
|
if (t__namespace.isJSXText(path.node)) {
|
|
3038
3014
|
const v = htmlEntities.decode(trimWhitespace(path.node.extra.raw));
|
|
3039
|
-
if (v.length)
|
|
3015
|
+
if (v.length) {
|
|
3016
|
+
pathNodes.push(path.node);
|
|
3017
|
+
memo.push(t__namespace.stringLiteral(v));
|
|
3018
|
+
}
|
|
3040
3019
|
} else {
|
|
3041
3020
|
const child = transformNode(path, {
|
|
3042
3021
|
topLevel: true,
|
|
@@ -3051,6 +3030,7 @@ function transformComponentChildren(children, config) {
|
|
|
3051
3030
|
) {
|
|
3052
3031
|
child.exprs[0] = child.exprs[0].body;
|
|
3053
3032
|
}
|
|
3033
|
+
pathNodes.push(path.node);
|
|
3054
3034
|
memo.push(getCreateTemplate(config, path, child)(path, child, filteredChildren.length > 1));
|
|
3055
3035
|
}
|
|
3056
3036
|
return memo;
|
|
@@ -3059,9 +3039,9 @@ function transformComponentChildren(children, config) {
|
|
|
3059
3039
|
if (transformedChildren.length === 1) {
|
|
3060
3040
|
transformedChildren = transformedChildren[0];
|
|
3061
3041
|
if (
|
|
3062
|
-
!t__namespace.isJSXExpressionContainer(
|
|
3063
|
-
!t__namespace.isJSXSpreadChild(
|
|
3064
|
-
!t__namespace.isJSXText(
|
|
3042
|
+
!t__namespace.isJSXExpressionContainer(pathNodes[0]) &&
|
|
3043
|
+
!t__namespace.isJSXSpreadChild(pathNodes[0]) &&
|
|
3044
|
+
!t__namespace.isJSXText(pathNodes[0])
|
|
3065
3045
|
) {
|
|
3066
3046
|
transformedChildren =
|
|
3067
3047
|
t__namespace.isCallExpression(transformedChildren) &&
|
|
@@ -3078,15 +3058,43 @@ function transformComponentChildren(children, config) {
|
|
|
3078
3058
|
return [transformedChildren, dynamic];
|
|
3079
3059
|
}
|
|
3080
3060
|
|
|
3061
|
+
function insertMarker(path, config, result) {
|
|
3062
|
+
if (config.generate === "ssr") {
|
|
3063
|
+
const open = { template: "<!---->", exprs: [] };
|
|
3064
|
+
result.push(getCreateTemplate(config, path, open)(path, open, true));
|
|
3065
|
+
} else {
|
|
3066
|
+
result.push(t__namespace.stringLiteral("<!>"));
|
|
3067
|
+
}
|
|
3068
|
+
}
|
|
3069
|
+
|
|
3081
3070
|
function transformFragmentChildren(children, results, config) {
|
|
3071
|
+
let prevResult;
|
|
3082
3072
|
const filteredChildren = filterChildren(children),
|
|
3083
3073
|
childNodes = filteredChildren.reduce((memo, path) => {
|
|
3084
3074
|
if (t__namespace.isJSXText(path.node)) {
|
|
3085
3075
|
const v = htmlEntities.decode(trimWhitespace(path.node.extra.raw));
|
|
3086
|
-
if (v.length)
|
|
3076
|
+
if (v.length) {
|
|
3077
|
+
if (config.hydratable &&
|
|
3078
|
+
prevResult &&
|
|
3079
|
+
!prevResult.tagName &&
|
|
3080
|
+
!prevResult.component &&
|
|
3081
|
+
prevResult.exprs.length &&
|
|
3082
|
+
!prevResult.spreadElement) insertMarker(path, config, memo);
|
|
3083
|
+
memo.push(t__namespace.stringLiteral(v));
|
|
3084
|
+
prevResult = v;
|
|
3085
|
+
}
|
|
3087
3086
|
} else {
|
|
3088
3087
|
const child = transformNode(path, { topLevel: true, fragmentChild: true });
|
|
3088
|
+
const insertMarkers =
|
|
3089
|
+
config.hydratable &&
|
|
3090
|
+
!child.component &&
|
|
3091
|
+
child.exprs.length &&
|
|
3092
|
+
!child.spreadElement &&
|
|
3093
|
+
prevResult &&
|
|
3094
|
+
(typeof prevResult !== "object" || !(prevResult.tagName || prevResult.component));
|
|
3095
|
+
if (insertMarkers) insertMarker(path, config, memo);
|
|
3089
3096
|
memo.push(getCreateTemplate(config, path, child)(path, child, true));
|
|
3097
|
+
prevResult = child;
|
|
3090
3098
|
}
|
|
3091
3099
|
return memo;
|
|
3092
3100
|
}, []);
|
|
@@ -3137,21 +3145,21 @@ function transformNode(path, info = {}) {
|
|
|
3137
3145
|
if (t__namespace.isJSXElement(node)) {
|
|
3138
3146
|
return transformElement(config, path, info);
|
|
3139
3147
|
} else if (t__namespace.isJSXFragment(node)) {
|
|
3140
|
-
let results = { template: "",
|
|
3148
|
+
let results = { template: "", declarations: [], exprs: [], dynamics: [] };
|
|
3141
3149
|
// <><div /><Component /></>
|
|
3142
3150
|
transformFragmentChildren(path.get("children"), results, config);
|
|
3143
3151
|
return results;
|
|
3144
3152
|
} else if (t__namespace.isJSXText(node) || (staticValue = getStaticExpression(path))) {
|
|
3145
3153
|
const text =
|
|
3146
3154
|
staticValue !== undefined
|
|
3147
|
-
?
|
|
3148
|
-
?
|
|
3149
|
-
: staticValue.toString()
|
|
3155
|
+
? info.doNotEscape
|
|
3156
|
+
? staticValue.toString()
|
|
3157
|
+
: escapeHTML(staticValue.toString())
|
|
3150
3158
|
: trimWhitespace(node.extra.raw);
|
|
3151
3159
|
if (!text.length) return null;
|
|
3152
3160
|
const results = {
|
|
3153
3161
|
template: config.generate === "ssr" ? text : escapeBackticks(text),
|
|
3154
|
-
|
|
3162
|
+
declarations: [],
|
|
3155
3163
|
exprs: [],
|
|
3156
3164
|
dynamics: [],
|
|
3157
3165
|
postExprs: [],
|
|
@@ -3237,13 +3245,9 @@ function transformElement(config, path, info = {}) {
|
|
|
3237
3245
|
// <div ...></div>
|
|
3238
3246
|
// const element = getTransformElemet(config, path, tagName);
|
|
3239
3247
|
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
tagRenderer = renderer;
|
|
3244
|
-
break;
|
|
3245
|
-
}
|
|
3246
|
-
}
|
|
3248
|
+
const tagRenderer = (config.renderers ?? []).find(
|
|
3249
|
+
renderer => renderer.elements.includes(tagName)
|
|
3250
|
+
);
|
|
3247
3251
|
|
|
3248
3252
|
if (tagRenderer?.name === "dom" || getConfig(path).generate === "dom") {
|
|
3249
3253
|
return transformElement$3(path, info);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-plugin-jsx-dom-expressions",
|
|
3
3
|
"description": "A JSX to DOM plugin that wraps expressions for fine grained change detection",
|
|
4
|
-
"version": "0.36.0-beta.
|
|
4
|
+
"version": "0.36.0-beta.2",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@babel/core": "^7.20.12"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "3afd7a16f14cae485c63e6227492bb6ed151d1b3"
|
|
35
35
|
}
|