babel-plugin-jsx-dom-expressions 0.30.7 → 0.31.0-beta.6
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/index.js +182 -166
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -227,36 +227,27 @@ function getConfig(path) {
|
|
|
227
227
|
function registerImportMethod(path, name) {
|
|
228
228
|
const imports =
|
|
229
229
|
path.scope.getProgramParent().data.imports ||
|
|
230
|
-
(path.scope.getProgramParent().data.imports = new
|
|
230
|
+
(path.scope.getProgramParent().data.imports = new Map());
|
|
231
231
|
if (!imports.has(name)) {
|
|
232
|
-
helperModuleImports.addNamed(path, name, getConfig(path).moduleName, {
|
|
232
|
+
const identifier = helperModuleImports.addNamed(path, name, getConfig(path).moduleName, {
|
|
233
233
|
nameHint: `_$${name}`
|
|
234
234
|
});
|
|
235
|
-
imports.
|
|
235
|
+
imports.set(name, identifier);
|
|
236
|
+
return identifier;
|
|
236
237
|
}
|
|
238
|
+
return imports.get(name);
|
|
237
239
|
}
|
|
238
240
|
|
|
239
241
|
function jsxElementNameToString(node) {
|
|
240
242
|
if (t__namespace.isJSXMemberExpression(node)) {
|
|
241
243
|
return `${jsxElementNameToString(node.object)}.${node.property.name}`;
|
|
242
244
|
}
|
|
243
|
-
if (t__namespace.isJSXIdentifier(node)) {
|
|
245
|
+
if (t__namespace.isJSXIdentifier(node) || t__namespace.isIdentifier(node)) {
|
|
244
246
|
return node.name;
|
|
245
247
|
}
|
|
246
248
|
return `${node.namespace.name}:${node.name.name}`;
|
|
247
249
|
}
|
|
248
250
|
|
|
249
|
-
function tagNameToIdentifier(name) {
|
|
250
|
-
const parts = name.split(".");
|
|
251
|
-
if (parts.length === 1) return t__namespace.identifier(name);
|
|
252
|
-
let part;
|
|
253
|
-
let base = t__namespace.identifier(parts.shift());
|
|
254
|
-
while ((part = parts.shift())) {
|
|
255
|
-
base = t__namespace.memberExpression(base, t__namespace.identifier(part));
|
|
256
|
-
}
|
|
257
|
-
return base;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
251
|
function getTagName(tag) {
|
|
261
252
|
const jsxName = tag.openingElement.name;
|
|
262
253
|
return jsxElementNameToString(jsxName);
|
|
@@ -319,12 +310,13 @@ function isDynamic(path, { checkMember, checkTags, checkCallExpressions = true,
|
|
|
319
310
|
|
|
320
311
|
function getStaticExpression(path) {
|
|
321
312
|
const node = path.node;
|
|
322
|
-
let value;
|
|
313
|
+
let value, type;
|
|
323
314
|
return (
|
|
324
315
|
t__namespace.isJSXExpressionContainer(node) &&
|
|
325
316
|
t__namespace.isJSXElement(path.parent) &&
|
|
326
317
|
!isComponent(getTagName(path.parent)) &&
|
|
327
318
|
(value = path.get("expression").evaluate().value) !== undefined &&
|
|
319
|
+
((type = typeof value) === "string" || type === "number") &&
|
|
328
320
|
value
|
|
329
321
|
);
|
|
330
322
|
}
|
|
@@ -395,7 +387,7 @@ function wrappedByText(list, startIndex) {
|
|
|
395
387
|
function transformCondition(path, inline, deep) {
|
|
396
388
|
const config = getConfig(path);
|
|
397
389
|
const expr = path.node;
|
|
398
|
-
registerImportMethod(path, config.memoWrapper);
|
|
390
|
+
const memo = registerImportMethod(path, config.memoWrapper);
|
|
399
391
|
let dTest, cond, id;
|
|
400
392
|
if (
|
|
401
393
|
t__namespace.isConditionalExpression(expr) &&
|
|
@@ -410,7 +402,7 @@ function transformCondition(path, inline, deep) {
|
|
|
410
402
|
if (!t__namespace.isBinaryExpression(cond))
|
|
411
403
|
cond = t__namespace.unaryExpression("!", t__namespace.unaryExpression("!", cond, true), true);
|
|
412
404
|
id = inline
|
|
413
|
-
? t__namespace.callExpression(
|
|
405
|
+
? t__namespace.callExpression(memo, [
|
|
414
406
|
t__namespace.arrowFunctionExpression([], cond),
|
|
415
407
|
t__namespace.booleanLiteral(true)
|
|
416
408
|
])
|
|
@@ -439,7 +431,7 @@ function transformCondition(path, inline, deep) {
|
|
|
439
431
|
if (!t__namespace.isBinaryExpression(cond))
|
|
440
432
|
cond = t__namespace.unaryExpression("!", t__namespace.unaryExpression("!", cond, true), true);
|
|
441
433
|
id = inline
|
|
442
|
-
? t__namespace.callExpression(
|
|
434
|
+
? t__namespace.callExpression(memo, [
|
|
443
435
|
t__namespace.arrowFunctionExpression([], cond),
|
|
444
436
|
t__namespace.booleanLiteral(true)
|
|
445
437
|
])
|
|
@@ -453,7 +445,7 @@ function transformCondition(path, inline, deep) {
|
|
|
453
445
|
t__namespace.variableDeclarator(
|
|
454
446
|
id,
|
|
455
447
|
config.memoWrapper
|
|
456
|
-
? t__namespace.callExpression(
|
|
448
|
+
? t__namespace.callExpression(memo, [
|
|
457
449
|
t__namespace.arrowFunctionExpression([], cond),
|
|
458
450
|
t__namespace.booleanLiteral(true)
|
|
459
451
|
])
|
|
@@ -547,9 +539,8 @@ function transformElement$2(path, info) {
|
|
|
547
539
|
results.template += `</${tagName}>`;
|
|
548
540
|
}
|
|
549
541
|
if (info.topLevel && config.hydratable && results.hasHydratableEvent) {
|
|
550
|
-
registerImportMethod(path, "runHydrationEvents");
|
|
551
542
|
results.postExprs.push(
|
|
552
|
-
t__namespace.expressionStatement(t__namespace.callExpression(
|
|
543
|
+
t__namespace.expressionStatement(t__namespace.callExpression(registerImportMethod(path, "runHydrationEvents"), []))
|
|
553
544
|
);
|
|
554
545
|
}
|
|
555
546
|
if (wrapSVG) results.template += "</svg>";
|
|
@@ -585,9 +576,8 @@ function setAttr$2(path, elem, name, value, { isSVG, dynamic, prevId, isCE }) {
|
|
|
585
576
|
}
|
|
586
577
|
|
|
587
578
|
if (name === "style") {
|
|
588
|
-
registerImportMethod(path, "style");
|
|
589
579
|
return t__namespace.callExpression(
|
|
590
|
-
|
|
580
|
+
registerImportMethod(path, "style"),
|
|
591
581
|
prevId ? [elem, value, prevId] : [elem, value]
|
|
592
582
|
);
|
|
593
583
|
}
|
|
@@ -597,9 +587,8 @@ function setAttr$2(path, elem, name, value, { isSVG, dynamic, prevId, isCE }) {
|
|
|
597
587
|
}
|
|
598
588
|
|
|
599
589
|
if (name === "classList") {
|
|
600
|
-
registerImportMethod(path, "classList");
|
|
601
590
|
return t__namespace.callExpression(
|
|
602
|
-
|
|
591
|
+
registerImportMethod(path, "classList"),
|
|
603
592
|
prevId ? [elem, value, prevId] : [elem, value]
|
|
604
593
|
);
|
|
605
594
|
}
|
|
@@ -625,16 +614,14 @@ function setAttr$2(path, elem, name, value, { isSVG, dynamic, prevId, isCE }) {
|
|
|
625
614
|
!isSVG && (name = name.toLowerCase());
|
|
626
615
|
const ns = isNameSpaced && SVGNamespace[name.split(":")[0]];
|
|
627
616
|
if (ns) {
|
|
628
|
-
registerImportMethod(path, "setAttributeNS")
|
|
629
|
-
return t__namespace.callExpression(t__namespace.identifier("_$setAttributeNS"), [
|
|
617
|
+
return t__namespace.callExpression(registerImportMethod(path, "setAttributeNS"), [
|
|
630
618
|
elem,
|
|
631
619
|
t__namespace.stringLiteral(ns),
|
|
632
620
|
t__namespace.stringLiteral(name),
|
|
633
621
|
value
|
|
634
622
|
]);
|
|
635
623
|
} else {
|
|
636
|
-
registerImportMethod(path, "setAttribute");
|
|
637
|
-
return t__namespace.callExpression(t__namespace.identifier("_$setAttribute"), [elem, t__namespace.stringLiteral(name), value]);
|
|
624
|
+
return t__namespace.callExpression(registerImportMethod(path, "setAttribute"), [elem, t__namespace.stringLiteral(name), value]);
|
|
638
625
|
}
|
|
639
626
|
}
|
|
640
627
|
|
|
@@ -657,8 +644,7 @@ function transformAttributes$2(path, results) {
|
|
|
657
644
|
hasHydratableEvent = false,
|
|
658
645
|
children,
|
|
659
646
|
attributes = path.get("openingElement").get("attributes");
|
|
660
|
-
const
|
|
661
|
-
tagName = getTagName(path.node),
|
|
647
|
+
const tagName = getTagName(path.node),
|
|
662
648
|
isSVG = SVGElements.has(tagName),
|
|
663
649
|
isCE = tagName.includes("-"),
|
|
664
650
|
hasChildren = path.node.children.length > 0,
|
|
@@ -793,10 +779,9 @@ function transformAttributes$2(path, results) {
|
|
|
793
779
|
.forEach(attribute => {
|
|
794
780
|
const node = attribute.node;
|
|
795
781
|
if (t__namespace.isJSXSpreadAttribute(node)) {
|
|
796
|
-
registerImportMethod(attribute, "spread");
|
|
797
782
|
results.exprs.push(
|
|
798
783
|
t__namespace.expressionStatement(
|
|
799
|
-
t__namespace.callExpression(spread, [
|
|
784
|
+
t__namespace.callExpression(registerImportMethod(attribute, "spread"), [
|
|
800
785
|
elem,
|
|
801
786
|
isDynamic(attribute.get("argument"), {
|
|
802
787
|
checkMember: true
|
|
@@ -898,9 +883,11 @@ function transformAttributes$2(path, results) {
|
|
|
898
883
|
);
|
|
899
884
|
}
|
|
900
885
|
} else if (key.startsWith("use:")) {
|
|
886
|
+
// Some trick to treat JSXIdentifier as Identifier
|
|
887
|
+
node.name.name.type = 'Identifier';
|
|
901
888
|
results.exprs.unshift(
|
|
902
889
|
t__namespace.expressionStatement(
|
|
903
|
-
t__namespace.callExpression(
|
|
890
|
+
t__namespace.callExpression(node.name.name, [
|
|
904
891
|
elem,
|
|
905
892
|
t__namespace.arrowFunctionExpression(
|
|
906
893
|
[],
|
|
@@ -972,10 +959,9 @@ function transformAttributes$2(path, results) {
|
|
|
972
959
|
)
|
|
973
960
|
);
|
|
974
961
|
} else {
|
|
975
|
-
registerImportMethod(path, "addEventListener");
|
|
976
962
|
results.exprs.unshift(
|
|
977
963
|
t__namespace.expressionStatement(
|
|
978
|
-
t__namespace.callExpression(
|
|
964
|
+
t__namespace.callExpression(registerImportMethod(path, "addEventListener"), [
|
|
979
965
|
elem,
|
|
980
966
|
t__namespace.stringLiteral(ev),
|
|
981
967
|
handler,
|
|
@@ -1012,10 +998,9 @@ function transformAttributes$2(path, results) {
|
|
|
1012
998
|
)
|
|
1013
999
|
);
|
|
1014
1000
|
} else {
|
|
1015
|
-
registerImportMethod(path, "addEventListener");
|
|
1016
1001
|
results.exprs.unshift(
|
|
1017
1002
|
t__namespace.expressionStatement(
|
|
1018
|
-
t__namespace.callExpression(
|
|
1003
|
+
t__namespace.callExpression(registerImportMethod(path, "addEventListener"), [
|
|
1019
1004
|
elem,
|
|
1020
1005
|
t__namespace.stringLiteral(ev),
|
|
1021
1006
|
handler
|
|
@@ -1097,6 +1082,7 @@ function transformChildren$2(path, results, config) {
|
|
|
1097
1082
|
if (!child) return;
|
|
1098
1083
|
results.template += child.template;
|
|
1099
1084
|
if (child.id) {
|
|
1085
|
+
if (child.tagName === "head") return;
|
|
1100
1086
|
if (config.hydratable && tagName === "html") {
|
|
1101
1087
|
registerImportMethod(path, "getNextMatch");
|
|
1102
1088
|
}
|
|
@@ -1108,7 +1094,7 @@ function transformChildren$2(path, results, config) {
|
|
|
1108
1094
|
t__namespace.variableDeclarator(
|
|
1109
1095
|
child.id,
|
|
1110
1096
|
config.hydratable && tagName === "html"
|
|
1111
|
-
? t__namespace.callExpression(
|
|
1097
|
+
? t__namespace.callExpression(registerImportMethod(path, "getNextMatch"), [
|
|
1112
1098
|
walk,
|
|
1113
1099
|
t__namespace.stringLiteral(child.tagName)
|
|
1114
1100
|
])
|
|
@@ -1123,7 +1109,7 @@ function transformChildren$2(path, results, config) {
|
|
|
1123
1109
|
nextPlaceholder = null;
|
|
1124
1110
|
i++;
|
|
1125
1111
|
} else if (child.exprs.length) {
|
|
1126
|
-
registerImportMethod(path, "insert");
|
|
1112
|
+
const insert = registerImportMethod(path, "insert");
|
|
1127
1113
|
const multi = checkLength(filteredChildren),
|
|
1128
1114
|
markers = config.hydratable && multi;
|
|
1129
1115
|
// boxed by textNodes
|
|
@@ -1139,7 +1125,7 @@ function transformChildren$2(path, results, config) {
|
|
|
1139
1125
|
results.exprs.push(
|
|
1140
1126
|
t__namespace.expressionStatement(
|
|
1141
1127
|
t__namespace.callExpression(
|
|
1142
|
-
|
|
1128
|
+
insert,
|
|
1143
1129
|
contentId
|
|
1144
1130
|
? [results.id, child.exprs[0], exprId, contentId]
|
|
1145
1131
|
: [results.id, child.exprs[0], exprId]
|
|
@@ -1150,7 +1136,7 @@ function transformChildren$2(path, results, config) {
|
|
|
1150
1136
|
} else if (multi) {
|
|
1151
1137
|
results.exprs.push(
|
|
1152
1138
|
t__namespace.expressionStatement(
|
|
1153
|
-
t__namespace.callExpression(
|
|
1139
|
+
t__namespace.callExpression(insert, [
|
|
1154
1140
|
results.id,
|
|
1155
1141
|
child.exprs[0],
|
|
1156
1142
|
nextChild$1(childNodes, index) || t__namespace.nullLiteral()
|
|
@@ -1161,7 +1147,7 @@ function transformChildren$2(path, results, config) {
|
|
|
1161
1147
|
results.exprs.push(
|
|
1162
1148
|
t__namespace.expressionStatement(
|
|
1163
1149
|
t__namespace.callExpression(
|
|
1164
|
-
|
|
1150
|
+
insert,
|
|
1165
1151
|
config.hydratable
|
|
1166
1152
|
? [
|
|
1167
1153
|
results.id,
|
|
@@ -1196,12 +1182,11 @@ function createPlaceholder(path, results, tempPath, i, char) {
|
|
|
1196
1182
|
let contentId;
|
|
1197
1183
|
results.template += `<!${char}>`;
|
|
1198
1184
|
if (config.hydratable && char === "/") {
|
|
1199
|
-
registerImportMethod(path, "getNextMarker");
|
|
1200
1185
|
contentId = path.scope.generateUidIdentifier("co$");
|
|
1201
1186
|
results.decl.push(
|
|
1202
1187
|
t__namespace.variableDeclarator(
|
|
1203
1188
|
t__namespace.arrayPattern([exprId, contentId]),
|
|
1204
|
-
t__namespace.callExpression(
|
|
1189
|
+
t__namespace.callExpression(registerImportMethod(path, "getNextMarker"), [
|
|
1205
1190
|
t__namespace.memberExpression(t__namespace.identifier(tempPath), t__namespace.identifier("nextSibling"))
|
|
1206
1191
|
])
|
|
1207
1192
|
)
|
|
@@ -1267,13 +1252,12 @@ function detectExpressions(children, index, config) {
|
|
|
1267
1252
|
}
|
|
1268
1253
|
|
|
1269
1254
|
function contextToCustomElement(path, results) {
|
|
1270
|
-
registerImportMethod(path, "getOwner");
|
|
1271
1255
|
results.exprs.push(
|
|
1272
1256
|
t__namespace.expressionStatement(
|
|
1273
1257
|
t__namespace.assignmentExpression(
|
|
1274
1258
|
"=",
|
|
1275
1259
|
t__namespace.memberExpression(results.id, t__namespace.identifier("_$owner")),
|
|
1276
|
-
t__namespace.callExpression(
|
|
1260
|
+
t__namespace.callExpression(registerImportMethod(path, "getOwner"), [])
|
|
1277
1261
|
)
|
|
1278
1262
|
)
|
|
1279
1263
|
);
|
|
@@ -1306,8 +1290,7 @@ function createTemplate$2(path, result, wrap) {
|
|
|
1306
1290
|
}
|
|
1307
1291
|
}
|
|
1308
1292
|
if (wrap && result.dynamic && config.memoWrapper) {
|
|
1309
|
-
registerImportMethod(path, config.memoWrapper);
|
|
1310
|
-
return t__namespace.callExpression(t__namespace.identifier(`_$${config.memoWrapper}`), [result.exprs[0]]);
|
|
1293
|
+
return t__namespace.callExpression(registerImportMethod(path, config.memoWrapper), [result.exprs[0]]);
|
|
1311
1294
|
}
|
|
1312
1295
|
return result.exprs[0];
|
|
1313
1296
|
}
|
|
@@ -1318,11 +1301,10 @@ function appendTemplates$1(path, templates) {
|
|
|
1318
1301
|
cooked: template.template,
|
|
1319
1302
|
raw: template.template
|
|
1320
1303
|
};
|
|
1321
|
-
registerImportMethod(path, "template");
|
|
1322
1304
|
return t__namespace.variableDeclarator(
|
|
1323
1305
|
template.id,
|
|
1324
1306
|
t__namespace.callExpression(
|
|
1325
|
-
|
|
1307
|
+
registerImportMethod(path, "template"),
|
|
1326
1308
|
[
|
|
1327
1309
|
t__namespace.templateLiteral([t__namespace.templateElement(tmpl, true)], []),
|
|
1328
1310
|
t__namespace.numericLiteral(template.elementCount)
|
|
@@ -1354,11 +1336,10 @@ function registerTemplate(path, results) {
|
|
|
1354
1336
|
});
|
|
1355
1337
|
}
|
|
1356
1338
|
}
|
|
1357
|
-
hydratable && registerImportMethod(path, "getNextElement");
|
|
1358
1339
|
decl = t__namespace.variableDeclarator(
|
|
1359
1340
|
results.id,
|
|
1360
1341
|
hydratable
|
|
1361
|
-
? t__namespace.callExpression(
|
|
1342
|
+
? t__namespace.callExpression(registerImportMethod(path, "getNextElement"), templateId ? [templateId] : [])
|
|
1362
1343
|
: t__namespace.callExpression(t__namespace.memberExpression(templateId, t__namespace.identifier("cloneNode")), [
|
|
1363
1344
|
t__namespace.booleanLiteral(true)
|
|
1364
1345
|
])
|
|
@@ -1371,9 +1352,8 @@ function registerTemplate(path, results) {
|
|
|
1371
1352
|
function wrapDynamics$1(path, dynamics) {
|
|
1372
1353
|
if (!dynamics.length) return;
|
|
1373
1354
|
const config = getConfig(path);
|
|
1374
|
-
registerImportMethod(path, config.effectWrapper);
|
|
1375
1355
|
|
|
1376
|
-
const effectWrapperId =
|
|
1356
|
+
const effectWrapperId = registerImportMethod(path, config.effectWrapper);
|
|
1377
1357
|
|
|
1378
1358
|
if (dynamics.length === 1) {
|
|
1379
1359
|
const prevValue =
|
|
@@ -1382,7 +1362,7 @@ function wrapDynamics$1(path, dynamics) {
|
|
|
1382
1362
|
: undefined;
|
|
1383
1363
|
|
|
1384
1364
|
return t__namespace.expressionStatement(
|
|
1385
|
-
t__namespace.callExpression(
|
|
1365
|
+
t__namespace.callExpression(effectWrapperId, [
|
|
1386
1366
|
t__namespace.arrowFunctionExpression(
|
|
1387
1367
|
prevValue ? [prevValue] : [],
|
|
1388
1368
|
setAttr$2(path, dynamics[0].elem, dynamics[0].key, dynamics[0].value, {
|
|
@@ -1434,7 +1414,7 @@ function wrapDynamics$1(path, dynamics) {
|
|
|
1434
1414
|
});
|
|
1435
1415
|
|
|
1436
1416
|
return t__namespace.expressionStatement(
|
|
1437
|
-
t__namespace.callExpression(
|
|
1417
|
+
t__namespace.callExpression(effectWrapperId, [
|
|
1438
1418
|
t__namespace.arrowFunctionExpression(
|
|
1439
1419
|
[prevId],
|
|
1440
1420
|
t__namespace.blockStatement([
|
|
@@ -1448,6 +1428,51 @@ function wrapDynamics$1(path, dynamics) {
|
|
|
1448
1428
|
);
|
|
1449
1429
|
}
|
|
1450
1430
|
|
|
1431
|
+
function createTemplate$1(path, result) {
|
|
1432
|
+
if (!result.template) {
|
|
1433
|
+
return result.exprs[0];
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
let template, id;
|
|
1437
|
+
|
|
1438
|
+
if (!Array.isArray(result.template)) {
|
|
1439
|
+
template = t__namespace.stringLiteral(result.template);
|
|
1440
|
+
} else if (result.template.length === 1) {
|
|
1441
|
+
template = t__namespace.stringLiteral(result.template[0]);
|
|
1442
|
+
} else {
|
|
1443
|
+
const strings = result.template.map(tmpl => t__namespace.stringLiteral(tmpl));
|
|
1444
|
+
template = t__namespace.arrayExpression(strings);
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
const templates =
|
|
1448
|
+
path.scope.getProgramParent().data.templates ||
|
|
1449
|
+
(path.scope.getProgramParent().data.templates = []);
|
|
1450
|
+
const found = templates.find(tmp => {
|
|
1451
|
+
if (t__namespace.isArrayExpression(tmp[1]) && t__namespace.isArrayExpression(template)) {
|
|
1452
|
+
return tmp[1].elements.every(
|
|
1453
|
+
(el, i) => template.elements[i] && el.value === template.elements[i].value
|
|
1454
|
+
);
|
|
1455
|
+
}
|
|
1456
|
+
return tmp[1].value === template.value;
|
|
1457
|
+
});
|
|
1458
|
+
if (!found) {
|
|
1459
|
+
id = path.scope.generateUidIdentifier("tmpl$");
|
|
1460
|
+
templates.push([id, template]);
|
|
1461
|
+
} else id = found[0];
|
|
1462
|
+
|
|
1463
|
+
return t__namespace.callExpression(
|
|
1464
|
+
registerImportMethod(path, "ssr"),
|
|
1465
|
+
result.template.length > 1 ? [id, ...result.templateValues] : [id]
|
|
1466
|
+
);
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
function appendTemplates(path, templates) {
|
|
1470
|
+
const declarators = templates.map(template => {
|
|
1471
|
+
return t__namespace.variableDeclarator(template[0], template[1]);
|
|
1472
|
+
});
|
|
1473
|
+
path.node.body.unshift(t__namespace.variableDeclaration("const", declarators));
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1451
1476
|
function appendToTemplate(template, value) {
|
|
1452
1477
|
let array;
|
|
1453
1478
|
if (Array.isArray(value)) {
|
|
@@ -1466,17 +1491,17 @@ function transformElement$1(path, info) {
|
|
|
1466
1491
|
templateValues: [],
|
|
1467
1492
|
decl: [],
|
|
1468
1493
|
exprs: [],
|
|
1469
|
-
dynamics: []
|
|
1494
|
+
dynamics: [],
|
|
1495
|
+
tagName
|
|
1470
1496
|
};
|
|
1471
1497
|
if (info.topLevel && config.hydratable) {
|
|
1472
|
-
registerImportMethod(path, "ssrHydrationKey");
|
|
1473
1498
|
results.template.push("");
|
|
1474
|
-
results.templateValues.push(t__namespace.callExpression(
|
|
1499
|
+
results.templateValues.push(t__namespace.callExpression(registerImportMethod(path, "ssrHydrationKey"), []));
|
|
1475
1500
|
}
|
|
1476
1501
|
transformAttributes$1(path, results);
|
|
1477
1502
|
appendToTemplate(results.template, ">");
|
|
1478
1503
|
if (!voidTag) {
|
|
1479
|
-
transformChildren$1(path, results, config);
|
|
1504
|
+
transformChildren$1(path, results, {...config, ...info});
|
|
1480
1505
|
appendToTemplate(results.template, `</${tagName}>`);
|
|
1481
1506
|
}
|
|
1482
1507
|
return results;
|
|
@@ -1537,9 +1562,8 @@ function escapeExpression(path, expression, attr) {
|
|
|
1537
1562
|
return expression;
|
|
1538
1563
|
}
|
|
1539
1564
|
|
|
1540
|
-
registerImportMethod(path, "escape");
|
|
1541
1565
|
return t__namespace.callExpression(
|
|
1542
|
-
|
|
1566
|
+
registerImportMethod(path, "escape"),
|
|
1543
1567
|
[expression].concat(attr ? [t__namespace.booleanLiteral(true)] : [])
|
|
1544
1568
|
);
|
|
1545
1569
|
}
|
|
@@ -1550,9 +1574,12 @@ function transformToObject(attrName, attributes, selectedAttributes) {
|
|
|
1550
1574
|
for (let i = 0; i < selectedAttributes.length; i++) {
|
|
1551
1575
|
const attr = selectedAttributes[i].node;
|
|
1552
1576
|
const computed = !t__namespace.isValidIdentifier(attr.name.name.name);
|
|
1577
|
+
if (!computed) {
|
|
1578
|
+
attr.name.name.type = 'Identifier';
|
|
1579
|
+
}
|
|
1553
1580
|
properties.push(
|
|
1554
1581
|
t__namespace.objectProperty(
|
|
1555
|
-
computed ? t__namespace.stringLiteral(attr.name.name.name) :
|
|
1582
|
+
computed ? t__namespace.stringLiteral(attr.name.name.name) : attr.name.name,
|
|
1556
1583
|
t__namespace.isJSXExpressionContainer(attr.value) ? attr.value.expression : attr.value
|
|
1557
1584
|
)
|
|
1558
1585
|
);
|
|
@@ -1620,8 +1647,7 @@ function transformAttributes$1(path, results) {
|
|
|
1620
1647
|
i && attributes.splice(attributes.indexOf(classAttributes[i].node), 1);
|
|
1621
1648
|
continue;
|
|
1622
1649
|
}
|
|
1623
|
-
registerImportMethod(path, "ssrClassList");
|
|
1624
|
-
expr = t__namespace.callExpression(t__namespace.identifier("_$ssrClassList"), [expr]);
|
|
1650
|
+
expr = t__namespace.callExpression(registerImportMethod(path, "ssrClassList"), [expr]);
|
|
1625
1651
|
}
|
|
1626
1652
|
values.push(t__namespace.logicalExpression("||", expr, t__namespace.stringLiteral("")));
|
|
1627
1653
|
quasis.push(t__namespace.TemplateElement({ raw: isLast ? "" : " " }));
|
|
@@ -1635,11 +1661,10 @@ function transformAttributes$1(path, results) {
|
|
|
1635
1661
|
attributes.forEach(attribute => {
|
|
1636
1662
|
const node = attribute.node;
|
|
1637
1663
|
if (t__namespace.isJSXSpreadAttribute(node)) {
|
|
1638
|
-
registerImportMethod(attribute, "ssrSpread");
|
|
1639
1664
|
appendToTemplate(results.template, " ");
|
|
1640
1665
|
results.template.push("");
|
|
1641
1666
|
results.templateValues.push(
|
|
1642
|
-
t__namespace.callExpression(
|
|
1667
|
+
t__namespace.callExpression(registerImportMethod(attribute, "ssrSpread"), [
|
|
1643
1668
|
isDynamic(attribute.get("argument"), {
|
|
1644
1669
|
checkMember: true,
|
|
1645
1670
|
native: true
|
|
@@ -1696,9 +1721,8 @@ function transformAttributes$1(path, results) {
|
|
|
1696
1721
|
dynamic = true;
|
|
1697
1722
|
|
|
1698
1723
|
if (BooleanAttributes.has(key)) {
|
|
1699
|
-
registerImportMethod(attribute, "ssrBoolean");
|
|
1700
1724
|
results.template.push("");
|
|
1701
|
-
const fn = t__namespace.callExpression(
|
|
1725
|
+
const fn = t__namespace.callExpression(registerImportMethod(attribute, "ssrBoolean"), [
|
|
1702
1726
|
t__namespace.stringLiteral(key),
|
|
1703
1727
|
value.expression
|
|
1704
1728
|
]);
|
|
@@ -1711,7 +1735,6 @@ function transformAttributes$1(path, results) {
|
|
|
1711
1735
|
t__namespace.isObjectExpression(value.expression) &&
|
|
1712
1736
|
!value.expression.properties.some(p => t__namespace.isSpreadElement(p))
|
|
1713
1737
|
) {
|
|
1714
|
-
registerImportMethod(path, "escape");
|
|
1715
1738
|
const props = value.expression.properties.map((p, i) =>
|
|
1716
1739
|
t__namespace.binaryExpression(
|
|
1717
1740
|
"+",
|
|
@@ -1724,7 +1747,7 @@ function transformAttributes$1(path, results) {
|
|
|
1724
1747
|
? p.value
|
|
1725
1748
|
: t__namespace.isTemplateLiteral(p.value) && p.value.expressions.length === 0
|
|
1726
1749
|
? t__namespace.stringLiteral(escapeHTML(p.value.quasis[0].value.raw))
|
|
1727
|
-
: t__namespace.callExpression(
|
|
1750
|
+
: t__namespace.callExpression(registerImportMethod(path, "escape"), [p.value, t__namespace.booleanLiteral(true)])
|
|
1728
1751
|
)
|
|
1729
1752
|
);
|
|
1730
1753
|
let res = props[0];
|
|
@@ -1733,8 +1756,7 @@ function transformAttributes$1(path, results) {
|
|
|
1733
1756
|
}
|
|
1734
1757
|
value.expression = res;
|
|
1735
1758
|
} else {
|
|
1736
|
-
registerImportMethod(path, "ssrStyle");
|
|
1737
|
-
value.expression = t__namespace.callExpression(t__namespace.identifier("_$ssrStyle"), [value.expression]);
|
|
1759
|
+
value.expression = t__namespace.callExpression(registerImportMethod(path, "ssrStyle"), [value.expression]);
|
|
1738
1760
|
}
|
|
1739
1761
|
doEscape = false;
|
|
1740
1762
|
}
|
|
@@ -1751,8 +1773,7 @@ function transformAttributes$1(path, results) {
|
|
|
1751
1773
|
value.expression = values[0];
|
|
1752
1774
|
} else value.expression = t__namespace.templateLiteral(quasis, values);
|
|
1753
1775
|
} else {
|
|
1754
|
-
registerImportMethod(path, "ssrClassList");
|
|
1755
|
-
value.expression = t__namespace.callExpression(t__namespace.identifier("_$ssrClassList"), [value.expression]);
|
|
1776
|
+
value.expression = t__namespace.callExpression(registerImportMethod(path, "ssrClassList"), [value.expression]);
|
|
1756
1777
|
}
|
|
1757
1778
|
key = "class";
|
|
1758
1779
|
doEscape = false;
|
|
@@ -1784,8 +1805,7 @@ function transformClasslistObject(path, expr, values, quasis) {
|
|
|
1784
1805
|
let key = prop.key;
|
|
1785
1806
|
if (t__namespace.isIdentifier(prop.key) && !prop.computed) key = t__namespace.stringLiteral(key.name);
|
|
1786
1807
|
else if (prop.computed) {
|
|
1787
|
-
registerImportMethod(path, "escape");
|
|
1788
|
-
key = t__namespace.callExpression(t__namespace.identifier("_$escape"), [prop.key, t__namespace.booleanLiteral(true)]);
|
|
1808
|
+
key = t__namespace.callExpression(registerImportMethod(path, "escape"), [prop.key, t__namespace.booleanLiteral(true)]);
|
|
1789
1809
|
} else key = t__namespace.stringLiteral(escapeHTML(prop.key.value));
|
|
1790
1810
|
if (t__namespace.isBooleanLiteral(prop.value)) {
|
|
1791
1811
|
if (prop.value.value === true) {
|
|
@@ -1813,6 +1833,24 @@ function transformChildren$1(path, results, { hydratable }) {
|
|
|
1813
1833
|
const doNotEscape = path.doNotEscape;
|
|
1814
1834
|
const filteredChildren = filterChildren(path.get("children"));
|
|
1815
1835
|
filteredChildren.forEach(node => {
|
|
1836
|
+
if (t__namespace.isJSXElement(node.node) && (getTagName(node.node) === "head")) {
|
|
1837
|
+
const child = transformNode(node, { doNotEscape, hydratable: false });
|
|
1838
|
+
registerImportMethod(path, "NoHydration");
|
|
1839
|
+
results.template.push("");
|
|
1840
|
+
results.templateValues.push(
|
|
1841
|
+
t__namespace.callExpression(t__namespace.identifier("_$NoHydration"), [
|
|
1842
|
+
t__namespace.objectExpression([
|
|
1843
|
+
t__namespace.objectMethod(
|
|
1844
|
+
"get",
|
|
1845
|
+
t__namespace.identifier("children"),
|
|
1846
|
+
[],
|
|
1847
|
+
t__namespace.blockStatement([t__namespace.returnStatement(createTemplate$1(path, child))])
|
|
1848
|
+
)
|
|
1849
|
+
])
|
|
1850
|
+
])
|
|
1851
|
+
);
|
|
1852
|
+
return;
|
|
1853
|
+
}
|
|
1816
1854
|
const child = transformNode(node, { doNotEscape });
|
|
1817
1855
|
appendToTemplate(results.template, child.template);
|
|
1818
1856
|
results.templateValues.push.apply(results.templateValues, child.templateValues || []);
|
|
@@ -1836,52 +1874,6 @@ function transformChildren$1(path, results, { hydratable }) {
|
|
|
1836
1874
|
});
|
|
1837
1875
|
}
|
|
1838
1876
|
|
|
1839
|
-
function createTemplate$1(path, result) {
|
|
1840
|
-
if (!result.template) {
|
|
1841
|
-
return result.exprs[0];
|
|
1842
|
-
}
|
|
1843
|
-
|
|
1844
|
-
let template, id;
|
|
1845
|
-
|
|
1846
|
-
registerImportMethod(path, "ssr");
|
|
1847
|
-
if (!Array.isArray(result.template)) {
|
|
1848
|
-
template = t__namespace.stringLiteral(result.template);
|
|
1849
|
-
} else if (result.template.length === 1) {
|
|
1850
|
-
template = t__namespace.stringLiteral(result.template[0]);
|
|
1851
|
-
} else {
|
|
1852
|
-
const strings = result.template.map(tmpl => t__namespace.stringLiteral(tmpl));
|
|
1853
|
-
template = t__namespace.arrayExpression(strings);
|
|
1854
|
-
}
|
|
1855
|
-
|
|
1856
|
-
const templates =
|
|
1857
|
-
path.scope.getProgramParent().data.templates ||
|
|
1858
|
-
(path.scope.getProgramParent().data.templates = []);
|
|
1859
|
-
const found = templates.find(tmp => {
|
|
1860
|
-
if (t__namespace.isArrayExpression(tmp[1]) && t__namespace.isArrayExpression(template)) {
|
|
1861
|
-
return tmp[1].elements.every(
|
|
1862
|
-
(el, i) => template.elements[i] && el.value === template.elements[i].value
|
|
1863
|
-
);
|
|
1864
|
-
}
|
|
1865
|
-
return tmp[1].value === template.value;
|
|
1866
|
-
});
|
|
1867
|
-
if (!found) {
|
|
1868
|
-
id = path.scope.generateUidIdentifier("tmpl$");
|
|
1869
|
-
templates.push([id, template]);
|
|
1870
|
-
} else id = found[0];
|
|
1871
|
-
|
|
1872
|
-
return t__namespace.callExpression(
|
|
1873
|
-
t__namespace.identifier(`_$ssr`),
|
|
1874
|
-
result.template.length > 1 ? [id, ...result.templateValues] : [id]
|
|
1875
|
-
);
|
|
1876
|
-
}
|
|
1877
|
-
|
|
1878
|
-
function appendTemplates(path, templates) {
|
|
1879
|
-
const declarators = templates.map(template => {
|
|
1880
|
-
return t__namespace.variableDeclarator(template[0], template[1]);
|
|
1881
|
-
});
|
|
1882
|
-
path.node.body.unshift(t__namespace.variableDeclaration("const", declarators));
|
|
1883
|
-
}
|
|
1884
|
-
|
|
1885
1877
|
function transformElement(path, info) {
|
|
1886
1878
|
let tagName = getTagName(path.node),
|
|
1887
1879
|
results = {
|
|
@@ -1893,11 +1885,10 @@ function transformElement(path, info) {
|
|
|
1893
1885
|
tagName
|
|
1894
1886
|
};
|
|
1895
1887
|
|
|
1896
|
-
registerImportMethod(path, "createElement");
|
|
1897
1888
|
results.decl.push(
|
|
1898
1889
|
t__namespace.variableDeclarator(
|
|
1899
1890
|
results.id,
|
|
1900
|
-
t__namespace.callExpression(
|
|
1891
|
+
t__namespace.callExpression(registerImportMethod(path, "createElement"), [t__namespace.stringLiteral(tagName)])
|
|
1901
1892
|
)
|
|
1902
1893
|
);
|
|
1903
1894
|
|
|
@@ -1910,7 +1901,6 @@ function transformElement(path, info) {
|
|
|
1910
1901
|
function transformAttributes(path, results) {
|
|
1911
1902
|
let children;
|
|
1912
1903
|
const elem = results.id,
|
|
1913
|
-
spread = t__namespace.identifier("_$spread"),
|
|
1914
1904
|
hasChildren = path.node.children.length > 0,
|
|
1915
1905
|
config = getConfig(path);
|
|
1916
1906
|
|
|
@@ -1920,10 +1910,9 @@ function transformAttributes(path, results) {
|
|
|
1920
1910
|
.forEach(attribute => {
|
|
1921
1911
|
const node = attribute.node;
|
|
1922
1912
|
if (t__namespace.isJSXSpreadAttribute(node)) {
|
|
1923
|
-
registerImportMethod(attribute, "spread");
|
|
1924
1913
|
results.exprs.push(
|
|
1925
1914
|
t__namespace.expressionStatement(
|
|
1926
|
-
t__namespace.callExpression(spread, [
|
|
1915
|
+
t__namespace.callExpression(registerImportMethod(attribute, "spread"), [
|
|
1927
1916
|
elem,
|
|
1928
1917
|
isDynamic(attribute.get("argument"), {
|
|
1929
1918
|
checkMember: true
|
|
@@ -2002,9 +1991,11 @@ function transformAttributes(path, results) {
|
|
|
2002
1991
|
);
|
|
2003
1992
|
}
|
|
2004
1993
|
} else if (key.startsWith("use:")) {
|
|
1994
|
+
// Some trick to treat JSXIdentifier as Identifier
|
|
1995
|
+
node.name.name.type = 'Identifier';
|
|
2005
1996
|
results.exprs.unshift(
|
|
2006
1997
|
t__namespace.expressionStatement(
|
|
2007
|
-
t__namespace.callExpression(
|
|
1998
|
+
t__namespace.callExpression(node.name.name, [
|
|
2008
1999
|
elem,
|
|
2009
2000
|
t__namespace.arrowFunctionExpression(
|
|
2010
2001
|
[],
|
|
@@ -2039,10 +2030,9 @@ function transformAttributes(path, results) {
|
|
|
2039
2030
|
}
|
|
2040
2031
|
|
|
2041
2032
|
function setAttr(path, elem, name, value, { prevId } = {}) {
|
|
2042
|
-
registerImportMethod(path, "setProp");
|
|
2043
2033
|
if (!value) value = t__namespace.booleanLiteral(true);
|
|
2044
2034
|
return t__namespace.callExpression(
|
|
2045
|
-
|
|
2035
|
+
registerImportMethod(path, "setProp"),
|
|
2046
2036
|
prevId ? [elem, t__namespace.stringLiteral(name), value, prevId] : [elem, t__namespace.stringLiteral(name), value]
|
|
2047
2037
|
);
|
|
2048
2038
|
}
|
|
@@ -2063,36 +2053,36 @@ function transformChildren(path, results) {
|
|
|
2063
2053
|
childNodes.forEach((child, index) => {
|
|
2064
2054
|
if (!child) return;
|
|
2065
2055
|
if (child.id) {
|
|
2066
|
-
registerImportMethod(path, "insertNode");
|
|
2056
|
+
const insertNode = registerImportMethod(path, "insertNode");
|
|
2067
2057
|
let insert = child.id;
|
|
2068
2058
|
if (child.text) {
|
|
2069
|
-
registerImportMethod(path, "createTextNode");
|
|
2059
|
+
const createTextNode = registerImportMethod(path, "createTextNode");
|
|
2070
2060
|
if (multi) {
|
|
2071
2061
|
results.decl.push(
|
|
2072
2062
|
t__namespace.variableDeclarator(
|
|
2073
2063
|
child.id,
|
|
2074
|
-
t__namespace.callExpression(
|
|
2064
|
+
t__namespace.callExpression(createTextNode, [
|
|
2075
2065
|
t__namespace.stringLiteral(htmlEntities.decode(child.template))
|
|
2076
2066
|
])
|
|
2077
2067
|
)
|
|
2078
2068
|
);
|
|
2079
2069
|
} else
|
|
2080
|
-
insert = t__namespace.callExpression(
|
|
2070
|
+
insert = t__namespace.callExpression(createTextNode, [
|
|
2081
2071
|
t__namespace.stringLiteral(htmlEntities.decode(child.template))
|
|
2082
2072
|
]);
|
|
2083
2073
|
}
|
|
2084
2074
|
appends.push(
|
|
2085
|
-
t__namespace.expressionStatement(t__namespace.callExpression(
|
|
2075
|
+
t__namespace.expressionStatement(t__namespace.callExpression(insertNode, [results.id, insert]))
|
|
2086
2076
|
);
|
|
2087
2077
|
results.decl.push(...child.decl);
|
|
2088
2078
|
results.exprs.push(...child.exprs);
|
|
2089
2079
|
results.dynamics.push(...child.dynamics);
|
|
2090
2080
|
} else if (child.exprs.length) {
|
|
2091
|
-
registerImportMethod(path, "insert");
|
|
2081
|
+
const insert = registerImportMethod(path, "insert");
|
|
2092
2082
|
if (multi) {
|
|
2093
2083
|
results.exprs.push(
|
|
2094
2084
|
t__namespace.expressionStatement(
|
|
2095
|
-
t__namespace.callExpression(
|
|
2085
|
+
t__namespace.callExpression(insert, [
|
|
2096
2086
|
results.id,
|
|
2097
2087
|
child.exprs[0],
|
|
2098
2088
|
nextChild(childNodes, index) || t__namespace.nullLiteral()
|
|
@@ -2102,7 +2092,7 @@ function transformChildren(path, results) {
|
|
|
2102
2092
|
} else {
|
|
2103
2093
|
results.exprs.push(
|
|
2104
2094
|
t__namespace.expressionStatement(
|
|
2105
|
-
t__namespace.callExpression(
|
|
2095
|
+
t__namespace.callExpression(insert, [results.id, child.exprs[0]])
|
|
2106
2096
|
)
|
|
2107
2097
|
);
|
|
2108
2098
|
}
|
|
@@ -2142,8 +2132,7 @@ function createTemplate(path, result, wrap) {
|
|
|
2142
2132
|
}
|
|
2143
2133
|
}
|
|
2144
2134
|
if (wrap && result.dynamic && config.memoWrapper) {
|
|
2145
|
-
registerImportMethod(path, config.memoWrapper);
|
|
2146
|
-
return t__namespace.callExpression(t__namespace.identifier(`_$${config.memoWrapper}`), [result.exprs[0]]);
|
|
2135
|
+
return t__namespace.callExpression(registerImportMethod(path, config.memoWrapper), [result.exprs[0]]);
|
|
2147
2136
|
}
|
|
2148
2137
|
return result.exprs[0];
|
|
2149
2138
|
}
|
|
@@ -2151,15 +2140,14 @@ function createTemplate(path, result, wrap) {
|
|
|
2151
2140
|
function wrapDynamics(path, dynamics) {
|
|
2152
2141
|
if (!dynamics.length) return;
|
|
2153
2142
|
const config = getConfig(path);
|
|
2154
|
-
registerImportMethod(path, config.effectWrapper);
|
|
2155
2143
|
|
|
2156
|
-
const effectWrapperId =
|
|
2144
|
+
const effectWrapperId = registerImportMethod(path, config.effectWrapper);
|
|
2157
2145
|
|
|
2158
2146
|
if (dynamics.length === 1) {
|
|
2159
2147
|
const prevValue = t__namespace.identifier("_$p");
|
|
2160
2148
|
|
|
2161
2149
|
return t__namespace.expressionStatement(
|
|
2162
|
-
t__namespace.callExpression(
|
|
2150
|
+
t__namespace.callExpression(effectWrapperId, [
|
|
2163
2151
|
t__namespace.arrowFunctionExpression(
|
|
2164
2152
|
[prevValue],
|
|
2165
2153
|
setAttr(path, dynamics[0].elem, dynamics[0].key, dynamics[0].value, {
|
|
@@ -2197,7 +2185,7 @@ function wrapDynamics(path, dynamics) {
|
|
|
2197
2185
|
});
|
|
2198
2186
|
|
|
2199
2187
|
return t__namespace.expressionStatement(
|
|
2200
|
-
t__namespace.callExpression(
|
|
2188
|
+
t__namespace.callExpression(effectWrapperId, [
|
|
2201
2189
|
t__namespace.arrowFunctionExpression(
|
|
2202
2190
|
[prevId],
|
|
2203
2191
|
t__namespace.blockStatement([
|
|
@@ -2211,18 +2199,51 @@ function wrapDynamics(path, dynamics) {
|
|
|
2211
2199
|
);
|
|
2212
2200
|
}
|
|
2213
2201
|
|
|
2202
|
+
function convertComponentIdentifier(node) {
|
|
2203
|
+
if (t__namespace.isJSXIdentifier(node)) {
|
|
2204
|
+
node.type = "Identifier";
|
|
2205
|
+
} else if (t__namespace.isJSXMemberExpression(node)) {
|
|
2206
|
+
return t__namespace.memberExpression(
|
|
2207
|
+
convertComponentIdentifier(node.object),
|
|
2208
|
+
convertComponentIdentifier(node.property),
|
|
2209
|
+
);
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
return node;
|
|
2213
|
+
}
|
|
2214
|
+
|
|
2215
|
+
|
|
2216
|
+
function convertJSXIdentifier(node) {
|
|
2217
|
+
if (t__namespace.isJSXIdentifier(node)) {
|
|
2218
|
+
if (t__namespace.isValidIdentifier(node.name, false)) {
|
|
2219
|
+
node.type = "Identifier";
|
|
2220
|
+
} else {
|
|
2221
|
+
return t__namespace.stringLiteral(node.name);
|
|
2222
|
+
}
|
|
2223
|
+
} else if (t__namespace.isJSXMemberExpression(node)) {
|
|
2224
|
+
return t__namespace.memberExpression(
|
|
2225
|
+
convertJSXIdentifier(node.object),
|
|
2226
|
+
convertJSXIdentifier(node.property),
|
|
2227
|
+
);
|
|
2228
|
+
} else if (t__namespace.isJSXNamespacedName(node)) {
|
|
2229
|
+
return t__namespace.stringLiteral(`${node.namespace.name}:${node.name.name}`);
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
return node;
|
|
2233
|
+
}
|
|
2234
|
+
|
|
2214
2235
|
function transformComponent(path) {
|
|
2215
2236
|
let exprs = [],
|
|
2216
2237
|
config = getConfig(path),
|
|
2217
|
-
|
|
2238
|
+
tagId = convertComponentIdentifier(path.node.openingElement.name),
|
|
2218
2239
|
props = [],
|
|
2219
2240
|
runningObject = [],
|
|
2220
2241
|
dynamicSpread = false,
|
|
2221
2242
|
hasChildren = path.node.children.length > 0;
|
|
2222
2243
|
|
|
2223
|
-
if (config.builtIns.indexOf(
|
|
2224
|
-
registerImportMethod(path,
|
|
2225
|
-
|
|
2244
|
+
if (config.builtIns.indexOf(tagId.name) > -1 && !path.scope.hasBinding(tagId.name)) {
|
|
2245
|
+
const newTagId = registerImportMethod(path, tagId.name);
|
|
2246
|
+
tagId.name = newTagId.name;
|
|
2226
2247
|
}
|
|
2227
2248
|
|
|
2228
2249
|
path
|
|
@@ -2246,10 +2267,8 @@ function transformComponent(path) {
|
|
|
2246
2267
|
);
|
|
2247
2268
|
} else {
|
|
2248
2269
|
const value = node.value || t__namespace.booleanLiteral(true),
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
: node.name.name,
|
|
2252
|
-
wrapName = t__namespace.isValidIdentifier(key) ? t__namespace.identifier : t__namespace.stringLiteral;
|
|
2270
|
+
id = convertJSXIdentifier(node.name),
|
|
2271
|
+
key = id.name;
|
|
2253
2272
|
if (hasChildren && key === "children") return;
|
|
2254
2273
|
if (t__namespace.isJSXExpressionContainer(value))
|
|
2255
2274
|
if (key === "ref") {
|
|
@@ -2335,14 +2354,14 @@ function transformComponent(path) {
|
|
|
2335
2354
|
runningObject.push(
|
|
2336
2355
|
t__namespace.objectMethod(
|
|
2337
2356
|
"get",
|
|
2338
|
-
|
|
2357
|
+
id,
|
|
2339
2358
|
[],
|
|
2340
2359
|
t__namespace.blockStatement([t__namespace.returnStatement(expr.body)]),
|
|
2341
2360
|
!t__namespace.isValidIdentifier(key)
|
|
2342
2361
|
)
|
|
2343
2362
|
);
|
|
2344
|
-
} else runningObject.push(t__namespace.objectProperty(
|
|
2345
|
-
else runningObject.push(t__namespace.objectProperty(
|
|
2363
|
+
} else runningObject.push(t__namespace.objectProperty(id, value.expression));
|
|
2364
|
+
else runningObject.push(t__namespace.objectProperty(id, value));
|
|
2346
2365
|
}
|
|
2347
2366
|
});
|
|
2348
2367
|
|
|
@@ -2366,12 +2385,10 @@ function transformComponent(path) {
|
|
|
2366
2385
|
if (runningObject.length || !props.length) props.push(t__namespace.objectExpression(runningObject));
|
|
2367
2386
|
|
|
2368
2387
|
if (props.length > 1 || dynamicSpread) {
|
|
2369
|
-
registerImportMethod(path, "mergeProps");
|
|
2370
|
-
props = [t__namespace.callExpression(t__namespace.identifier("_$mergeProps"), props)];
|
|
2388
|
+
props = [t__namespace.callExpression(registerImportMethod(path, "mergeProps"), props)];
|
|
2371
2389
|
}
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
exprs.push(t__namespace.callExpression(t__namespace.identifier("_$createComponent"), componentArgs));
|
|
2390
|
+
const componentArgs = [tagId, props[0]];
|
|
2391
|
+
exprs.push(t__namespace.callExpression(registerImportMethod(path, "createComponent"), componentArgs));
|
|
2375
2392
|
|
|
2376
2393
|
// handle hoisting conditionals
|
|
2377
2394
|
if (exprs.length > 1) {
|
|
@@ -2449,7 +2466,7 @@ function transformFragmentChildren(children, results, config) {
|
|
|
2449
2466
|
if (v.length) memo.push(t__namespace.stringLiteral(v));
|
|
2450
2467
|
} else {
|
|
2451
2468
|
const child = transformNode(path, { topLevel: true, fragmentChild: true });
|
|
2452
|
-
memo.push(createTemplate$3(path, child,
|
|
2469
|
+
memo.push(createTemplate$3(path, child, true));
|
|
2453
2470
|
}
|
|
2454
2471
|
return memo;
|
|
2455
2472
|
}, []);
|
|
@@ -2596,10 +2613,9 @@ function transformNode(path, info = {}) {
|
|
|
2596
2613
|
var postprocess = path => {
|
|
2597
2614
|
const config = getConfig(path);
|
|
2598
2615
|
if (path.scope.data.events) {
|
|
2599
|
-
registerImportMethod(path, "delegateEvents");
|
|
2600
2616
|
path.node.body.push(
|
|
2601
2617
|
t__namespace.expressionStatement(
|
|
2602
|
-
t__namespace.callExpression(
|
|
2618
|
+
t__namespace.callExpression(registerImportMethod(path, "delegateEvents"), [
|
|
2603
2619
|
t__namespace.arrayExpression(Array.from(path.scope.data.events).map(e => t__namespace.stringLiteral(e)))
|
|
2604
2620
|
])
|
|
2605
2621
|
)
|
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.
|
|
4
|
+
"version": "0.31.0-beta.6",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -23,5 +23,5 @@
|
|
|
23
23
|
"@babel/types": "^7.11.5",
|
|
24
24
|
"html-entities": "2.3.2"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "eb9258c44a11aae76b5498549f1dd32645bb6b01"
|
|
27
27
|
}
|