@barefootjs/test 0.19.1 → 0.21.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 +192 -14
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -189792,6 +189792,135 @@ function internalInvariant(cond, message) {
189792
189792
  }
189793
189793
  }
189794
189794
 
189795
+ // ../jsx/src/rich-type-evidence.ts
189796
+ var HOST_RICH_TYPE_NAMES = new Set([
189797
+ "Date",
189798
+ "Map",
189799
+ "Set",
189800
+ "WeakMap",
189801
+ "WeakSet",
189802
+ "URL",
189803
+ "URLSearchParams",
189804
+ "RegExp",
189805
+ "Promise",
189806
+ "Error",
189807
+ "Symbol",
189808
+ "BigInt",
189809
+ "Function"
189810
+ ]);
189811
+ function baseTypeName(raw) {
189812
+ const idx = raw.indexOf("<");
189813
+ return (idx === -1 ? raw : raw.slice(0, idx)).trim();
189814
+ }
189815
+ function isNullishArm(t) {
189816
+ if (t.kind === "primitive" && (t.primitive === "null" || t.primitive === "undefined"))
189817
+ return true;
189818
+ return t.kind === "unknown" && (t.raw === "null" || t.raw === "undefined");
189819
+ }
189820
+ function stripUnion(type2) {
189821
+ if (!type2 || type2.kind !== "union" || !type2.unionTypes)
189822
+ return type2;
189823
+ const nonNullish = type2.unionTypes.filter((t) => !isNullishArm(t));
189824
+ return nonNullish.length === 1 ? stripUnion(nonNullish[0]) : type2;
189825
+ }
189826
+ function derefNamedType(type2, meta) {
189827
+ if (type2.kind !== "interface")
189828
+ return type2;
189829
+ if (type2.properties && type2.properties.length > 0)
189830
+ return type2;
189831
+ const name = baseTypeName(type2.raw);
189832
+ const def = meta.typeDefinitions.find((d) => d.name === name);
189833
+ if (!def?.properties)
189834
+ return type2;
189835
+ return { ...type2, properties: def.properties };
189836
+ }
189837
+ function lookupProperty(objType, propName, meta) {
189838
+ const stripped = stripUnion(objType);
189839
+ if (!stripped)
189840
+ return null;
189841
+ const deref = derefNamedType(stripped, meta);
189842
+ const prop = deref.properties?.find((p) => p.name === propName);
189843
+ return prop ? stripUnion(prop.type) : null;
189844
+ }
189845
+ function resolveReceiverType(expr, meta, bindings) {
189846
+ if (expr.kind === "identifier") {
189847
+ if (bindings.has(expr.name))
189848
+ return stripUnion(bindings.get(expr.name) ?? null);
189849
+ if (meta.propsObjectName !== null) {
189850
+ return expr.name === meta.propsObjectName ? stripUnion(meta.propsType) : null;
189851
+ }
189852
+ const param = meta.propsParams.find((p) => p.name === expr.name && !p.isRest);
189853
+ if (!param)
189854
+ return null;
189855
+ return lookupProperty(meta.propsType, param.sourceName ?? param.name, meta);
189856
+ }
189857
+ if (expr.kind === "member" && !expr.computed) {
189858
+ const objType = resolveReceiverType(expr.object, meta, bindings);
189859
+ return lookupProperty(objType, expr.property, meta);
189860
+ }
189861
+ return null;
189862
+ }
189863
+
189864
+ // ../jsx/src/date-lowering.ts
189865
+ var CATALOGUED_RICH_TYPE_NAMES = new Set(["Date"]);
189866
+ var DATE_METHODS = new Set([
189867
+ "getUTCFullYear",
189868
+ "getUTCMonth",
189869
+ "getUTCDate",
189870
+ "getUTCHours",
189871
+ "getUTCMinutes",
189872
+ "getUTCSeconds",
189873
+ "getTime",
189874
+ "toISOString"
189875
+ ]);
189876
+ var EMPTY_BINDINGS = new Map;
189877
+ function typeReachesDate(type2, meta, seen) {
189878
+ const stripped = stripUnion(type2);
189879
+ if (!stripped)
189880
+ return false;
189881
+ if (stripped.kind === "interface") {
189882
+ const name = baseTypeName(stripped.raw);
189883
+ if (name === "Date")
189884
+ return true;
189885
+ if (seen.has(name))
189886
+ return false;
189887
+ seen.add(name);
189888
+ } else if (stripped.kind !== "object") {
189889
+ return false;
189890
+ }
189891
+ const deref = derefNamedType(stripped, meta);
189892
+ if (!deref.properties)
189893
+ return false;
189894
+ return deref.properties.some((p) => typeReachesDate(p.type, meta, seen));
189895
+ }
189896
+ function matchDateCall(callee, args, metadata) {
189897
+ if (callee.kind !== "member" || callee.computed)
189898
+ return null;
189899
+ if (args.length !== 0 || !DATE_METHODS.has(callee.property))
189900
+ return null;
189901
+ const receiverType = resolveReceiverType(callee.object, metadata, EMPTY_BINDINGS);
189902
+ if (!receiverType || receiverType.kind !== "interface")
189903
+ return null;
189904
+ const typeName = baseTypeName(receiverType.raw);
189905
+ if (typeName !== "Date")
189906
+ return null;
189907
+ if (metadata.typeDefinitions.some((d) => d.name === typeName))
189908
+ return null;
189909
+ return {
189910
+ kind: "helper-call",
189911
+ helper: "date",
189912
+ args: [callee.object, { kind: "literal", value: callee.property, literalType: "string" }]
189913
+ };
189914
+ }
189915
+ var datePlugin = {
189916
+ name: "date",
189917
+ prepare(metadata) {
189918
+ if (!metadata.propsType || !typeReachesDate(metadata.propsType, metadata, new Set))
189919
+ return null;
189920
+ return (callee, args) => matchDateCall(callee, args, metadata);
189921
+ }
189922
+ };
189923
+
189795
189924
  // ../jsx/src/analyzer.ts
