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