babel-plugin-jsx-dom-expressions 0.30.3 → 0.30.8

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.
Files changed (2) hide show
  1. package/index.js +33 -18
  2. 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
- if (config.memoWrapper) {
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(
@@ -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 &&
@@ -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,7 +2238,7 @@ function transformComponent(path) {
2219
2238
  props.push(
2220
2239
  isDynamic(attribute.get("argument"), {
2221
2240
  checkMember: true
2222
- })
2241
+ }) && (dynamicSpread = true)
2223
2242
  ? t__namespace.isCallExpression(node.argument) && !node.argument.arguments.length
2224
2243
  ? node.argument.callee
2225
2244
  : t__namespace.arrowFunctionExpression([], 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
  }
@@ -2434,7 +2449,7 @@ function transformFragmentChildren(children, results, config) {
2434
2449
  if (v.length) memo.push(t__namespace.stringLiteral(v));
2435
2450
  } else {
2436
2451
  const child = transformNode(path, { topLevel: true, fragmentChild: true });
2437
- memo.push(createTemplate$3(path, child, !singleChild));
2452
+ memo.push(createTemplate$3(path, child, true));
2438
2453
  }
2439
2454
  return memo;
2440
2455
  }, []);
@@ -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.3",
4
+ "version": "0.30.8",
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": "4eb94a2d860cb1b1fa09cce9b47c52e72f2e6648"
26
+ "gitHead": "b8381ac126158615afb3438a31c8c35204a0cfaf"
27
27
  }