babel-plugin-jsx-dom-expressions 0.37.9 → 0.37.11
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 +125 -81
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -630,6 +630,22 @@ function canNativeSpread(key, { checkNameSpaces } = {}) {
|
|
|
630
630
|
return true;
|
|
631
631
|
}
|
|
632
632
|
|
|
633
|
+
const chars = "etaoinshrdlucwmfygpbTAOISWCBvkxjqzPHFMDRELNGUKVYJQZX_$";
|
|
634
|
+
const base = chars.length;
|
|
635
|
+
|
|
636
|
+
function getNumberedId(num) {
|
|
637
|
+
let out = "";
|
|
638
|
+
|
|
639
|
+
do {
|
|
640
|
+
const digit = num % base;
|
|
641
|
+
|
|
642
|
+
num = Math.floor(num / base);
|
|
643
|
+
out = chars[digit] + out;
|
|
644
|
+
} while (num !== 0);
|
|
645
|
+
|
|
646
|
+
return out;
|
|
647
|
+
}
|
|
648
|
+
|
|
633
649
|
const InlineElements = [
|
|
634
650
|
"a",
|
|
635
651
|
"abbr",
|
|
@@ -761,7 +777,8 @@ function transformElement$3(path, info) {
|
|
|
761
777
|
isSVG: wrapSVG,
|
|
762
778
|
hasCustomElement: isCustomElement,
|
|
763
779
|
tagName,
|
|
764
|
-
renderer: "dom"
|
|
780
|
+
renderer: "dom",
|
|
781
|
+
skipTemplate: false
|
|
765
782
|
};
|
|
766
783
|
if (config.hydratable && (tagName === "html" || tagName === "head" || tagName === "body")) {
|
|
767
784
|
results.skipTemplate = true;
|
|
@@ -1002,12 +1019,12 @@ function transformAttributes$2(path, results) {
|
|
|
1002
1019
|
.node.attributes.splice(
|
|
1003
1020
|
styleAttribute.key + ++i,
|
|
1004
1021
|
0,
|
|
1005
|
-
t__namespace.
|
|
1006
|
-
t__namespace.
|
|
1007
|
-
t__namespace.
|
|
1008
|
-
t__namespace.
|
|
1022
|
+
t__namespace.jsxAttribute(
|
|
1023
|
+
t__namespace.jsxNamespacedName(
|
|
1024
|
+
t__namespace.jsxIdentifier("style"),
|
|
1025
|
+
t__namespace.jsxIdentifier(t__namespace.isIdentifier(p.key) ? p.key.name : p.key.value)
|
|
1009
1026
|
),
|
|
1010
|
-
t__namespace.
|
|
1027
|
+
t__namespace.jsxExpressionContainer(p.value)
|
|
1011
1028
|
)
|
|
1012
1029
|
);
|
|
1013
1030
|
styleAttribute.node.value.expression.properties.splice(index - i - 1, 1);
|
|
@@ -1046,12 +1063,12 @@ function transformAttributes$2(path, results) {
|
|
|
1046
1063
|
.node.attributes.splice(
|
|
1047
1064
|
classListAttribute.key + ++i,
|
|
1048
1065
|
0,
|
|
1049
|
-
t__namespace.
|
|
1050
|
-
t__namespace.
|
|
1051
|
-
t__namespace.
|
|
1052
|
-
t__namespace.
|
|
1066
|
+
t__namespace.jsxAttribute(
|
|
1067
|
+
t__namespace.jsxNamespacedName(
|
|
1068
|
+
t__namespace.jsxIdentifier("class"),
|
|
1069
|
+
t__namespace.jsxIdentifier(t__namespace.isIdentifier(p.key) ? p.key.name : p.key.value)
|
|
1053
1070
|
),
|
|
1054
|
-
t__namespace.
|
|
1071
|
+
t__namespace.jsxExpressionContainer(p.value)
|
|
1055
1072
|
)
|
|
1056
1073
|
);
|
|
1057
1074
|
} else if (computed) {
|
|
@@ -1060,8 +1077,8 @@ function transformAttributes$2(path, results) {
|
|
|
1060
1077
|
.node.attributes.splice(
|
|
1061
1078
|
classListAttribute.key + ++i,
|
|
1062
1079
|
0,
|
|
1063
|
-
t__namespace.
|
|
1064
|
-
t__namespace.
|
|
1080
|
+
t__namespace.jsxAttribute(
|
|
1081
|
+
t__namespace.jsxIdentifier("class"),
|
|
1065
1082
|
t__namespace.stringLiteral(t__namespace.isIdentifier(p.key) ? p.key.name : p.key.value)
|
|
1066
1083
|
)
|
|
1067
1084
|
);
|
|
@@ -1080,24 +1097,24 @@ function transformAttributes$2(path, results) {
|
|
|
1080
1097
|
if (classAttributes.length > 1) {
|
|
1081
1098
|
const first = classAttributes[0].node,
|
|
1082
1099
|
values = [],
|
|
1083
|
-
quasis = [t__namespace.
|
|
1100
|
+
quasis = [t__namespace.templateElement({ raw: "" })];
|
|
1084
1101
|
for (let i = 0; i < classAttributes.length; i++) {
|
|
1085
1102
|
const attr = classAttributes[i].node,
|
|
1086
1103
|
isLast = i === classAttributes.length - 1;
|
|
1087
1104
|
if (!t__namespace.isJSXExpressionContainer(attr.value)) {
|
|
1088
1105
|
const prev = quasis.pop();
|
|
1089
1106
|
quasis.push(
|
|
1090
|
-
t__namespace.
|
|
1107
|
+
t__namespace.templateElement({
|
|
1091
1108
|
raw: (prev ? prev.value.raw : "") + `${attr.value.value}` + (isLast ? "" : " ")
|
|
1092
1109
|
})
|
|
1093
1110
|
);
|
|
1094
1111
|
} else {
|
|
1095
1112
|
values.push(t__namespace.logicalExpression("||", attr.value.expression, t__namespace.stringLiteral("")));
|
|
1096
|
-
quasis.push(t__namespace.
|
|
1113
|
+
quasis.push(t__namespace.templateElement({ raw: isLast ? "" : " " }));
|
|
1097
1114
|
}
|
|
1098
1115
|
i && attributes.splice(attributes.indexOf(classAttributes[i]), 1);
|
|
1099
1116
|
}
|
|
1100
|
-
if (values.length) first.value = t__namespace.
|
|
1117
|
+
if (values.length) first.value = t__namespace.jsxExpressionContainer(t__namespace.templateLiteral(quasis, values));
|
|
1101
1118
|
else first.value = t__namespace.stringLiteral(quasis[0].value.raw);
|
|
1102
1119
|
}
|
|
1103
1120
|
path.get("openingElement").set(
|
|
@@ -1133,7 +1150,7 @@ function transformAttributes$2(path, results) {
|
|
|
1133
1150
|
reservedNameSpace &&
|
|
1134
1151
|
!t__namespace.isJSXExpressionContainer(value)
|
|
1135
1152
|
) {
|
|
1136
|
-
node.value = value = t__namespace.
|
|
1153
|
+
node.value = value = t__namespace.jsxExpressionContainer(value || t__namespace.jsxEmptyExpression());
|
|
1137
1154
|
}
|
|
1138
1155
|
if (
|
|
1139
1156
|
t__namespace.isJSXExpressionContainer(value) &&
|
|
@@ -1370,7 +1387,7 @@ function transformAttributes$2(path, results) {
|
|
|
1370
1387
|
}
|
|
1371
1388
|
if (key === "textContent") {
|
|
1372
1389
|
nextElem = attribute.scope.generateUidIdentifier("el$");
|
|
1373
|
-
children = t__namespace.
|
|
1390
|
+
children = t__namespace.jsxText(" ");
|
|
1374
1391
|
children.extra = { raw: " ", rawValue: " " };
|
|
1375
1392
|
results.declarations.push(
|
|
1376
1393
|
t__namespace.variableDeclarator(nextElem, t__namespace.memberExpression(elem, t__namespace.identifier("firstChild")))
|
|
@@ -1919,50 +1936,65 @@ function wrapDynamics$1(path, dynamics) {
|
|
|
1919
1936
|
])
|
|
1920
1937
|
);
|
|
1921
1938
|
}
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1939
|
+
|
|
1940
|
+
const prevId = t__namespace.identifier("_p$");
|
|
1941
|
+
|
|
1942
|
+
/** @type {t.VariableDeclarator[]} */
|
|
1943
|
+
const declarations = [];
|
|
1944
|
+
/** @type {t.ExpressionStatement[]} */
|
|
1945
|
+
const statements = [];
|
|
1946
|
+
/** @type {t.Identifier[]} */
|
|
1947
|
+
const properties = [];
|
|
1948
|
+
|
|
1949
|
+
dynamics.forEach(({ elem, key, value, isSVG, isCE, tagName }, index) => {
|
|
1950
|
+
const varIdent = path.scope.generateUidIdentifier("v$");
|
|
1951
|
+
|
|
1952
|
+
const propIdent = t__namespace.identifier(getNumberedId(index));
|
|
1953
|
+
const propMember = t__namespace.memberExpression(prevId, propIdent);
|
|
1954
|
+
|
|
1955
|
+
if (
|
|
1956
|
+
key.startsWith("class:") &&
|
|
1957
|
+
!t__namespace.isBooleanLiteral(value) &&
|
|
1958
|
+
!t__namespace.isUnaryExpression(value)
|
|
1959
|
+
) {
|
|
1929
1960
|
value = t__namespace.unaryExpression("!", t__namespace.unaryExpression("!", value));
|
|
1930
1961
|
}
|
|
1931
|
-
|
|
1932
|
-
|
|
1962
|
+
|
|
1963
|
+
properties.push(propIdent);
|
|
1964
|
+
declarations.push(t__namespace.variableDeclarator(varIdent, value));
|
|
1965
|
+
|
|
1933
1966
|
if (key === "classList" || key === "style") {
|
|
1934
|
-
const prev = t__namespace.memberExpression(prevId, identifier);
|
|
1935
1967
|
statements.push(
|
|
1936
1968
|
t__namespace.expressionStatement(
|
|
1937
1969
|
t__namespace.assignmentExpression(
|
|
1938
1970
|
"=",
|
|
1939
|
-
|
|
1940
|
-
setAttr$2(path, elem, key,
|
|
1971
|
+
propMember,
|
|
1972
|
+
setAttr$2(path, elem, key, varIdent, {
|
|
1941
1973
|
isSVG,
|
|
1942
1974
|
isCE,
|
|
1943
1975
|
tagName,
|
|
1944
1976
|
dynamic: true,
|
|
1945
|
-
prevId:
|
|
1946
|
-
})
|
|
1947
|
-
)
|
|
1948
|
-
)
|
|
1977
|
+
prevId: propMember,
|
|
1978
|
+
}),
|
|
1979
|
+
),
|
|
1980
|
+
),
|
|
1949
1981
|
);
|
|
1950
1982
|
} else {
|
|
1951
|
-
const prev = key.startsWith("style:") ?
|
|
1983
|
+
const prev = key.startsWith("style:") ? varIdent : undefined;
|
|
1952
1984
|
statements.push(
|
|
1953
1985
|
t__namespace.expressionStatement(
|
|
1954
1986
|
t__namespace.logicalExpression(
|
|
1955
1987
|
"&&",
|
|
1956
|
-
t__namespace.binaryExpression("!==",
|
|
1988
|
+
t__namespace.binaryExpression("!==", varIdent, propMember),
|
|
1957
1989
|
setAttr$2(
|
|
1958
1990
|
path,
|
|
1959
1991
|
elem,
|
|
1960
1992
|
key,
|
|
1961
|
-
t__namespace.assignmentExpression("=",
|
|
1962
|
-
{ isSVG, isCE, tagName, dynamic: true, prevId: prev }
|
|
1963
|
-
)
|
|
1964
|
-
)
|
|
1965
|
-
)
|
|
1993
|
+
t__namespace.assignmentExpression("=", propMember, varIdent),
|
|
1994
|
+
{ isSVG, isCE, tagName, dynamic: true, prevId: prev },
|
|
1995
|
+
),
|
|
1996
|
+
),
|
|
1997
|
+
),
|
|
1966
1998
|
);
|
|
1967
1999
|
}
|
|
1968
2000
|
});
|
|
@@ -1974,11 +2006,13 @@ function wrapDynamics$1(path, dynamics) {
|
|
|
1974
2006
|
t__namespace.blockStatement([
|
|
1975
2007
|
t__namespace.variableDeclaration("const", declarations),
|
|
1976
2008
|
...statements,
|
|
1977
|
-
t__namespace.returnStatement(prevId)
|
|
1978
|
-
])
|
|
2009
|
+
t__namespace.returnStatement(prevId),
|
|
2010
|
+
]),
|
|
1979
2011
|
),
|
|
1980
|
-
t__namespace.objectExpression(
|
|
1981
|
-
|
|
2012
|
+
t__namespace.objectExpression(
|
|
2013
|
+
properties.map((id) => t__namespace.objectProperty(id, t__namespace.identifier("undefined"))),
|
|
2014
|
+
),
|
|
2015
|
+
]),
|
|
1982
2016
|
);
|
|
1983
2017
|
}
|
|
1984
2018
|
|
|
@@ -2261,17 +2295,16 @@ function normalizeAttributes(path) {
|
|
|
2261
2295
|
if (classAttributes.length > 1) {
|
|
2262
2296
|
const first = classAttributes[0].node,
|
|
2263
2297
|
values = [],
|
|
2264
|
-
quasis = [t__namespace.
|
|
2298
|
+
quasis = [t__namespace.templateElement({ raw: "" })];
|
|
2265
2299
|
for (let i = 0; i < classAttributes.length; i++) {
|
|
2266
2300
|
const attr = classAttributes[i].node,
|
|
2267
2301
|
isLast = i === classAttributes.length - 1;
|
|
2268
2302
|
if (!t__namespace.isJSXExpressionContainer(attr.value)) {
|
|
2269
2303
|
const prev = quasis.pop();
|
|
2270
2304
|
quasis.push(
|
|
2271
|
-
t__namespace.
|
|
2305
|
+
t__namespace.templateElement({
|
|
2272
2306
|
raw:
|
|
2273
2307
|
(prev ? prev.value.raw : "") +
|
|
2274
|
-
(i ? " " : "") +
|
|
2275
2308
|
`${attr.value.value}` +
|
|
2276
2309
|
(isLast ? "" : " ")
|
|
2277
2310
|
})
|
|
@@ -2281,18 +2314,19 @@ function normalizeAttributes(path) {
|
|
|
2281
2314
|
if (attr.name.name === "classList") {
|
|
2282
2315
|
if (t__namespace.isObjectExpression(expr) && !expr.properties.some(p => t__namespace.isSpreadElement(p))) {
|
|
2283
2316
|
transformClasslistObject(path, expr, values, quasis);
|
|
2317
|
+
if (!isLast) quasis[quasis.length - 1].value.raw += " ";
|
|
2284
2318
|
i && attributes.splice(attributes.indexOf(classAttributes[i]), 1);
|
|
2285
2319
|
continue;
|
|
2286
2320
|
}
|
|
2287
2321
|
expr = t__namespace.callExpression(registerImportMethod(path, "ssrClassList"), [expr]);
|
|
2288
2322
|
}
|
|
2289
2323
|
values.push(t__namespace.logicalExpression("||", expr, t__namespace.stringLiteral("")));
|
|
2290
|
-
quasis.push(t__namespace.
|
|
2324
|
+
quasis.push(t__namespace.templateElement({ raw: isLast ? "" : " " }));
|
|
2291
2325
|
}
|
|
2292
2326
|
i && attributes.splice(attributes.indexOf(classAttributes[i]), 1);
|
|
2293
2327
|
}
|
|
2294
|
-
first.name = t__namespace.
|
|
2295
|
-
first.value = t__namespace.
|
|
2328
|
+
first.name = t__namespace.jsxIdentifier("class");
|
|
2329
|
+
first.value = t__namespace.jsxExpressionContainer(t__namespace.templateLiteral(quasis, values));
|
|
2296
2330
|
}
|
|
2297
2331
|
if (styleAttributes.length) transformToObject("style", attributes, styleAttributes);
|
|
2298
2332
|
return attributes;
|
|
@@ -2318,7 +2352,7 @@ function transformAttributes$1(path, results, info) {
|
|
|
2318
2352
|
((t__namespace.isJSXNamespacedName(node.name) && reservedNameSpace) || ChildProperties.has(key)) &&
|
|
2319
2353
|
!t__namespace.isJSXExpressionContainer(value)
|
|
2320
2354
|
) {
|
|
2321
|
-
node.value = value = t__namespace.
|
|
2355
|
+
node.value = value = t__namespace.jsxExpressionContainer(value || t__namespace.jsxEmptyExpression());
|
|
2322
2356
|
}
|
|
2323
2357
|
|
|
2324
2358
|
if (
|
|
@@ -2385,7 +2419,7 @@ function transformAttributes$1(path, results, info) {
|
|
|
2385
2419
|
!value.expression.properties.some(p => t__namespace.isSpreadElement(p))
|
|
2386
2420
|
) {
|
|
2387
2421
|
const values = [],
|
|
2388
|
-
quasis = [t__namespace.
|
|
2422
|
+
quasis = [t__namespace.templateElement({ raw: "" })];
|
|
2389
2423
|
transformClasslistObject(path, value.expression, values, quasis);
|
|
2390
2424
|
if (!values.length) value.expression = t__namespace.stringLiteral(quasis[0].value.raw);
|
|
2391
2425
|
else if (values.length === 1 && !quasis[0].value.raw && !quasis[1].value.raw) {
|
|
@@ -2447,19 +2481,19 @@ function transformClasslistObject(path, expr, values, quasis) {
|
|
|
2447
2481
|
if (!prop.computed) {
|
|
2448
2482
|
const prev = quasis.pop();
|
|
2449
2483
|
quasis.push(
|
|
2450
|
-
t__namespace.
|
|
2484
|
+
t__namespace.templateElement({
|
|
2451
2485
|
raw:
|
|
2452
2486
|
(prev ? prev.value.raw : "") + (i ? " " : "") + `${key.value}` + (isLast ? "" : " ")
|
|
2453
2487
|
})
|
|
2454
2488
|
);
|
|
2455
2489
|
} else {
|
|
2456
2490
|
values.push(key);
|
|
2457
|
-
quasis.push(t__namespace.
|
|
2491
|
+
quasis.push(t__namespace.templateElement({ raw: isLast ? "" : " " }));
|
|
2458
2492
|
}
|
|
2459
2493
|
}
|
|
2460
2494
|
} else {
|
|
2461
2495
|
values.push(t__namespace.conditionalExpression(prop.value, key, t__namespace.stringLiteral("")));
|
|
2462
|
-
quasis.push(t__namespace.
|
|
2496
|
+
quasis.push(t__namespace.templateElement({ raw: isLast ? "" : " " }));
|
|
2463
2497
|
}
|
|
2464
2498
|
});
|
|
2465
2499
|
}
|
|
@@ -2697,7 +2731,7 @@ function transformAttributes(path, results) {
|
|
|
2697
2731
|
reservedNameSpace &&
|
|
2698
2732
|
!t__namespace.isJSXExpressionContainer(value)
|
|
2699
2733
|
) {
|
|
2700
|
-
node.value = value = t__namespace.
|
|
2734
|
+
node.value = value = t__namespace.jsxExpressionContainer(value || t__namespace.jsxEmptyExpression());
|
|
2701
2735
|
}
|
|
2702
2736
|
if (t__namespace.isJSXExpressionContainer(value)) {
|
|
2703
2737
|
if (key === "ref") {
|
|
@@ -3046,29 +3080,37 @@ function wrapDynamics(path, dynamics) {
|
|
|
3046
3080
|
])
|
|
3047
3081
|
);
|
|
3048
3082
|
}
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3083
|
+
|
|
3084
|
+
const prevId = t__namespace.identifier("_p$");
|
|
3085
|
+
|
|
3086
|
+
/** @type {t.VariableDeclarator[]} */
|
|
3087
|
+
const declarations = [];
|
|
3088
|
+
/** @type {t.ExpressionStatement[]} */
|
|
3089
|
+
const statements = [];
|
|
3090
|
+
/** @type {t.Identifier[]} */
|
|
3091
|
+
const properties = [];
|
|
3092
|
+
|
|
3093
|
+
dynamics.forEach(({ elem, key, value }, index) => {
|
|
3094
|
+
const varIdent = path.scope.generateUidIdentifier("v$");
|
|
3095
|
+
|
|
3096
|
+
const propIdent = t__namespace.identifier(getNumberedId(index));
|
|
3097
|
+
const propMember = t__namespace.memberExpression(prevId, propIdent);
|
|
3098
|
+
|
|
3099
|
+
properties.push(propIdent);
|
|
3100
|
+
declarations.push(t__namespace.variableDeclarator(varIdent, value));
|
|
3101
|
+
|
|
3058
3102
|
statements.push(
|
|
3059
3103
|
t__namespace.expressionStatement(
|
|
3060
3104
|
t__namespace.logicalExpression(
|
|
3061
3105
|
"&&",
|
|
3062
|
-
t__namespace.binaryExpression("!==",
|
|
3063
|
-
t__namespace.assignmentExpression(
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
key,
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
)
|
|
3071
|
-
)
|
|
3106
|
+
t__namespace.binaryExpression("!==", varIdent, propMember),
|
|
3107
|
+
t__namespace.assignmentExpression(
|
|
3108
|
+
"=",
|
|
3109
|
+
propMember,
|
|
3110
|
+
setAttr(path, elem, key, varIdent, { dynamic: true, prevId: propMember }),
|
|
3111
|
+
),
|
|
3112
|
+
),
|
|
3113
|
+
),
|
|
3072
3114
|
);
|
|
3073
3115
|
});
|
|
3074
3116
|
|
|
@@ -3079,11 +3121,13 @@ function wrapDynamics(path, dynamics) {
|
|
|
3079
3121
|
t__namespace.blockStatement([
|
|
3080
3122
|
t__namespace.variableDeclaration("const", declarations),
|
|
3081
3123
|
...statements,
|
|
3082
|
-
t__namespace.returnStatement(prevId)
|
|
3083
|
-
])
|
|
3124
|
+
t__namespace.returnStatement(prevId),
|
|
3125
|
+
]),
|
|
3084
3126
|
),
|
|
3085
|
-
t__namespace.objectExpression(
|
|
3086
|
-
|
|
3127
|
+
t__namespace.objectExpression(
|
|
3128
|
+
properties.map((id) => t__namespace.objectProperty(id, t__namespace.identifier("undefined"))),
|
|
3129
|
+
),
|
|
3130
|
+
]),
|
|
3087
3131
|
);
|
|
3088
3132
|
}
|
|
3089
3133
|
|
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.37.
|
|
4
|
+
"version": "0.37.11",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@babel/core": "^7.20.12"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "74d433381256e4355adc644124026fe0a2ef9875"
|
|
35
35
|
}
|