babel-plugin-jsx-dom-expressions 0.30.5 → 0.30.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 +22 -17
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -319,12 +319,13 @@ function isDynamic(path, { checkMember, checkTags, checkCallExpressions = true,
|
|
|
319
319
|
|
|
320
320
|
function getStaticExpression(path) {
|
|
321
321
|
const node = path.node;
|
|
322
|
-
let value;
|
|
322
|
+
let value, type;
|
|
323
323
|
return (
|
|
324
324
|
t__namespace.isJSXExpressionContainer(node) &&
|
|
325
325
|
t__namespace.isJSXElement(path.parent) &&
|
|
326
326
|
!isComponent(getTagName(path.parent)) &&
|
|
327
327
|
(value = path.get("expression").evaluate().value) !== undefined &&
|
|
328
|
+
((type = typeof value) === "string" || type === "number") &&
|
|
328
329
|
value
|
|
329
330
|
);
|
|
330
331
|
}
|
|
@@ -392,12 +393,10 @@ function wrappedByText(list, startIndex) {
|
|
|
392
393
|
return false;
|
|
393
394
|
}
|
|
394
395
|
|
|
395
|
-
function transformCondition(path, deep) {
|
|
396
|
+
function transformCondition(path, inline, deep) {
|
|
396
397
|
const config = getConfig(path);
|
|
397
398
|
const expr = path.node;
|
|
398
|
-
|
|
399
|
-
registerImportMethod(path, config.memoWrapper);
|
|
400
|
-
}
|
|
399
|
+
registerImportMethod(path, config.memoWrapper);
|
|
401
400
|
let dTest, cond, id;
|
|
402
401
|
if (
|
|
403
402
|
t__namespace.isConditionalExpression(expr) &&
|
|
@@ -409,15 +408,20 @@ function transformCondition(path, deep) {
|
|
|
409
408
|
dTest = isDynamic(path.get("test"), { checkMember: true });
|
|
410
409
|
if (dTest) {
|
|
411
410
|
cond = expr.test;
|
|
412
|
-
id = path.scope.generateUidIdentifier("_c$");
|
|
413
411
|
if (!t__namespace.isBinaryExpression(cond))
|
|
414
412
|
cond = t__namespace.unaryExpression("!", t__namespace.unaryExpression("!", cond, true), true);
|
|
413
|
+
id = inline
|
|
414
|
+
? t__namespace.callExpression(t__namespace.identifier(`_$${config.memoWrapper}`), [
|
|
415
|
+
t__namespace.arrowFunctionExpression([], cond),
|
|
416
|
+
t__namespace.booleanLiteral(true)
|
|
417
|
+
])
|
|
418
|
+
: path.scope.generateUidIdentifier("_c$");
|
|
415
419
|
expr.test = t__namespace.callExpression(id, []);
|
|
416
420
|
if (t__namespace.isConditionalExpression(expr.consequent) || t__namespace.isLogicalExpression(expr.consequent)) {
|
|
417
|
-
expr.consequent = transformCondition(path.get("consequent"), true);
|
|
421
|
+
expr.consequent = transformCondition(path.get("consequent"), inline, true);
|
|
418
422
|
}
|
|
419
423
|
if (t__namespace.isConditionalExpression(expr.alternate) || t__namespace.isLogicalExpression(expr.alternate)) {
|
|
420
|
-
expr.alternate = transformCondition(path.get("alternate"), true);
|
|
424
|
+
expr.alternate = transformCondition(path.get("alternate"), inline, true);
|
|
421
425
|
}
|
|
422
426
|
}
|
|
423
427
|
} else if (t__namespace.isLogicalExpression(expr)) {
|
|
@@ -433,13 +437,18 @@ function transformCondition(path, deep) {
|
|
|
433
437
|
}));
|
|
434
438
|
if (dTest) {
|
|
435
439
|
cond = nextPath.node.left;
|
|
436
|
-
id = path.scope.generateUidIdentifier("_c$");
|
|
437
440
|
if (!t__namespace.isBinaryExpression(cond))
|
|
438
441
|
cond = t__namespace.unaryExpression("!", t__namespace.unaryExpression("!", cond, true), true);
|
|
442
|
+
id = inline
|
|
443
|
+
? t__namespace.callExpression(t__namespace.identifier(`_$${config.memoWrapper}`), [
|
|
444
|
+
t__namespace.arrowFunctionExpression([], cond),
|
|
445
|
+
t__namespace.booleanLiteral(true)
|
|
446
|
+
])
|
|
447
|
+
: path.scope.generateUidIdentifier("_c$");
|
|
439
448
|
nextPath.node.left = t__namespace.callExpression(id, []);
|
|
440
449
|
}
|
|
441
450
|
}
|
|
442
|
-
if (dTest) {
|
|
451
|
+
if (dTest && !inline) {
|
|
443
452
|
const statements = [
|
|
444
453
|
t__namespace.variableDeclaration("const", [
|
|
445
454
|
t__namespace.variableDeclarator(
|
|
@@ -2322,12 +2331,8 @@ function transformComponent(path) {
|
|
|
2322
2331
|
config.generate !== "ssr" &&
|
|
2323
2332
|
(t__namespace.isLogicalExpression(value.expression) ||
|
|
2324
2333
|
t__namespace.isConditionalExpression(value.expression))
|
|
2325
|
-
? transformCondition(attribute.get("value").get("expression"))
|
|
2334
|
+
? transformCondition(attribute.get("value").get("expression"), true)
|
|
2326
2335
|
: t__namespace.arrowFunctionExpression([], value.expression);
|
|
2327
|
-
if (expr.length > 1) {
|
|
2328
|
-
exprs.push(expr[0]);
|
|
2329
|
-
expr = expr[1];
|
|
2330
|
-
}
|
|
2331
2336
|
runningObject.push(
|
|
2332
2337
|
t__namespace.objectMethod(
|
|
2333
2338
|
"get",
|
|
@@ -2445,7 +2450,7 @@ function transformFragmentChildren(children, results, config) {
|
|
|
2445
2450
|
if (v.length) memo.push(t__namespace.stringLiteral(v));
|
|
2446
2451
|
} else {
|
|
2447
2452
|
const child = transformNode(path, { topLevel: true, fragmentChild: true });
|
|
2448
|
-
memo.push(createTemplate$3(path, child,
|
|
2453
|
+
memo.push(createTemplate$3(path, child, true));
|
|
2449
2454
|
}
|
|
2450
2455
|
return memo;
|
|
2451
2456
|
}, []);
|
|
@@ -2547,7 +2552,7 @@ function transformNode(path, info = {}) {
|
|
|
2547
2552
|
config.wrapConditionals &&
|
|
2548
2553
|
config.generate !== "ssr" &&
|
|
2549
2554
|
(t__namespace.isLogicalExpression(node.expression) || t__namespace.isConditionalExpression(node.expression))
|
|
2550
|
-
? transformCondition(path.get("expression"))
|
|
2555
|
+
? transformCondition(path.get("expression"), info.componentChild)
|
|
2551
2556
|
: !info.componentChild &&
|
|
2552
2557
|
(config.generate !== "ssr" || info.fragmentChild) &&
|
|
2553
2558
|
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.9",
|
|
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": "a31ebd7b178840291107cb7156157f6df74524b2"
|
|
27
27
|
}
|