@barefootjs/test 0.33.3 → 0.33.4

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 +46 -8
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -196461,6 +196461,10 @@ function extractLoopKey(node) {
196461
196461
  return null;
196462
196462
  return normalizeKeyExpr(a) === normalizeKeyExpr(b) ? a : null;
196463
196463
  }
196464
+ if (node.type === "fragment") {
196465
+ const first = node.children.find((c) => !(c.type === "text" && typeof c.value === "string" && !c.value.trim()));
196466
+ return first ? extractLoopKey(first) : null;
196467
+ }
196464
196468
  return null;
196465
196469
  }
196466
196470
  function keyAttrValueToExpr(v) {
@@ -196651,7 +196655,7 @@ function leafIsWirelessElement(el) {
196651
196655
  }
196652
196656
  if (import_typescript13.default.isJsxAttribute(attr)) {
196653
196657
  const name = attr.name.getText();
196654
- if (/^on[A-Z]/.test(name)) {
196658
+ if (isEventHandlerAttrName(name)) {
196655
196659
  ok = false;
196656
196660
  return;
196657
196661
  }
@@ -196707,6 +196711,12 @@ function applyLoopKeyAttr(node, name, value) {
196707
196711
  if (node.type === "conditional") {
196708
196712
  applyLoopKeyAttr(node.whenTrue, name, value);
196709
196713
  applyLoopKeyAttr(node.whenFalse, name, value);
196714
+ return;
196715
+ }
196716
+ if (node.type === "fragment") {
196717
+ const first = node.children.find((c) => !(c.type === "text" && typeof c.value === "string" && !c.value.trim()));
196718
+ if (first)
196719
+ applyLoopKeyAttr(first, name, value);
196710
196720
  }
196711
196721
  }
196712
196722
  function loopBodyItemConditional(children) {
@@ -196939,7 +196949,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
196939
196949
  children = [foldMultiReturnBranches(multiReturn, ctx, loc, ctx.getJS)];
196940
196950
  const pre = multiReturn.preamble ?? [];
196941
196951
  if (pre.length > 0) {
196942
- preamble = preambleFromValueStatements(pre, ctx);
196952
+ preamble = preambleFromValueStatements(pre, ctx, body.statements);
196943
196953
  if (!preamble.declarations && !isClientOnly && !(ctx.analyzer.acceptsCallbackBody?.("map") ?? false)) {
196944
196954
  ctx.analyzer.errors.push(createError(ErrorCodes.UNSUPPORTED_JSX_PATTERN, loc, {
196945
196955
  message: "A .map() callback body with a preamble before its branches cannot be " + "lowered to a template: the preamble is not a sequence of value " + "declarations, so this backend has no per-row local to carry into the " + "branches.",
@@ -197026,7 +197036,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
197026
197036
  valueStmts.push(stmt);
197027
197037
  }
197028
197038
  if (valueStmts.length > 0) {
197029
- preamble = preambleFromValueStatements(valueStmts, ctx);
197039
+ preamble = preambleFromValueStatements(valueStmts, ctx, body.statements);
197030
197040
  if (!preamble.declarations && !isClientOnly && !(ctx.analyzer.acceptsCallbackBody?.("map") ?? false)) {
197031
197041
  ctx.analyzer.errors.push(createError(ErrorCodes.UNSUPPORTED_JSX_PATTERN, getSourceLocation(body, ctx.sourceFile, ctx.filePath), {
197032
197042
  message: "A .map() callback preamble that is not a sequence of value " + "declarations cannot be lowered to a template: this backend can " + "declare a per-row local, but cannot run arbitrary statements per row.",
@@ -197489,7 +197499,7 @@ function computePreambleReactiveNames(statements, ctx) {
197489
197499
  }
197490
197500
  return reactiveNames;
197491
197501
  }
197492
- function preambleFromValueStatements(statements, ctx) {
197502
+ function preambleFromValueStatements(statements, ctx, bodyStatements) {
197493
197503
  const segments = [];
197494
197504
  const typedParts = [];
197495
197505
  const declared = new Set;
@@ -197509,11 +197519,11 @@ function preambleFromValueStatements(statements, ctx) {
197509
197519
  ssrText: tsxSourceText(typedParts.join(" ")),
197510
197520
  declaredNames: [...declared],
197511
197521
  builderNames: [],
197512
- declarations: neutralPreambleDeclarations(statements, ctx) ?? undefined,
197522
+ declarations: neutralPreambleDeclarations(statements, ctx, bodyStatements) ?? undefined,
197513
197523
  reactiveNames: reactiveNames.size > 0 ? [...reactiveNames] : undefined
197514
197524
  };
197515
197525
  }
197516
- function neutralPreambleDeclarations(statements, ctx) {
197526
+ function neutralPreambleDeclarations(statements, ctx, bodyStatements) {
197517
197527
  const out = [];
197518
197528
  for (const stmt of statements) {
197519
197529
  if (!import_typescript13.default.isVariableStatement(stmt))
@@ -197523,6 +197533,11 @@ function neutralPreambleDeclarations(statements, ctx) {
197523
197533
  return null;
197524
197534
  if (!decl.initializer)
197525
197535
  return null;
197536
+ if (isFunctionLiteral(decl.initializer)) {
197537
+ if (everyReadIsEventHandlerPropValue(decl.name.text, bodyStatements))
197538
+ continue;
197539
+ return null;
197540
+ }
197526
197541
  const valueParsed = tsNodeToParsedExpr(decl.initializer);
197527
197542
  if (!isSupported(valueParsed).supported)
197528
197543
  return null;
@@ -197533,7 +197548,30 @@ function neutralPreambleDeclarations(statements, ctx) {
197533
197548
  });
197534
197549
  }
197535
197550
  }
197536
- return out.length > 0 ? out : null;
197551
+ return out;
197552
+ }
197553
+ function isFunctionLiteral(node) {
197554
+ return import_typescript13.default.isArrowFunction(node) || import_typescript13.default.isFunctionExpression(node);
197555
+ }
197556
+ function everyReadIsEventHandlerPropValue(name, bodyStatements) {
197557
+ const findDisallowedRead = (node) => {
197558
+ if (import_typescript13.default.isIdentifier(node) && node.text === name) {
197559
+ const isBindingName = import_typescript13.default.isVariableDeclaration(node.parent) && node.parent.name === node;
197560
+ const isPropertyName = import_typescript13.default.isPropertyAccessExpression(node.parent) && node.parent.name === node;
197561
+ if (!isBindingName && !isPropertyName) {
197562
+ const jsxExpr = node.parent;
197563
+ const attr = jsxExpr.parent;
197564
+ const isEventHandlerAttrValue = import_typescript13.default.isJsxExpression(jsxExpr) && import_typescript13.default.isJsxAttribute(attr) && attr.initializer === jsxExpr && import_typescript13.default.isIdentifier(attr.name) && isEventHandlerAttrName(attr.name.text);
197565
+ if (!isEventHandlerAttrValue)
197566
+ return true;
197567
+ }
197568
+ }
197569
+ return import_typescript13.default.forEachChild(node, findDisallowedRead);
197570
+ };
197571
+ return !bodyStatements.some(findDisallowedRead);
197572
+ }
197573
+ function isEventHandlerAttrName(name) {
197574
+ return /^on[A-Z]/.test(name);
197537
197575
  }
197538
197576
  function trimPreambleSegments(segments) {
197539
197577
  const last = segments[segments.length - 1];
@@ -197730,7 +197768,7 @@ function processAttributes(attributes, ctx) {
197730
197768
  }
197731
197769
  continue;
197732
197770
  }
197733
- if (/^on[A-Z]/.test(rawName)) {
197771
+ if (isEventHandlerAttrName(rawName)) {
197734
197772
  if (attr.initializer && import_typescript13.default.isJsxExpression(attr.initializer) && attr.initializer.expression) {
197735
197773
  const eventName = rawName.slice(2).toLowerCase();
197736
197774
  reportJsxBranchLocalInCallback(attr.initializer.expression, ctx);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barefootjs/test",
3
- "version": "0.33.3",
3
+ "version": "0.33.4",
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.33.3"
42
+ "@barefootjs/jsx": "0.33.4"
43
43
  },
44
44
  "devDependencies": {
45
45
  "typescript": "^5.0.0"