babel-plugin-jsx-dom-expressions 0.30.0 → 0.30.7
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 +36 -21
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -392,12 +392,10 @@ function wrappedByText(list, startIndex) {
|
|
|
392
392
|
return false;
|
|
393
393
|
}
|
|
394
394
|
|
|
395
|
-
function transformCondition(path, deep) {
|
|
395
|
+
function transformCondition(path, inline, deep) {
|
|
396
396
|
const config = getConfig(path);
|
|
397
397
|
const expr = path.node;
|
|
398
|
-
|
|
399
|
-
registerImportMethod(path, config.memoWrapper);
|
|
400
|
-
}
|
|
398
|
+
registerImportMethod(path, config.memoWrapper);
|
|
401
399
|
let dTest, cond, id;
|
|
402
400
|
if (
|
|
403
401
|
t__namespace.isConditionalExpression(expr) &&
|
|
@@ -409,15 +407,20 @@ function transformCondition(path, deep) {
|
|
|
409
407
|
dTest = isDynamic(path.get("test"), { checkMember: true });
|
|
410
408
|
if (dTest) {
|
|
411
409
|
cond = expr.test;
|
|
412
|
-
id = path.scope.generateUidIdentifier("_c$");
|
|
413
410
|
if (!t__namespace.isBinaryExpression(cond))
|
|
414
411
|
cond = t__namespace.unaryExpression("!", t__namespace.unaryExpression("!", cond, true), true);
|
|
412
|
+
id = inline
|
|
413
|
+
? t__namespace.callExpression(t__namespace.identifier(`_$${config.memoWrapper}`), [
|
|
414
|
+
t__namespace.arrowFunctionExpression([], cond),
|
|
415
|
+
t__namespace.booleanLiteral(true)
|
|
416
|
+
])
|
|
417
|
+
: path.scope.generateUidIdentifier("_c$");
|
|
415
418
|
expr.test = t__namespace.callExpression(id, []);
|
|
416
419
|
if (t__namespace.isConditionalExpression(expr.consequent) || t__namespace.isLogicalExpression(expr.consequent)) {
|
|
417
|
-
expr.consequent = transformCondition(path.get("consequent"), true);
|
|
420
|
+
expr.consequent = transformCondition(path.get("consequent"), inline, true);
|
|
418
421
|
}
|
|
419
422
|
if (t__namespace.isConditionalExpression(expr.alternate) || t__namespace.isLogicalExpression(expr.alternate)) {
|
|
420
|
-
expr.alternate = transformCondition(path.get("alternate"), true);
|
|
423
|
+
expr.alternate = transformCondition(path.get("alternate"), inline, true);
|
|
421
424
|
}
|
|
422
425
|
}
|
|
423
426
|
} else if (t__namespace.isLogicalExpression(expr)) {
|
|
@@ -433,13 +436,18 @@ function transformCondition(path, deep) {
|
|
|
433
436
|
}));
|
|
434
437
|
if (dTest) {
|
|
435
438
|
cond = nextPath.node.left;
|
|
436
|
-
id = path.scope.generateUidIdentifier("_c$");
|
|
437
439
|
if (!t__namespace.isBinaryExpression(cond))
|
|
438
440
|
cond = t__namespace.unaryExpression("!", t__namespace.unaryExpression("!", cond, true), true);
|
|
441
|
+
id = inline
|
|
442
|
+
? t__namespace.callExpression(t__namespace.identifier(`_$${config.memoWrapper}`), [
|
|
443
|
+
t__namespace.arrowFunctionExpression([], cond),
|
|
444
|
+
t__namespace.booleanLiteral(true)
|
|
445
|
+
])
|
|
446
|
+
: path.scope.generateUidIdentifier("_c$");
|
|
439
447
|
nextPath.node.left = t__namespace.callExpression(id, []);
|
|
440
448
|
}
|
|
441
449
|
}
|
|
442
|
-
if (dTest) {
|
|
450
|
+
if (dTest && !inline) {
|
|
443
451
|
const statements = [
|
|
444
452
|
t__namespace.variableDeclaration("const", [
|
|
445
453
|
t__namespace.variableDeclarator(
|
|
@@ -793,7 +801,7 @@ function transformAttributes$2(path, results) {
|
|
|
793
801
|
isDynamic(attribute.get("argument"), {
|
|
794
802
|
checkMember: true
|
|
795
803
|
})
|
|
796
|
-
? t__namespace.isCallExpression(node.argument)
|
|
804
|
+
? t__namespace.isCallExpression(node.argument) && !node.argument.arguments.length
|
|
797
805
|
? node.argument.callee
|
|
798
806
|
: t__namespace.arrowFunctionExpression([], node.argument)
|
|
799
807
|
: node.argument,
|
|
@@ -813,6 +821,16 @@ function transformAttributes$2(path, results) {
|
|
|
813
821
|
: node.name.name,
|
|
814
822
|
reservedNameSpace =
|
|
815
823
|
t__namespace.isJSXNamespacedName(node.name) && reservedNameSpaces.has(node.name.namespace.name);
|
|
824
|
+
if (t__namespace.isJSXExpressionContainer(value)) {
|
|
825
|
+
const evaluated = attribute.get("value").get("expression").evaluate().value;
|
|
826
|
+
let type;
|
|
827
|
+
if (
|
|
828
|
+
evaluated !== undefined &&
|
|
829
|
+
((type = typeof evaluated) === "string" || type === "number")
|
|
830
|
+
) {
|
|
831
|
+
value = t__namespace.stringLiteral(String(evaluated));
|
|
832
|
+
}
|
|
833
|
+
}
|
|
816
834
|
if (
|
|
817
835
|
t__namespace.isJSXNamespacedName(node.name) &&
|
|
818
836
|
reservedNameSpace &&
|
|
@@ -1626,7 +1644,7 @@ function transformAttributes$1(path, results) {
|
|
|
1626
1644
|
checkMember: true,
|
|
1627
1645
|
native: true
|
|
1628
1646
|
})
|
|
1629
|
-
? t__namespace.isCallExpression(node.argument)
|
|
1647
|
+
? t__namespace.isCallExpression(node.argument) && !node.argument.arguments.length
|
|
1630
1648
|
? node.argument.callee
|
|
1631
1649
|
: t__namespace.arrowFunctionExpression([], node.argument)
|
|
1632
1650
|
: node.argument,
|
|
@@ -1910,7 +1928,7 @@ function transformAttributes(path, results) {
|
|
|
1910
1928
|
isDynamic(attribute.get("argument"), {
|
|
1911
1929
|
checkMember: true
|
|
1912
1930
|
})
|
|
1913
|
-
? t__namespace.isCallExpression(node.argument)
|
|
1931
|
+
? t__namespace.isCallExpression(node.argument) && !node.argument.arguments.length
|
|
1914
1932
|
? node.argument.callee
|
|
1915
1933
|
: t__namespace.arrowFunctionExpression([], node.argument)
|
|
1916
1934
|
: node.argument,
|
|
@@ -2199,6 +2217,7 @@ function transformComponent(path) {
|
|
|
2199
2217
|
tagName = getTagName(path.node),
|
|
2200
2218
|
props = [],
|
|
2201
2219
|
runningObject = [],
|
|
2220
|
+
dynamicSpread = false,
|
|
2202
2221
|
hasChildren = path.node.children.length > 0;
|
|
2203
2222
|
|
|
2204
2223
|
if (config.builtIns.indexOf(tagName) > -1 && !path.scope.hasBinding(tagName)) {
|
|
@@ -2219,8 +2238,8 @@ function transformComponent(path) {
|
|
|
2219
2238
|
props.push(
|
|
2220
2239
|
isDynamic(attribute.get("argument"), {
|
|
2221
2240
|
checkMember: true
|
|
2222
|
-
})
|
|
2223
|
-
? t__namespace.isCallExpression(node.argument)
|
|
2241
|
+
}) && (dynamicSpread = true)
|
|
2242
|
+
? t__namespace.isCallExpression(node.argument) && !node.argument.arguments.length
|
|
2224
2243
|
? node.argument.callee
|
|
2225
2244
|
: t__namespace.arrowFunctionExpression([], node.argument)
|
|
2226
2245
|
: node.argument
|
|
@@ -2311,12 +2330,8 @@ function transformComponent(path) {
|
|
|
2311
2330
|
config.generate !== "ssr" &&
|
|
2312
2331
|
(t__namespace.isLogicalExpression(value.expression) ||
|
|
2313
2332
|
t__namespace.isConditionalExpression(value.expression))
|
|
2314
|
-
? transformCondition(attribute.get("value").get("expression"))
|
|
2333
|
+
? transformCondition(attribute.get("value").get("expression"), true)
|
|
2315
2334
|
: t__namespace.arrowFunctionExpression([], value.expression);
|
|
2316
|
-
if (expr.length > 1) {
|
|
2317
|
-
exprs.push(expr[0]);
|
|
2318
|
-
expr = expr[1];
|
|
2319
|
-
}
|
|
2320
2335
|
runningObject.push(
|
|
2321
2336
|
t__namespace.objectMethod(
|
|
2322
2337
|
"get",
|
|
@@ -2350,7 +2365,7 @@ function transformComponent(path) {
|
|
|
2350
2365
|
}
|
|
2351
2366
|
if (runningObject.length || !props.length) props.push(t__namespace.objectExpression(runningObject));
|
|
2352
2367
|
|
|
2353
|
-
if (props.length > 1) {
|
|
2368
|
+
if (props.length > 1 || dynamicSpread) {
|
|
2354
2369
|
registerImportMethod(path, "mergeProps");
|
|
2355
2370
|
props = [t__namespace.callExpression(t__namespace.identifier("_$mergeProps"), props)];
|
|
2356
2371
|
}
|
|
@@ -2536,7 +2551,7 @@ function transformNode(path, info = {}) {
|
|
|
2536
2551
|
config.wrapConditionals &&
|
|
2537
2552
|
config.generate !== "ssr" &&
|
|
2538
2553
|
(t__namespace.isLogicalExpression(node.expression) || t__namespace.isConditionalExpression(node.expression))
|
|
2539
|
-
? transformCondition(path.get("expression"))
|
|
2554
|
+
? transformCondition(path.get("expression"), info.componentChild)
|
|
2540
2555
|
: !info.componentChild &&
|
|
2541
2556
|
(config.generate !== "ssr" || info.fragmentChild) &&
|
|
2542
2557
|
t__namespace.isCallExpression(node.expression) &&
|
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.30.
|
|
4
|
+
"version": "0.30.7",
|
|
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": "41e356571808b2c331783a406312a05977ab316c"
|
|
27
27
|
}
|