@barefootjs/jsx 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 (39) hide show
  1. package/dist/analyzer.d.ts.map +1 -1
  2. package/dist/builtin-lowering-plugins.d.ts.map +1 -1
  3. package/dist/compiler.d.ts.map +1 -1
  4. package/dist/date-lowering.d.ts +33 -0
  5. package/dist/date-lowering.d.ts.map +1 -0
  6. package/dist/index.js +663 -218
  7. package/dist/ir-to-client-js/emit-reactive.d.ts.map +1 -1
  8. package/dist/ir-to-client-js/generate-init.d.ts.map +1 -1
  9. package/dist/ir-to-client-js/imports.d.ts +2 -2
  10. package/dist/ir-to-client-js/imports.d.ts.map +1 -1
  11. package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
  12. package/dist/ir-to-client-js/types.d.ts +14 -1
  13. package/dist/ir-to-client-js/types.d.ts.map +1 -1
  14. package/dist/jsx-to-ir.d.ts.map +1 -1
  15. package/dist/rich-type-evidence.d.ts +67 -0
  16. package/dist/rich-type-evidence.d.ts.map +1 -0
  17. package/dist/rich-type-refusal.d.ts +35 -0
  18. package/dist/rich-type-refusal.d.ts.map +1 -0
  19. package/dist/types.d.ts +9 -0
  20. package/dist/types.d.ts.map +1 -1
  21. package/package.json +2 -2
  22. package/src/__tests__/client-js-generation.test.ts +59 -0
  23. package/src/__tests__/date-lowering.test.ts +232 -0
  24. package/src/__tests__/nested-loop-reactive-attrs.test.ts +56 -0
  25. package/src/__tests__/rich-type-method-refusal.test.ts +323 -0
  26. package/src/analyzer.ts +21 -2
  27. package/src/builtin-lowering-plugins.ts +2 -1
  28. package/src/compiler.ts +3 -0
  29. package/src/date-lowering.ts +117 -0
  30. package/src/ir-to-client-js/emit-reactive.ts +103 -2
  31. package/src/ir-to-client-js/generate-init.ts +11 -4
  32. package/src/ir-to-client-js/imports.ts +4 -0
  33. package/src/ir-to-client-js/index.ts +2 -0
  34. package/src/ir-to-client-js/reactivity.ts +13 -2
  35. package/src/ir-to-client-js/types.ts +15 -0
  36. package/src/jsx-to-ir.ts +128 -3
  37. package/src/rich-type-evidence.ts +159 -0
  38. package/src/rich-type-refusal.ts +311 -0
  39. package/src/types.ts +9 -0
package/dist/index.js CHANGED
@@ -5302,6 +5302,135 @@ function internalInvariant(cond, message) {
5302
5302
  }
5303
5303
  }
5304
5304
 
5305
+ // src/rich-type-evidence.ts
5306
+ var HOST_RICH_TYPE_NAMES = new Set([
5307
+ "Date",
5308
+ "Map",
5309
+ "Set",
5310
+ "WeakMap",
5311
+ "WeakSet",
5312
+ "URL",
5313
+ "URLSearchParams",
5314
+ "RegExp",
5315
+ "Promise",
5316
+ "Error",
5317
+ "Symbol",
5318
+ "BigInt",
5319
+ "Function"
5320
+ ]);
5321
+ function baseTypeName(raw) {
5322
+ const idx = raw.indexOf("<");
5323
+ return (idx === -1 ? raw : raw.slice(0, idx)).trim();
5324
+ }
5325
+ function isNullishArm(t) {
5326
+ if (t.kind === "primitive" && (t.primitive === "null" || t.primitive === "undefined"))
5327
+ return true;
5328
+ return t.kind === "unknown" && (t.raw === "null" || t.raw === "undefined");
5329
+ }
5330
+ function stripUnion(type) {
5331
+ if (!type || type.kind !== "union" || !type.unionTypes)
5332
+ return type;
5333
+ const nonNullish = type.unionTypes.filter((t) => !isNullishArm(t));
5334
+ return nonNullish.length === 1 ? stripUnion(nonNullish[0]) : type;
5335
+ }
5336
+ function derefNamedType(type, meta) {
5337
+ if (type.kind !== "interface")
5338
+ return type;
5339
+ if (type.properties && type.properties.length > 0)
5340
+ return type;
5341
+ const name = baseTypeName(type.raw);
5342
+ const def = meta.typeDefinitions.find((d) => d.name === name);
5343
+ if (!def?.properties)
5344
+ return type;
5345
+ return { ...type, properties: def.properties };
5346
+ }
5347
+ function lookupProperty(objType, propName, meta) {
5348
+ const stripped = stripUnion(objType);
5349
+ if (!stripped)
5350
+ return null;
5351
+ const deref = derefNamedType(stripped, meta);
5352
+ const prop = deref.properties?.find((p) => p.name === propName);
5353
+ return prop ? stripUnion(prop.type) : null;
5354
+ }
5355
+ function resolveReceiverType(expr, meta, bindings) {
5356
+ if (expr.kind === "identifier") {
5357
+ if (bindings.has(expr.name))
5358
+ return stripUnion(bindings.get(expr.name) ?? null);
5359
+ if (meta.propsObjectName !== null) {
5360
+ return expr.name === meta.propsObjectName ? stripUnion(meta.propsType) : null;
5361
+ }
5362
+ const param = meta.propsParams.find((p) => p.name === expr.name && !p.isRest);
5363
+ if (!param)
5364
+ return null;
5365
+ return lookupProperty(meta.propsType, param.sourceName ?? param.name, meta);
5366
+ }
5367
+ if (expr.kind === "member" && !expr.computed) {
5368
+ const objType = resolveReceiverType(expr.object, meta, bindings);
5369
+ return lookupProperty(objType, expr.property, meta);
5370
+ }
5371
+ return null;
5372
+ }
5373
+
5374
+ // src/date-lowering.ts
5375
+ var CATALOGUED_RICH_TYPE_NAMES = new Set(["Date"]);
5376
+ var DATE_METHODS = new Set([
5377
+ "getUTCFullYear",
5378
+ "getUTCMonth",
5379
+ "getUTCDate",
5380
+ "getUTCHours",
5381
+ "getUTCMinutes",
5382
+ "getUTCSeconds",
5383
+ "getTime",
5384
+ "toISOString"
5385
+ ]);
5386
+ var EMPTY_BINDINGS = new Map;
5387
+ function typeReachesDate(type, meta, seen) {
5388
+ const stripped = stripUnion(type);
5389
+ if (!stripped)
5390
+ return false;
5391
+ if (stripped.kind === "interface") {
5392
+ const name = baseTypeName(stripped.raw);
5393
+ if (name === "Date")
5394
+ return true;
5395
+ if (seen.has(name))
5396
+ return false;
5397
+ seen.add(name);
5398
+ } else if (stripped.kind !== "object") {
5399
+ return false;
5400
+ }
5401
+ const deref = derefNamedType(stripped, meta);
5402
+ if (!deref.properties)
5403
+ return false;
5404
+ return deref.properties.some((p) => typeReachesDate(p.type, meta, seen));
5405
+ }
5406
+ function matchDateCall(callee, args, metadata) {
5407
+ if (callee.kind !== "member" || callee.computed)
5408
+ return null;
5409
+ if (args.length !== 0 || !DATE_METHODS.has(callee.property))
5410
+ return null;
5411
+ const receiverType = resolveReceiverType(callee.object, metadata, EMPTY_BINDINGS);
5412
+ if (!receiverType || receiverType.kind !== "interface")
5413
+ return null;
5414
+ const typeName = baseTypeName(receiverType.raw);
5415
+ if (typeName !== "Date")
5416
+ return null;
5417
+ if (metadata.typeDefinitions.some((d) => d.name === typeName))
5418
+ return null;
5419
+ return {
5420
+ kind: "helper-call",
5421
+ helper: "date",
5422
+ args: [callee.object, { kind: "literal", value: callee.property, literalType: "string" }]
5423
+ };
5424
+ }
5425
+ var datePlugin = {
5426
+ name: "date",
5427
+ prepare(metadata) {
5428
+ if (!metadata.propsType || !typeReachesDate(metadata.propsType, metadata, new Set))
5429
+ return null;
5430
+ return (callee, args) => matchDateCall(callee, args, metadata);
5431
+ }
5432
+ };
5433
+
5305
5434
  // src/analyzer.ts
5306
5435
  var { default: fs} = (() => ({}));
5307
5436
  var REACTIVE_BRAND_PACKAGES = [
@@ -7090,7 +7219,8 @@ function extractProps(param, ctx) {
7090
7219
  type: resolvedType,
7091
7220
  optional: !!member?.optional || !!element.initializer,
7092
7221
  defaultValue,
7093
- defaultContainsArrow: defaultContainsArrow || undefined
7222
+ defaultContainsArrow: defaultContainsArrow || undefined,
7223
+ ...sourcePropName !== localName && { sourceName: sourcePropName }
7094
7224
  });
7095
7225
  }
7096
7226
  }
@@ -7149,7 +7279,7 @@ function collectKeysFromMembers(members, ctx) {
7149
7279
  return keys;
7150
7280
  }
