@barefootjs/test 0.25.0 → 0.26.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 +132 -24
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -191421,6 +191421,37 @@ function extractFreeIdentifiersFromNode(node) {
191421
191421
  visit2(node);
191422
191422
  return ids;
191423
191423
  }
191424
+ function extractFreeTypeIdentifiersFromNode(node) {
191425
+ const ids = new Set;
191426
+ const boundTypeParams = new Set;
191427
+ function rootName(name) {
191428
+ return import_typescript8.default.isQualifiedName(name) ? rootName(name.left) : name;
191429
+ }
191430
+ function visit2(n) {
191431
+ if (import_typescript8.default.isTypeReferenceNode(n)) {
191432
+ const name = rootName(n.typeName).text;
191433
+ if (!boundTypeParams.has(name))
191434
+ ids.add(name);
191435
+ }
191436
+ if (import_typescript8.default.isTypeQueryNode(n)) {
191437
+ const name = rootName(n.exprName).text;
191438
+ if (!boundTypeParams.has(name))
191439
+ ids.add(name);
191440
+ }
191441
+ if (import_typescript8.default.isFunctionLike(n) && n.typeParameters && n.typeParameters.length > 0) {
191442
+ const names = n.typeParameters.map((p) => p.name.text);
191443
+ for (const p of names)
191444
+ boundTypeParams.add(p);
191445
+ import_typescript8.default.forEachChild(n, visit2);
191446
+ for (const p of names)
191447
+ boundTypeParams.delete(p);
191448
+ return;
191449
+ }
191450
+ import_typescript8.default.forEachChild(n, visit2);
191451
+ }
191452
+ visit2(node);
191453
+ return ids;
191454
+ }
191424
191455
  function initializerShapeContainsJsx(node) {
191425
191456
  let found = false;
191426
191457
  function visit2(n) {
@@ -192243,16 +192274,17 @@ function buildEntryImportIndex(sf, filePath) {
192243
192274
  continue;
192244
192275
  if (!import_typescript8.default.isStringLiteral(stmt.moduleSpecifier))
192245
192276
  continue;
192246
- if (stmt.importClause?.isTypeOnly)
192247
- continue;
192248
192277
  const src = stmt.moduleSpecifier.text;
192249
192278
  const targetKey = src.startsWith("./") || src.startsWith("../") ? resolveRelativeImportToFile(src, filePath) ?? "unresolved:" + src : src;
192279
+ const wholeTypeOnly = stmt.importClause?.isTypeOnly === true;
192250
192280
  const namedBindings = stmt.importClause?.namedBindings;
192251
192281
  if (namedBindings && import_typescript8.default.isNamedImports(namedBindings)) {
192252
192282
  for (const el of namedBindings.elements) {
192253
- if (el.isTypeOnly)
192254
- continue;
192255
- index.set(el.name.text, { targetKey, exportedName: (el.propertyName ?? el.name).text });
192283
+ index.set(el.name.text, {
192284
+ targetKey,
192285
+ exportedName: (el.propertyName ?? el.name).text,
192286
+ isTypeOnly: wholeTypeOnly || el.isTypeOnly
192287
+ });
192256
192288
  }
192257
192289
  }
192258
192290
  }
@@ -192282,6 +192314,9 @@ function collectEntryBindingNames(sf) {
192282
192314
  if ((import_typescript8.default.isFunctionDeclaration(node) || import_typescript8.default.isClassDeclaration(node) || import_typescript8.default.isEnumDeclaration(node)) && node.name) {
192283
192315
  names.add(node.name.text);
192284
192316
  }
192317
+ if ((import_typescript8.default.isTypeAliasDeclaration(node) || import_typescript8.default.isInterfaceDeclaration(node)) && node.name) {
192318
+ names.add(node.name.text);
192319
+ }
192285
192320
  if (import_typescript8.default.isFunctionLike(node)) {
192286
192321
  for (const p of node.parameters) {
192287
192322
  const out = [];
@@ -192477,7 +192512,11 @@ function prescanImportedReactiveFactories(entrySourceFile, filePath, result) {
192477
192512
  const required = [];
192478
192513
  const pending = [];
192479
192514
  let declinedEntry = null;
192480
- for (const ref of capture.importedRefs) {
192515
+ const allRefs = [
192516
+ ...capture.importedRefs.map((r) => ({ ...r, isTypeOnly: false })),
192517
+ ...capture.importedTypeRefs.map((r) => ({ ...r, isTypeOnly: true }))
192518
+ ];
192519
+ for (const ref of allRefs) {
192481
192520
  let specifier;
192482
192521
  let targetKey;
192483
192522
  if (ref.source.startsWith("./") || ref.source.startsWith("../")) {
@@ -192497,7 +192536,7 @@ function prescanImportedReactiveFactories(entrySourceFile, filePath, result) {
192497
192536
  targetKey = ref.source;
192498
192537
  }
192499
192538
  const existing = entryImportIndex.get(ref.localName);
192500
- if (existing && existing.targetKey === targetKey && existing.exportedName === ref.exportedName) {
192539
+ if (existing && existing.targetKey === targetKey && existing.exportedName === ref.exportedName && (ref.isTypeOnly || !existing.isTypeOnly)) {
192501
192540
  continue;
192502
192541
  }
192503
192542
  const planned = plannedInjections.get(ref.localName);
@@ -192511,7 +192550,7 @@ function prescanImportedReactiveFactories(entrySourceFile, filePath, result) {
192511
192550
  break;
192512
192551
  }
192513
192552
  pending.push([ref.localName, { targetKey, exportedName: ref.exportedName }]);
192514
- required.push({ localName: ref.localName, exportedName: ref.exportedName, specifier });
192553
+ required.push({ localName: ref.localName, exportedName: ref.exportedName, specifier, isTypeOnly: ref.isTypeOnly || undefined });
192515
192554
  }
192516
192555
  if (declinedEntry) {
192517
192556
  result.declined.set(spec.local, declinedEntry);
@@ -192531,6 +192570,8 @@ function prescanImportedReactiveFactories(entrySourceFile, filePath, result) {
192531
192570
  }
192532
192571
  function collectHelperModuleValueBindings(sf) {
192533
192572
  const local = new Set;
192573
+ const localTypes = new Set;
192574
+ const importedTypes = new Map;
192534
192575
  const imported = new Map;
192535
192576
  for (const stmt of sf.statements) {
192536
192577
  if (import_typescript8.default.isVariableStatement(stmt)) {
@@ -192546,35 +192587,41 @@ function collectHelperModuleValueBindings(sf) {
192546
192587
  local.add(stmt.name.text);
192547
192588
  continue;
192548
192589
  }
192590
+ if ((import_typescript8.default.isTypeAliasDeclaration(stmt) || import_typescript8.default.isInterfaceDeclaration(stmt)) && stmt.name) {
192591
+ localTypes.add(stmt.name.text);
192592
+ continue;
192593
+ }
192549
192594
  if (import_typescript8.default.isImportDeclaration(stmt)) {
192550
- if (stmt.importClause?.isTypeOnly)
192551
- continue;
192552
192595
  if (!import_typescript8.default.isStringLiteral(stmt.moduleSpecifier))
192553
192596
  continue;
192554
192597
  const src = stmt.moduleSpecifier.text;
192555
192598
  if (src === "@barefootjs/client" || src === "@barefootjs/client/runtime")
192556
192599
  continue;
192600
+ const wholeTypeOnly = stmt.importClause?.isTypeOnly === true;
192557
192601
  if (stmt.importClause?.name)
192558
- local.add(stmt.importClause.name.text);
192602
+ (wholeTypeOnly ? localTypes : local).add(stmt.importClause.name.text);
192559
192603
  const namedBindings = stmt.importClause?.namedBindings;
192560
192604
  if (namedBindings && import_typescript8.default.isNamedImports(namedBindings)) {
192561
192605
  for (const el of namedBindings.elements) {
192562
- if (el.isTypeOnly)
192563
- continue;
192564
- imported.set(el.name.text, { source: src, exportedName: (el.propertyName ?? el.name).text });
192606
+ const entry = { source: src, exportedName: (el.propertyName ?? el.name).text };
192607
+ if (wholeTypeOnly || el.isTypeOnly)
192608
+ importedTypes.set(el.name.text, entry);
192609
+ else
192610
+ imported.set(el.name.text, entry);
192565
192611
  }
192566
192612
  }
192567
192613
  if (namedBindings && import_typescript8.default.isNamespaceImport(namedBindings)) {
192568
- local.add(namedBindings.name.text);
192614
+ (wholeTypeOnly ? localTypes : local).add(namedBindings.name.text);
192569
192615
  }
192570
192616
  }
192571
192617
  }
192572
- return { local, imported };
192618
+ return { local, imported, localTypes, importedTypes };
192573
192619
  }
192574
192620
  function moduleCaptureCheck(fn, info, moduleBindings, selfName) {
192575
192621
  if (!fn.body)
192576
- return { captured: [], importedRefs: [] };
192622
+ return { captured: [], importedRefs: [], importedTypeRefs: [] };
192577
192623
  const free = extractFreeIdentifiersFromNode(fn.body);
192624
+ const freeTypes = extractFreeTypeIdentifiersFromNode(fn.body);
192578
192625
  const exclude = new Set(info.params);
192579
192626
  for (const b of info.localBindings)
192580
192627
  exclude.add(b);
@@ -192583,8 +192630,12 @@ function moduleCaptureCheck(fn, info, moduleBindings, selfName) {
192583
192630
  for (const p of REACTIVE_PRIMITIVES)
192584
192631
  exclude.add(p);
192585
192632
  exclude.add(selfName);
192633
+ if (fn.typeParameters)
192634
+ for (const p of fn.typeParameters)
192635
+ exclude.add(p.name.text);
192586
192636
  const captured = [];
192587
192637
  const importedRefs = [];
192638
+ const importedTypeRefs = [];
192588
192639
  for (const id of free) {
192589
192640
  if (exclude.has(id))
192590
192641
  continue;
@@ -192596,9 +192647,28 @@ function moduleCaptureCheck(fn, info, moduleBindings, selfName) {
192596
192647
  if (imp)
192597
192648
  importedRefs.push({ localName: id, source: imp.source, exportedName: imp.exportedName });
192598
192649
  }
192650
+ for (const id of freeTypes) {
192651
+ if (exclude.has(id))
192652
+ continue;
192653
+ if (free.has(id))
192654
+ continue;
192655
+ if (moduleBindings.localTypes.has(id) || moduleBindings.local.has(id)) {
192656
+ captured.push(id);
192657
+ continue;
192658
+ }
192659
+ const typeImp = moduleBindings.importedTypes.get(id);
192660
+ if (typeImp) {
192661
+ importedTypeRefs.push({ localName: id, source: typeImp.source, exportedName: typeImp.exportedName });
192662
+ continue;
192663
+ }
192664
+ const valueImp = moduleBindings.imported.get(id);
192665
+ if (valueImp)
192666
+ importedRefs.push({ localName: id, source: valueImp.source, exportedName: valueImp.exportedName });
192667
+ }
192599
192668
  captured.sort();
192600
192669
  importedRefs.sort((a, b) => a.localName < b.localName ? -1 : 1);
192601
- return { captured, importedRefs };
192670
+ importedTypeRefs.sort((a, b) => a.localName < b.localName ? -1 : 1);
192671
+ return { captured, importedRefs, importedTypeRefs };
192602
192672
  }
192603
192673
  function detectReactiveFactory(node, sourceFile, filePath) {
192604
192674
  if (!node.body || !node.name)
@@ -192937,20 +193007,44 @@ function rewriteFactoryCallsInSource(source, prescan) {
192937
193007
  if (edits.length === 0)
192938
193008
  return source;
192939
193009
  const importsBySpecifier = new Map;
193010
+ const typeImportsBySpecifier = new Map;
192940
193011
  for (const f of inlinedFactories) {
192941
193012
  for (const r of f.requiredImports ?? []) {
192942
- let names = importsBySpecifier.get(r.specifier);
193013
+ const bySpecifier = r.isTypeOnly ? typeImportsBySpecifier : importsBySpecifier;
193014
+ let names = bySpecifier.get(r.specifier);
192943
193015
  if (!names) {
192944
193016
  names = new Map;
192945
- importsBySpecifier.set(r.specifier, names);
193017
+ bySpecifier.set(r.specifier, names);
192946
193018
  }
192947
193019
  names.set(r.localName, r.exportedName);
192948
193020
  }
192949
193021
  }
192950
- if (importsBySpecifier.size > 0) {
192951
- const lines = [...importsBySpecifier].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([spec, names]) => {
193022
+ for (const [spec, typeNames] of typeImportsBySpecifier) {
193023
+ const valueNames = importsBySpecifier.get(spec);
193024
+ if (!valueNames)
193025
+ continue;
193026
+ for (const local of [...typeNames.keys()]) {
193027
+ if (valueNames.has(local))
193028
+ typeNames.delete(local);
193029
+ }
193030
+ if (typeNames.size === 0)
193031
+ typeImportsBySpecifier.delete(spec);
193032
+ }
193033
+ if (importsBySpecifier.size > 0 || typeImportsBySpecifier.size > 0) {
193034
+ const buildLine = (names, keyword, spec) => {
192952
193035
  const specifiers = [...names].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([local, exported]) => exported === local ? local : `${exported} as ${local}`);
192953
- return `import { ${specifiers.join(", ")} } from '${spec}'`;
193036
+ return `import ${keyword}{ ${specifiers.join(", ")} } from '${spec}'`;
193037
+ };
193038
+ const allSpecifiers = new Set([...importsBySpecifier.keys(), ...typeImportsBySpecifier.keys()]);
193039
+ const lines = [...allSpecifiers].sort().flatMap((spec) => {
193040
+ const out2 = [];
193041
+ const valueNames = importsBySpecifier.get(spec);
193042
+ if (valueNames)
193043
+ out2.push(buildLine(valueNames, "", spec));
193044
+ const typeNames = typeImportsBySpecifier.get(spec);
193045
+ if (typeNames)
193046
+ out2.push(buildLine(typeNames, "type ", spec));
193047
+ return out2;
192954
193048
  });
192955
193049
  const at = factoryImportInsertionOffset(sourceFile);
192956
193050
  edits.push({ start: at, end: at, replacement: at === 0 ? lines.join(`
@@ -193530,6 +193624,20 @@ function resolveFreeRefs(node, env) {
193530
193624
 
193531
193625
  // ../jsx/src/to-locale-date-lowering.ts
193532
193626
  var TO_LOCALE_TZ_RE = /^(?:UTC|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/;
193627
+ var tzProbeCache = new Map;
193628
+ function isBuildResolvableTimeZone(value) {
193629
+ const cached = tzProbeCache.get(value);
193630
+ if (cached !== undefined)
193631
+ return cached;
193632
+ let verified;
193633
+ try {
193634
+ verified = new Intl.DateTimeFormat("en-US", { timeZone: value }).resolvedOptions().timeZone === value;
193635
+ } catch {
193636
+ verified = false;
193637
+ }
193638
+ tzProbeCache.set(value, verified);
193639
+ return verified;
193640
+ }
193533
193641
  var PROBE_UTC = new Date(Date.UTC(2001, 1, 3));
193534
193642
  var formatCache = new Map;
193535
193643
  var namesCache = new Map;
@@ -193768,7 +193876,7 @@ function matchToLocaleDateStringCall(callee, args, metadata) {
193768
193876
  return null;
193769
193877
  const value = String(prop.value.value);
193770
193878
  if (prop.key === "timeZone") {
193771
- if (!TO_LOCALE_TZ_RE.test(value))
193879
+ if (!TO_LOCALE_TZ_RE.test(value) && !isBuildResolvableTimeZone(value))
193772
193880
  return null;
193773
193881
  tz = value;
193774
193882
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barefootjs/test",
3
- "version": "0.25.0",
3
+ "version": "0.26.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.25.0"
42
+ "@barefootjs/jsx": "0.26.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "typescript": "^5.0.0"