@barefootjs/test 0.31.3 → 0.31.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 +111 -92
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -188846,6 +188846,24 @@ function templatePartsToJsExpr(parts, opts) {
188846
188846
  return result;
188847
188847
  }
188848
188848
 
188849
+ // ../jsx/src/identifier-pattern.ts
188850
+ function withUnicodeFlag(flags) {
188851
+ return flags.includes("u") ? flags : `${flags}u`;
188852
+ }
188853
+ function escapeIdentifierForRegex(name) {
188854
+ return name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
188855
+ }
188856
+ var ID_BOUNDARY_BEFORE = "(?<![\\p{ID_Continue}$])";
188857
+ var ID_BOUNDARY_AFTER = "(?![\\p{ID_Continue}$])";
188858
+ function identifierPattern(name, flags = "") {
188859
+ const esc = escapeIdentifierForRegex(name);
188860
+ return new RegExp(`${ID_BOUNDARY_BEFORE}${esc}${ID_BOUNDARY_AFTER}`, withUnicodeFlag(flags));
188861
+ }
188862
+ function identifierCallPattern(name, flags = "") {
188863
+ const esc = escapeIdentifierForRegex(name);
188864
+ return new RegExp(`${ID_BOUNDARY_BEFORE}${esc}\\s*\\(`, withUnicodeFlag(flags));
188865
+ }
188866
+
188849
188867
  // ../jsx/src/scanner/js-scanner.ts
188850
188868
  var import_typescript2 = __toESM(require_typescript(), 1);
