@barefootjs/test 0.20.0 → 0.21.2

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 +194 -31
  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} = (() => ({}));
@@ -191641,7 +191770,7 @@ function collectKeysFromMembers(members, ctx) {
191641
191770
  return keys;
191642
191771
  }
191643
191772
  function collectMemberTypes(typeNode, ctx) {
191644
- 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));
191645
191774
  const fromMembers = (members) => {
191646
191775
  const map = new Map;
191647
191776
  for (const member of members) {
@@ -192744,18 +192873,60 @@ function exprHasFunctionCalls(expr) {
192744
192873
  visit2(expr);
192745
192874
  return found;
192746
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
+ }
192747
192917
  function rewriteBarePropRefs2(text, expr, ctx) {
192918
+ const dateLowered = lowerDateCalls(text, expr, ctx);
192748
192919
  let propNames = getDestructuredPropNames(ctx);
192749
192920
  if (!propNames)
192750
- return;
192921
+ return dateLowered === text ? undefined : dateLowered;
192751
192922
  if (ctx.loopParams.size > 0) {
192752
192923
  const filtered = new Set([...propNames].filter((n) => !ctx.loopParams.has(n)));
192753
192924
  if (filtered.size === 0)
192754
- return;
192925
+ return dateLowered === text ? undefined : dateLowered;
192755
192926
  propNames = filtered;
192756
192927
  }
192757
192928
  const extraPropRefs = collectBranchLocalPropRefsViaSubstitution(expr, ctx);
192758
- return rewriteBarePropRefs(text, expr, propNames, extraPropRefs);
192929
+ return rewriteBarePropRefs(dateLowered, expr, propNames, extraPropRefs);
192759
192930
  }
192760
192931
  function collectBranchLocalPropRefsViaSubstitution(node, ctx) {
192761
192932
  const propDepsMap = ctx._branchScopePropDeps;
@@ -195127,6 +195298,12 @@ function getAttributeValue(attr, ctx) {
195127
195298
  return AttrValueOf.template(parts);
195128
195299
  }
195129
195300
  }
195301
+ if (import_typescript11.default.isElementAccessExpression(expr) && !import_typescript11.default.isStringLiteralLike(expr.argumentExpression) && !import_typescript11.default.isNumericLiteral(expr.argumentExpression)) {
195302
+ const parts = tryResolveTemplateSpanFromConst(expr, ctx);
195303
+ if (parts) {
195304
+ return AttrValueOf.template(parts);
195305
+ }
195306
+ }
195130
195307
  if (import_typescript11.default.isIdentifier(expr)) {
195131
195308
  const resolved = tryResolveIdentifierAsTemplateLiteral(expr, ctx);
195132
195309
  if (resolved) {
@@ -196171,6 +196348,9 @@ var QUERY_HREF_SOURCES = new Set([
196171
196348
  "@barefootjs/client/runtime"
196172
196349
  ]);
196173
196350
 
196351
+ // ../jsx/src/ir-to-client-js/emit-reactive.ts
196352
+ var import_typescript14 = __toESM(require_typescript(), 1);
196353
+
196174
196354
  // ../jsx/src/ir-to-client-js/control-flow/stringify/event-delegation.ts
196175
196355
  var NON_BUBBLING_EVENTS = new Set([
196176
196356
  "blur",
@@ -196184,7 +196364,7 @@ var NON_BUBBLING_EVENTS = new Set([
196184
196364
  ]);
196185
196365
 
196186
196366
  // ../jsx/src/ir-to-client-js/rewrite-props-object.ts
196187
- var import_typescript14 = __toESM(require_typescript(), 1);
196367
+ var import_typescript15 = __toESM(require_typescript(), 1);
196188
196368
 
196189
196369
  // ../jsx/src/ir-to-client-js/source-map.ts
196190
196370
  var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -196275,38 +196455,21 @@ class SourceMapGenerator {
196275
196455
  }
196276
196456
 
196277
196457
  // ../jsx/src/preprocess-inline-jsx-callbacks.ts
196278
- var import_typescript15 = __toESM(require_typescript(), 1);
196458
+ var import_typescript16 = __toESM(require_typescript(), 1);
196279
196459
 
196280
196460
  // ../jsx/src/ssr-defaults.ts
196281
- var import_typescript16 = __toESM(require_typescript(), 1);
196461
+ var import_typescript17 = __toESM(require_typescript(), 1);
196282
196462
  var UNRESOLVED = Symbol("unresolved");
196283
196463
  var NO_RETURN = Symbol("no-return");
196284
196464
 
196285
196465
  // ../jsx/src/augment-inherited-props.ts
196286
- var import_typescript17 = __toESM(require_typescript(), 1);
196287
-
196288
- // ../jsx/src/rich-type-evidence.ts
196289
- var HOST_RICH_TYPE_NAMES = new Set([
196290
- "Date",
196291
- "Map",
196292
- "Set",
196293
- "WeakMap",
196294
- "WeakSet",
196295
- "URL",
196296
- "URLSearchParams",
196297
- "RegExp",
196298
- "Promise",
196299
- "Error",
196300
- "Symbol",
196301
- "BigInt",
196302
- "Function"
196303
- ]);
196466
+ var import_typescript18 = __toESM(require_typescript(), 1);
196304
196467
 
196305
196468
  // ../jsx/src/rich-type-refusal.ts
196306
- var EMPTY_BINDINGS = new Map;
196469
+ var EMPTY_BINDINGS2 = new Map;
196307
196470
  // ../jsx/src/shared-program.ts
196308
196471
  init_path();
196309
- var import_typescript18 = __toESM(require_typescript(), 1);
196472
+ var import_typescript19 = __toESM(require_typescript(), 1);
196310
196473
  // ../jsx/src/adapters/interface.ts
196311
196474
  class BaseAdapter {
196312
196475
  renderChildren(children) {
@@ -196805,15 +196968,15 @@ var queryHrefPlugin = {
196805
196968
  };
196806
196969
  }
196807
196970
  };
196808
- var BUILTIN_LOWERING_PLUGINS = [queryHrefPlugin];
196971
+ var BUILTIN_LOWERING_PLUGINS = [queryHrefPlugin, datePlugin];
196809
196972
  function registerBuiltinLoweringPlugins() {
196810
196973
  for (const plugin of BUILTIN_LOWERING_PLUGINS)
196811
196974
  registerLoweringPlugin(plugin);
196812
196975
  }
196813
196976
  // ../jsx/src/combine-client-js.ts
196814
- var import_typescript19 = __toESM(require_typescript(), 1);
196815
- // ../jsx/src/debug.ts
196816
196977
  var import_typescript20 = __toESM(require_typescript(), 1);
196978
+ // ../jsx/src/debug.ts
196979
+ var import_typescript21 = __toESM(require_typescript(), 1);
196817
196980
  function escapeForIdBoundary(name) {
196818
196981
  return name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
196819
196982
  }
@@ -196905,7 +197068,7 @@ function resolveSetters(handler, setterToSignal, fnSetters) {
196905
197068
  return refs;
196906
197069
  }
196907
197070
  // ../jsx/src/profiler.ts
196908
- var import_typescript21 = __toESM(require_typescript(), 1);
197071
+ var import_typescript22 = __toESM(require_typescript(), 1);
196909
197072
 
196910
197073
  // ../jsx/src/index.ts
196911
197074
  registerBuiltinLoweringPlugins();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barefootjs/test",
3
- "version": "0.20.0",
3
+ "version": "0.21.2",
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.20.0"
42
+ "@barefootjs/jsx": "0.21.2"
43
43
  },
44
44
  "devDependencies": {
45
45
  "typescript": "^5.0.0"