@barefootjs/test 0.5.0 → 0.5.1

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/dist/index.js +87 -18
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -192681,6 +192681,23 @@ function containsJsxInExpression(node) {
192681
192681
  }
192682
192682
  return import_typescript11.default.forEachChild(node, containsJsxInExpression) ?? false;
192683
192683
  }
192684
+ function callsJsxHelper(node, ctx) {
192685
+ let found = false;
192686
+ const visit2 = (n) => {
192687
+ if (found)
192688
+ return;
192689
+ if (import_typescript11.default.isCallExpression(n) && import_typescript11.default.isIdentifier(n.expression)) {
192690
+ const name = n.expression.text;
192691
+ if (ctx.analyzer.jsxFunctions.has(name) || ctx.analyzer.jsxMultiReturnFunctions.has(name)) {
192692
+ found = true;
192693
+ return;
192694
+ }
192695
+ }
192696
+ import_typescript11.default.forEachChild(n, visit2);
192697
+ };
192698
+ visit2(node);
192699
+ return found;
192700
+ }
192684
192701
  function containsAwaitExpression(node) {
192685
192702
  if (import_typescript11.default.isAwaitExpression(node))
192686
192703
  return true;
@@ -192760,7 +192777,7 @@ function transformJsxExpression(expr, ctx, isClientOnly = false) {
192760
192777
  if (node.operatorToken.kind === import_typescript11.default.SyntaxKind.AmpersandAmpersandToken) {
192761
192778
  return transformLogicalAnd(node, ctx);
192762
192779
  }
192763
- if ((node.operatorToken.kind === import_typescript11.default.SyntaxKind.QuestionQuestionToken || node.operatorToken.kind === import_typescript11.default.SyntaxKind.BarBarToken) && containsJsxInExpression(node.right)) {
192780
+ if ((node.operatorToken.kind === import_typescript11.default.SyntaxKind.QuestionQuestionToken || node.operatorToken.kind === import_typescript11.default.SyntaxKind.BarBarToken) && (containsJsxInExpression(node.right) || callsJsxHelper(node.right, ctx))) {
192764
192781
  return transformNullishCoalescing(node, ctx);
192765
192782
  }
192766
192783
  return null;
@@ -193217,23 +193234,23 @@ function checkLoopKey(callback, ctx, isNested) {
193217
193234
  }
193218
193235
  while (import_typescript11.default.isParenthesizedExpression(body))
193219
193236
  body = body.expression;
193237
+ function checkJsxOperand(node) {
193238
+ let n = node;
193239
+ while (import_typescript11.default.isParenthesizedExpression(n))
193240
+ n = n.expression;
193241
+ if (import_typescript11.default.isJsxElement(n))
193242
+ checkOpening(n.openingElement);
193243
+ else if (import_typescript11.default.isJsxSelfClosingElement(n))
193244
+ checkOpening(n);
193245
+ }
193220
193246
  if (import_typescript11.default.isConditionalExpression(body)) {
193221
- const whenTrue = body.whenTrue;
193222
- const whenFalse = body.whenFalse;
193223
- let wt = whenTrue;
193224
- let wf = whenFalse;
193225
- while (import_typescript11.default.isParenthesizedExpression(wt))
193226
- wt = wt.expression;
193227
- while (import_typescript11.default.isParenthesizedExpression(wf))
193228
- wf = wf.expression;
193229
- if (import_typescript11.default.isJsxElement(wt))
193230
- checkOpening(wt.openingElement);
193231
- else if (import_typescript11.default.isJsxSelfClosingElement(wt))
193232
- checkOpening(wt);
193233
- if (import_typescript11.default.isJsxElement(wf))
193234
- checkOpening(wf.openingElement);
193235
- else if (import_typescript11.default.isJsxSelfClosingElement(wf))
193236
- checkOpening(wf);
193247
+ checkJsxOperand(body.whenTrue);
193248
+ checkJsxOperand(body.whenFalse);
193249
+ return;
193250
+ }
193251
+ if (import_typescript11.default.isBinaryExpression(body) && (body.operatorToken.kind === import_typescript11.default.SyntaxKind.AmpersandAmpersandToken || body.operatorToken.kind === import_typescript11.default.SyntaxKind.BarBarToken || body.operatorToken.kind === import_typescript11.default.SyntaxKind.QuestionQuestionToken)) {
193252
+ checkJsxOperand(body.left);
193253
+ checkJsxOperand(body.right);
193237
193254
  return;
193238
193255
  }
193239
193256
  if (import_typescript11.default.isJsxElement(body)) {
@@ -193256,6 +193273,38 @@ function loopBodyIsMultiRoot(children) {
193256
193273
  return false;
193257
193274
  return loopBodyIsMultiRoot(only.children);
193258
193275
  }
193276
+ function branchHasNoElement(node) {
193277
+ if (node.type === "element" || node.type === "component")
193278
+ return false;
193279
+ if (node.type === "conditional") {
193280
+ return branchHasNoElement(node.whenTrue) || branchHasNoElement(node.whenFalse);
193281
+ }
193282
+ if (node.type === "fragment") {
193283
+ const real = node.children.filter((c) => !(c.type === "text" && typeof c.value === "string" && !c.value.trim()));
193284
+ return real.length !== 1 || branchHasNoElement(real[0]);
193285
+ }
193286
+ return true;
193287
+ }
193288
+ function loopBodyItemConditional(children) {
193289
+ const real = children.filter((c) => !(c.type === "text" && typeof c.value === "string" && !c.value.trim()));
193290
+ if (real.length !== 1)
193291
+ return null;
193292
+ const only = real[0];
193293
+ if (only.type !== "conditional")
193294
+ return null;
193295
+ if (branchHasNoElement(only.whenTrue) || branchHasNoElement(only.whenFalse)) {
193296
+ return only;
193297
+ }
193298
+ return null;
193299
+ }
193300
+ function extractItemConditionalKey(cond) {
193301
+ const a = branchHasNoElement(cond.whenTrue) ? null : extractLoopKey(cond.whenTrue);
193302
+ const b = branchHasNoElement(cond.whenFalse) ? null : extractLoopKey(cond.whenFalse);
193303
+ if (a !== null && b !== null) {
193304
+ return normalizeKeyExpr(a) === normalizeKeyExpr(b) ? a : null;
193305
+ }
193306
+ return a ?? b;
193307
+ }
193259
193308
  function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
193260
193309
  const isNested = ctx.loopParams.size > 0;
193261
193310
  const propAccess = node.expression;
@@ -193418,6 +193467,19 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
193418
193467
  }
193419
193468
  if (index)
193420
193469
  ctx.loopParams.add(index);
193470
+ const tryTransformRenderableBody = (expr) => {
193471
+ if (!import_typescript11.default.isBinaryExpression(expr))
193472
+ return;
193473
+ const op = expr.operatorToken.kind;
193474
+ if (op !== import_typescript11.default.SyntaxKind.AmpersandAmpersandToken && op !== import_typescript11.default.SyntaxKind.BarBarToken && op !== import_typescript11.default.SyntaxKind.QuestionQuestionToken) {
193475
+ return;
193476
+ }
193477
+ if (!containsJsxInExpression(expr) && !callsJsxHelper(expr, ctx))
193478
+ return;
193479
+ const transformed = transformJsxExpression(expr, ctx, isClientOnly);
193480
+ if (transformed)
193481
+ children = [transformed];
193482
+ };
193421
193483
  const body = callback.body;
193422
193484
  if (import_typescript11.default.isJsxElement(body) || import_typescript11.default.isJsxSelfClosingElement(body) || import_typescript11.default.isJsxFragment(body)) {
193423
193485
  const transformed = transformNode(body, ctx);
@@ -193440,6 +193502,8 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
193440
193502
  children = [transformConditional(inner, ctx)];
193441
193503
  } else if (method === "flatMap" && import_typescript11.default.isArrayLiteralExpression(inner)) {
193442
193504
  children = transformArrayLiteralChildren(inner, ctx);
193505
+ } else {
193506
+ tryTransformRenderableBody(inner);
193443
193507
  }
193444
193508
  } else if (method === "flatMap" && import_typescript11.default.isArrayLiteralExpression(body)) {
193445
193509
  children = transformArrayLiteralChildren(body, ctx);
@@ -193488,6 +193552,8 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
193488
193552
  if (method === "flatMap" && children.length === 0) {
193489
193553
  flatMapCallback = buildFlatMapCallback(callback, body, ctx);
193490
193554
  }
193555
+ } else {
193556
+ tryTransformRenderableBody(body);
193491
193557
  }
193492
193558
  if (paramBindings) {
193493
193559
  for (const b of paramBindings)
@@ -193504,7 +193570,9 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
193504
193570
  if (import_typescript11.default.isArrowFunction(node.arguments[0]) && children.length > 0) {
193505
193571
  checkLoopKey(node.arguments[0], ctx, isNested);
193506
193572
  }
193507
- const key = children.length > 0 ? extractLoopKey(children[0]) : null;
193573
+ const itemConditional = children.length > 0 ? loopBodyItemConditional(children) : null;
193574
+ const bodyIsItemConditional = itemConditional !== null;
193575
+ const key = bodyIsItemConditional ? extractItemConditionalKey(itemConditional) : children.length > 0 ? extractLoopKey(children[0]) : null;
193508
193576
  let childComponent;
193509
193577
  if (children.length === 1 && children[0].type === "component") {
193510
193578
  const comp = children[0];
@@ -193543,6 +193611,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
193543
193611
  callsReactiveGetters: callsReactive || undefined,
193544
193612
  hasFunctionCalls: hasCalls || undefined,
193545
193613
  bodyIsMultiRoot: bodyIsMultiRoot || undefined,
193614
+ bodyIsItemConditional: bodyIsItemConditional || undefined,
193546
193615
  childComponent,
193547
193616
  nestedComponents,
193548
193617
  filterPredicate,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barefootjs/test",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Test utilities for BarefootJS - IR-based component testing without a browser",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -39,7 +39,7 @@
39
39
  "directory": "packages/test"
40
40
  },
41
41
  "dependencies": {
42
- "@barefootjs/jsx": "0.5.0"
42
+ "@barefootjs/jsx": "0.5.1"
43
43
  },
44
44
  "devDependencies": {
45
45
  "typescript": "^5.0.0"