babel-plugin-jsx-dom-expressions 0.30.5 → 0.30.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 +20 -14
- 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,20 @@ 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
450
|
if (dTest) {
|
|
451
|
+
if (inline) return t__namespace.arrowFunctionExpression([], expr);
|
|
452
|
+
|
|
443
453
|
const statements = [
|
|
444
454
|
t__namespace.variableDeclaration("const", [
|
|
445
455
|
t__namespace.variableDeclarator(
|
|
@@ -2322,12 +2332,8 @@ function transformComponent(path) {
|
|
|
2322
2332
|
config.generate !== "ssr" &&
|
|
2323
2333
|
(t__namespace.isLogicalExpression(value.expression) ||
|
|
2324
2334
|
t__namespace.isConditionalExpression(value.expression))
|
|
2325
|
-
? transformCondition(attribute.get("value").get("expression"))
|
|
2335
|
+
? transformCondition(attribute.get("value").get("expression"), true)
|
|
2326
2336
|
: t__namespace.arrowFunctionExpression([], value.expression);
|
|
2327
|
-
if (expr.length > 1) {
|
|
2328
|
-
exprs.push(expr[0]);
|
|
2329
|
-
expr = expr[1];
|
|
2330
|
-
}
|
|
2331
2337
|
runningObject.push(
|
|
2332
2338
|
t__namespace.objectMethod(
|
|
2333
2339
|
"get",
|
|
@@ -2547,7 +2553,7 @@ function transformNode(path, info = {}) {
|
|
|
2547
2553
|
config.wrapConditionals &&
|
|
2548
2554
|
config.generate !== "ssr" &&
|
|
2549
2555
|
(t__namespace.isLogicalExpression(node.expression) || t__namespace.isConditionalExpression(node.expression))
|
|
2550
|
-
? transformCondition(path.get("expression"))
|
|
2556
|
+
? transformCondition(path.get("expression"), info.componentChild)
|
|
2551
2557
|
: !info.componentChild &&
|
|
2552
2558
|
(config.generate !== "ssr" || info.fragmentChild) &&
|
|
2553
2559
|
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.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": "a2cc48a877bd4edff32f398c6c84d0b7bf6d584e"
|
|
27
27
|
}
|