@barefootjs/test 0.33.6 → 0.35.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 +125 -49
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -187295,6 +187295,29 @@ var import_typescript10 = __toESM(require_typescript(), 1);
187295
187295
 
187296
187296
  // ../jsx/src/expression-parser.ts
187297
187297
  var import_typescript = __toESM(require_typescript(), 1);
187298
+
187299
+ // ../jsx/src/lowering-registry.ts
187300
+ var plugins = [];
187301
+ function registerLoweringPlugin(plugin) {
187302
+ const existing = plugins.findIndex((p) => p.name === plugin.name);
187303
+ if (existing >= 0)
187304
+ plugins[existing] = plugin;
187305
+ else
187306
+ plugins.push(plugin);
187307
+ }
187308
+ function loweringNodeChildren(node) {
187309
+ if (node.kind === "helper-call")
187310
+ return [...node.args];
187311
+ const children = [node.base];
187312
+ for (const t of node.triples) {
187313
+ if (t.guard)
187314
+ children.push(t.guard);
187315
+ children.push(t.value);
187316
+ }
187317
+ return children;
187318
+ }
187319
+
187320
+ // ../jsx/src/expression-parser.ts
187298
187321
  var UNSUPPORTED_METHODS = new Set([
187299
187322
  "filter",
187300
187323
  "map",
@@ -187454,7 +187477,7 @@ function convertNode(node, raw) {
187454
187477
  }
187455
187478
  if (n === undefined || Number.isNaN(n)) {
187456
187479
  const parsedDepth = convertNode(depthNode, raw);
187457
- if (checkSupport(parsedDepth, "rendered").supported) {
187480
+ if (checkSupport(parsedDepth, "rendered", []).supported) {
187458
187481
  depthExpr = parsedDepth;
187459
187482
  flatDepth = 1;
187460
187483
  } else {
@@ -188232,10 +188255,10 @@ function getUnaryOperatorString(op) {
188232
188255
  return "unknown";
188233
188256
  }
188234
188257
  }
188235
- function isSupported(expr) {
188236
- return checkSupport(expr, "rendered");
188258
+ function isSupported(expr, opts) {
188259
+ return checkSupport(expr, "rendered", opts?.loweringMatchers ?? []);
188237
188260
  }
188238
- function checkSupport(expr, pos) {
188261
+ function checkSupport(expr, pos, matchers) {
188239
188262
  switch (expr.kind) {
188240
188263
  case "unsupported":
188241
188264
  return { supported: false, reason: expr.reason };
@@ -188244,7 +188267,7 @@ function checkSupport(expr, pos) {
188244
188267
  return { supported: false, reason: "Unsupported syntax: ObjectLiteralExpression" };
188245
188268
  }
188246
188269
  for (const prop of expr.properties) {
188247
- const propSupport = checkSupport(prop.kind === "spread" ? prop.expr : prop.value, pos);
188270
+ const propSupport = checkSupport(prop.kind === "spread" ? prop.expr : prop.value, pos, matchers);
188248
188271
  if (!propSupport.supported)
188249
188272
  return propSupport;
188250
188273
  }
@@ -188259,7 +188282,7 @@ function checkSupport(expr, pos) {
188259
188282
  return { supported: false, reason: "Standalone arrow functions / regex literals are not supported" };
188260
188283
  case "array-literal": {
188261
188284
  for (const el of expr.elements) {
188262
- const elSupport = checkSupport(el, pos);
188285
+ const elSupport = checkSupport(el, pos, matchers);
188263
188286
  if (!elSupport.supported)
188264
188287
  return elSupport;
188265
188288
  }
@@ -188272,28 +188295,39 @@ function checkSupport(expr, pos) {
188272
188295
  reason: `String.prototype.${expr.method} supports only a string pattern + string replacement (the regex form is deferred); use a string pattern or wrap the expression in /* @client */`
188273
188296
  };
188274
188297
  }
188275
- const objSupport = checkSupport(expr.object, pos);
188298
+ const objSupport = checkSupport(expr.object, pos, matchers);
188276
188299
  if (!objSupport.supported)
188277
188300
  return objSupport;
188278
188301
  for (const arg of expr.args) {
188279
- const argSupport = checkSupport(arg, pos);
188302
+ const argSupport = checkSupport(arg, pos, matchers);
188280
188303
  if (!argSupport.supported)
188281
188304
  return argSupport;
188282
188305
  }
188283
188306
  if (expr.method === "flat" && expr.depthExpr) {
188284
- const depthSupport = checkSupport(expr.depthExpr, pos);
188307
+ const depthSupport = checkSupport(expr.depthExpr, pos, matchers);
188285
188308
  if (!depthSupport.supported)
188286
188309
  return depthSupport;
188287
188310
  }
188288
188311
  return { supported: true, level: "L2" };
188289
188312
  }
188290
188313
  case "call": {
188314
+ for (const matcher of matchers) {
188315
+ const node = matcher(expr.callee, expr.args);
188316
+ if (!node)
188317
+ continue;
188318
+ for (const child of loweringNodeChildren(node)) {
188319
+ const childSupport = checkSupport(child, pos, matchers);
188320
+ if (!childSupport.supported)
188321
+ return childSupport;
188322
+ }
188323
+ return { supported: true, level: "L2" };
188324
+ }
188291
188325
  const cb = asCallbackMethodCall(expr);
188292
188326
  if (cb) {
188293
- const objSupport = checkSupport(cb.object, pos);
188327
+ const objSupport = checkSupport(cb.object, pos, matchers);
188294
188328
  if (!objSupport.supported)
188295
188329
  return objSupport;
188296
- const bodySupport = checkSupport(cb.arrow.body, pos);
188330
+ const bodySupport = checkSupport(cb.arrow.body, pos, matchers);
188297
188331
  if (!bodySupport.supported) {
188298
188332
  return {
188299
188333
  supported: false,
@@ -188302,13 +188336,13 @@ function checkSupport(expr, pos) {
188302
188336
  };
188303
188337
  }
188304
188338
  for (const rest of cb.args) {
188305
- const restSupport = checkSupport(rest, pos);
188339
+ const restSupport = checkSupport(rest, pos, matchers);
188306
188340
  if (!restSupport.supported)
188307
188341
  return restSupport;
188308
188342
  }
188309
188343
  return { supported: true, level: "L5" };
188310
188344
  }
188311
- const calleeSupport = checkSupport(expr.callee, pos);
188345
+ const calleeSupport = checkSupport(expr.callee, pos, matchers);
188312
188346
  if (!calleeSupport.supported) {
188313
188347
  return calleeSupport;
188314
188348
  }
@@ -188327,7 +188361,7 @@ function checkSupport(expr, pos) {
188327
188361
  return { supported: true, level: "L1" };
188328
188362
  }
188329
188363
  for (const arg of expr.args) {
188330
- const argSupport = checkSupport(arg, pos);
188364
+ const argSupport = checkSupport(arg, pos, matchers);
188331
188365
  if (!argSupport.supported) {
188332
188366
  return argSupport;
188333
188367
  }
@@ -188335,7 +188369,7 @@ function checkSupport(expr, pos) {
188335
188369
  return { supported: true, level: "L2" };
188336
188370
  }
188337
188371
  case "member": {
188338
- const objSupport = checkSupport(expr.object, pos);
188372
+ const objSupport = checkSupport(expr.object, pos, matchers);
188339
188373
  if (!objSupport.supported) {
188340
188374
  return objSupport;
188341
188375
  }
@@ -188345,19 +188379,19 @@ function checkSupport(expr, pos) {
188345
188379
  return { supported: true, level: "L2" };
188346
188380
  }
188347
188381
  case "index-access": {
188348
- const objSupport = checkSupport(expr.object, pos);
188382
+ const objSupport = checkSupport(expr.object, pos, matchers);
188349
188383
  if (!objSupport.supported)
188350
188384
  return objSupport;
188351
- const indexSupport = checkSupport(expr.index, pos);
188385
+ const indexSupport = checkSupport(expr.index, pos, matchers);
188352
188386
  if (!indexSupport.supported)
188353
188387
  return indexSupport;
188354
188388
  return { supported: true, level: "L2" };
188355
188389
  }
188356
188390
  case "binary": {
188357
- const leftSupport = checkSupport(expr.left, pos);
188391
+ const leftSupport = checkSupport(expr.left, pos, matchers);
188358
188392
  if (!leftSupport.supported)
188359
188393
  return leftSupport;
188360
- const rightSupport = checkSupport(expr.right, pos);
188394
+ const rightSupport = checkSupport(expr.right, pos, matchers);
188361
188395
  if (!rightSupport.supported)
188362
188396
  return rightSupport;
188363
188397
  if (["===", "==", "!==", "!=", ">", "<", ">=", "<="].includes(expr.op)) {
@@ -188369,7 +188403,7 @@ function checkSupport(expr, pos) {
188369
188403
  return { supported: false, reason: `Unknown operator: ${expr.op}` };
188370
188404
  }
188371
188405
  case "unary": {
188372
- const argSupport = checkSupport(expr.argument, pos);
188406
+ const argSupport = checkSupport(expr.argument, pos, matchers);
188373
188407
  if (!argSupport.supported)
188374
188408
  return argSupport;
188375
188409
  if (expr.op === "!") {
@@ -188381,25 +188415,25 @@ function checkSupport(expr, pos) {
188381
188415
  return { supported: false, reason: `Unsupported unary operator: ${expr.op}` };
188382
188416
  }
188383
188417
  case "logical": {
188384
- const leftSupport = checkSupport(expr.left, pos);
188418
+ const leftSupport = checkSupport(expr.left, pos, matchers);
188385
188419
  if (!leftSupport.supported)
188386
188420
  return leftSupport;
188387
188421
  if (expr.op === "??" && expr.right.kind === "object-literal" && expr.right.properties.length === 0) {
188388
188422
  return { supported: true, level: "L4" };
188389
188423
  }
188390
- const rightSupport = checkSupport(expr.right, pos);
188424
+ const rightSupport = checkSupport(expr.right, pos, matchers);
188391
188425
  if (!rightSupport.supported)
188392
188426
  return rightSupport;
188393
188427
  return { supported: true, level: "L4" };
188394
188428
  }
188395
188429
  case "conditional": {
188396
- const testSupport = checkSupport(expr.test, pos);
188430
+ const testSupport = checkSupport(expr.test, pos, matchers);
188397
188431
  if (!testSupport.supported)
188398
188432
  return testSupport;
188399
- const consSupport = checkSupport(expr.consequent, pos);
188433
+ const consSupport = checkSupport(expr.consequent, pos, matchers);
188400
188434
  if (!consSupport.supported)
188401
188435
  return consSupport;
188402
- const altSupport = checkSupport(expr.alternate, pos);
188436
+ const altSupport = checkSupport(expr.alternate, pos, matchers);
188403
188437
  if (!altSupport.supported)
188404
188438
  return altSupport;
188405
188439
  return { supported: true, level: "L4" };
@@ -188407,7 +188441,7 @@ function checkSupport(expr, pos) {
188407
188441
  case "template-literal": {
188408
188442
  for (const part of expr.parts) {
188409
188443
  if (part.type === "expression") {
188410
- const partSupport = checkSupport(part.expr, pos);
188444
+ const partSupport = checkSupport(part.expr, pos, matchers);
188411
188445
  if (!partSupport.supported)
188412
188446
  return partSupport;
188413
188447
  }
@@ -189404,6 +189438,12 @@ class BindingScope {
189404
189438
  }
189405
189439
  }
189406
189440
 
189441
+ // ../jsx/src/ir-to-client-js/safe-html.ts
189442
+ function safeHtml(expr) {
189443
+ return expr;
189444
+ }
189445
+ var EMPTY_MARKUP = safeHtml("''");
189446
+
189407
189447
  // ../jsx/src/ir-to-client-js/html-template.ts
189408
189448
  function splitTemplateInterpolations(inner) {
189409
189449
  const parts = [];
@@ -189592,8 +189632,6 @@ function collectAstPropRefs(node, propNames, out) {
189592
189632
  walkWithScope(node, (n, parent, shadowed) => {
189593
189633
  if (shadowed || !propNames.has(n.text))
189594
189634
  return;
189595
- if (parent && import_typescript7.default.isShorthandPropertyAssignment(parent) && parent.name === n)
189596
- return;
189597
189635
  if (isNonValuePosition(n, parent))
189598
189636
  return;
189599
189637
  out.add(n.text);
@@ -191415,6 +191453,7 @@ var CLIENT_EXPORTS = new Set([
191415
191453
  "isSSRPortal",
191416
191454
  "findSiblingSlot",
191417
191455
  "cleanupPortalPlaceholder",
191456
+ "trackPosition",
191418
191457
  "createSearchParams",
191419
191458
  "queryHref",
191420
191459
  "formatDate",
@@ -192734,7 +192773,8 @@ var BROWSER_ONLY_CLIENT_APIS = new Set([
192734
192773
  "createPortal",
192735
192774
  "isSSRPortal",
192736
192775
  "findSiblingSlot",
192737
- "cleanupPortalPlaceholder"
192776
+ "cleanupPortalPlaceholder",
192777
+ "trackPosition"
192738
192778
  ]);
192739
192779
  function importsBrowserOnlyClientApi(ctx) {
192740
192780
  for (const imp of ctx.imports) {
@@ -194807,9 +194847,8 @@ function collectBranchLocalPropRefsViaSubstitution(node, ctx) {
194807
194847
  function visit2(n, parent) {
194808
194848
  if (import_typescript14.default.isIdentifier(n) && propDepsMap.has(n.text)) {
194809
194849
  const isObjectKey = parent && import_typescript14.default.isPropertyAssignment(parent) && parent.name === n;
194810
- const isShorthand = parent && import_typescript14.default.isShorthandPropertyAssignment(parent) && parent.name === n;
194811
194850
  const isAccessName = parent && import_typescript14.default.isPropertyAccessExpression(parent) && parent.name === n;
194812
- if (!isObjectKey && !isShorthand && !isAccessName) {
194851
+ if (!isObjectKey && !isAccessName) {
194813
194852
  const deps = propDepsMap.get(n.text);
194814
194853
  if (deps && deps.size > 0) {
194815
194854
  if (!acc)
@@ -195287,8 +195326,7 @@ function lowerFormControlValueSsr(tagName, attrs, children) {
195287
195326
  children.push({
195288
195327
  type: "expression",
195289
195328
  expr,
195290
- templateExpr: `escapeText(${templateExpr ?? expr})`,
195291
- escapeInClientTemplate: true,
195329
+ templateExpr,
195292
195330
  typeInfo: null,
195293
195331
  reactive: false,
195294
195332
  slotId: null,
@@ -195299,26 +195337,76 @@ function lowerFormControlValueSsr(tagName, attrs, children) {
195299
195337
  }
195300
195338
  const selectedForLiteral = (optValue) => AttrValueOf.expression(`(${expr}) === ${JSON.stringify(optValue)}`, templateExpr !== undefined ? { templateExpr: `(${templateExpr}) === ${JSON.stringify(optValue)}` } : undefined);
195301
195339
  const selectedForExpr = (optExpr, optTemplateExpr) => AttrValueOf.expression(`(${expr}) === (${optExpr})`, templateExpr !== undefined || optTemplateExpr !== undefined ? { templateExpr: `(${templateExpr ?? expr}) === (${optTemplateExpr ?? optExpr})` } : undefined);
195340
+ const matchConditions = [];
195341
+ let optionSetIsDynamic = false;
195302
195342
  const distribute = (nodes) => {
195303
195343
  for (const n of nodes) {
195344
+ if (n.type === "text")
195345
+ continue;
195304
195346
  if (n.type === "element" && n.tag === "option") {
195305
- if (n.attrs.some((a) => a.name === "selected"))
195347
+ if (n.attrs.some((a) => a.name === "selected")) {
195348
+ optionSetIsDynamic = true;
195306
195349
  continue;
195350
+ }
195307
195351
  const optValue = n.attrs.find((a) => a.name === "value");
195308
- if (!optValue)
195352
+ if (!optValue) {
195353
+ optionSetIsDynamic = true;
195309
195354
  continue;
195355
+ }
195310
195356
  if (optValue.value.kind === "literal") {
195311
- n.attrs.push({ name: "selected", value: selectedForLiteral(optValue.value.value), loc: n.loc });
195357
+ const selected = selectedForLiteral(optValue.value.value);
195358
+ n.attrs.push({ name: "selected", value: selected, loc: n.loc });
195359
+ matchConditions.push(selected);
195312
195360
  } else if (optValue.value.kind === "expression") {
195313
195361
  const selected = selectedForExpr(optValue.value.expr, optValue.value.templateExpr);
195314
195362
  n.attrs.push({ name: "selected", value: selected, loc: n.loc });
195363
+ matchConditions.push(selected);
195364
+ } else {
195365
+ optionSetIsDynamic = true;
195315
195366
  }
195316
- } else if (n.type === "fragment" || n.type === "loop" || n.type === "element" && n.tag === "optgroup") {
195367
+ } else if (n.type === "fragment" || n.type === "element" && n.tag === "optgroup") {
195317
195368
  distribute(n.children);
195369
+ } else if (n.type === "loop") {
195370
+ optionSetIsDynamic = true;
195371
+ distribute(n.children);
195372
+ } else {
195373
+ optionSetIsDynamic = true;
195318
195374
  }
195319
195375
  }
195320
195376
  };
195321
195377
  distribute(children);
195378
+ if (optionSetIsDynamic || matchConditions.length === 0)
195379
+ return;
195380
+ if (isMultiSelection(attrs))
195381
+ return;
195382
+ const orExpr = matchConditions.map((c) => `(${c.expr})`).join(" || ");
195383
+ const orTemplateExpr = matchConditions.some((c) => c.templateExpr !== undefined) ? matchConditions.map((c) => `(${c.templateExpr ?? c.expr})`).join(" || ") : undefined;
195384
+ children.unshift({
195385
+ type: "element",
195386
+ tag: "option",
195387
+ attrs: [
195388
+ { name: "value", value: AttrValueOf.literal(""), loc: valueAttr.loc },
195389
+ { name: "disabled", value: AttrValueOf.booleanAttr(), loc: valueAttr.loc },
195390
+ { name: "hidden", value: AttrValueOf.booleanAttr(), loc: valueAttr.loc },
195391
+ {
195392
+ name: "selected",
195393
+ value: AttrValueOf.expression(`!(${orExpr})`, orTemplateExpr !== undefined ? { templateExpr: `!(${orTemplateExpr})` } : undefined),
195394
+ loc: valueAttr.loc
195395
+ }
195396
+ ],
195397
+ events: [],
195398
+ ref: null,
195399
+ children: [],
195400
+ slotId: null,
195401
+ needsScope: false,
195402
+ loc: valueAttr.loc
195403
+ });
195404
+ }
195405
+ function isMultiSelection(attrs) {
195406
+ if (attrs.some((a) => a.name === "multiple"))
195407
+ return true;
195408
+ const sizeAttr = attrs.find((a) => a.name === "size");
195409
+ return sizeAttr?.value.kind === "literal" && Number(sizeAttr.value.value) > 1;
195322
195410
  }
195323
195411
  function transformHtmlElement(node, ctx, tagName) {
195324
195412
  const { attrs, events, ref } = processAttributes(node.openingElement.attributes, ctx);
@@ -199072,18 +199160,6 @@ var import_typescript16 = __toESM(require_typescript(), 1);
199072
199160
 
199073
199161
  // ../jsx/src/relocate.ts
199074
199162
  var import_typescript18 = __toESM(require_typescript(), 1);
199075
-
199076
- // ../jsx/src/lowering-registry.ts
199077
- var plugins = [];
199078
- function registerLoweringPlugin(plugin) {
199079
- const existing = plugins.findIndex((p) => p.name === plugin.name);
199080
- if (existing >= 0)
199081
- plugins[existing] = plugin;
199082
- else
199083
- plugins.push(plugin);
199084
- }
199085
-
199086
- // ../jsx/src/relocate.ts
199087
199163
  var REGISTRY_SAFE_BINDING_KINDS = new Set([
199088
199164
  "global",
199089
199165
  "module-import",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barefootjs/test",
3
- "version": "0.33.6",
3
+ "version": "0.35.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.33.6"
42
+ "@barefootjs/jsx": "0.35.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "typescript": "^5.0.0"