7151
7281
  function collectMemberTypes(typeNode, ctx) {
7152
- const isResolvablePrimitive = (info) => info.kind === "primitive" && (info.primitive === "string" || info.primitive === "number" || info.primitive === "boolean");
7282
+ 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));
7153
7283
  const fromMembers = (members) => {
7154
7284
  const map = new Map;
7155
7285
  for (const member of members) {
@@ -8386,18 +8516,60 @@ function exprHasFunctionCalls(expr) {
8386
8516
  visit2(expr);
8387
8517
  return found;
8388
8518
  }
8519
+ function getDateLoweringMatcher(ctx) {
8520
+ if (ctx._dateLoweringMatcher === undefined) {
8521
+ const a = ctx.analyzer;
8522
+ const metadataSlice = {
8523
+ propsType: a.propsType,
8524
+ propsObjectName: a.propsObjectName,
8525
+ propsParams: a.propsParams,
8526
+ typeDefinitions: a.typeDefinitions
8527
+ };
8528
+ ctx._dateLoweringMatcher = datePlugin.prepare(metadataSlice);
8529
+ }
8530
+ return ctx._dateLoweringMatcher;
8531
+ }
8532
+ function lowerDateCalls(text, expr, ctx) {
8533
+ const matcher = getDateLoweringMatcher(ctx);
8534
+ if (!matcher)
8535
+ return text;
8536
+ const candidates = [];
8537
+ function visit2(n) {
8538
+ if (ts11.isCallExpression(n) && n.arguments.length === 0 && ts11.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && DATE_METHODS.has(n.expression.name.text)) {
8539
+ candidates.push(n);
8540
+ }
8541
+ ts11.forEachChild(n, visit2);
8542
+ }
8543
+ visit2(expr);
8544
+ if (candidates.length === 0)
8545
+ return text;
8546
+ const { protect, restore } = createTemplateAwareStringProtector();
8547
+ let result = protect(text);
8548
+ for (const call of candidates) {
8549
+ const propAccess = call.expression;
8550
+ const node = matcher(tsNodeToParsedExpr(propAccess), []);
8551
+ if (!node || node.kind !== "helper-call" || node.helper !== "date")
8552
+ continue;
8553
+ const op = propAccess.name.text;
8554
+ const receiverText = ctx.getJS(propAccess.expression);
8555
+ const matchText = ctx.getJS(call);
8556
+ result = result.replace(matchText, () => `date(${receiverText}, "${op}")`);
8557
+ }
8558
+ return restore(result);
8559
+ }
8389
8560
  function rewriteBarePropRefs2(text, expr, ctx) {
8561
+ const dateLowered = lowerDateCalls(text, expr, ctx);
8390
8562
  let propNames = getDestructuredPropNames(ctx);
8391
8563
  if (!propNames)
8392
- return;
8564
+ return dateLowered === text ? undefined : dateLowered;
8393
8565
  if (ctx.loopParams.size > 0) {
8394
8566
  const filtered = new Set([...propNames].filter((n) => !ctx.loopParams.has(n)));
8395
8567
  if (filtered.size === 0)
8396
- return;
8568
+ return dateLowered === text ? undefined : dateLowered;
8397
8569
  propNames = filtered;
8398
8570
  }
8399
8571
  const extraPropRefs = collectBranchLocalPropRefsViaSubstitution(expr, ctx);
8400
- return rewriteBarePropRefs(text, expr, propNames, extraPropRefs);
8572
+ return rewriteBarePropRefs(dateLowered, expr, propNames, extraPropRefs);
8401
8573
  }
8402
8574
  function collectBranchLocalPropRefsViaSubstitution(node, ctx) {
8403
8575
  const propDepsMap = ctx._branchScopePropDeps;
@@ -11829,7 +12001,8 @@ function collectLoopChildReactiveTexts(node, ctx, loopParam, loopParamBindings)
11829
12001
  return;
11830
12002
  const originFreeIds = freeIdsFromRefs(n.origin?.freeRefs);
11831
12003
  const expanded = expandConstantForReactivity(n.expr, ctx, originFreeIds);
11832
- if (classifyReactivity(expanded.expr, ctx, loopParam, loopParamBindings, expanded.freeIds).kind === "none")
12004
+ const reactive = classifyReactivity(expanded.expr, ctx, loopParam, loopParamBindings, expanded.freeIds).kind !== "none" || decideWrapFromAstFlags(n).wrap;
12005
+ if (!reactive)
11833
12006
  return;
11834
12007
  texts.push({
11835
12008
  slotId: n.slotId,
@@ -13230,7 +13403,8 @@ var RUNTIME_IMPORT_CANDIDATES = [
13230
13403
  "__bfText",
13231
13404
  "tAfter",
13232
13405
  "beginTurn",
13233
- "endTurn"
13406
+ "endTurn",
13407
+ "date"
13234
13408
  ];
13235
13409
  var RUNTIME_MODULE = "@barefootjs/client/runtime";
13236
13410
  var IMPORT_PLACEHOLDER = "/* __BAREFOOTJS_DOM_IMPORTS__ */";
@@ -16325,6 +16499,7 @@ function buildArmBody(branch, options) {
16325
16499
  }
16326
16500
 
16327
16501
  // src/ir-to-client-js/emit-reactive.ts
16502
+ import ts14 from "typescript";
16328
16503
  function bindingIdArg(ctx, slotId) {
16329
16504
  if (!ctx.profile || !slotId)
16330
16505
  return "";
@@ -16384,7 +16559,56 @@ function rewriteDestructuredPropsInExpr(expr, ctx) {
16384
16559
  }
16385
16560
  return restore(result);
16386
16561
  }
16562
+ function getReactiveDateLoweringMatcher(ctx) {
16563
+ if (!ctx.propsType)
16564
+ return null;
16565
+ const metadataSlice = {
16566
+ propsType: ctx.propsType,
16567
+ propsObjectName: ctx.propsObjectName,
16568
+ propsParams: ctx.propsParams,
16569
+ typeDefinitions: ctx.typeDefinitions ?? []
16570
+ };
16571
+ return datePlugin.prepare(metadataSlice);
16572
+ }
16573
+ function lowerDateCallsInReactiveExpr(expr, matcher) {
16574
+ if (!matcher)
16575
+ return expr;
16576
+ let sourceFile;
16577
+ try {
16578
+ sourceFile = ts14.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts14.ScriptTarget.Latest, true, ts14.ScriptKind.TS);
16579
+ } catch {
16580
+ return expr;
16581
+ }
16582
+ const stmt = sourceFile.statements[0];
16583
+ if (!stmt || !ts14.isExpressionStatement(stmt))
16584
+ return expr;
16585
+ const root = ts14.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
16586
+ const candidates = [];
16587
+ const visit3 = (n) => {
16588
+ if (ts14.isCallExpression(n) && n.arguments.length === 0 && ts14.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && DATE_METHODS.has(n.expression.name.text)) {
16589
+ candidates.push(n);
16590
+ }
16591
+ ts14.forEachChild(n, visit3);
16592
+ };
16593
+ visit3(root);
16594
+ if (candidates.length === 0)
16595
+ return expr;
16596
+ const { protect, restore } = createTemplateAwareStringProtector();
16597
+ let result = protect(expr);
16598
+ for (const call of candidates) {
16599
+ const propAccess = call.expression;
16600
+ const node = matcher(tsNodeToParsedExpr(propAccess), []);
16601
+ if (!node || node.kind !== "helper-call" || node.helper !== "date")
16602
+ continue;
16603
+ const op = propAccess.name.text;
16604
+ const receiverText = propAccess.expression.getText(sourceFile);
16605
+ const matchText = call.getText(sourceFile);
16606
+ result = result.replace(matchText, () => `date(${receiverText}, "${op}")`);
16607
+ }
16608
+ return restore(result);
16609
+ }
16387
16610
  function emitDynamicTextUpdates(lines, ctx) {
16611
+ const dateLoweringMatcher = getReactiveDateLoweringMatcher(ctx);
16388
16612
  const byExpression = new Map;
16389
16613
  for (const elem of ctx.dynamicElements) {
16390
16614
  const key = elem.expression;
@@ -16393,7 +16617,8 @@ function emitDynamicTextUpdates(lines, ctx) {
16393
16617
  }
16394
16618
  byExpression.get(key).push(elem);
16395
16619
  }
16396
- for (const [expr, elems] of byExpression) {
16620
+ for (const [rawExpr, elems] of byExpression) {
16621
+ const expr = lowerDateCallsInReactiveExpr(rawExpr, dateLoweringMatcher);
16397
16622
  const conditionalElems = elems.filter((e) => e.insideConditional);
16398
16623
  const normalElems = elems.filter((e) => !e.insideConditional);
16399
16624
  if (normalElems.length > 0 || conditionalElems.length > 0) {
@@ -17893,20 +18118,20 @@ var PHASES = [
17893
18118
  ];
17894
18119
 
17895
18120
  // src/ir-to-client-js/rewrite-props-object.ts
17896
- import ts14 from "typescript";
18121
+ import ts15 from "typescript";
17897
18122
  function rewritePropsObjectRef(code, propsObjectName) {
17898
18123
  const srcPropsName = propsObjectName ?? "props";
17899
18124
  if (srcPropsName === PROPS_PARAM)
17900
18125
  return code;
17901
18126
  if (!new RegExp(`\\b${srcPropsName}\\b`).test(code))
17902
18127
  return code;
17903
- const sourceFile = ts14.createSourceFile("init-body.ts", code, ts14.ScriptTarget.Latest, true, ts14.ScriptKind.TS);
18128
+ const sourceFile = ts15.createSourceFile("init-body.ts", code, ts15.ScriptTarget.Latest, true, ts15.ScriptKind.TS);
17904
18129
  const spans = [];
17905
18130
  function visit3(node) {
17906
- if (ts14.isIdentifier(node) && node.text === srcPropsName && shouldRewrite(node)) {
18131
+ if (ts15.isIdentifier(node) && node.text === srcPropsName && shouldRewrite(node)) {
17907
18132
  spans.push([node.getStart(sourceFile), node.getEnd()]);
17908
18133
  }
17909
- ts14.forEachChild(node, visit3);
18134
+ ts15.forEachChild(node, visit3);
17910
18135
  }
17911
18136
  visit3(sourceFile);
17912
18137
  if (spans.length === 0)
@@ -17922,17 +18147,17 @@ function shouldRewrite(node) {
17922
18147
  const parent = node.parent;
17923
18148
  if (!parent)
17924
18149
  return true;
17925
- if (ts14.isPropertyAccessExpression(parent) && parent.name === node)
18150
+ if (ts15.isPropertyAccessExpression(parent) && parent.name === node)
17926
18151
  return false;
17927
- if (ts14.isPropertyAssignment(parent) && parent.name === node)
18152
+ if (ts15.isPropertyAssignment(parent) && parent.name === node)
17928
18153
  return false;
17929
- if (ts14.isShorthandPropertyAssignment(parent) && parent.name === node)
18154
+ if (ts15.isShorthandPropertyAssignment(parent) && parent.name === node)
17930
18155
  return false;
17931
- if (ts14.isPropertySignature(parent) && parent.name === node)
18156
+ if (ts15.isPropertySignature(parent) && parent.name === node)
17932
18157
  return false;
17933
- if (ts14.isPropertyDeclaration(parent) && parent.name === node)
18158
+ if (ts15.isPropertyDeclaration(parent) && parent.name === node)
17934
18159
  return false;
17935
- if (ts14.isBindingElement(parent) && parent.name === node)
18160
+ if (ts15.isBindingElement(parent) && parent.name === node)
17936
18161
  return false;
17937
18162
  return true;
17938
18163
  }
@@ -17969,9 +18194,10 @@ function generateInitFunction(ir, ctx, siblingComponents, localImportPrefixes) {
17969
18194
  `), ctx.propsObjectName);
17970
18195
  generatedCode += `
17971
18196
  ` + hydrateLine;
17972
- const allImportLines = resolveFinalImports(generatedCode, ir, localImportPrefixes);
17973
18197
  const moduleConstantsCode = emitModuleLevelDeclarations(classification.moduleLevelConstants, classification.moduleLevelFunctions, classification.moduleLevelSignals, classification.moduleLevelMemos);
17974
- return generatedCode.replace(IMPORT_PLACEHOLDER, allImportLines).replace(MODULE_CONSTANTS_PLACEHOLDER, moduleConstantsCode);
18198
+ const codeWithModuleConstants = generatedCode.replace(MODULE_CONSTANTS_PLACEHOLDER, () => moduleConstantsCode);
18199
+ const allImportLines = resolveFinalImports(codeWithModuleConstants, ir, localImportPrefixes);
18200
+ return codeWithModuleConstants.replace(IMPORT_PLACEHOLDER, () => allImportLines);
17975
18201
  }
17976
18202
 
17977
18203
  // src/ir-to-client-js/source-map.ts
@@ -18219,6 +18445,8 @@ function createContext(ir, scope, adapterCapabilities, profile) {
18219
18445
  propsParams: ir.metadata.propsParams,
18220
18446
  propsObjectName: ir.metadata.propsObjectName,
18221
18447
  restPropsName: ir.metadata.restPropsName,
18448
+ propsType: ir.metadata.propsType,
18449
+ typeDefinitions: ir.metadata.typeDefinitions,
18222
18450
  interactiveElements: [],
18223
18451
  dynamicElements: [],
18224
18452
  conditionalElements: [],
@@ -18454,7 +18682,7 @@ function walkIR2(node, visitor) {
18454
18682
  }
18455
18683
 
18456
18684
  // src/preprocess-inline-jsx-callbacks.ts
18457
- import ts15 from "typescript";
18685
+ import ts16 from "typescript";
18458
18686
  var SYNTHETIC_PREFIX = "BFInlineJsxCallback";
18459
18687
  var MAX_FIXPOINT_ITERATIONS = 16;
18460
18688
  function preprocessInlineJsxCallbacks(source, filePath) {
@@ -18476,8 +18704,8 @@ function preprocessInlineJsxCallbacks(source, filePath) {
18476
18704
  return { source: current, errors, syntheticNames };
18477
18705
  }
18478
18706
  function runSinglePass(source, filePath, startingCounter) {
18479
- const sourceFile = ts15.createSourceFile(filePath, source, ts15.ScriptTarget.Latest, true, ts15.ScriptKind.TSX);
18480
- const hasUseClient = sourceFile.statements.some((stmt) => ts15.isExpressionStatement(stmt) && ts15.isStringLiteral(stmt.expression) && (stmt.expression.text === "use client" || stmt.expression.text === "'use client'"));
18707
+ const sourceFile = ts16.createSourceFile(filePath, source, ts16.ScriptTarget.Latest, true, ts16.ScriptKind.TSX);
18708
+ const hasUseClient = sourceFile.statements.some((stmt) => ts16.isExpressionStatement(stmt) && ts16.isStringLiteral(stmt.expression) && (stmt.expression.text === "use client" || stmt.expression.text === "'use client'"));
18481
18709
  if (!hasUseClient) {
18482
18710
  return { source, errors: [], syntheticNames: [], counterAfter: startingCounter };
18483
18711
  }
@@ -18499,22 +18727,22 @@ function runSinglePass(source, filePath, startingCounter) {
18499
18727
  }
18500
18728
  }
18501
18729
  function visit3(node) {
18502
- if (ts15.isJsxAttribute(node) && node.initializer && ts15.isJsxExpression(node.initializer) && node.initializer.expression) {
18730
+ if (ts16.isJsxAttribute(node) && node.initializer && ts16.isJsxExpression(node.initializer) && node.initializer.expression) {
18503
18731
  if (tryHandleArrowValue(node.initializer.expression)) {
18504
18732
  return;
18505
18733
  }
18506
18734
  }
18507
- if (ts15.isPropertyAssignment(node) && node.initializer) {
18735
+ if (ts16.isPropertyAssignment(node) && node.initializer) {
18508
18736
  if (tryHandleArrowValue(node.initializer))
18509
18737
  return;
18510
18738
  }
18511
- ts15.forEachChild(node, visit3);
18739
+ ts16.forEachChild(node, visit3);
18512
18740
  }
18513
18741
  function tryHandleArrowValue(initializer) {
18514
18742
  let expr = initializer;
18515
- while (ts15.isParenthesizedExpression(expr))
18743
+ while (ts16.isParenthesizedExpression(expr))
18516
18744
  expr = expr.expression;
18517
- if (ts15.isArrowFunction(expr) && arrowBodyContainsJsx(expr)) {
18745
+ if (ts16.isArrowFunction(expr) && arrowBodyContainsJsx(expr)) {
18518
18746
  return handleInlineArrow(expr);
18519
18747
  }
18520
18748
  return false;
@@ -18551,7 +18779,7 @@ function runSinglePass(source, filePath, startingCounter) {
18551
18779
  replacements.push({ start: arrowStart, end: arrowEnd, text: name });
18552
18780
  return true;
18553
18781
  }
18554
- ts15.forEachChild(sourceFile, visit3);
18782
+ ts16.forEachChild(sourceFile, visit3);
18555
18783
  if (replacements.length === 0) {
18556
18784
  return { source, errors, syntheticNames, counterAfter: counter };
18557
18785
  }
@@ -18574,11 +18802,11 @@ function errorMessageForCapture(captures) {
18574
18802
  return `Inline JSX-returning arrow function captures non-module identifier(s): ` + `${captures.sort().join(", ")}. ` + `Extract the callback into a top-level '\\'use client\\'' component (e.g. ` + `\`function MyNode(n) { return <div/> }\` then \`renderNode={MyNode}\`) ` + `or pass captured values via component props.`;
18575
18803
  }
18576
18804
  function arrowBodyContainsJsx(arrow) {
18577
- if (ts15.isBlock(arrow.body)) {
18805
+ if (ts16.isBlock(arrow.body)) {
18578
18806
  return blockReturnsJsx(arrow.body);
18579
18807
  }
18580
18808
  let body = arrow.body;
18581
- while (ts15.isParenthesizedExpression(body))
18809
+ while (ts16.isParenthesizedExpression(body))
18582
18810
  body = body.expression;
18583
18811
  return isJsxLike(body);
18584
18812
  }
@@ -18587,24 +18815,24 @@ function blockReturnsJsx(block) {
18587
18815
  function visit3(n) {
18588
18816
  if (found)
18589
18817
  return;
18590
- if (ts15.isReturnStatement(n) && n.expression) {
18818
+ if (ts16.isReturnStatement(n) && n.expression) {
18591
18819
  let e = n.expression;
18592
- while (ts15.isParenthesizedExpression(e))
18820
+ while (ts16.isParenthesizedExpression(e))
18593
18821
  e = e.expression;
18594
18822
  if (isJsxLike(e)) {
18595
18823
  found = true;
18596
18824
  return;
18597
18825
  }
18598
18826
  }
18599
- if (ts15.isArrowFunction(n) || ts15.isFunctionDeclaration(n) || ts15.isFunctionExpression(n))
18827
+ if (ts16.isArrowFunction(n) || ts16.isFunctionDeclaration(n) || ts16.isFunctionExpression(n))
18600
18828
  return;
18601
- ts15.forEachChild(n, visit3);
18829
+ ts16.forEachChild(n, visit3);
18602
18830
  }
18603
- ts15.forEachChild(block, visit3);
18831
+ ts16.forEachChild(block, visit3);
18604
18832
  return found;
18605
18833
  }
18606
18834
  function isJsxLike(expr) {
18607
- return ts15.isJsxElement(expr) || ts15.isJsxSelfClosingElement(expr) || ts15.isJsxFragment(expr);
18835
+ return ts16.isJsxElement(expr) || ts16.isJsxSelfClosingElement(expr) || ts16.isJsxFragment(expr);
18608
18836
  }
18609
18837
  function collectArrowParamNames(arrow) {
18610
18838
  const names = new Set;
@@ -18614,13 +18842,13 @@ function collectArrowParamNames(arrow) {
18614
18842
  }
18615
18843
  function collectBindingNames(name, out) {
18616
18844
  const push = Array.isArray(out) ? (n) => out.push(n) : (n) => out.add(n);
18617
- if (ts15.isIdentifier(name)) {
18845
+ if (ts16.isIdentifier(name)) {
18618
18846
  push(name.text);
18619
- } else if (ts15.isObjectBindingPattern(name)) {
18847
+ } else if (ts16.isObjectBindingPattern(name)) {
18620
18848
  name.elements.forEach((el) => collectBindingNames(el.name, out));
18621
- } else if (ts15.isArrayBindingPattern(name)) {
18849
+ } else if (ts16.isArrayBindingPattern(name)) {
18622
18850
  name.elements.forEach((el) => {
18623
- if (!ts15.isOmittedExpression(el))
18851
+ if (!ts16.isOmittedExpression(el))
18624
18852
  collectBindingNames(el.name, out);
18625
18853
  });
18626
18854
  }
@@ -18647,48 +18875,48 @@ function collectFreeIdentifiers(arrow) {
18647
18875
  return bound.includes(name);
18648
18876
  }
18649
18877
  function visit3(node) {
18650
- if (ts15.isIdentifier(node)) {
18878
+ if (ts16.isIdentifier(node)) {
18651
18879
  const parent = node.parent;
18652
- if (parent && ts15.isPropertyAccessExpression(parent) && parent.name === node)
18880
+ if (parent && ts16.isPropertyAccessExpression(parent) && parent.name === node)
18653
18881
  return;
18654
- if (parent && ts15.isPropertyAssignment(parent) && parent.name === node)
18882
+ if (parent && ts16.isPropertyAssignment(parent) && parent.name === node)
18655
18883
  return;
18656
- if (parent && ts15.isPropertySignature(parent) && parent.name === node)
18884
+ if (parent && ts16.isPropertySignature(parent) && parent.name === node)
18657
18885
  return;
18658
- if (parent && ts15.isPropertyDeclaration(parent) && parent.name === node)
18886
+ if (parent && ts16.isPropertyDeclaration(parent) && parent.name === node)
18659
18887
  return;
18660
- if (parent && ts15.isMethodDeclaration(parent) && parent.name === node)
18888
+ if (parent && ts16.isMethodDeclaration(parent) && parent.name === node)
18661
18889
  return;
18662
- if (parent && ts15.isMethodSignature(parent) && parent.name === node)
18890
+ if (parent && ts16.isMethodSignature(parent) && parent.name === node)
18663
18891
  return;
18664
- if (parent && ts15.isGetAccessorDeclaration(parent) && parent.name === node)
18892
+ if (parent && ts16.isGetAccessorDeclaration(parent) && parent.name === node)
18665
18893
  return;
18666
- if (parent && ts15.isSetAccessorDeclaration(parent) && parent.name === node)
18894
+ if (parent && ts16.isSetAccessorDeclaration(parent) && parent.name === node)
18667
18895
  return;
18668
- if (parent && ts15.isEnumMember(parent) && parent.name === node)
18896
+ if (parent && ts16.isEnumMember(parent) && parent.name === node)
18669
18897
  return;
18670
- if (parent && ts15.isBindingElement(parent) && parent.propertyName === node)
18898
+ if (parent && ts16.isBindingElement(parent) && parent.propertyName === node)
18671
18899
  return;
18672
- if (parent && ts15.isShorthandPropertyAssignment(parent) && parent.name === node) {
18900
+ if (parent && ts16.isShorthandPropertyAssignment(parent) && parent.name === node) {
18673
18901
  if (!isBound(node.text))
18674
18902
  ids.add(node.text);
18675
18903
  return;
18676
18904
  }
18677
- if (parent && ts15.isParameter(parent) && parent.name === node)
18905
+ if (parent && ts16.isParameter(parent) && parent.name === node)
18678
18906
  return;
18679
- if (parent && ts15.isVariableDeclaration(parent) && parent.name === node)
18907
+ if (parent && ts16.isVariableDeclaration(parent) && parent.name === node)
18680
18908
  return;
18681
- if (parent && ts15.isFunctionDeclaration(parent) && parent.name === node)
18909
+ if (parent && ts16.isFunctionDeclaration(parent) && parent.name === node)
18682
18910
  return;
18683
- if (parent && ts15.isClassDeclaration(parent) && parent.name === node)
18911
+ if (parent && ts16.isClassDeclaration(parent) && parent.name === node)
18684
18912
  return;
18685
- if (parent && ts15.isJsxAttribute(parent) && parent.name === node)
18913
+ if (parent && ts16.isJsxAttribute(parent) && parent.name === node)
18686
18914
  return;
18687
- if (parent && ts15.isJsxOpeningElement(parent) && parent.tagName === node) {
18915
+ if (parent && ts16.isJsxOpeningElement(parent) && parent.tagName === node) {
18688
18916
  if (/^[a-z]/.test(node.text))
18689
18917
  return;
18690
18918
  }
18691
- if (parent && ts15.isJsxClosingElement(parent) && parent.tagName === node) {
18919
+ if (parent && ts16.isJsxClosingElement(parent) && parent.tagName === node) {
18692
18920
  if (/^[a-z]/.test(node.text))
18693
18921
  return;
18694
18922
  }
@@ -18697,43 +18925,43 @@ function collectFreeIdentifiers(arrow) {
18697
18925
  ids.add(node.text);
18698
18926
  return;
18699
18927
  }
18700
- if (ts15.isVariableDeclaration(node)) {
18928
+ if (ts16.isVariableDeclaration(node)) {
18701
18929
  const declared = pushBindings(node.name);
18702
18930
  if (node.initializer)
18703
18931
  visit3(node.initializer);
18704
18932
  return;
18705
18933
  }
18706
- if (ts15.isFunctionDeclaration(node)) {
18934
+ if (ts16.isFunctionDeclaration(node)) {
18707
18935
  if (node.name)
18708
18936
  bound.push(node.name.text);
18709
18937
  visitInsideNewScope(node);
18710
18938
  return;
18711
18939
  }
18712
- if (ts15.isClassDeclaration(node)) {
18940
+ if (ts16.isClassDeclaration(node)) {
18713
18941
  if (node.name)
18714
18942
  bound.push(node.name.text);
18715
- ts15.forEachChild(node, visit3);
18943
+ ts16.forEachChild(node, visit3);
18716
18944
  return;
18717
18945
  }
18718
- if (ts15.isArrowFunction(node) || ts15.isFunctionExpression(node)) {
18946
+ if (ts16.isArrowFunction(node) || ts16.isFunctionExpression(node)) {
18719
18947
  visitInsideNewScope(node);
18720
18948
  return;
18721
18949
  }
18722
- if (ts15.isCatchClause(node)) {
18950
+ if (ts16.isCatchClause(node)) {
18723
18951
  const before = bound.length;
18724
18952
  if (node.variableDeclaration)
18725
18953
  pushBindings(node.variableDeclaration.name);
18726
- ts15.forEachChild(node, visit3);
18954
+ ts16.forEachChild(node, visit3);
18727
18955
  popN(bound.length - before);
18728
18956
  return;
18729
18957
  }
18730
- if (ts15.isBlock(node)) {
18958
+ if (ts16.isBlock(node)) {
18731
18959
  const before = bound.length;
18732
- ts15.forEachChild(node, visit3);
18960
+ ts16.forEachChild(node, visit3);
18733
18961
  popN(bound.length - before);
18734
18962
  return;
18735
18963
  }
18736
- ts15.forEachChild(node, visit3);
18964
+ ts16.forEachChild(node, visit3);
18737
18965
  }
18738
18966
  function visitInsideNewScope(fn) {
18739
18967
  const before = bound.length;
@@ -18756,29 +18984,29 @@ function collectFreeIdentifiers(arrow) {
18756
18984
  function collectModuleScopeNames(sourceFile) {
18757
18985
  const names = new Set;
18758
18986
  for (const stmt of sourceFile.statements) {
18759
- if (ts15.isFunctionDeclaration(stmt) && stmt.name)
18987
+ if (ts16.isFunctionDeclaration(stmt) && stmt.name)
18760
18988
  names.add(stmt.name.text);
18761
- else if (ts15.isClassDeclaration(stmt) && stmt.name)
18989
+ else if (ts16.isClassDeclaration(stmt) && stmt.name)
18762
18990
  names.add(stmt.name.text);
18763
- else if (ts15.isVariableStatement(stmt)) {
18991
+ else if (ts16.isVariableStatement(stmt)) {
18764
18992
  for (const decl of stmt.declarationList.declarations)
18765
18993
  collectBindingNames(decl.name, names);
18766
- } else if (ts15.isImportDeclaration(stmt) && stmt.importClause) {
18994
+ } else if (ts16.isImportDeclaration(stmt) && stmt.importClause) {
18767
18995
  const ic = stmt.importClause;
18768
18996
  if (ic.name)
18769
18997
  names.add(ic.name.text);
18770
18998
  if (ic.namedBindings) {
18771
- if (ts15.isNamespaceImport(ic.namedBindings))
18999
+ if (ts16.isNamespaceImport(ic.namedBindings))
18772
19000
  names.add(ic.namedBindings.name.text);
18773
19001
  else
18774
19002
  for (const e of ic.namedBindings.elements)
18775
19003
  names.add(e.name.text);
18776
19004
  }
18777
- } else if (ts15.isTypeAliasDeclaration(stmt))
19005
+ } else if (ts16.isTypeAliasDeclaration(stmt))
18778
19006
  names.add(stmt.name.text);
18779
- else if (ts15.isInterfaceDeclaration(stmt))
19007
+ else if (ts16.isInterfaceDeclaration(stmt))
18780
19008
  names.add(stmt.name.text);
18781
- else if (ts15.isEnumDeclaration(stmt))
19009
+ else if (ts16.isEnumDeclaration(stmt))
18782
19010
  names.add(stmt.name.text);
18783
19011
  }
18784
19012
  return names;
@@ -18786,7 +19014,7 @@ function collectModuleScopeNames(sourceFile) {
18786
19014
  function buildSyntheticDeclaration(name, arrow, sourceFile) {
18787
19015
  const paramsText = arrow.parameters.length === 0 ? "" : arrow.parameters.map((p) => p.getText(sourceFile)).join(", ");
18788
19016
  let bodyText;
18789
- if (ts15.isBlock(arrow.body)) {
19017
+ if (ts16.isBlock(arrow.body)) {
18790
19018
  bodyText = arrow.body.getText(sourceFile);
18791
19019
  } else {
18792
19020
  const expr = arrow.body.getText(sourceFile);
@@ -18796,7 +19024,7 @@ function buildSyntheticDeclaration(name, arrow, sourceFile) {
18796
19024
  }
18797
19025
 
18798
19026
  // src/ssr-defaults.ts
18799
- import ts16 from "typescript";
19027
+ import ts17 from "typescript";
18800
19028
  var UNRESOLVED = Symbol("unresolved");
18801
19029
  var NO_RETURN = Symbol("no-return");
18802
19030
  function extractSsrDefaults(metadata) {
@@ -18872,11 +19100,11 @@ function collectPropRefs(expr, propsObjectName, out) {
18872
19100
  if (!node)
18873
19101
  return;
18874
19102
  const visit3 = (n) => {
18875
- if (ts16.isPropertyAccessExpression(n) && ts16.isIdentifier(n.expression) && n.expression.text === propsObjectName && ts16.isIdentifier(n.name)) {
19103
+ if (ts17.isPropertyAccessExpression(n) && ts17.isIdentifier(n.expression) && n.expression.text === propsObjectName && ts17.isIdentifier(n.name)) {
18876
19104
  out.add(n.name.text);
18877
19105
  return;
18878
19106
  }
18879
- ts16.forEachChild(n, visit3);
19107
+ ts17.forEachChild(n, visit3);
18880
19108
  };
18881
19109
  visit3(node);
18882
19110
  }
@@ -18897,23 +19125,23 @@ function tryStaticEval(expr, ctx) {
18897
19125
  }
18898
19126
  function evalStatementsForReturn(statements, ctx) {
18899
19127
  for (const stmt of statements) {
18900
- if (ts16.isVariableStatement(stmt)) {
19128
+ if (ts17.isVariableStatement(stmt)) {
18901
19129
  for (const d of stmt.declarationList.declarations) {
18902
- if (!ts16.isIdentifier(d.name) || !d.initializer)
19130
+ if (!ts17.isIdentifier(d.name) || !d.initializer)
18903
19131
  continue;
18904
19132
  const v = evalNode(d.initializer, ctx);
18905
19133
  if (v !== UNRESOLVED)
18906
19134
  ctx.bindings[d.name.text] = v;
18907
19135
  }
18908
- } else if (ts16.isReturnStatement(stmt)) {
19136
+ } else if (ts17.isReturnStatement(stmt)) {
18909
19137
  return stmt.expression ? evalNode(stmt.expression, ctx) : UNRESOLVED;
18910
- } else if (ts16.isIfStatement(stmt)) {
19138
+ } else if (ts17.isIfStatement(stmt)) {
18911
19139
  const cond = evalNode(stmt.expression, ctx);
18912
19140
  if (cond === UNRESOLVED)
18913
19141
  return UNRESOLVED;
18914
19142
  const branch = cond ? stmt.thenStatement : stmt.elseStatement;
18915
19143
  if (branch) {
18916
- const taken = evalStatementsForReturn(ts16.isBlock(branch) ? branch.statements : [branch], ctx);
19144
+ const taken = evalStatementsForReturn(ts17.isBlock(branch) ? branch.statements : [branch], ctx);
18917
19145
  if (taken !== NO_RETURN)
18918
19146
  return taken;
18919
19147
  }
@@ -18924,45 +19152,45 @@ function evalStatementsForReturn(statements, ctx) {
18924
19152
  return NO_RETURN;
18925
19153
  }
18926
19154
  function parseExpression2(expr) {
18927
- const sf = ts16.createSourceFile("__ssr_default__.ts", `(${expr})`, ts16.ScriptTarget.Latest, false, ts16.ScriptKind.TS);
19155
+ const sf = ts17.createSourceFile("__ssr_default__.ts", `(${expr})`, ts17.ScriptTarget.Latest, false, ts17.ScriptKind.TS);
18928
19156
  const stmt = sf.statements[0];
18929
- if (!stmt || !ts16.isExpressionStatement(stmt))
19157
+ if (!stmt || !ts17.isExpressionStatement(stmt))
18930
19158
  return null;
18931
- const inner = ts16.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
19159
+ const inner = ts17.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
18932
19160
  return inner;
18933
19161
  }
18934
19162
  function evalNode(node, ctx) {
18935
- if (ts16.isParenthesizedExpression(node))
19163
+ if (ts17.isParenthesizedExpression(node))
18936
19164
  return evalNode(node.expression, ctx);
18937
- if (ts16.isAsExpression(node))
19165
+ if (ts17.isAsExpression(node))
18938
19166
  return evalNode(node.expression, ctx);
18939
- if (ts16.isSatisfiesExpression(node))
19167
+ if (ts17.isSatisfiesExpression(node))
18940
19168
  return evalNode(node.expression, ctx);
18941
- if (ts16.isTypeAssertionExpression(node))
19169
+ if (ts17.isTypeAssertionExpression(node))
18942
19170
  return evalNode(node.expression, ctx);
18943
- if (ts16.isNonNullExpression(node))
19171
+ if (ts17.isNonNullExpression(node))
18944
19172
  return evalNode(node.expression, ctx);
18945
- if (ts16.isArrowFunction(node)) {
19173
+ if (ts17.isArrowFunction(node)) {
18946
19174
  if (node.parameters.length !== 0)
18947
19175
  return UNRESOLVED;
18948
- if (!ts16.isBlock(node.body))
19176
+ if (!ts17.isBlock(node.body))
18949
19177
  return evalNode(node.body, ctx);
18950
19178
  const localBindings = { ...ctx.bindings };
18951
19179
  const localCtx = { ...ctx, bindings: localBindings };
18952
19180
  const result = evalStatementsForReturn(node.body.statements, localCtx);
18953
19181
  return result === NO_RETURN ? UNRESOLVED : result;
18954
19182
  }
18955
- if (ts16.isNumericLiteral(node))
19183
+ if (ts17.isNumericLiteral(node))
18956
19184
  return Number(node.text);
18957
- if (ts16.isStringLiteralLike(node))
19185
+ if (ts17.isStringLiteralLike(node))
18958
19186
  return node.text;
18959
- if (node.kind === ts16.SyntaxKind.TrueKeyword)
19187
+ if (node.kind === ts17.SyntaxKind.TrueKeyword)
18960
19188
  return true;
18961
- if (node.kind === ts16.SyntaxKind.FalseKeyword)
19189
+ if (node.kind === ts17.SyntaxKind.FalseKeyword)
18962
19190
  return false;
18963
- if (node.kind === ts16.SyntaxKind.NullKeyword)
19191
+ if (node.kind === ts17.SyntaxKind.NullKeyword)
18964
19192
  return null;
18965
- if (ts16.isIdentifier(node)) {
19193
+ if (ts17.isIdentifier(node)) {
18966
19194
  if (node.text === "undefined")
18967
19195
  return;
18968
19196
  if (node.text in ctx.bindings)
@@ -18971,29 +19199,29 @@ function evalNode(node, ctx) {
18971
19199
  return;
18972
19200
  return UNRESOLVED;
18973
19201
  }
18974
- if (ts16.isPrefixUnaryExpression(node)) {
19202
+ if (ts17.isPrefixUnaryExpression(node)) {
18975
19203
  const arg = evalNode(node.operand, ctx);
18976
19204
  if (arg === UNRESOLVED)
18977
19205
  return UNRESOLVED;
18978
19206
  switch (node.operator) {
18979
- case ts16.SyntaxKind.MinusToken:
19207
+ case ts17.SyntaxKind.MinusToken:
18980
19208
  return typeof arg === "number" ? -arg : UNRESOLVED;
18981
- case ts16.SyntaxKind.PlusToken:
19209
+ case ts17.SyntaxKind.PlusToken:
18982
19210
  return typeof arg === "number" ? +arg : UNRESOLVED;
18983
- case ts16.SyntaxKind.ExclamationToken:
19211
+ case ts17.SyntaxKind.ExclamationToken:
18984
19212
  return !arg;
18985
19213
  }
18986
19214
  return UNRESOLVED;
18987
19215
  }
18988
- if (ts16.isObjectLiteralExpression(node)) {
19216
+ if (ts17.isObjectLiteralExpression(node)) {
18989
19217
  const obj = {};
18990
19218
  for (const prop of node.properties) {
18991
- if (!ts16.isPropertyAssignment(prop))
19219
+ if (!ts17.isPropertyAssignment(prop))
18992
19220
  return UNRESOLVED;
18993
19221
  let key;
18994
- if (ts16.isIdentifier(prop.name) || ts16.isStringLiteralLike(prop.name)) {
19222
+ if (ts17.isIdentifier(prop.name) || ts17.isStringLiteralLike(prop.name)) {
18995
19223
  key = prop.name.text;
18996
- } else if (ts16.isNumericLiteral(prop.name)) {
19224
+ } else if (ts17.isNumericLiteral(prop.name)) {
18997
19225
  key = prop.name.text;
18998
19226
  } else {
18999
19227
  return UNRESOLVED;
@@ -19005,10 +19233,10 @@ function evalNode(node, ctx) {
19005
19233
  }
19006
19234
  return obj;
19007
19235
  }
19008
- if (ts16.isArrayLiteralExpression(node)) {
19236
+ if (ts17.isArrayLiteralExpression(node)) {
19009
19237
  const arr = [];
19010
19238
  for (const elem of node.elements) {
19011
- if (ts16.isOmittedExpression(elem))
19239
+ if (ts17.isOmittedExpression(elem))
19012
19240
  return UNRESOLVED;
19013
19241
  const v = evalNode(elem, ctx);
19014
19242
  if (v === UNRESOLVED)
@@ -19017,7 +19245,7 @@ function evalNode(node, ctx) {
19017
19245
  }
19018
19246
  return arr;
19019
19247
  }
19020
- if (ts16.isElementAccessExpression(node)) {
19248
+ if (ts17.isElementAccessExpression(node)) {
19021
19249
  const base = evalNode(node.expression, ctx);
19022
19250
  if (base === undefined)
19023
19251
  return;
@@ -19031,17 +19259,17 @@ function evalNode(node, ctx) {
19031
19259
  const k = String(key);
19032
19260
  return Object.prototype.hasOwnProperty.call(base, k) ? base[k] : undefined;
19033
19261
  }
19034
- if (ts16.isPropertyAccessExpression(node)) {
19262
+ if (ts17.isPropertyAccessExpression(node)) {
19035
19263
  const baseResult = evalNode(node.expression, ctx);
19036
19264
  if (baseResult === undefined)
19037
19265
  return;
19038
19266
  return UNRESOLVED;
19039
19267
  }
19040
- if (ts16.isCallExpression(node)) {
19041
- if (node.arguments.length === 0 && ts16.isIdentifier(node.expression) && node.expression.text in ctx.bindings) {
19268
+ if (ts17.isCallExpression(node)) {
19269
+ if (node.arguments.length === 0 && ts17.isIdentifier(node.expression) && node.expression.text in ctx.bindings) {
19042
19270
  return ctx.bindings[node.expression.text];
19043
19271
  }
19044
- if (ts16.isPropertyAccessExpression(node.expression) && node.expression.name.text === "join") {
19272
+ if (ts17.isPropertyAccessExpression(node.expression) && node.expression.name.text === "join") {
19045
19273
  const recv = evalNode(node.expression.expression, ctx);
19046
19274
  if (Array.isArray(recv)) {
19047
19275
  let sep2 = ",";
@@ -19057,27 +19285,27 @@ function evalNode(node, ctx) {
19057
19285
  }
19058
19286
  return UNRESOLVED;
19059
19287
  }
19060
- if (ts16.isConditionalExpression(node)) {
19288
+ if (ts17.isConditionalExpression(node)) {
19061
19289
  const cond = evalNode(node.condition, ctx);
19062
19290
  if (cond === UNRESOLVED)
19063
19291
  return UNRESOLVED;
19064
19292
  return cond ? evalNode(node.whenTrue, ctx) : evalNode(node.whenFalse, ctx);
19065
19293
  }
19066
- if (ts16.isBinaryExpression(node)) {
19294
+ if (ts17.isBinaryExpression(node)) {
19067
19295
  const op = node.operatorToken.kind;
19068
- if (op === ts16.SyntaxKind.QuestionQuestionToken) {
19296
+ if (op === ts17.SyntaxKind.QuestionQuestionToken) {
19069
19297
  const l2 = evalNode(node.left, ctx);
19070
19298
  if (l2 !== UNRESOLVED && l2 !== null && l2 !== undefined)
19071
19299
  return l2;
19072
19300
  return evalNode(node.right, ctx);
19073
19301
  }
19074
- if (op === ts16.SyntaxKind.BarBarToken) {
19302
+ if (op === ts17.SyntaxKind.BarBarToken) {
19075
19303
  const l2 = evalNode(node.left, ctx);
19076
19304
  if (l2 !== UNRESOLVED && l2)
19077
19305
  return l2;
19078
19306
  return evalNode(node.right, ctx);
19079
19307
  }
19080
- if (op === ts16.SyntaxKind.AmpersandAmpersandToken) {
19308
+ if (op === ts17.SyntaxKind.AmpersandAmpersandToken) {
19081
19309
  const l2 = evalNode(node.left, ctx);
19082
19310
  if (l2 === UNRESOLVED)
19083
19311
  return UNRESOLVED;
@@ -19090,30 +19318,30 @@ function evalNode(node, ctx) {
19090
19318
  if (l === UNRESOLVED || r === UNRESOLVED)
19091
19319
  return UNRESOLVED;
19092
19320
  switch (op) {
19093
- case ts16.SyntaxKind.PlusToken:
19321
+ case ts17.SyntaxKind.PlusToken:
19094
19322
  if (typeof l === "string" || typeof r === "string")
19095
19323
  return `${l}${r}`;
19096
19324
  if (typeof l === "number" && typeof r === "number")
19097
19325
  return l + r;
19098
19326
  return UNRESOLVED;
19099
- case ts16.SyntaxKind.MinusToken:
19327
+ case ts17.SyntaxKind.MinusToken:
19100
19328
  return typeof l === "number" && typeof r === "number" ? l - r : UNRESOLVED;
19101
- case ts16.SyntaxKind.AsteriskToken:
19329
+ case ts17.SyntaxKind.AsteriskToken:
19102
19330
  return typeof l === "number" && typeof r === "number" ? l * r : UNRESOLVED;
19103
- case ts16.SyntaxKind.SlashToken:
19331
+ case ts17.SyntaxKind.SlashToken:
19104
19332
  return typeof l === "number" && typeof r === "number" && r !== 0 ? l / r : UNRESOLVED;
19105
- case ts16.SyntaxKind.PercentToken:
19333
+ case ts17.SyntaxKind.PercentToken:
19106
19334
  return typeof l === "number" && typeof r === "number" && r !== 0 ? l % r : UNRESOLVED;
19107
- case ts16.SyntaxKind.EqualsEqualsEqualsToken:
19108
- case ts16.SyntaxKind.EqualsEqualsToken:
19335
+ case ts17.SyntaxKind.EqualsEqualsEqualsToken:
19336
+ case ts17.SyntaxKind.EqualsEqualsToken:
19109
19337
  return l === r;
19110
- case ts16.SyntaxKind.ExclamationEqualsEqualsToken:
19111
- case ts16.SyntaxKind.ExclamationEqualsToken:
19338
+ case ts17.SyntaxKind.ExclamationEqualsEqualsToken:
19339
+ case ts17.SyntaxKind.ExclamationEqualsToken:
19112
19340
  return l !== r;
19113
19341
  }
19114
19342
  return UNRESOLVED;
19115
19343
  }
19116
- if (ts16.isTemplateExpression(node)) {
19344
+ if (ts17.isTemplateExpression(node)) {
19117
19345
  if (node.templateSpans.length === 0)
19118
19346
  return node.head.text;
19119
19347
  let acc = node.head.text;
@@ -19125,13 +19353,13 @@ function evalNode(node, ctx) {
19125
19353
  }
19126
19354
  return acc;
19127
19355
  }
19128
- if (ts16.isNoSubstitutionTemplateLiteral(node))
19356
+ if (ts17.isNoSubstitutionTemplateLiteral(node))
19129
19357
  return node.text;
19130
19358
  return UNRESOLVED;
19131
19359
  }
19132
19360
 
19133
19361
  // src/augment-inherited-props.ts
19134
- import ts17 from "typescript";
19362
+ import ts18 from "typescript";
19135
19363
  function collectContextConsumers(metadata) {
19136
19364
  const constants = metadata.localConstants ?? [];
19137
19365
  const contextDefaults = new Map;
@@ -19163,47 +19391,47 @@ function collectContextConsumers(metadata) {
19163
19391
  }
19164
19392
  function parseUseContextArg(source) {
19165
19393
  const expr = parseSingleExpression(source);
19166
- if (!expr || !ts17.isCallExpression(expr))
19394
+ if (!expr || !ts18.isCallExpression(expr))
19167
19395
  return null;
19168
- if (!ts17.isIdentifier(expr.expression) || expr.expression.text !== "useContext")
19396
+ if (!ts18.isIdentifier(expr.expression) || expr.expression.text !== "useContext")
19169
19397
  return null;
19170
19398
  if (expr.arguments.length !== 1)
19171
19399
  return null;
19172
19400
  const arg = expr.arguments[0];
19173
- return ts17.isIdentifier(arg) ? arg.text : null;
19401
+ return ts18.isIdentifier(arg) ? arg.text : null;
19174
19402
  }
19175
19403
  function parseCreateContextDefault(source) {
19176
19404
  const expr = parseSingleExpression(source);
19177
- if (!expr || !ts17.isCallExpression(expr))
19405
+ if (!expr || !ts18.isCallExpression(expr))
19178
19406
  return null;
19179
19407
  if (expr.arguments.length === 0)
19180
19408
  return null;
19181
19409
  const arg = expr.arguments[0];
19182
- if (ts17.isStringLiteral(arg) || ts17.isNoSubstitutionTemplateLiteral(arg))
19410
+ if (ts18.isStringLiteral(arg) || ts18.isNoSubstitutionTemplateLiteral(arg))
19183
19411
  return arg.text;
19184
- if (ts17.isNumericLiteral(arg))
19412
+ if (ts18.isNumericLiteral(arg))
19185
19413
  return Number(arg.text);
19186
- if (arg.kind === ts17.SyntaxKind.TrueKeyword)
19414
+ if (arg.kind === ts18.SyntaxKind.TrueKeyword)
19187
19415
  return true;
19188
- if (arg.kind === ts17.SyntaxKind.FalseKeyword)
19416
+ if (arg.kind === ts18.SyntaxKind.FalseKeyword)
19189
19417
  return false;
19190
19418
  return null;
19191
19419
  }
19192
19420
  function isObjectLiteralCreateContextDefault(source) {
19193
19421
  const expr = parseSingleExpression(source);
19194
- if (!expr || !ts17.isCallExpression(expr))
19422
+ if (!expr || !ts18.isCallExpression(expr))
19195
19423
  return false;
19196
19424
  if (expr.arguments.length === 0)
19197
19425
  return false;
19198
- return ts17.isObjectLiteralExpression(expr.arguments[0]);
19426
+ return ts18.isObjectLiteralExpression(expr.arguments[0]);
19199
19427
  }
19200
19428
  function parseSingleExpression(source) {
19201
- const sf = ts17.createSourceFile("__ctx.ts", `(${source})`, ts17.ScriptTarget.Latest, false);
19429
+ const sf = ts18.createSourceFile("__ctx.ts", `(${source})`, ts18.ScriptTarget.Latest, false);
19202
19430
  const stmt = sf.statements[0];
19203
- if (!stmt || !ts17.isExpressionStatement(stmt))
19431
+ if (!stmt || !ts18.isExpressionStatement(stmt))
19204
19432
  return null;
19205
19433
  let e = stmt.expression;
19206
- while (ts17.isParenthesizedExpression(e))
19434
+ while (ts18.isParenthesizedExpression(e))
19207
19435
  e = e.expression;
19208
19436
  return e;
19209
19437
  }
@@ -19228,25 +19456,25 @@ function augmentInheritedPropAccesses(ir) {
19228
19456
  const pinCoalesceLiterals = (s) => {
19229
19457
  if (!s || !s.includes(propsObj))
19230
19458
  return;
19231
- const sf = ts17.createSourceFile("__aug.ts", `(${s})`, ts17.ScriptTarget.Latest, false);
19459
+ const sf = ts18.createSourceFile("__aug.ts", `(${s})`, ts18.ScriptTarget.Latest, false);
19232
19460
  const visit3 = (n) => {
19233
- if (ts17.isBinaryExpression(n) && (n.operatorToken.kind === ts17.SyntaxKind.QuestionQuestionToken || n.operatorToken.kind === ts17.SyntaxKind.BarBarToken)) {
19461
+ if (ts18.isBinaryExpression(n) && (n.operatorToken.kind === ts18.SyntaxKind.QuestionQuestionToken || n.operatorToken.kind === ts18.SyntaxKind.BarBarToken)) {
19234
19462
  let left = n.left;
19235
- while (ts17.isParenthesizedExpression(left))
19463
+ while (ts18.isParenthesizedExpression(left))
19236
19464
  left = left.expression;
19237
- if (ts17.isPropertyAccessExpression(left) && ts17.isIdentifier(left.expression) && left.expression.text === propsObj) {
19465
+ if (ts18.isPropertyAccessExpression(left) && ts18.isIdentifier(left.expression) && left.expression.text === propsObj) {
19238
19466
  const name = left.name.text;
19239
19467
  let right = n.right;
19240
- while (ts17.isParenthesizedExpression(right))
19468
+ while (ts18.isParenthesizedExpression(right))
19241
19469
  right = right.expression;
19242
- if (ts17.isPrefixUnaryExpression(right))
19470
+ if (ts18.isPrefixUnaryExpression(right))
19243
19471
  right = right.operand;
19244
- const kind = ts17.isNumericLiteral(right) ? "number" : right.kind === ts17.SyntaxKind.TrueKeyword || right.kind === ts17.SyntaxKind.FalseKeyword ? "boolean" : ts17.isStringLiteralLike(right) ? "string" : null;
19472
+ const kind = ts18.isNumericLiteral(right) ? "number" : right.kind === ts18.SyntaxKind.TrueKeyword || right.kind === ts18.SyntaxKind.FalseKeyword ? "boolean" : ts18.isStringLiteralLike(right) ? "string" : null;
19245
19473
  if (kind && !coalesceLiteralTypes.has(name))
19246
19474
  coalesceLiteralTypes.set(name, kind);
19247
19475
  }
19248
19476
  }
19249
- ts17.forEachChild(n, visit3);
19477
+ ts18.forEachChild(n, visit3);
19250
19478
  };
19251
19479
  visit3(sf);
19252
19480
  };
@@ -19357,33 +19585,33 @@ function augmentInheritedPropAccesses(ir) {
19357
19585
  }
19358
19586
  }
19359
19587
  function parseStaticStringConst(source) {
19360
- const sf = ts17.createSourceFile("__const.ts", `const __x = (${source});`, ts17.ScriptTarget.Latest, false);
19588
+ const sf = ts18.createSourceFile("__const.ts", `const __x = (${source});`, ts18.ScriptTarget.Latest, false);
19361
19589
  const stmt = sf.statements[0];
19362
- if (!stmt || !ts17.isVariableStatement(stmt))
19590
+ if (!stmt || !ts18.isVariableStatement(stmt))
19363
19591
  return null;
19364
19592
  let init = stmt.declarationList.declarations[0]?.initializer;
19365
- while (init && ts17.isParenthesizedExpression(init))
19593
+ while (init && ts18.isParenthesizedExpression(init))
19366
19594
  init = init.expression;
19367
19595
  if (!init)
19368
19596
  return null;
19369
- if (ts17.isStringLiteral(init) || ts17.isNoSubstitutionTemplateLiteral(init)) {
19597
+ if (ts18.isStringLiteral(init) || ts18.isNoSubstitutionTemplateLiteral(init)) {
19370
19598
  return init.text;
19371
19599
  }
19372
19600
  return evalStringArrayJoin(source);
19373
19601
  }
19374
19602
  function evalTemplateOfStringConsts(source, resolved) {
19375
- const sf = ts17.createSourceFile("__const.ts", `const __x = (${source});`, ts17.ScriptTarget.Latest, false);
19603
+ const sf = ts18.createSourceFile("__const.ts", `const __x = (${source});`, ts18.ScriptTarget.Latest, false);
19376
19604
  const stmt = sf.statements[0];
19377
- if (!stmt || !ts17.isVariableStatement(stmt))
19605
+ if (!stmt || !ts18.isVariableStatement(stmt))
19378
19606
  return null;
19379
19607
  let init = stmt.declarationList.declarations[0]?.initializer;
19380
- while (init && ts17.isParenthesizedExpression(init))
19608
+ while (init && ts18.isParenthesizedExpression(init))
19381
19609
  init = init.expression;
19382
- if (!init || !ts17.isTemplateExpression(init))
19610
+ if (!init || !ts18.isTemplateExpression(init))
19383
19611
  return null;
19384
19612
  let out = init.head.text;
19385
19613
  for (const span of init.templateSpans) {
19386
- if (!ts17.isIdentifier(span.expression))
19614
+ if (!ts18.isIdentifier(span.expression))
19387
19615
  return null;
19388
19616
  const value = resolved.get(span.expression.text);
19389
19617
  if (value === undefined)
@@ -19414,30 +19642,30 @@ function lookupStaticRecordLiteral(objectName, key, constants) {
19414
19642
  const constInfo = (constants ?? []).find((c) => c.name === objectName && c.isModule);
19415
19643
  if (constInfo?.value === undefined)
19416
19644
  return null;
19417
- const sf = ts17.createSourceFile("__rec.ts", `(${constInfo.value})`, ts17.ScriptTarget.Latest, true);
19645
+ const sf = ts18.createSourceFile("__rec.ts", `(${constInfo.value})`, ts18.ScriptTarget.Latest, true);
19418
19646
  if (sf.statements.length !== 1)
19419
19647
  return null;
19420
19648
  const stmt = sf.statements[0];
19421
- if (!ts17.isExpressionStatement(stmt))
19649
+ if (!ts18.isExpressionStatement(stmt))
19422
19650
  return null;
19423
19651
  let parsed = stmt.expression;
19424
- while (ts17.isParenthesizedExpression(parsed))
19652
+ while (ts18.isParenthesizedExpression(parsed))
19425
19653
  parsed = parsed.expression;
19426
- if (!ts17.isObjectLiteralExpression(parsed))
19654
+ if (!ts18.isObjectLiteralExpression(parsed))
19427
19655
  return null;
19428
19656
  for (const prop of parsed.properties) {
19429
- if (!ts17.isPropertyAssignment(prop))
19657
+ if (!ts18.isPropertyAssignment(prop))
19430
19658
  continue;
19431
19659
  const name = prop.name;
19432
- const propKey = ts17.isIdentifier(name) || ts17.isStringLiteral(name) || ts17.isNoSubstitutionTemplateLiteral(name) ? name.text : null;
19660
+ const propKey = ts18.isIdentifier(name) || ts18.isStringLiteral(name) || ts18.isNoSubstitutionTemplateLiteral(name) ? name.text : null;
19433
19661
  if (propKey !== key)
19434
19662
  continue;
19435
19663
  let v = prop.initializer;
19436
- while (ts17.isParenthesizedExpression(v))
19664
+ while (ts18.isParenthesizedExpression(v))
19437
19665
  v = v.expression;
19438
- if (ts17.isNumericLiteral(v))
19666
+ if (ts18.isNumericLiteral(v))
19439
19667
  return { kind: "number", text: v.text };
19440
- if (ts17.isStringLiteral(v) || ts17.isNoSubstitutionTemplateLiteral(v)) {
19668
+ if (ts18.isStringLiteral(v) || ts18.isNoSubstitutionTemplateLiteral(v)) {
19441
19669
  return { kind: "string", text: v.text };
19442
19670
  }
19443
19671
  return null;
@@ -19445,28 +19673,28 @@ function lookupStaticRecordLiteral(objectName, key, constants) {
19445
19673
  return null;
19446
19674
  }
19447
19675
  function evalStringArrayJoin(source) {
19448
- const sf = ts17.createSourceFile("__join.ts", `const __x = (${source});`, ts17.ScriptTarget.Latest, false);
19676
+ const sf = ts18.createSourceFile("__join.ts", `const __x = (${source});`, ts18.ScriptTarget.Latest, false);
19449
19677
  const stmt = sf.statements[0];
19450
- if (!stmt || !ts17.isVariableStatement(stmt))
19678
+ if (!stmt || !ts18.isVariableStatement(stmt))
19451
19679
  return null;
19452
19680
  let node = stmt.declarationList.declarations[0]?.initializer;
19453
- while (node && ts17.isParenthesizedExpression(node))
19681
+ while (node && ts18.isParenthesizedExpression(node))
19454
19682
  node = node.expression;
19455
- if (!node || !ts17.isCallExpression(node))
19683
+ if (!node || !ts18.isCallExpression(node))
19456
19684
  return null;
19457
19685
  const callee = node.expression;
19458
- if (!ts17.isPropertyAccessExpression(callee))
19686
+ if (!ts18.isPropertyAccessExpression(callee))
19459
19687
  return null;
19460
19688
  if (callee.name.text !== "join")
19461
19689
  return null;
19462
19690
  let recv = callee.expression;
19463
- while (ts17.isParenthesizedExpression(recv))
19691
+ while (ts18.isParenthesizedExpression(recv))
19464
19692
  recv = recv.expression;
19465
- if (!ts17.isArrayLiteralExpression(recv))
19693
+ if (!ts18.isArrayLiteralExpression(recv))
19466
19694
  return null;
19467
19695
  const parts = [];
19468
19696
  for (const el of recv.elements) {
19469
- if (ts17.isStringLiteral(el) || ts17.isNoSubstitutionTemplateLiteral(el)) {
19697
+ if (ts18.isStringLiteral(el) || ts18.isNoSubstitutionTemplateLiteral(el)) {
19470
19698
  parts.push(el.text);
19471
19699
  } else {
19472
19700
  return null;
@@ -19475,7 +19703,7 @@ function evalStringArrayJoin(source) {
19475
19703
  let sep2 = ",";
19476
19704
  if (node.arguments.length >= 1) {
19477
19705
  const arg = node.arguments[0];
19478
- if (ts17.isStringLiteral(arg) || ts17.isNoSubstitutionTemplateLiteral(arg))
19706
+ if (ts18.isStringLiteral(arg) || ts18.isNoSubstitutionTemplateLiteral(arg))
19479
19707
  sep2 = arg.text;
19480
19708
  else
19481
19709
  return null;
@@ -19483,11 +19711,11 @@ function evalStringArrayJoin(source) {
19483
19711
  return parts.join(sep2);
19484
19712
  }
19485
19713
  function parseRecordIndexAccess(val, localConstants, propsParams, resolveKey) {
19486
- if (!ts17.isElementAccessExpression(val))
19714
+ if (!ts18.isElementAccessExpression(val))
19487
19715
  return null;
19488
19716
  const obj = val.expression;
19489
19717
  const arg = val.argumentExpression;
19490
- if (!ts17.isIdentifier(obj) || !ts17.isIdentifier(arg))
19718
+ if (!ts18.isIdentifier(obj) || !ts18.isIdentifier(arg))
19491
19719
  return null;
19492
19720
  let indexPropName;
19493
19721
  let defaultKey;
@@ -19503,35 +19731,35 @@ function parseRecordIndexAccess(val, localConstants, propsParams, resolveKey) {
19503
19731
  const constInfo = localConstants.find((c) => c.name === obj.text && c.isModule);
19504
19732
  if (constInfo?.value === undefined)
19505
19733
  return null;
19506
- const sf = ts17.createSourceFile("__rec.ts", `(${constInfo.value})`, ts17.ScriptTarget.Latest, true);
19734
+ const sf = ts18.createSourceFile("__rec.ts", `(${constInfo.value})`, ts18.ScriptTarget.Latest, true);
19507
19735
  if (sf.statements.length !== 1)
19508
19736
  return null;
19509
19737
  const stmt = sf.statements[0];
19510
- if (!ts17.isExpressionStatement(stmt))
19738
+ if (!ts18.isExpressionStatement(stmt))
19511
19739
  return null;
19512
19740
  let parsed = stmt.expression;
19513
- while (ts17.isParenthesizedExpression(parsed))
19741
+ while (ts18.isParenthesizedExpression(parsed))
19514
19742
  parsed = parsed.expression;
19515
- if (!ts17.isObjectLiteralExpression(parsed))
19743
+ if (!ts18.isObjectLiteralExpression(parsed))
19516
19744
  return null;
19517
19745
  const entries = [];
19518
19746
  for (const prop of parsed.properties) {
19519
- if (!ts17.isPropertyAssignment(prop))
19747
+ if (!ts18.isPropertyAssignment(prop))
19520
19748
  return null;
19521
19749
  let key;
19522
- if (ts17.isIdentifier(prop.name)) {
19750
+ if (ts18.isIdentifier(prop.name)) {
19523
19751
  key = prop.name.text;
19524
- } else if (ts17.isStringLiteral(prop.name) || ts17.isNoSubstitutionTemplateLiteral(prop.name)) {
19752
+ } else if (ts18.isStringLiteral(prop.name) || ts18.isNoSubstitutionTemplateLiteral(prop.name)) {
19525
19753
  key = prop.name.text;
19526
19754
  } else {
19527
19755
  return null;
19528
19756
  }
19529
19757
  let v = prop.initializer;
19530
- while (ts17.isParenthesizedExpression(v))
19758
+ while (ts18.isParenthesizedExpression(v))
19531
19759
  v = v.expression;
19532
- if (ts17.isNumericLiteral(v)) {
19760
+ if (ts18.isNumericLiteral(v)) {
19533
19761
  entries.push({ key, value: { kind: "number", text: v.text } });
19534
- } else if (ts17.isStringLiteral(v) || ts17.isNoSubstitutionTemplateLiteral(v)) {
19762
+ } else if (ts18.isStringLiteral(v) || ts18.isNoSubstitutionTemplateLiteral(v)) {
19535
19763
  entries.push({ key, value: { kind: "string", text: v.text } });
19536
19764
  } else {
19537
19765
  return null;
@@ -19584,6 +19812,221 @@ function computeSsrSeedPlan(metadata) {
19584
19812
  return { baseScope, steps };
19585
19813
  }
19586
19814
 
19815
+ // src/rich-type-refusal.ts
19816
+ var EMPTY_BINDINGS2 = new Map;
19817
+ function checkRichTypeMethodCalls(root, metadata, errors) {
19818
+ if (!metadata.propsType)
19819
+ return;
19820
+ const matchers = prepareLoweringMatchers(metadata);
19821
+ const seen = new Set;
19822
+ walkNode(root, metadata, EMPTY_BINDINGS2, matchers, errors, seen);
19823
+ }
19824
+ function isLoweringClaimed(matchers, callee, args) {
19825
+ return matchers.some((m) => m(callee, args) !== null);
19826
+ }
19827
+ function describeReceiverPath(expr) {
19828
+ if (expr.kind === "identifier")
19829
+ return expr.name;
19830
+ if (expr.kind === "member" && !expr.computed)
19831
+ return `${describeReceiverPath(expr.object)}.${expr.property}`;
19832
+ return "<expression>";
19833
+ }
19834
+ function receiverRootIsProp(expr, bindings) {
19835
+ let root = expr;
19836
+ while (root.kind === "member" && !root.computed)
19837
+ root = root.object;
19838
+ return root.kind === "identifier" && !bindings.has(root.name);
19839
+ }
19840
+ function pushDiagnostic(errors, seen, loc, method, receiverPath, isProp, typeName) {
19841
+ const key = `${loc.start.line}:${loc.start.column}:${receiverPath}.${method}`;
19842
+ if (seen.has(key))
19843
+ return;
19844
+ seen.add(key);
19845
+ const receiver = isProp ? `prop '${receiverPath}'` : `'${receiverPath}'`;
19846
+ errors.push({
19847
+ code: ErrorCodes.UNSUPPORTED_JSX_PATTERN,
19848
+ severity: "error",
19849
+ message: `Expression cannot be compiled to marked template: method '.${method}()' on ${receiver} of host type '${typeName}' has no catalogued lowering.`,
19850
+ loc,
19851
+ suggestion: {
19852
+ message: "Add /* @client */ to evaluate this expression on the client only, or pre-compute the value server-side."
19853
+ }
19854
+ });
19855
+ }
19856
+ function checkExpr(expr, loc, meta, bindings, matchers, errors, seen) {
19857
+ const recurse = (e, b = bindings) => checkExpr(e, loc, meta, b, matchers, errors, seen);
19858
+ switch (expr.kind) {
19859
+ case "call": {
19860
+ if (expr.callee.kind === "member") {
19861
+ const receiverType = resolveReceiverType(expr.callee.object, meta, bindings);
19862
+ if (receiverType && receiverType.kind === "interface") {
19863
+ const typeName = baseTypeName(receiverType.raw);
19864
+ const inFileShadow = meta.typeDefinitions.some((d) => d.name === typeName);
19865
+ if (HOST_RICH_TYPE_NAMES.has(typeName) && !inFileShadow && !isLoweringClaimed(matchers, expr.callee, expr.args)) {
19866
+ pushDiagnostic(errors, seen, loc, expr.callee.property, describeReceiverPath(expr.callee.object), receiverRootIsProp(expr.callee.object, bindings), typeName);
19867
+ }
19868
+ }
19869
+ }
19870
+ recurse(expr.callee);
19871
+ for (const arg of expr.args)
19872
+ recurse(arg);
19873
+ break;
19874
+ }
19875
+ case "member":
19876
+ recurse(expr.object);
19877
+ break;
19878
+ case "index-access":
19879
+ recurse(expr.object);
19880
+ recurse(expr.index);
19881
+ break;
19882
+ case "binary":
19883
+ recurse(expr.left);
19884
+ recurse(expr.right);
19885
+ break;
19886
+ case "unary":
19887
+ recurse(expr.argument);
19888
+ break;
19889
+ case "conditional":
19890
+ recurse(expr.test);
19891
+ recurse(expr.consequent);
19892
+ recurse(expr.alternate);
19893
+ break;
19894
+ case "logical":
19895
+ recurse(expr.left);
19896
+ recurse(expr.right);
19897
+ break;
19898
+ case "template-literal":
19899
+ for (const part of expr.parts)
19900
+ if (part.type === "expression")
19901
+ recurse(part.expr);
19902
+ break;
19903
+ case "arrow": {
19904
+ const shadowed = new Map(bindings);
19905
+ for (const param of expr.params)
19906
+ shadowed.set(param, null);
19907
+ recurse(expr.body, shadowed);
19908
+ break;
19909
+ }
19910
+ case "array-literal":
19911
+ for (const el of expr.elements)
19912
+ recurse(el);
19913
+ break;
19914
+ case "object-literal":
19915
+ for (const prop of expr.properties)
19916
+ recurse(prop.value);
19917
+ break;
19918
+ case "array-method":
19919
+ recurse(expr.object);
19920
+ for (const arg of expr.args)
19921
+ recurse(arg);
19922
+ break;
19923
+ case "identifier":
19924
+ case "literal":
19925
+ case "regex":
19926
+ case "unsupported":
19927
+ break;
19928
+ }
19929
+ }
19930
+ function walkTemplateParts(parts, loc, meta, bindings, matchers, errors, seen) {
19931
+ for (const part of parts) {
19932
+ if (part.type === "ternary") {
19933
+ const trimmed = part.condition.trim();
19934
+ if (trimmed)
19935
+ checkExpr(parseExpression(trimmed), loc, meta, bindings, matchers, errors, seen);
19936
+ } else if (part.type === "lookup") {
19937
+ const trimmed = part.key.trim();
19938
+ if (trimmed)
19939
+ checkExpr(parseExpression(trimmed), loc, meta, bindings, matchers, errors, seen);
19940
+ }
19941
+ }
19942
+ }
19943
+ function walkAttrValue(value, clientOnly, loc, meta, bindings, matchers, errors, seen) {
19944
+ if (clientOnly)
19945
+ return;
19946
+ if (value.kind === "expression") {
19947
+ if (value.parsed)
19948
+ checkExpr(value.parsed, loc, meta, bindings, matchers, errors, seen);
19949
+ if (value.parts)
19950
+ walkTemplateParts(value.parts, loc, meta, bindings, matchers, errors, seen);
19951
+ } else if (value.kind === "spread") {
19952
+ if (value.parsed)
19953
+ checkExpr(value.parsed, loc, meta, bindings, matchers, errors, seen);
19954
+ } else if (value.kind === "template") {
19955
+ walkTemplateParts(value.parts, loc, meta, bindings, matchers, errors, seen);
19956
+ }
19957
+ }
19958
+ function walkNode(node, meta, bindings, matchers, errors, seen) {
19959
+ if (node.type === "expression") {
19960
+ if (!node.clientOnly && node.parsed)
19961
+ checkExpr(node.parsed, node.loc, meta, bindings, matchers, errors, seen);
19962
+ } else if (node.type === "conditional") {
19963
+ if (!node.clientOnly && node.parsedCondition)
19964
+ checkExpr(node.parsedCondition, node.loc, meta, bindings, matchers, errors, seen);
19965
+ } else if (node.type === "if-statement") {
19966
+ if (node.parsedCondition)
19967
+ checkExpr(node.parsedCondition, node.loc, meta, bindings, matchers, errors, seen);
19968
+ }
19969
+ if (node.type === "element") {
19970
+ for (const attr of node.attrs)
19971
+ walkAttrValue(attr.value, attr.clientOnly, attr.loc, meta, bindings, matchers, errors, seen);
19972
+ } else if (node.type === "component") {
19973
+ for (const prop of node.props)
19974
+ walkAttrValue(prop.value, prop.clientOnly, prop.loc, meta, bindings, matchers, errors, seen);
19975
+ } else if (node.type === "provider") {
19976
+ walkAttrValue(node.valueProp.value, node.valueProp.clientOnly, node.valueProp.loc, meta, bindings, matchers, errors, seen);
19977
+ }
19978
+ switch (node.type) {
19979
+ case "element":
19980
+ case "component":
19981
+ case "fragment":
19982
+ case "provider":
19983
+ for (const child of node.children)
19984
+ walkNode(child, meta, bindings, matchers, errors, seen);
19985
+ break;
19986
+ case "async":
19987
+ walkNode(node.fallback, meta, bindings, matchers, errors, seen);
19988
+ for (const child of node.children)
19989
+ walkNode(child, meta, bindings, matchers, errors, seen);
19990
+ break;
19991
+ case "loop": {
19992
+ if (node.clientOnly)
19993
+ break;
19994
+ if (node.arrayParsed)
19995
+ checkExpr(node.arrayParsed, node.loc, meta, bindings, matchers, errors, seen);
19996
+ const loopBindings = new Map(bindings);
19997
+ const arrayType = node.arrayParsed ? resolveReceiverType(node.arrayParsed, meta, bindings) : null;
19998
+ loopBindings.set(node.param, arrayType?.kind === "array" ? arrayType.elementType ?? null : null);
19999
+ if (node.index)
20000
+ loopBindings.set(node.index, null);
20001
+ for (const child of node.children)
20002
+ walkNode(child, meta, loopBindings, matchers, errors, seen);
20003
+ if (node.childComponent) {
20004
+ for (const child of node.childComponent.children)
20005
+ walkNode(child, meta, loopBindings, matchers, errors, seen);
20006
+ }
20007
+ for (const nested of node.nestedComponents ?? []) {
20008
+ for (const child of nested.children)
20009
+ walkNode(child, meta, loopBindings, matchers, errors, seen);
20010
+ }
20011
+ for (const frag of node.flatMapCallback?.fragments ?? []) {
20012
+ walkNode(frag.ir, meta, loopBindings, matchers, errors, seen);
20013
+ }
20014
+ break;
20015
+ }
20016
+ case "conditional":
20017
+ if (node.clientOnly)
20018
+ break;
20019
+ walkNode(node.whenTrue, meta, bindings, matchers, errors, seen);
20020
+ walkNode(node.whenFalse, meta, bindings, matchers, errors, seen);
20021
+ break;
20022
+ case "if-statement":
20023
+ walkNode(node.consequent, meta, bindings, matchers, errors, seen);
20024
+ if (node.alternate)
20025
+ walkNode(node.alternate, meta, bindings, matchers, errors, seen);
20026
+ break;
20027
+ }
20028
+ }
20029
+
19587
20030
  // src/compiler.ts
19588
20031
  function mergeTemplateImports(lines) {
19589
20032
  const result = [];
@@ -19644,6 +20087,7 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
19644
20087
  errors: []
19645
20088
  };
19646
20089
  componentIR.metadata.clientAnalysis = analyzeClientNeeds(componentIR);
20090
+ checkRichTypeMethodCalls(componentIR.root, componentIR.metadata, errors);
19647
20091
  if (options.cssLayerPrefix) {
19648
20092
  applyCssLayerPrefix(componentIR, options.cssLayerPrefix);
19649
20093
  }
@@ -19982,6 +20426,7 @@ function compileJSX(source, filePath, options) {
19982
20426
  errors: []
19983
20427
  };
19984
20428
  componentIR.metadata.clientAnalysis = analyzeClientNeeds(componentIR);
20429
+ checkRichTypeMethodCalls(componentIR.root, componentIR.metadata, errors);
19985
20430
  if (ctx.importedClientSignalNames.size > 0) {
19986
20431
  const sources = new Set;
19987
20432
  for (const imp of ctx.imports) {
@@ -20086,7 +20531,7 @@ function compileJSX(source, filePath, options) {
20086
20531
  return { files, errors };
20087
20532
  }
20088
20533
  // src/shared-program.ts
20089
- import ts18 from "typescript";
20534
+ import ts19 from "typescript";
20090
20535
  function commonParent(paths) {
20091
20536
  if (paths.length === 0)
20092
20537
  return process.cwd();
@@ -20107,10 +20552,10 @@ function commonParent(paths) {
20107
20552
  function createProgramForCorpus(files, options = {}) {
20108
20553
  const baseUrl = options.baseUrl ?? commonParent(files);
20109
20554
  const compilerOptions = {
20110
- target: ts18.ScriptTarget.Latest,
20111
- module: ts18.ModuleKind.ESNext,
20112
- moduleResolution: ts18.ModuleResolutionKind.Bundler,
20113
- jsx: ts18.JsxEmit.ReactJSX,
20555
+ target: ts19.ScriptTarget.Latest,
20556
+ module: ts19.ModuleKind.ESNext,
20557
+ moduleResolution: ts19.ModuleResolutionKind.Bundler,
20558
+ jsx: ts19.JsxEmit.ReactJSX,
20114
20559
  strict: true,
20115
20560
  skipLibCheck: true,
20116
20561
  noEmit: true,
@@ -20120,7 +20565,7 @@ function createProgramForCorpus(files, options = {}) {
20120
20565
  ...options.compilerOptions
20121
20566
  };
20122
20567
  const absolute = files.map((f) => path_default.resolve(f));
20123
- return ts18.createProgram(absolute, compilerOptions, undefined, options.oldProgram);
20568
+ return ts19.createProgram(absolute, compilerOptions, undefined, options.oldProgram);
20124
20569
  }
20125
20570
  // src/adapters/interface.ts
20126
20571
  class BaseAdapter {
@@ -20933,7 +21378,7 @@ var queryHrefPlugin = {
20933
21378
  };
20934
21379
  }
20935
21380
  };
20936
- var BUILTIN_LOWERING_PLUGINS = [queryHrefPlugin];
21381
+ var BUILTIN_LOWERING_PLUGINS = [queryHrefPlugin, datePlugin];
20937
21382
  function registerBuiltinLoweringPlugins() {
20938
21383
  for (const plugin of BUILTIN_LOWERING_PLUGINS)
20939
21384
  registerLoweringPlugin(plugin);
@@ -21059,7 +21504,7 @@ function dangerousInnerHtmlDiagnostic(expr, loc, reason) {
21059
21504
  };
21060
21505
  }
21061
21506
  // src/combine-client-js.ts
21062
- import ts19 from "typescript";
21507
+ import ts20 from "typescript";
21063
21508
  var CHILD_PLACEHOLDER_RE = /import '\/\* @bf-child:(\w+) \*\/'/g;
21064
21509
  function combineParentChildClientJs(files) {
21065
21510
  const result = new Map;
@@ -21116,10 +21561,10 @@ function combineParentChildClientJs(files) {
21116
21561
  return result;
21117
21562
  }
21118
21563
  function parseAndMerge(content, importsBySource, otherImports, codeSections) {
21119
- const sourceFile = ts19.createSourceFile("combine.js", content, ts19.ScriptTarget.Latest, false, ts19.ScriptKind.JS);
21564
+ const sourceFile = ts20.createSourceFile("combine.js", content, ts20.ScriptTarget.Latest, false, ts20.ScriptKind.JS);
21120
21565
  const importSpans = [];
21121
21566
  for (const stmt of sourceFile.statements) {
21122
- if (!ts19.isImportDeclaration(stmt))
21567
+ if (!ts20.isImportDeclaration(stmt))
21123
21568
  continue;
21124
21569
  const start = stmt.getStart(sourceFile);
21125
21570
  const end = stmt.getEnd();
@@ -21129,8 +21574,8 @@ function parseAndMerge(content, importsBySource, otherImports, codeSections) {
21129
21574
  continue;
21130
21575
  const clause = stmt.importClause;
21131
21576
  const bindings = clause?.namedBindings;
21132
- const specifier = ts19.isStringLiteral(stmt.moduleSpecifier) ? stmt.moduleSpecifier.text : "";
21133
- if (clause && !clause.name && bindings && ts19.isNamedImports(bindings)) {
21577
+ const specifier = ts20.isStringLiteral(stmt.moduleSpecifier) ? stmt.moduleSpecifier.text : "";
21578
+ if (clause && !clause.name && bindings && ts20.isNamedImports(bindings)) {
21134
21579
  if (!importsBySource.has(specifier)) {
21135
21580
  importsBySource.set(specifier, new Set);
21136
21581
  }
@@ -21293,7 +21738,7 @@ function escapeRe(s) {
21293
21738
  return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
21294
21739
  }
21295
21740
  // src/debug.ts
21296
- import ts20 from "typescript";
21741
+ import ts21 from "typescript";
21297
21742
  function buildComponentGraph(source, filePath, componentName) {
21298
21743
  const ctx = analyzeComponent(source, filePath, componentName);
21299
21744
  if (!ctx.jsxReturn) {
@@ -22578,7 +23023,7 @@ function truncateExpr(expr, max = 40) {
22578
23023
  function exprReadsPropMember(expr, propsObjectName) {
22579
23024
  let sf;
22580
23025
  try {
22581
- sf = ts20.createSourceFile("__attr.tsx", `(${expr})`, ts20.ScriptTarget.Latest, true, ts20.ScriptKind.TSX);
23026
+ sf = ts21.createSourceFile("__attr.tsx", `(${expr})`, ts21.ScriptTarget.Latest, true, ts21.ScriptKind.TSX);
22582
23027
  } catch {
22583
23028
  return false;
22584
23029
  }
@@ -22586,11 +23031,11 @@ function exprReadsPropMember(expr, propsObjectName) {
22586
23031
  const visit3 = (n) => {
22587
23032
  if (found)
22588
23033
  return;
22589
- if (ts20.isPropertyAccessExpression(n) && ts20.isIdentifier(n.expression) && n.expression.text === propsObjectName && n.name.text !== "children") {
23034
+ if (ts21.isPropertyAccessExpression(n) && ts21.isIdentifier(n.expression) && n.expression.text === propsObjectName && n.name.text !== "children") {
22590
23035
  found = true;
22591
23036
  return;
22592
23037
  }
22593
- ts20.forEachChild(n, visit3);
23038
+ ts21.forEachChild(n, visit3);
22594
23039
  };
22595
23040
  visit3(sf);
22596
23041
  return found;
@@ -22660,7 +23105,7 @@ function findSourceFile2(meta) {
22660
23105
  return null;
22661
23106
  }
22662
23107
  // src/profiler.ts
22663
- import ts21 from "typescript";
23108
+ import ts22 from "typescript";
22664
23109
  var PROFILE_SCHEMA_VERSION = 1;
22665
23110
  var DEFAULT_FANOUT_THRESHOLD = 8;
22666
23111
  function buildStaticBudget(source, filePath, componentName, options = {}) {
@@ -22930,15 +23375,15 @@ function joinProfilerEvents(events, index) {
22930
23375
  return { joined, unattributed, diagnostics };
22931
23376
  }
22932
23377
  function findUninstrumentedEffects(source, filePath, instrumentedLines) {
22933
- const sf = ts21.createSourceFile(filePath, source, ts21.ScriptTarget.Latest, true, ts21.ScriptKind.TSX);
23378
+ const sf = ts22.createSourceFile(filePath, source, ts22.ScriptTarget.Latest, true, ts22.ScriptKind.TSX);
22934
23379
  const out = [];
22935
23380
  const visit3 = (node) => {
22936
- if (ts21.isCallExpression(node) && ts21.isIdentifier(node.expression) && node.expression.text === "createEffect") {
23381
+ if (ts22.isCallExpression(node) && ts22.isIdentifier(node.expression) && node.expression.text === "createEffect") {
22937
23382
  const line = sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1;
22938
23383
  if (!instrumentedLines.has(line))
22939
23384
  out.push({ file: filePath, line });
22940
23385
  }
22941
- ts21.forEachChild(node, visit3);
23386
+ ts22.forEachChild(node, visit3);
22942
23387
  };
22943
23388
  visit3(sf);
22944
23389
  out.sort((a, b) => a.line - b.line);
@@ -23246,13 +23691,13 @@ function assessBatchSafety(args) {
23246
23691
  const signalGetters = new Set(args.graph.signals.map((s) => s.name));
23247
23692
  let sf;
23248
23693
  try {
23249
- sf = ts21.createSourceFile("__h.ts", `const __h = ${args.handler}`, ts21.ScriptTarget.Latest, true);
23694
+ sf = ts22.createSourceFile("__h.ts", `const __h = ${args.handler}`, ts22.ScriptTarget.Latest, true);
23250
23695
  } catch {
23251
23696
  return "unverified";
23252
23697
  }
23253
23698
  const calls = [];
23254
23699
  const visit3 = (node) => {
23255
- if (ts21.isCallExpression(node) && ts21.isIdentifier(node.expression)) {
23700
+ if (ts22.isCallExpression(node) && ts22.isIdentifier(node.expression)) {
23256
23701
  const name = node.expression.text;
23257
23702
  if (setters.has(name))
23258
23703
  calls.push({ pos: node.getStart(sf), kind: "write" });
@@ -23261,7 +23706,7 @@ function assessBatchSafety(args) {
23261
23706
  else if (!signalGetters.has(name) && !memoNames.has(name))
23262
23707
  calls.push({ pos: node.getStart(sf), kind: "risky" });
23263
23708
  }
23264
- ts21.forEachChild(node, visit3);
23709
+ ts22.forEachChild(node, visit3);
23265
23710
  };
23266
23711
  visit3(sf);
23267
23712
  calls.sort((a, b) => a.pos - b.pos);