189796
189925
  init_path();
189797
189926
  var { default: fs} = (() => ({}));
@@ -191581,7 +191710,8 @@ function extractProps(param, ctx) {
191581
191710
  type: resolvedType,
191582
191711
  optional: !!member?.optional || !!element.initializer,
191583
191712
  defaultValue,
191584
- defaultContainsArrow: defaultContainsArrow || undefined
191713
+ defaultContainsArrow: defaultContainsArrow || undefined,
191714
+ ...sourcePropName !== localName && { sourceName: sourcePropName }
191585
191715
  });
191586
191716
  }
191587
191717
  }
@@ -191640,7 +191770,7 @@ function collectKeysFromMembers(members, ctx) {
191640
191770
  return keys;
191641
191771
  }
191642
191772
  function collectMemberTypes(typeNode, ctx) {
191643
- const isResolvablePrimitive = (info) => info.kind === "primitive" && (info.primitive === "string" || info.primitive === "number" || info.primitive === "boolean");
191773
+ const isResolvablePrimitive = (info) => info.kind === "primitive" && (info.primitive === "string" || info.primitive === "number" || info.primitive === "boolean") || info.kind === "interface" && CATALOGUED_RICH_TYPE_NAMES.has(baseTypeName(info.raw));
191644
191774
  const fromMembers = (members) => {
191645
191775
  const map = new Map;
191646
191776
  for (const member of members) {
@@ -192743,18 +192873,60 @@ function exprHasFunctionCalls(expr) {
192743
192873
  visit2(expr);
192744
192874
  return found;
192745
192875
  }
192876
+ function getDateLoweringMatcher(ctx) {
192877
+ if (ctx._dateLoweringMatcher === undefined) {
192878
+ const a = ctx.analyzer;
192879
+ const metadataSlice = {
192880
+ propsType: a.propsType,
192881
+ propsObjectName: a.propsObjectName,
192882
+ propsParams: a.propsParams,
192883
+ typeDefinitions: a.typeDefinitions
192884
+ };
192885
+ ctx._dateLoweringMatcher = datePlugin.prepare(metadataSlice);
192886
+ }
192887
+ return ctx._dateLoweringMatcher;
192888
+ }
192889
+ function lowerDateCalls(text, expr, ctx) {
192890
+ const matcher = getDateLoweringMatcher(ctx);
192891
+ if (!matcher)
192892
+ return text;
192893
+ const candidates = [];
192894
+ function visit2(n) {
192895
+ if (import_typescript11.default.isCallExpression(n) && n.arguments.length === 0 && import_typescript11.default.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && DATE_METHODS.has(n.expression.name.text)) {
192896
+ candidates.push(n);
192897
+ }
192898
+ import_typescript11.default.forEachChild(n, visit2);
192899
+ }
192900
+ visit2(expr);
192901
+ if (candidates.length === 0)
192902
+ return text;
192903
+ const { protect, restore } = createTemplateAwareStringProtector();
192904
+ let result = protect(text);
192905
+ for (const call of candidates) {
192906
+ const propAccess = call.expression;
192907
+ const node = matcher(tsNodeToParsedExpr(propAccess), []);
192908
+ if (!node || node.kind !== "helper-call" || node.helper !== "date")
192909
+ continue;
192910
+ const op = propAccess.name.text;
192911
+ const receiverText = ctx.getJS(propAccess.expression);
192912
+ const matchText = ctx.getJS(call);
192913
+ result = result.replace(matchText, () => `date(${receiverText}, "${op}")`);
192914
+ }
192915
+ return restore(result);
192916
+ }
192746
192917
  function rewriteBarePropRefs2(text, expr, ctx) {
192918
+ const dateLowered = lowerDateCalls(text, expr, ctx);
192747
192919
  let propNames = getDestructuredPropNames(ctx);
192748
192920
  if (!propNames)
192749
- return;
192921
+ return dateLowered === text ? undefined : dateLowered;
192750
192922
  if (ctx.loopParams.size > 0) {
192751
192923
  const filtered = new Set([...propNames].filter((n) => !ctx.loopParams.has(n)));
192752
192924
  if (filtered.size === 0)
192753
- return;
192925
+ return dateLowered === text ? undefined : dateLowered;
192754
192926
  propNames = filtered;
192755
192927
  }
192756
192928
  const extraPropRefs = collectBranchLocalPropRefsViaSubstitution(expr, ctx);
192757
- return rewriteBarePropRefs(text, expr, propNames, extraPropRefs);
192929
+ return rewriteBarePropRefs(dateLowered, expr, propNames, extraPropRefs);
192758
192930
  }
192759
192931
  function collectBranchLocalPropRefsViaSubstitution(node, ctx) {
192760
192932
  const propDepsMap = ctx._branchScopePropDeps;
@@ -196170,6 +196342,9 @@ var QUERY_HREF_SOURCES = new Set([
196170
196342
  "@barefootjs/client/runtime"
196171
196343
  ]);
196172
196344
 
196345
+ // ../jsx/src/ir-to-client-js/emit-reactive.ts
196346
+ var import_typescript14 = __toESM(require_typescript(), 1);
196347
+
196173
196348
  // ../jsx/src/ir-to-client-js/control-flow/stringify/event-delegation.ts
196174
196349
  var NON_BUBBLING_EVENTS = new Set([
196175
196350
  "blur",
@@ -196183,7 +196358,7 @@ var NON_BUBBLING_EVENTS = new Set([
196183
196358
  ]);
196184
196359
 
196185
196360
  // ../jsx/src/ir-to-client-js/rewrite-props-object.ts
196186
- var import_typescript14 = __toESM(require_typescript(), 1);
196361
+ var import_typescript15 = __toESM(require_typescript(), 1);
196187
196362
 
196188
196363
  // ../jsx/src/ir-to-client-js/source-map.ts
196189
196364
  var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -196274,18 +196449,21 @@ class SourceMapGenerator {
196274
196449
  }
196275
196450
 
196276
196451
  // ../jsx/src/preprocess-inline-jsx-callbacks.ts
196277
- var import_typescript15 = __toESM(require_typescript(), 1);
196452
+ var import_typescript16 = __toESM(require_typescript(), 1);
196278
196453
 
196279
196454
  // ../jsx/src/ssr-defaults.ts
196280
- var import_typescript16 = __toESM(require_typescript(), 1);
196455
+ var import_typescript17 = __toESM(require_typescript(), 1);
196281
196456
  var UNRESOLVED = Symbol("unresolved");
196282
196457
  var NO_RETURN = Symbol("no-return");
196283
196458
 
196284
196459
  // ../jsx/src/augment-inherited-props.ts
196285
- var import_typescript17 = __toESM(require_typescript(), 1);
196460
+ var import_typescript18 = __toESM(require_typescript(), 1);
196461
+
196462
+ // ../jsx/src/rich-type-refusal.ts
196463
+ var EMPTY_BINDINGS2 = new Map;
196286
196464
  // ../jsx/src/shared-program.ts
196287
196465
  init_path();
196288
- var import_typescript18 = __toESM(require_typescript(), 1);
196466
+ var import_typescript19 = __toESM(require_typescript(), 1);
196289
196467
  // ../jsx/src/adapters/interface.ts
196290
196468
  class BaseAdapter {
196291
196469
  renderChildren(children) {
@@ -196784,15 +196962,15 @@ var queryHrefPlugin = {
196784
196962
  };
196785
196963
  }
196786
196964
  };
196787
- var BUILTIN_LOWERING_PLUGINS = [queryHrefPlugin];
196965
+ var BUILTIN_LOWERING_PLUGINS = [queryHrefPlugin, datePlugin];
196788
196966
  function registerBuiltinLoweringPlugins() {
196789
196967
  for (const plugin of BUILTIN_LOWERING_PLUGINS)
196790
196968
  registerLoweringPlugin(plugin);
196791
196969
  }
196792
196970
  // ../jsx/src/combine-client-js.ts
196793
- var import_typescript19 = __toESM(require_typescript(), 1);
196794
- // ../jsx/src/debug.ts
196795
196971
  var import_typescript20 = __toESM(require_typescript(), 1);
196972
+ // ../jsx/src/debug.ts
196973
+ var import_typescript21 = __toESM(require_typescript(), 1);
196796
196974
  function escapeForIdBoundary(name) {
196797
196975
  return name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
196798
196976
  }
@@ -196884,7 +197062,7 @@ function resolveSetters(handler, setterToSignal, fnSetters) {
196884
197062
  return refs;
196885
197063
  }
196886
197064
  // ../jsx/src/profiler.ts
196887
- var import_typescript21 = __toESM(require_typescript(), 1);
197065
+ var import_typescript22 = __toESM(require_typescript(), 1);
196888
197066
 
196889
197067
  // ../jsx/src/index.ts
196890
197068
  registerBuiltinLoweringPlugins();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barefootjs/test",
3
- "version": "0.19.1",
3
+ "version": "0.21.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.19.1"
42
+ "@barefootjs/jsx": "0.21.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "typescript": "^5.0.0"