@barefootjs/test 0.18.5 → 0.19.0

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 +196 -86
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -189250,6 +189250,32 @@ var VOID_ELEMENTS = new Set([
189250
189250
  "track",
189251
189251
  "wbr"
189252
189252
  ]);
189253
+ var SKELETON_PATH_HAZARD_TAGS = new Set([
189254
+ "table",
189255
+ "thead",
189256
+ "tbody",
189257
+ "tfoot",
189258
+ "caption",
189259
+ "colgroup",
189260
+ "col",
189261
+ "select",
189262
+ "optgroup",
189263
+ "p",
189264
+ "pre",
189265
+ "textarea",
189266
+ "listing",
189267
+ "template",
189268
+ "math"
189269
+ ]);
189270
+ var SKELETON_PATH_FORCE_CLOSE_GROUPS = [
189271
+ new Set(["a"]),
189272
+ new Set(["button"]),
189273
+ new Set(["form"]),
189274
+ new Set(["option"]),
189275
+ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]),
189276
+ new Set(["dd", "dt"]),
189277
+ new Set(["li"])
189278
+ ];
189253
189279
 
189254
189280
  // ../jsx/src/prop-rewrite.ts
189255
189281
  function collectAstPropRefs(node, propNames, out) {
@@ -189777,6 +189803,8 @@ function needsTypeBasedDetection(source) {
189777
189803
  return true;
189778
189804
  if (/\.map\s*\(/.test(source))
189779
189805
  return true;
189806
+ if (source.includes("createSelector"))
189807
+ return true;
189780
189808
  return false;
189781
189809
  }
189782
189810
  function findBrandPackageImportLoc(sourceFile, filePath) {
@@ -190753,6 +190781,7 @@ var CLIENT_EXPORTS = new Set([
190753
190781
  "createEffect",
190754
190782
  "createDisposableEffect",
190755
190783
  "createMemo",
190784
+ "createSelector",
190756
190785
  "createRoot",
190757
190786
  "onCleanup",
190758
190787
  "onMount",
@@ -191536,12 +191565,13 @@ function extractProps(param, ctx) {
191536
191565
  continue;
191537
191566
  }
191538
191567
  const sourcePropName = element.propertyName && import_typescript8.default.isIdentifier(element.propertyName) ? element.propertyName.text : localName;
191539
- const resolvedType = memberTypes?.get(sourcePropName) ?? { kind: "unknown", raw: "unknown" };
191568
+ const member = memberTypes?.get(sourcePropName);
191569
+ const resolvedType = member?.type ?? { kind: "unknown", raw: "unknown" };
191540
191570
  const defaultContainsArrow = element.initializer ? nodeContainsArrow(element.initializer) : false;
191541
191571
  ctx.propsParams.push({
191542
191572
  name: localName,
191543
191573
  type: resolvedType,
191544
- optional: !!element.initializer,
191574
+ optional: !!member?.optional || !!element.initializer,
191545
191575
  defaultValue,
191546
191576
  defaultContainsArrow: defaultContainsArrow || undefined
191547
191577
  });
@@ -191606,11 +191636,12 @@ function collectMemberTypes(typeNode, ctx) {
191606
191636
  const fromMembers = (members) => {
191607
191637
  const map = new Map;
191608
191638
  for (const member of members) {
191609
- if (import_typescript8.default.isPropertySignature(member) && member.name && member.type && !member.questionToken) {
191610
- const info = typeNodeToTypeInfo(member.type, ctx.sourceFile);
191611
- if (info && isResolvablePrimitive(info)) {
191612
- map.set(member.name.getText(ctx.sourceFile), info);
191613
- }
191639
+ if (import_typescript8.default.isPropertySignature(member) && member.name) {
191640
+ const info = member.type ? typeNodeToTypeInfo(member.type, ctx.sourceFile) : null;
191641
+ map.set(member.name.getText(ctx.sourceFile), {
191642
+ type: info && isResolvablePrimitive(info) ? info : null,
191643
+ optional: !!member.questionToken
191644
+ });
191614
191645
  }
191615
191646
  }
191616
191647
  return map;
@@ -192705,9 +192736,15 @@ function exprHasFunctionCalls(expr) {
192705
192736
  return found;
192706
192737
  }
192707
192738
  function rewriteBarePropRefs2(text, expr, ctx) {
192708
- const propNames = getDestructuredPropNames(ctx);
192739
+ let propNames = getDestructuredPropNames(ctx);
192709
192740
  if (!propNames)
192710
192741
  return;
192742
+ if (ctx.loopParams.size > 0) {
192743
+ const filtered = new Set([...propNames].filter((n) => !ctx.loopParams.has(n)));
192744
+ if (filtered.size === 0)
192745
+ return;
192746
+ propNames = filtered;
192747
+ }
192711
192748
  const extraPropRefs = collectBranchLocalPropRefsViaSubstitution(expr, ctx);
192712
192749
  return rewriteBarePropRefs(text, expr, propNames, extraPropRefs);
192713
192750
  }
@@ -192873,26 +192910,29 @@ function makeBindingEnv(ctx) {
192873
192910
  function parseValueExpr(trimmed) {
192874
192911
  return parseExpression(trimmed.startsWith("{") ? `(${trimmed})` : trimmed);
192875
192912
  }
192876
- function attachParsedExpressions(node) {
192913
+ var EMPTY_BOUND = new Set;
192914
+ function attachParsedExpressions(node, analyzer, bound = EMPTY_BOUND) {
192915
+ const parse2 = (trimmed) => resolveCallbackMethodFunctionReferences(parseExpression(trimmed), analyzer, bound);
192916
+ const parseValue = (trimmed) => resolveCallbackMethodFunctionReferences(parseValueExpr(trimmed), analyzer, bound);
192877
192917
  if (node.type === "expression") {
192878
192918
  const trimmed = node.expr.trim();
192879
192919
  if (trimmed)
192880
- node.parsed = parseExpression(trimmed);
192920
+ node.parsed = parse2(trimmed);
192881
192921
  } else if (node.type === "conditional" || node.type === "if-statement") {
192882
192922
  const trimmed = node.condition.trim();
192883
192923
  if (trimmed)
192884
- node.parsedCondition = parseExpression(trimmed);
192924
+ node.parsedCondition = parse2(trimmed);
192885
192925
  }
192886
192926
  if (node.type === "element") {
192887
192927
  for (const attr of node.attrs) {
192888
192928
  if (attr.value.kind === "expression") {
192889
192929
  const trimmed = attr.value.expr.trim();
192890
192930
  if (trimmed)
192891
- attr.value.parsed = parseValueExpr(trimmed);
192931
+ attr.value.parsed = parseValue(trimmed);
192892
192932
  } else if (attr.value.kind === "spread") {
192893
192933
  const trimmed = attr.value.expr.trim();
192894
192934
  if (trimmed)
192895
- attr.value.parsed = parseExpression(trimmed);
192935
+ attr.value.parsed = parse2(trimmed);
192896
192936
  }
192897
192937
  }
192898
192938
  } else if (node.type === "component") {
@@ -192900,14 +192940,14 @@ function attachParsedExpressions(node) {
192900
192940
  if (prop.value.kind === "expression") {
192901
192941
  const trimmed = prop.value.expr.trim();
192902
192942
  if (trimmed)
192903
- prop.value.parsed = parseValueExpr(trimmed);
192943
+ prop.value.parsed = parseValue(trimmed);
192904
192944
  }
192905
192945
  }
192906
192946
  } else if (node.type === "provider") {
192907
192947
  if (node.valueProp.value.kind === "expression") {
192908
192948
  const trimmed = node.valueProp.value.expr.trim();
192909
192949
  if (trimmed)
192910
- node.valueProp.value.parsed = parseValueExpr(trimmed);
192950
+ node.valueProp.value.parsed = parseValue(trimmed);
192911
192951
  }
192912
192952
  }
192913
192953
  switch (node.type) {
@@ -192916,47 +192956,51 @@ function attachParsedExpressions(node) {
192916
192956
  case "fragment":
192917
192957
  case "provider":
192918
192958
  for (const child of node.children)
192919
- attachParsedExpressions(child);
192959
+ attachParsedExpressions(child, analyzer, bound);
192920
192960
  break;
192921
192961
  case "async":
192922
- attachParsedExpressions(node.fallback);
192962
+ attachParsedExpressions(node.fallback, analyzer, bound);
192923
192963
  for (const child of node.children)
192924
- attachParsedExpressions(child);
192964
+ attachParsedExpressions(child, analyzer, bound);
192925
192965
  break;
192926
192966
  case "loop": {
192927
192967
  const trimmedArray = node.array.trim();
192928
192968
  if (trimmedArray)
192929
- node.arrayParsed = parseExpression(trimmedArray);
192969
+ node.arrayParsed = parse2(trimmedArray);
192970
+ const loopBound = new Set(bound);
192971
+ loopBound.add(node.param);
192972
+ if (node.index)
192973
+ loopBound.add(node.index);
192930
192974
  for (const child of node.children)
192931
- attachParsedExpressions(child);
192975
+ attachParsedExpressions(child, analyzer, loopBound);
192932
192976
  if (node.childComponent) {
192933
192977
  for (const child of node.childComponent.children)
192934
- attachParsedExpressions(child);
192978
+ attachParsedExpressions(child, analyzer, loopBound);
192935
192979
  }
192936
192980
  for (const nested of node.nestedComponents ?? []) {
192937
192981
  for (const child of nested.children)
192938
- attachParsedExpressions(child);
192982
+ attachParsedExpressions(child, analyzer, loopBound);
192939
192983
  }
192940
192984
  for (const frag of node.flatMapCallback?.fragments ?? []) {
192941
- attachParsedExpressions(frag.ir);
192985
+ attachParsedExpressions(frag.ir, analyzer, loopBound);
192942
192986
  }
192943
192987
  break;
192944
192988
  }
192945
192989
  case "conditional":
192946
- attachParsedExpressions(node.whenTrue);
192947
- attachParsedExpressions(node.whenFalse);
192990
+ attachParsedExpressions(node.whenTrue, analyzer, bound);
192991
+ attachParsedExpressions(node.whenFalse, analyzer, bound);
192948
192992
  break;
192949
192993
  case "if-statement":
192950
- attachParsedExpressions(node.consequent);
192994
+ attachParsedExpressions(node.consequent, analyzer, bound);
192951
192995
  if (node.alternate)
192952
- attachParsedExpressions(node.alternate);
192996
+ attachParsedExpressions(node.alternate, analyzer, bound);
192953
192997
  break;
192954
192998
  }
192955
192999
  }
192956
193000
  function jsxToIR(analyzer) {
192957
193001
  const root = buildIRRoot(analyzer);
192958
193002
  if (root)
192959
- attachParsedExpressions(root);
193003
+ attachParsedExpressions(root, analyzer);
192960
193004
  return root;
192961
193005
  }
192962
193006
  function buildIRRoot(analyzer) {
@@ -194043,8 +194087,8 @@ function extractSortComparator(callback, _method, ctx) {
194043
194087
  };
194044
194088
  }
194045
194089
  function resolveSortComparatorIdentifier(name, ctx) {
194046
- const constInfo = findLocalConst(name, ctx);
194047
- const fnInfo = findLocalFunction(name, ctx);
194090
+ const constInfo = findLocalConst(name, ctx.analyzer);
194091
+ const fnInfo = findLocalFunction(name, ctx.analyzer);
194048
194092
  if (constInfo && fnInfo)
194049
194093
  return null;
194050
194094
  if (constInfo) {
@@ -194057,6 +194101,72 @@ function resolveSortComparatorIdentifier(name, ctx) {
194057
194101
  }
194058
194102
  return null;
194059
194103
  }
194104
+ function resolveCallbackMethodFunctionReferenceIdentifier(name, analyzer) {
194105
+ const constInfo = findLocalConst(name, analyzer);
194106
+ const fnInfo = findLocalFunction(name, analyzer);
194107
+ if (constInfo && fnInfo)
194108
+ return null;
194109
+ if (constInfo) {
194110
+ const ast = parseConstInitializer(constInfo);
194111
+ return ast && (import_typescript11.default.isArrowFunction(ast) || import_typescript11.default.isFunctionExpression(ast)) ? ast : null;
194112
+ }
194113
+ if (fnInfo) {
194114
+ const ast = parseFunctionInfoAsExpr(fnInfo);
194115
+ return ast && (import_typescript11.default.isArrowFunction(ast) || import_typescript11.default.isFunctionExpression(ast)) ? ast : null;
194116
+ }
194117
+ return null;
194118
+ }
194119
+ function resolveCallbackMethodFunctionReferences(expr, analyzer, bound = EMPTY_BOUND) {
194120
+ function visit2(e, bound2) {
194121
+ switch (e.kind) {
194122
+ case "literal":
194123
+ case "identifier":
194124
+ case "regex":
194125
+ case "unsupported":
194126
+ return e;
194127
+ case "call": {
194128
+ const callee = visit2(e.callee, bound2);
194129
+ const args = e.args.map((a) => visit2(a, bound2));
194130
+ if (callee.kind === "member" && !callee.computed && CALLBACK_METHODS.has(callee.property) && args[0]?.kind === "identifier" && !bound2.has(args[0].name)) {
194131
+ const resolved = resolveCallbackMethodFunctionReferenceIdentifier(args[0].name, analyzer);
194132
+ const arrow = resolved ? tsNodeToParsedExpr(resolved) : null;
194133
+ if (arrow && arrow.kind === "arrow")
194134
+ args[0] = arrow;
194135
+ }
194136
+ return { ...e, callee, args };
194137
+ }
194138
+ case "member":
194139
+ return { ...e, object: visit2(e.object, bound2) };
194140
+ case "index-access":
194141
+ return { ...e, object: visit2(e.object, bound2), index: visit2(e.index, bound2) };
194142
+ case "binary":
194143
+ case "logical":
194144
+ return { ...e, left: visit2(e.left, bound2), right: visit2(e.right, bound2) };
194145
+ case "unary":
194146
+ return { ...e, argument: visit2(e.argument, bound2) };
194147
+ case "conditional":
194148
+ return { ...e, test: visit2(e.test, bound2), consequent: visit2(e.consequent, bound2), alternate: visit2(e.alternate, bound2) };
194149
+ case "template-literal":
194150
+ return { ...e, parts: e.parts.map((p) => p.type === "expression" ? { ...p, expr: visit2(p.expr, bound2) } : p) };
194151
+ case "array-literal":
194152
+ return { ...e, elements: e.elements.map((el) => visit2(el, bound2)) };
194153
+ case "array-method":
194154
+ return {
194155
+ ...e,
194156
+ object: visit2(e.object, bound2),
194157
+ args: e.args.map((a) => visit2(a, bound2)),
194158
+ ...e.method === "flat" && e.depthExpr ? { depthExpr: visit2(e.depthExpr, bound2) } : {}
194159
+ };
194160
+ case "object-literal":
194161
+ return { ...e, properties: e.properties.map((p) => ({ ...p, value: visit2(p.value, bound2) })) };
194162
+ case "arrow": {
194163
+ const inner = e.params.length === 0 ? bound2 : new Set([...bound2, ...e.params]);
194164
+ return { ...e, body: visit2(e.body, inner) };
194165
+ }
194166
+ }
194167
+ }
194168
+ return visit2(expr, bound);
194169
+ }
194060
194170
  function extractFilterPredicate(callback, ctx) {
194061
194171
  if (!import_typescript11.default.isArrowFunction(callback))
194062
194172
  return { result: null };
@@ -194524,13 +194634,11 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
194524
194634
  setArray(innerSort.array);
194525
194635
  }
194526
194636
  } else {
194527
- array = ctx.getJS(filterInfo.array);
194528
- arrayExpr = filterInfo.array;
194637
+ setArray(filterInfo.array);
194529
194638
  }
194530
194639
  }
194531
194640
  } else {
194532
- array = ctx.getJS(chainSource);
194533
- arrayExpr = chainSource;
194641
+ setArray(chainSource);
194534
194642
  }
194535
194643
  const callback = node.arguments[0];
194536
194644
  let param = "item";
@@ -195080,7 +195188,7 @@ function parseTemplateLiteral(expr, ctx) {
195080
195188
  }
195081
195189
  function tryResolveTemplateSpanFromConst(expr, ctx) {
195082
195190
  if (import_typescript11.default.isIdentifier(expr)) {
195083
- const constInfo = findLocalConst(expr.text, ctx);
195191
+ const constInfo = findLocalConst(expr.text, ctx.analyzer);
195084
195192
  if (!constInfo)
195085
195193
  return null;
195086
195194
  const ast = parseConstInitializer(constInfo);
@@ -195094,7 +195202,7 @@ function tryResolveTemplateSpanFromConst(expr, ctx) {
195094
195202
  if (import_typescript11.default.isElementAccessExpression(expr)) {
195095
195203
  if (!import_typescript11.default.isIdentifier(expr.expression))
195096
195204
  return null;
195097
- const constInfo = findLocalConst(expr.expression.text, ctx);
195205
+ const constInfo = findLocalConst(expr.expression.text, ctx.analyzer);
195098
195206
  if (!constInfo)
195099
195207
  return null;
195100
195208
  const ast = parseConstInitializer(constInfo);
@@ -195120,16 +195228,16 @@ function tryResolveTemplateSpanFromConst(expr, ctx) {
195120
195228
  }
195121
195229
  return null;
195122
195230
  }
195123
- function findLocalConst(name, ctx) {
195124
- const matches = ctx.analyzer.localConstants.filter((c) => c.name === name);
195231
+ function findLocalConst(name, analyzer) {
195232
+ const matches = analyzer.localConstants.filter((c) => c.name === name);
195125
195233
  if (matches.length === 0)
195126
195234
  return;
195127
195235
  const fnScoped = matches.filter((c) => !c.isModule);
195128
195236
  const pool = fnScoped.length > 0 ? fnScoped : matches;
195129
195237
  return pool[pool.length - 1];
195130
195238
  }
195131
- function findLocalFunction(name, ctx) {
195132
- const matches = ctx.analyzer.localFunctions.filter((f) => f.name === name);
195239
+ function findLocalFunction(name, analyzer) {
195240
+ const matches = analyzer.localFunctions.filter((f) => f.name === name);
195133
195241
  if (matches.length === 0)
195134
195242
  return;
195135
195243
  const fnScoped = matches.filter((f) => !f.isModule);
@@ -195171,7 +195279,9 @@ function hasDynamicTagBinding(name, sourceFile) {
195171
195279
  return found;
195172
195280
  }
195173
195281
  function tryResolveIdentifierAsTemplateLiteral(ident, ctx) {
195174
- const constInfo = findLocalConst(ident.text, ctx);
195282
+ if (ctx.loopParams.has(ident.text))
195283
+ return null;
195284
+ const constInfo = findLocalConst(ident.text, ctx.analyzer);
195175
195285
  if (!constInfo)
195176
195286
  return null;
195177
195287
  const ast = parseConstInitializer(constInfo);
@@ -195268,8 +195378,8 @@ function tryDesugarInterleaveTaggedTemplate(expr, ctx) {
195268
195378
  return rewritten ?? expr;
195269
195379
  }
195270
195380
  function resolveInterleaveTagIdentifier(name, ctx) {
195271
- const constInfo = findLocalConst(name, ctx);
195272
- const fnInfo = findLocalFunction(name, ctx);
195381
+ const constInfo = findLocalConst(name, ctx.analyzer);
195382
+ const fnInfo = findLocalFunction(name, ctx.analyzer);
195273
195383
  if (constInfo && fnInfo)
195274
195384
  return null;
195275
195385
  if (constInfo) {
@@ -195794,6 +195904,49 @@ function buildIfStatementChain(analyzer, ctx) {
195794
195904
  return alternate;
195795
195905
  }
195796
195906
 
195907
+ // ../jsx/src/ir-to-client-js/control-flow/stringify/template-parse.ts
195908
+ var SVG_ROOT_TAGS = new Set([
195909
+ "svg",
195910
+ "path",
195911
+ "circle",
195912
+ "rect",
195913
+ "line",
195914
+ "polyline",
195915
+ "polygon",
195916
+ "ellipse",
195917
+ "text",
195918
+ "tspan",
195919
+ "textPath",
195920
+ "g",
195921
+ "defs",
195922
+ "use",
195923
+ "symbol",
195924
+ "switch",
195925
+ "clipPath",
195926
+ "mask",
195927
+ "marker",
195928
+ "pattern",
195929
+ "linearGradient",
195930
+ "radialGradient",
195931
+ "stop",
195932
+ "image",
195933
+ "foreignObject",
195934
+ "filter",
195935
+ "feBlend",
195936
+ "feColorMatrix",
195937
+ "feComposite",
195938
+ "feFlood",
195939
+ "feGaussianBlur",
195940
+ "feMerge",
195941
+ "feMergeNode",
195942
+ "feMorphology",
195943
+ "feOffset",
195944
+ "feTurbulence",
195945
+ "animate",
195946
+ "animateTransform",
195947
+ "animateMotion"
195948
+ ]);
195949
+
195797
195950
  // ../jsx/src/ir-to-client-js/collect-elements.ts
195798
195951
  var EMPTY_RENDER_EXPRS = new Set(["null", "undefined", "false", "''", '""', "``"]);
195799
195952
 
@@ -196009,49 +196162,6 @@ var QUERY_HREF_SOURCES = new Set([
196009
196162
  "@barefootjs/client/runtime"
196010
196163
  ]);
196011
196164
 
196012
- // ../jsx/src/ir-to-client-js/control-flow/stringify/template-parse.ts
196013
- var SVG_ROOT_TAGS = new Set([
196014
- "svg",
196015
- "path",
196016
- "circle",
196017
- "rect",
196018
- "line",
196019
- "polyline",
196020
- "polygon",
196021
- "ellipse",
196022
- "text",
196023
- "tspan",
196024
- "textPath",
196025
- "g",
196026
- "defs",
196027
- "use",
196028
- "symbol",
196029
- "switch",
196030
- "clipPath",
196031
- "mask",
196032
- "marker",
196033
- "pattern",
196034
- "linearGradient",
196035
- "radialGradient",
196036
- "stop",
196037
- "image",
196038
- "foreignObject",
196039
- "filter",
196040
- "feBlend",
196041
- "feColorMatrix",
196042
- "feComposite",
196043
- "feFlood",
196044
- "feGaussianBlur",
196045
- "feMerge",
196046
- "feMergeNode",
196047
- "feMorphology",
196048
- "feOffset",
196049
- "feTurbulence",
196050
- "animate",
196051
- "animateTransform",
196052
- "animateMotion"
196053
- ]);
196054
-
196055
196165
  // ../jsx/src/ir-to-client-js/control-flow/stringify/event-delegation.ts
196056
196166
  var NON_BUBBLING_EVENTS = new Set([
196057
196167
  "blur",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barefootjs/test",
3
- "version": "0.18.5",
3
+ "version": "0.19.0",
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.18.5"
42
+ "@barefootjs/jsx": "0.19.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "typescript": "^5.0.0"