188851
188869
  function* iterateJsTokens(text, start = 0, end = text.length) {
@@ -189229,6 +189247,83 @@ function extractFreeIdentifiersFromText(text) {
189229
189247
  return extractFreeIdentifiersFromNode(expr);
189230
189248
  }
189231
189249
 
189250
+ // ../jsx/src/scope/binding-scope.ts
189251
+ class BindingScope {
189252
+ frames;
189253
+ static EMPTY = new BindingScope([]);
189254
+ constructor(frames) {
189255
+ this.frames = frames;
189256
+ }
189257
+ enterLoopRow(loop) {
189258
+ const bindings = new Map;
189259
+ if (loop.paramBindings && loop.paramBindings.length > 0) {
189260
+ for (const b of loop.paramBindings)
189261
+ bindings.set(b.name, { source: "destructure" });
189262
+ } else {
189263
+ bindings.set(loop.param, { source: "item" });
189264
+ }
189265
+ if (loop.index != null)
189266
+ bindings.set(loop.index, { source: "index" });
189267
+ for (const name of loop.preamble?.declaredNames ?? [])
189268
+ bindings.set(name, { source: "preamble" });
189269
+ const frame = { kind: "loop-row", bindings };
189270
+ return new BindingScope([frame, ...this.frames]);
189271
+ }
189272
+ enterCallback(params) {
189273
+ const bindings = new Map;
189274
+ for (const name of params)
189275
+ bindings.set(name, { source: "param" });
189276
+ const frame = { kind: "callback", bindings };
189277
+ return new BindingScope([frame, ...this.frames]);
189278
+ }
189279
+ isBound(name) {
189280
+ for (const frame of this.frames) {
189281
+ if (frame.bindings.has(name))
189282
+ return true;
189283
+ }
189284
+ return false;
189285
+ }
189286
+ lookup(name) {
189287
+ for (let depth = 0;depth < this.frames.length; depth++) {
189288
+ const frame = this.frames[depth];
189289
+ const binding = frame.bindings.get(name);
189290
+ if (binding)
189291
+ return { depth, frame, binding };
189292
+ }
189293
+ return null;
189294
+ }
189295
+ boundNames() {
189296
+ if (this.boundNamesCache)
189297
+ return this.boundNamesCache;
189298
+ const names = new Set;
189299
+ for (const frame of this.frames) {
189300
+ for (const name of frame.bindings.keys())
189301
+ names.add(name);
189302
+ }
189303
+ this.boundNamesCache = names;
189304
+ return names;
189305
+ }
189306
+ boundNamesCache;
189307
+ valueBoundNamesCache;
189308
+ valueBoundNames() {
189309
+ if (this.valueBoundNamesCache)
189310
+ return this.valueBoundNamesCache;
189311
+ const names = new Set;
189312
+ for (const frame of this.frames) {
189313
+ for (const [name, binding] of frame.bindings) {
189314
+ if (binding.source === "item" || binding.source === "index" || binding.source === "destructure") {
189315
+ names.add(name);
189316
+ }
189317
+ }
189318
+ }
189319
+ this.valueBoundNamesCache = names;
189320
+ return names;
189321
+ }
189322
+ asShadowPredicate() {
189323
+ return (name) => this.isBound(name);
189324
+ }
189325
+ }
189326
+
189232
189327
  // ../jsx/src/ir-to-client-js/html-template.ts
189233
189328
  function splitTemplateInterpolations(inner) {
189234
189329
  const parts = [];
@@ -193633,7 +193728,7 @@ function findReachableNames(primaryRefs, declarations) {
193633
193728
  const reachable = new Set;
193634
193729
  const queue = [];
193635
193730
  for (const name of allNames) {
193636
- if (new RegExp(`\\b${name}\\b`).test(primaryRefs)) {
193731
+ if (identifierPattern(name).test(primaryRefs)) {
193637
193732
  reachable.add(name);
193638
193733
  queue.push(name);
193639
193734
  }
@@ -193642,7 +193737,7 @@ function findReachableNames(primaryRefs, declarations) {
193642
193737
  const current = queue.shift();
193643
193738
  const body = bodyMap.get(current) || "";
193644
193739
  for (const name of allNames) {
193645
- if (!reachable.has(name) && new RegExp(`\\b${name}\\b`).test(body)) {
193740
+ if (!reachable.has(name) && identifierPattern(name).test(body)) {
193646
193741
  reachable.add(name);
193647
193742
  queue.push(name);
193648
193743
  }
@@ -194294,83 +194389,6 @@ var toLocaleDatePlugin = {
194294
194389
  }
194295
194390
  };
194296
194391
 
194297
- // ../jsx/src/scope/binding-scope.ts
194298
- class BindingScope {
194299
- frames;
194300
- static EMPTY = new BindingScope([]);
194301
- constructor(frames) {
194302
- this.frames = frames;
194303
- }
194304
- enterLoopRow(loop) {
194305
- const bindings = new Map;
194306
- if (loop.paramBindings && loop.paramBindings.length > 0) {
194307
- for (const b of loop.paramBindings)
194308
- bindings.set(b.name, { source: "destructure" });
194309
- } else {
194310
- bindings.set(loop.param, { source: "item" });
194311
- }
194312
- if (loop.index != null)
194313
- bindings.set(loop.index, { source: "index" });
194314
- for (const name of loop.preamble?.declaredNames ?? [])
194315
- bindings.set(name, { source: "preamble" });
194316
- const frame = { kind: "loop-row", bindings };
194317
- return new BindingScope([frame, ...this.frames]);
194318
- }
194319
- enterCallback(params) {
194320
- const bindings = new Map;
194321
- for (const name of params)
194322
- bindings.set(name, { source: "param" });
194323
- const frame = { kind: "callback", bindings };
194324
- return new BindingScope([frame, ...this.frames]);
194325
- }
194326
- isBound(name) {
194327
- for (const frame of this.frames) {
194328
- if (frame.bindings.has(name))
194329
- return true;
194330
- }
194331
- return false;
194332
- }
194333
- lookup(name) {
194334
- for (let depth = 0;depth < this.frames.length; depth++) {
194335
- const frame = this.frames[depth];
194336
- const binding = frame.bindings.get(name);
194337
- if (binding)
194338
- return { depth, frame, binding };
194339
- }
194340
- return null;
194341
- }
194342
- boundNames() {
194343
- if (this.boundNamesCache)
194344
- return this.boundNamesCache;
194345
- const names = new Set;
194346
- for (const frame of this.frames) {
194347
- for (const name of frame.bindings.keys())
194348
- names.add(name);
194349
- }
194350
- this.boundNamesCache = names;
194351
- return names;
194352
- }
194353
- boundNamesCache;
194354
- valueBoundNamesCache;
194355
- valueBoundNames() {
194356
- if (this.valueBoundNamesCache)
194357
- return this.valueBoundNamesCache;
194358
- const names = new Set;
194359
- for (const frame of this.frames) {
194360
- for (const [name, binding] of frame.bindings) {
194361
- if (binding.source === "item" || binding.source === "index" || binding.source === "destructure") {
194362
- names.add(name);
194363
- }
194364
- }
194365
- }
194366
- this.valueBoundNamesCache = names;
194367
- return names;
194368
- }
194369
- asShadowPredicate() {
194370
- return (name) => this.isBound(name);
194371
- }
194372
- }
194373
-
194374
194392
  // ../jsx/src/jsx-to-ir.ts
194375
194393
  var CLIENT_DIRECTIVE_INTERIOR_RE2 = /^\s*@client\s*$/;
194376
194394
  var BLOCK_COMMENT_RE2 = /\/\*([\s\S]*?)\*\//g;
@@ -194634,17 +194652,17 @@ function createTransformContext(analyzer) {
194634
194652
  patterns: {
194635
194653
  signals: analyzer.signals.map((s) => ({
194636
194654
  getter: s.getter,
194637
- pattern: new RegExp(`\\b${s.getter}\\s*\\(`)
194655
+ pattern: identifierCallPattern(s.getter)
194638
194656
  })),
194639
194657
  memos: analyzer.memos.map((m) => ({
194640
194658
  name: m.name,
194641
- pattern: new RegExp(`\\b${m.name}\\s*\\(`)
194659
+ pattern: identifierCallPattern(m.name)
194642
194660
  })),
194643
- props: analyzer.propsParams.filter((p) => p.name !== "children").map((p) => ({ name: p.name, pattern: new RegExp(`\\b${p.name}\\b`) })),
194661
+ props: analyzer.propsParams.filter((p) => p.name !== "children").map((p) => ({ name: p.name, pattern: identifierPattern(p.name) })),
194644
194662
  constants: analyzer.localConstants.map((c) => ({
194645
194663
  name: c.name,
194646
194664
  value: c.value,
194647
- pattern: new RegExp(`\\b${c.name}\\b`)
194665
+ pattern: identifierPattern(c.name)
194648
194666
  }))
194649
194667
  },
194650
194668
  getJS(node) {
@@ -195416,7 +195434,7 @@ function transformExpressionInner(expr, ctx, node, isClientOnly) {
195416
195434
  };
195417
195435
  const reactive = isReactiveExpression(exprText, ctx, expr) || isReactiveOrigin(origin);
195418
195436
  const scopeValueNames = ctx.scope.valueBoundNames();
195419
- const refsLoopParam = scopeValueNames.size > 0 && Array.from(scopeValueNames).some((p) => new RegExp(`\\b${p}\\b`).test(exprText));
195437
+ const refsLoopParam = scopeValueNames.size > 0 && Array.from(scopeValueNames).some((p) => identifierPattern(p).test(exprText));
195420
195438
  const callsReactive = exprCallsReactiveGetters(expr, ctx);
195421
195439
  const hasCalls = exprHasFunctionCalls(expr);
195422
195440
  const needsSlot = reactive || isClientOnly || refsLoopParam || callsReactive || hasCalls;
@@ -195451,7 +195469,7 @@ function transformJsxFunctionCall(callExpr, jsxFunc, ctx, _isClientOnly) {
195451
195469
  const substitutedGetJS = (node) => {
195452
195470
  let text = baseGetJS(node);
195453
195471
  for (const [paramName, argExpr] of substitutions) {
195454
- text = text.replace(new RegExp(`\\b${paramName}\\b`, "g"), argExpr);
195472
+ text = text.replace(identifierPattern(paramName, "g"), () => argExpr);
195455
195473
  }
195456
195474
  return text;
195457
195475
  };
@@ -195493,7 +195511,7 @@ function transformMultiReturnJsxFunctionCall(callExpr, info, ctx) {
195493
195511
  const substitutedGetJS = (node) => {
195494
195512
  let text = baseGetJS(node);
195495
195513
  for (const [paramName, argExpr] of substitutions) {
195496
- text = text.replace(new RegExp(`\\b${paramName}\\b`, "g"), argExpr);
195514
+ text = text.replace(identifierPattern(paramName, "g"), () => argExpr);
195497
195515
  }
195498
195516
  return text;
195499
195517
  };
@@ -198038,7 +198056,7 @@ function referencesLoopParam(expr, ctx) {
198038
198056
  if (boundNames.size === 0)
198039
198057
  return false;
198040
198058
  for (const p of boundNames) {
198041
- if (new RegExp(`\\b${p}\\b`).test(expr))
198059
+ if (identifierPattern(p).test(expr))
198042
198060
  return true;
198043
198061
  }
198044
198062
  return false;
@@ -198120,7 +198138,7 @@ function hasReactiveAttributes(attrs, ctx) {
198120
198138
  const scopeValueNames = ctx.scope.valueBoundNames();
198121
198139
  if (scopeValueNames.size > 0) {
198122
198140
  for (const p of scopeValueNames) {
198123
- if (new RegExp(`\\b${p}\\b`).test(valueToCheck))
198141
+ if (identifierPattern(p).test(valueToCheck))
198124
198142
  return true;
198125
198143
  }
198126
198144
  }
@@ -198857,7 +198875,7 @@ class JsxAdapter extends BaseAdapter {
198857
198875
  lines.push(` const ${signal.getter} = () => ${initialValue}`);
198858
198876
  }
198859
198877
  if (signal.setter) {
198860
- const setterUsed = new RegExp(`\\b${signal.setter}\\b`).test(setterRefText);
198878
+ const setterUsed = identifierPattern(signal.setter).test(setterRefText);
198861
198879
  if (setterUsed) {
198862
198880
  lines.push(` const ${signal.setter} = (..._args: any[]) => {}`);
198863
198881
  }
@@ -199055,6 +199073,7 @@ class JsxAdapter extends BaseAdapter {
199055
199073
  }
199056
199074
 
199057
199075
  // ../jsx/src/adapters/template-imports.ts
199076
+ var import_typescript25 = __toESM(require_typescript(), 1);
199058
199077
  var CLIENT_PACKAGE_SOURCES = new Set([
199059
199078
  "@barefootjs/client",
199060
199079
  "@barefootjs/client/runtime"
@@ -199444,9 +199463,9 @@ function registerBuiltinLoweringPlugins() {
199444
199463
  registerLoweringPlugin(plugin);
199445
199464
  }
199446
199465
  // ../jsx/src/combine-client-js.ts
199447
- var import_typescript25 = __toESM(require_typescript(), 1);
199448
- // ../jsx/src/debug.ts
199449
199466
  var import_typescript26 = __toESM(require_typescript(), 1);
199467
+ // ../jsx/src/debug.ts
199468
+ var import_typescript27 = __toESM(require_typescript(), 1);
199450
199469
  function escapeForIdBoundary(name) {
199451
199470
  return name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
199452
199471
  }
@@ -199538,7 +199557,7 @@ function resolveSetters(handler, setterToSignal, fnSetters) {
199538
199557
  return refs;
199539
199558
  }
199540
199559
  // ../jsx/src/profiler.ts
199541
- var import_typescript27 = __toESM(require_typescript(), 1);
199560
+ var import_typescript28 = __toESM(require_typescript(), 1);
199542
199561
 
199543
199562
  // ../jsx/src/index.ts
199544
199563
  registerBuiltinLoweringPlugins();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barefootjs/test",
3
- "version": "0.31.3",
3
+ "version": "0.31.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.31.3"
42
+ "@barefootjs/jsx": "0.31.4"
43
43
  },
44
44
  "devDependencies": {
45
45
  "typescript": "^5.0.0"