babel-plugin-jsx-dom-expressions 0.33.8 → 0.33.12
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 +96 -83
- package/package.json +5 -2
package/index.js
CHANGED
|
@@ -311,6 +311,9 @@ function isDynamic(path, { checkMember, checkTags, checkCallExpressions = true,
|
|
|
311
311
|
OptionalMemberExpression(p) {
|
|
312
312
|
checkMember && (dynamic = true) && p.stop();
|
|
313
313
|
},
|
|
314
|
+
SpreadElement(p) {
|
|
315
|
+
checkMember && (dynamic = true) && p.stop();
|
|
316
|
+
},
|
|
314
317
|
JSXElement(p) {
|
|
315
318
|
checkTags ? (dynamic = true) && p.stop() : p.skip();
|
|
316
319
|
},
|
|
@@ -592,26 +595,28 @@ function setAttr$2(path, elem, name, value, { isSVG, dynamic, prevId, isCE }) {
|
|
|
592
595
|
}
|
|
593
596
|
|
|
594
597
|
if (name === "style") {
|
|
595
|
-
return t__namespace.callExpression(
|
|
598
|
+
return t__namespace.callExpression(
|
|
599
|
+
registerImportMethod(path, "style", getRendererConfig(path, "dom").moduleName),
|
|
600
|
+
prevId ? [elem, value, prevId] : [elem, value]
|
|
601
|
+
);
|
|
596
602
|
}
|
|
597
603
|
|
|
598
604
|
if (!isSVG && name === "class") {
|
|
599
|
-
return t__namespace.callExpression(
|
|
605
|
+
return t__namespace.callExpression(
|
|
606
|
+
registerImportMethod(path, "className", getRendererConfig(path, "dom").moduleName),
|
|
607
|
+
[elem, value]
|
|
608
|
+
);
|
|
600
609
|
}
|
|
601
610
|
|
|
602
611
|
if (name === "classList") {
|
|
603
|
-
return t__namespace.callExpression(
|
|
604
|
-
path,
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
), prevId ? [elem, value, prevId] : [elem, value]);
|
|
612
|
+
return t__namespace.callExpression(
|
|
613
|
+
registerImportMethod(path, "classList", getRendererConfig(path, "dom").moduleName),
|
|
614
|
+
prevId ? [elem, value, prevId] : [elem, value]
|
|
615
|
+
);
|
|
608
616
|
}
|
|
609
617
|
|
|
610
618
|
if (config.hydratable && name === "innerHTML") {
|
|
611
|
-
return t__namespace.callExpression(
|
|
612
|
-
registerImportMethod(path, "innerHTML"),
|
|
613
|
-
[elem, value]
|
|
614
|
-
);
|
|
619
|
+
return t__namespace.callExpression(registerImportMethod(path, "innerHTML"), [elem, value]);
|
|
615
620
|
}
|
|
616
621
|
|
|
617
622
|
if (dynamic && name === "textContent") {
|
|
@@ -635,22 +640,15 @@ function setAttr$2(path, elem, name, value, { isSVG, dynamic, prevId, isCE }) {
|
|
|
635
640
|
!isSVG && (name = name.toLowerCase());
|
|
636
641
|
const ns = isNameSpaced && SVGNamespace[name.split(":")[0]];
|
|
637
642
|
if (ns) {
|
|
638
|
-
return t__namespace.callExpression(
|
|
639
|
-
path,
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
), [
|
|
643
|
-
elem,
|
|
644
|
-
t__namespace.stringLiteral(ns),
|
|
645
|
-
t__namespace.stringLiteral(name),
|
|
646
|
-
value
|
|
647
|
-
]);
|
|
643
|
+
return t__namespace.callExpression(
|
|
644
|
+
registerImportMethod(path, "setAttributeNS", getRendererConfig(path, "dom").moduleName),
|
|
645
|
+
[elem, t__namespace.stringLiteral(ns), t__namespace.stringLiteral(name), value]
|
|
646
|
+
);
|
|
648
647
|
} else {
|
|
649
|
-
return t__namespace.callExpression(
|
|
650
|
-
path,
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
), [elem, t__namespace.stringLiteral(name), value]);
|
|
648
|
+
return t__namespace.callExpression(
|
|
649
|
+
registerImportMethod(path, "setAttribute", getRendererConfig(path, "dom").moduleName),
|
|
650
|
+
[elem, t__namespace.stringLiteral(name), value]
|
|
651
|
+
);
|
|
654
652
|
}
|
|
655
653
|
}
|
|
656
654
|
|
|
@@ -810,22 +808,21 @@ function transformAttributes$2(path, results) {
|
|
|
810
808
|
if (t__namespace.isJSXSpreadAttribute(node)) {
|
|
811
809
|
results.exprs.push(
|
|
812
810
|
t__namespace.expressionStatement(
|
|
813
|
-
t__namespace.callExpression(
|
|
814
|
-
attribute,
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
])
|
|
811
|
+
t__namespace.callExpression(
|
|
812
|
+
registerImportMethod(attribute, "spread", getRendererConfig(path, "dom").moduleName),
|
|
813
|
+
[
|
|
814
|
+
elem,
|
|
815
|
+
isDynamic(attribute.get("argument"), {
|
|
816
|
+
checkMember: true
|
|
817
|
+
})
|
|
818
|
+
? t__namespace.isCallExpression(node.argument) && !node.argument.arguments.length
|
|
819
|
+
? node.argument.callee
|
|
820
|
+
: t__namespace.arrowFunctionExpression([], node.argument)
|
|
821
|
+
: node.argument,
|
|
822
|
+
t__namespace.booleanLiteral(isSVG),
|
|
823
|
+
t__namespace.booleanLiteral(hasChildren)
|
|
824
|
+
]
|
|
825
|
+
)
|
|
829
826
|
)
|
|
830
827
|
);
|
|
831
828
|
//NOTE: can't be checked at compile time so add to compiled output
|
|
@@ -917,7 +914,7 @@ function transformAttributes$2(path, results) {
|
|
|
917
914
|
}
|
|
918
915
|
} else if (key.startsWith("use:")) {
|
|
919
916
|
// Some trick to treat JSXIdentifier as Identifier
|
|
920
|
-
node.name.name.type =
|
|
917
|
+
node.name.name.type = "Identifier";
|
|
921
918
|
results.exprs.unshift(
|
|
922
919
|
t__namespace.expressionStatement(
|
|
923
920
|
t__namespace.callExpression(node.name.name, [
|
|
@@ -994,16 +991,14 @@ function transformAttributes$2(path, results) {
|
|
|
994
991
|
} else {
|
|
995
992
|
results.exprs.unshift(
|
|
996
993
|
t__namespace.expressionStatement(
|
|
997
|
-
t__namespace.callExpression(
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
t__namespace.stringLiteral(ev),
|
|
1004
|
-
|
|
1005
|
-
t__namespace.booleanLiteral(true)
|
|
1006
|
-
])
|
|
994
|
+
t__namespace.callExpression(
|
|
995
|
+
registerImportMethod(
|
|
996
|
+
path,
|
|
997
|
+
"addEventListener",
|
|
998
|
+
getRendererConfig(path, "dom").moduleName
|
|
999
|
+
),
|
|
1000
|
+
[elem, t__namespace.stringLiteral(ev), handler, t__namespace.booleanLiteral(true)]
|
|
1001
|
+
)
|
|
1007
1002
|
)
|
|
1008
1003
|
);
|
|
1009
1004
|
}
|
|
@@ -1037,22 +1032,44 @@ function transformAttributes$2(path, results) {
|
|
|
1037
1032
|
} else {
|
|
1038
1033
|
results.exprs.unshift(
|
|
1039
1034
|
t__namespace.expressionStatement(
|
|
1040
|
-
t__namespace.callExpression(
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1035
|
+
t__namespace.callExpression(
|
|
1036
|
+
registerImportMethod(
|
|
1037
|
+
path,
|
|
1038
|
+
"addEventListener",
|
|
1039
|
+
getRendererConfig(path, "dom").moduleName
|
|
1040
|
+
),
|
|
1041
|
+
[elem, t__namespace.stringLiteral(ev), handler]
|
|
1042
|
+
)
|
|
1045
1043
|
)
|
|
1046
1044
|
);
|
|
1047
1045
|
}
|
|
1048
1046
|
}
|
|
1049
1047
|
} else if (
|
|
1050
1048
|
config.effectWrapper &&
|
|
1051
|
-
isDynamic(attribute.get("value").get("expression"), {
|
|
1049
|
+
(isDynamic(attribute.get("value").get("expression"), {
|
|
1052
1050
|
checkMember: true
|
|
1053
|
-
})
|
|
1051
|
+
}) ||
|
|
1052
|
+
((key === "classList" || key === "style") &&
|
|
1053
|
+
!attribute.get("value").get("expression").evaluate().confident))
|
|
1054
1054
|
) {
|
|
1055
1055
|
let nextElem = elem;
|
|
1056
|
+
if (key === "value" || key === "checked") {
|
|
1057
|
+
const effectWrapperId = registerImportMethod(path, config.effectWrapper);
|
|
1058
|
+
results.postExprs.push(
|
|
1059
|
+
t__namespace.expressionStatement(
|
|
1060
|
+
t__namespace.callExpression(effectWrapperId, [
|
|
1061
|
+
t__namespace.arrowFunctionExpression(
|
|
1062
|
+
[],
|
|
1063
|
+
setAttr$2(path, elem, key, value.expression, {
|
|
1064
|
+
isSVG,
|
|
1065
|
+
isCE
|
|
1066
|
+
})
|
|
1067
|
+
)
|
|
1068
|
+
])
|
|
1069
|
+
)
|
|
1070
|
+
);
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1056
1073
|
if (key === "textContent") {
|
|
1057
1074
|
nextElem = attribute.scope.generateUidIdentifier("el$");
|
|
1058
1075
|
children = t__namespace.JSXText(" ");
|
|
@@ -1081,7 +1098,7 @@ function transformAttributes$2(path, results) {
|
|
|
1081
1098
|
} else {
|
|
1082
1099
|
!isSVG && (key = key.toLowerCase());
|
|
1083
1100
|
results.template += ` ${key}`;
|
|
1084
|
-
results.template += value ? `="${escapeBackticks(value.value)}"` : "";
|
|
1101
|
+
results.template += value ? `="${escapeBackticks(escapeHTML(value.value, true))}"` : "";
|
|
1085
1102
|
}
|
|
1086
1103
|
}
|
|
1087
1104
|
});
|
|
@@ -1098,22 +1115,22 @@ function transformChildren$2(path, results, config) {
|
|
|
1098
1115
|
nextPlaceholder,
|
|
1099
1116
|
i = 0;
|
|
1100
1117
|
const filteredChildren = filterChildren(path.get("children")),
|
|
1101
|
-
childNodes = filteredChildren
|
|
1102
|
-
.
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1118
|
+
childNodes = filteredChildren.reduce((memo, child, index) => {
|
|
1119
|
+
if (child.isJSXFragment()) {
|
|
1120
|
+
throw new Error(
|
|
1121
|
+
`Fragments can only be used top level in JSX. Not used under a <${tagName}>.`
|
|
1122
|
+
);
|
|
1123
|
+
}
|
|
1124
|
+
const transformed = transformNode(child, {
|
|
1125
|
+
skipId: !results.id || !detectExpressions(filteredChildren, index, config)
|
|
1126
|
+
});
|
|
1127
|
+
if (!transformed) return memo;
|
|
1128
|
+
const i = memo.length;
|
|
1129
|
+
if (transformed.text && i && memo[i - 1].text) {
|
|
1130
|
+
memo[i - 1].template += transformed.template;
|
|
1131
|
+
} else memo.push(transformed);
|
|
1132
|
+
return memo;
|
|
1133
|
+
}, []);
|
|
1117
1134
|
|
|
1118
1135
|
childNodes.forEach((child, index) => {
|
|
1119
1136
|
if (!child) return;
|
|
@@ -1149,6 +1166,7 @@ function transformChildren$2(path, results, config) {
|
|
|
1149
1166
|
results.decl.push(...child.decl);
|
|
1150
1167
|
results.exprs.push(...child.exprs);
|
|
1151
1168
|
results.dynamics.push(...child.dynamics);
|
|
1169
|
+
results.postExprs.push(...child.postExprs);
|
|
1152
1170
|
results.hasHydratableEvent = results.hasHydratableEvent || child.hasHydratableEvent;
|
|
1153
1171
|
results.hasCustomElement = results.hasCustomElement || child.hasCustomElement;
|
|
1154
1172
|
tempPath = child.id.name;
|
|
@@ -1191,12 +1209,7 @@ function transformChildren$2(path, results, config) {
|
|
|
1191
1209
|
);
|
|
1192
1210
|
} else {
|
|
1193
1211
|
results.exprs.push(
|
|
1194
|
-
t__namespace.expressionStatement(
|
|
1195
|
-
t__namespace.callExpression(
|
|
1196
|
-
insert,
|
|
1197
|
-
[results.id, child.exprs[0]]
|
|
1198
|
-
)
|
|
1199
|
-
)
|
|
1212
|
+
t__namespace.expressionStatement(t__namespace.callExpression(insert, [results.id, child.exprs[0]]))
|
|
1200
1213
|
);
|
|
1201
1214
|
}
|
|
1202
1215
|
} else nextPlaceholder = null;
|
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.33.
|
|
4
|
+
"version": "0.33.12",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -23,5 +23,8 @@
|
|
|
23
23
|
"@babel/types": "^7.16.0",
|
|
24
24
|
"html-entities": "2.3.2"
|
|
25
25
|
},
|
|
26
|
-
"
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@babel/core": "^7.0.0"
|
|
28
|
+
},
|
|
29
|
+
"gitHead": "3c593d43147a73ddd52c58ba8c49f4f1e0e7e560"
|
|
27
30
|
}
|