@tsplc/compiler 0.3.0 → 0.4.1

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.
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { mkdirSync, writeFileSync as writeFileSync2 } from "node:fs";
3
3
  import { createRequire as createRequire2 } from "node:module";
4
4
  import { dirname as dirname7, join as join4, relative as relative5, resolve as resolve7 } from "node:path";
5
5
  import { hasErrors } from "@tsplc/compiler/ir";
6
- import ts32 from "typescript";
6
+ import ts33 from "typescript";
7
7
 
8
8
  // packages/compiler/src/frontend/analyzer.ts
9
9
  import { resolve as resolve2 } from "node:path";
@@ -4647,7 +4647,7 @@ import {
4647
4647
  error as error6
4648
4648
  } from "@tsplc/compiler/ir";
4649
4649
  import { generatedDirectory } from "@tsplc/config/project-files";
4650
- import ts27 from "typescript";
4650
+ import ts28 from "typescript";
4651
4651
 
4652
4652
  // packages/compiler/src/frontend/elaborate/graph.ts
4653
4653
  import { spawnSync } from "node:child_process";
@@ -4715,7 +4715,8 @@ var capturedGraphSchema = z.strictObject({
4715
4715
  file: z.string(),
4716
4716
  name: z.string(),
4717
4717
  value: capturedValueSchema
4718
- }))
4718
+ })),
4719
+ retained: z.array(z.number().int().nonnegative())
4719
4720
  }).superRefine((graph, context) => {
4720
4721
  const references = [
4721
4722
  ...graph.bindings.map((binding) => binding.value),
@@ -4729,6 +4730,9 @@ var capturedGraphSchema = z.strictObject({
4729
4730
  return [];
4730
4731
  })
4731
4732
  ];
4733
+ for (const id of graph.retained) {
4734
+ references.push({ kind: "node", id });
4735
+ }
4732
4736
  for (const value of references) {
4733
4737
  if (value.kind === "node" && value.id >= graph.nodes.length) {
4734
4738
  context.addIssue({
@@ -5027,12 +5031,143 @@ class Model {
5027
5031
  }
5028
5032
  }
5029
5033
 
5034
+ // packages/compiler/src/frontend/elaborate/retention.ts
5035
+ import ts18 from "typescript";
5036
+
5037
+ // packages/compiler/src/frontend/elaborate/values.ts
5038
+ var constant = (value) => ({
5039
+ kind: "const",
5040
+ value
5041
+ });
5042
+ var repeatable = (text) => /^[\w.[\]]+$/.test(String(text));
5043
+
5044
+ class SpecializeError extends Error {
5045
+ node;
5046
+ constructor(node, message) {
5047
+ super(message);
5048
+ this.node = node;
5049
+ }
5050
+ }
5051
+
5052
+ // packages/compiler/src/frontend/elaborate/retention.ts
5053
+ var primitive = (type) => {
5054
+ if (type.isUnion()) {
5055
+ return type.types.every(primitive);
5056
+ }
5057
+ if (type.isIntersection()) {
5058
+ return type.types.some(primitive);
5059
+ }
5060
+ return !(type.flags & (ts18.TypeFlags.Object | ts18.TypeFlags.NonPrimitive));
5061
+ };
5062
+ var retainedDeclaration = (call) => {
5063
+ const parent = call.parent;
5064
+ if (ts18.isPropertyDeclaration(parent) && parent.initializer === call) {
5065
+ return parent;
5066
+ }
5067
+ if (ts18.isVariableDeclaration(parent) && parent.initializer === call && ts18.isVariableDeclarationList(parent.parent) && ts18.isVariableStatement(parent.parent.parent) && ts18.isSourceFile(parent.parent.parent.parent)) {
5068
+ return parent;
5069
+ }
5070
+ return;
5071
+ };
5072
+ var retainedDeclarations = (sources, checker, sdk) => {
5073
+ const found = new Set;
5074
+ const visit = (node) => {
5075
+ if (ts18.isCallExpression(node) && namesSdk(checker, sdk, node.expression, "retain")) {
5076
+ const symbol = checker.getSymbolAtLocation(node.expression);
5077
+ if (!symbol || !(symbol.flags & ts18.SymbolFlags.Alias)) {
5078
+ throw new SpecializeError(node, 'Setup runs under Bun, where the global retain has no value: import { retain } from "@tsplc/compiler/retain".');
5079
+ }
5080
+ const [argument] = node.arguments;
5081
+ if (argument && primitive(checker.getTypeAtLocation(argument))) {
5082
+ const declaration = retainedDeclaration(node);
5083
+ if (!declaration) {
5084
+ throw new SpecializeError(node, "A primitive is retained only as a module let's or a class field's initializer; retain the record that holds it.");
5085
+ }
5086
+ found.add(declaration);
5087
+ }
5088
+ }
5089
+ ts18.forEachChild(node, visit);
5090
+ };
5091
+ for (const source of sources) {
5092
+ visit(source);
5093
+ }
5094
+ return found;
5095
+ };
5096
+
5097
+ class Retention {
5098
+ model;
5099
+ storage;
5100
+ declarations;
5101
+ objects;
5102
+ claimed = new Set;
5103
+ constructor(model, storage, declarations) {
5104
+ this.model = model;
5105
+ this.storage = storage;
5106
+ this.declarations = declarations;
5107
+ this.objects = new Set(model.graph.retained);
5108
+ }
5109
+ global(root, field) {
5110
+ const node = this.model.node(root.value);
5111
+ if (field === null || !node) {
5112
+ return this.claim(this.declarations.has(root.declaration) ? root.declaration : null, this.holds(root.value, { root, steps: [] }));
5113
+ }
5114
+ const member = node.captured.kind === "instance" ? this.model.member(this.model.classOf(node), field) : undefined;
5115
+ const value = (node.captured.kind === "instance" || node.captured.kind === "object" ? node.captured.fields[field] : undefined) ?? { kind: "undefined" };
5116
+ const held = this.holds(value, {
5117
+ root,
5118
+ steps: [{ kind: "field", name: field }]
5119
+ });
5120
+ const declared = member && this.declarations.has(member) ? member : null;
5121
+ const whole = this.objects.has(node.id) ? node.id : null;
5122
+ return [this.claim(declared, held), this.claim(whole, held)].some(Boolean);
5123
+ }
5124
+ unclaimed() {
5125
+ const objects = [...this.objects].filter((id) => !this.claimed.has(id)).map((id) => {
5126
+ const owner = this.model.nodes[id]?.owner;
5127
+ return new Error(`${owner ? tsPath(owner) : "A retained object"}: retain retains nothing the PLC stores; retain state scan code writes, or exported data.`);
5128
+ });
5129
+ const declarations = [...this.declarations].filter((declaration) => !this.claimed.has(declaration)).map((declaration) => new SpecializeError(declaration, "retain retains nothing the PLC stores; retain state scan code writes, or exported data."));
5130
+ return [...objects, ...declarations];
5131
+ }
5132
+ claim(mark, held) {
5133
+ if (mark === null) {
5134
+ return held;
5135
+ }
5136
+ this.claimed.add(mark);
5137
+ return true;
5138
+ }
5139
+ holds(value, at) {
5140
+ const node = this.model.node(value);
5141
+ if (!node?.owner || node.owner.root !== at.root) {
5142
+ return false;
5143
+ }
5144
+ if (tsPath(node.owner) !== tsPath(at)) {
5145
+ return false;
5146
+ }
5147
+ const marks = [
5148
+ ...this.objects.has(node.id) && this.storage.hasState(node) ? [node.id] : [],
5149
+ ...this.retainedMembers(node)
5150
+ ];
5151
+ for (const mark of marks) {
5152
+ this.claimed.add(mark);
5153
+ }
5154
+ const inner = children(node.captured).map(([step, held]) => this.holds(held, { root: at.root, steps: [...at.steps, step] }));
5155
+ return marks.length > 0 || inner.some(Boolean);
5156
+ }
5157
+ retainedMembers(node) {
5158
+ if (node.captured.kind !== "instance") {
5159
+ return [];
5160
+ }
5161
+ return this.model.fields(this.model.classOf(node)).filter((member) => this.declarations.has(member) && this.storage.stored(node, member.name.getText()));
5162
+ }
5163
+ }
5164
+
5030
5165
  // packages/compiler/src/frontend/elaborate/specialize.ts
5031
- import ts26 from "typescript";
5166
+ import ts27 from "typescript";
5032
5167
 
5033
5168
  // packages/compiler/src/frontend/elaborate/dialect.ts
5034
5169
  import { canAssign as canAssign2, integerType, primitiveTypes as primitiveTypes2 } from "@tsplc/compiler/ir";
5035
- import ts18 from "typescript";
5170
+ import ts19 from "typescript";
5036
5171
  class DialectText {
5037
5172
  model;
5038
5173
  checker;
@@ -5127,7 +5262,7 @@ class DialectText {
5127
5262
  }), ", ")} }`;
5128
5263
  }
5129
5264
  assignmentText(value, declared, iec) {
5130
- const target = iec ?? (declared && declared.flags & ts18.TypeFlags.Number ? "DINT" : undefined);
5265
+ const target = iec ?? (declared && declared.flags & ts19.TypeFlags.Number ? "DINT" : undefined);
5131
5266
  if (target && value.kind === "code" && needsConversion(value.iec ?? "DINT", target)) {
5132
5267
  this.imports.conversions.add("wrap");
5133
5268
  return mapped`wrap<${target}>(${this.code(value, undefined)})`;
@@ -5159,9 +5294,9 @@ class DialectText {
5159
5294
  condition(value, at) {
5160
5295
  if (value.kind === "code" && value.declared) {
5161
5296
  const declared = value.declared;
5162
- if (this.layouts.isOptionalRecord(declared) && !ts18.isPrefixUnaryExpression(at)) {
5297
+ if (this.layouts.isOptionalRecord(declared) && !ts19.isPrefixUnaryExpression(at)) {
5163
5298
  const type = this.checker.getTypeAtLocation(at);
5164
- if (!(type.flags & ts18.TypeFlags.BooleanLike)) {
5299
+ if (!(type.flags & ts19.TypeFlags.BooleanLike)) {
5165
5300
  return mapped`${value.text}.has`;
5166
5301
  }
5167
5302
  }
@@ -5195,27 +5330,10 @@ var needsConversion = (from, to) => {
5195
5330
  };
5196
5331
 
5197
5332
  // packages/compiler/src/frontend/elaborate/expressions.ts
5198
- import ts22 from "typescript";
5199
-
5200
- // packages/compiler/src/frontend/elaborate/calls.ts
5201
- import ts19 from "typescript";
5202
-
5203
- // packages/compiler/src/frontend/elaborate/values.ts
5204
- var constant = (value) => ({
5205
- kind: "const",
5206
- value
5207
- });
5208
- var repeatable = (text) => /^[\w.[\]]+$/.test(String(text));
5209
-
5210
- class SpecializeError extends Error {
5211
- node;
5212
- constructor(node, message) {
5213
- super(message);
5214
- this.node = node;
5215
- }
5216
- }
5333
+ import ts23 from "typescript";
5217
5334
 
5218
5335
  // packages/compiler/src/frontend/elaborate/calls.ts
5336
+ import ts20 from "typescript";
5219
5337
  class CallSpecializer {
5220
5338
  expressions;
5221
5339
  model;
@@ -5237,12 +5355,12 @@ class CallSpecializer {
5237
5355
  }
5238
5356
  call(node, frame, expected) {
5239
5357
  const callee = node.expression;
5240
- if (ts19.isPropertyAccessExpression(callee) || ts19.isPropertyAccessChain(callee)) {
5358
+ if (ts20.isPropertyAccessExpression(callee) || ts20.isPropertyAccessChain(callee)) {
5241
5359
  const name = callee.name.text;
5242
- if (ts19.isIdentifier(callee.expression) && callee.expression.text === "Math") {
5360
+ if (ts20.isIdentifier(callee.expression) && callee.expression.text === "Math") {
5243
5361
  return this.math(name, node, frame);
5244
5362
  }
5245
- if (ts19.isIdentifier(callee.expression) && callee.expression.text === "Object" && name === "values") {
5363
+ if (ts20.isIdentifier(callee.expression) && callee.expression.text === "Object" && name === "values") {
5246
5364
  const [argument] = node.arguments;
5247
5365
  const object = argument && this.expressions.expression(argument, frame);
5248
5366
  if (object?.kind === "static" && object.node.captured.kind === "object") {
@@ -5286,24 +5404,24 @@ class CallSpecializer {
5286
5404
  const fn = this.functionDeclaration(target.node.captured.file, target.node.captured.name);
5287
5405
  return this.expressions.invoke({ kind: "function", declaration: fn }, node.arguments.map((argument, index) => this.argument(argument, { kind: "function", declaration: fn }, index, frame)), node, frame, expected);
5288
5406
  }
5289
- if (ts19.isIdentifier(callee) && this.sdkCall(callee)) {
5407
+ if (ts20.isIdentifier(callee) && this.sdkCall(callee)) {
5290
5408
  return this.sdk(callee.text, node, frame);
5291
5409
  }
5292
5410
  return this.expressions.invoke(target, node.arguments.map((argument, index) => this.argument(argument, target, index, frame)), node, frame, expected);
5293
5411
  }
5294
5412
  argument(node, callee, index, frame) {
5295
- const parameter = callee.kind === "function" && !ts19.isGetAccessorDeclaration(callee.declaration) ? callee.declaration.parameters[index] : undefined;
5413
+ const parameter = callee.kind === "function" && !ts20.isGetAccessorDeclaration(callee.declaration) ? callee.declaration.parameters[index] : undefined;
5296
5414
  return this.expressions.expression(node, frame, parameter && this.checker.getTypeAtLocation(parameter));
5297
5415
  }
5298
5416
  functionDeclaration(file, name) {
5299
5417
  const source = this.sources.find((item) => item.fileName === file);
5300
5418
  for (const statement of source?.statements ?? []) {
5301
- if (ts19.isFunctionDeclaration(statement) && statement.name?.text === name) {
5419
+ if (ts20.isFunctionDeclaration(statement) && statement.name?.text === name) {
5302
5420
  return statement;
5303
5421
  }
5304
- if (ts19.isVariableStatement(statement)) {
5422
+ if (ts20.isVariableStatement(statement)) {
5305
5423
  for (const declaration of statement.declarationList.declarations) {
5306
- if (ts19.isIdentifier(declaration.name) && declaration.name.text === name && declaration.initializer && (ts19.isArrowFunction(declaration.initializer) || ts19.isFunctionExpression(declaration.initializer))) {
5424
+ if (ts20.isIdentifier(declaration.name) && declaration.name.text === name && declaration.initializer && (ts20.isArrowFunction(declaration.initializer) || ts20.isFunctionExpression(declaration.initializer))) {
5307
5425
  return declaration.initializer;
5308
5426
  }
5309
5427
  }
@@ -5320,19 +5438,19 @@ class CallSpecializer {
5320
5438
  return file !== undefined && inSdk(this.sdkFile, file) && file.endsWith("/telemetry.d.ts");
5321
5439
  }
5322
5440
  telemetry(node, callee, frame) {
5323
- const value = (argument) => ts19.isCallExpression(argument) && ts19.isPropertyAccessExpression(argument.expression) && this.telemetryCall(argument.expression) ? this.telemetry(argument, argument.expression, frame) : this.dialect.code(this.expressions.expression(argument, frame), this.checker.getTypeAtLocation(argument));
5441
+ const value = (argument) => ts20.isCallExpression(argument) && ts20.isPropertyAccessExpression(argument.expression) && this.telemetryCall(argument.expression) ? this.telemetry(argument, argument.expression, frame) : this.dialect.code(this.expressions.expression(argument, frame), this.checker.getTypeAtLocation(argument));
5324
5442
  const args = node.arguments.map((argument) => {
5325
- if (ts19.isStringLiteral(argument) || ts19.isNoSubstitutionTemplateLiteral(argument)) {
5443
+ if (ts20.isStringLiteral(argument) || ts20.isNoSubstitutionTemplateLiteral(argument)) {
5326
5444
  return copied(argument);
5327
5445
  }
5328
- if (!ts19.isObjectLiteralExpression(argument)) {
5446
+ if (!ts20.isObjectLiteralExpression(argument)) {
5329
5447
  return value(argument);
5330
5448
  }
5331
5449
  const properties = argument.properties.map((property) => {
5332
- if (ts19.isShorthandPropertyAssignment(property)) {
5450
+ if (ts20.isShorthandPropertyAssignment(property)) {
5333
5451
  return mapped`${copied(property.name)}: ${value(property.name)}`;
5334
5452
  }
5335
- if (!ts19.isPropertyAssignment(property)) {
5453
+ if (!ts20.isPropertyAssignment(property)) {
5336
5454
  throw new SpecializeError(property, "Name each telemetry property.");
5337
5455
  }
5338
5456
  return mapped`${copied(property.name)}: ${value(property.initializer)}`;
@@ -5542,7 +5660,7 @@ var arrayMethods = new Set([
5542
5660
 
5543
5661
  // packages/compiler/src/frontend/elaborate/layouts.ts
5544
5662
  import { primitiveTypes as primitiveTypes3 } from "@tsplc/compiler/ir";
5545
- import ts20 from "typescript";
5663
+ import ts21 from "typescript";
5546
5664
  var iecNames = new Set(primitiveTypes3.map((type) => type.id));
5547
5665
 
5548
5666
  class Layouts {
@@ -5562,7 +5680,7 @@ class Layouts {
5562
5680
  this.kept = kept;
5563
5681
  for (const source of keptSources) {
5564
5682
  for (const statement of source.statements) {
5565
- if ((ts20.isTypeAliasDeclaration(statement) || ts20.isInterfaceDeclaration(statement)) && isExported(statement)) {
5683
+ if ((ts21.isTypeAliasDeclaration(statement) || ts21.isInterfaceDeclaration(statement)) && isExported(statement)) {
5566
5684
  const symbol = checker.getSymbolAtLocation(statement.name);
5567
5685
  if (symbol) {
5568
5686
  this.keptTypes.set(checker.getDeclaredTypeOfSymbol(symbol), {
@@ -5590,7 +5708,7 @@ class Layouts {
5590
5708
  }
5591
5709
  literals(type) {
5592
5710
  const parts = type.isUnion() ? type.types : [type];
5593
- const defined = parts.filter((part) => !(part.flags & ts20.TypeFlags.Undefined));
5711
+ const defined = parts.filter((part) => !(part.flags & ts21.TypeFlags.Undefined));
5594
5712
  const members = defined.flatMap((part) => part.isStringLiteral() ? [part.value] : []);
5595
5713
  if (!members.length || members.length !== defined.length) {
5596
5714
  return;
@@ -5633,9 +5751,9 @@ class Layouts {
5633
5751
  if (!type.isUnion()) {
5634
5752
  return;
5635
5753
  }
5636
- const variants = type.types.filter((part) => !(part.flags & ts20.TypeFlags.Undefined));
5754
+ const variants = type.types.filter((part) => !(part.flags & ts21.TypeFlags.Undefined));
5637
5755
  const [first, ...others] = variants;
5638
- if (!first || !others.length || variants.some((part) => !(part.flags & ts20.TypeFlags.Object))) {
5756
+ if (!first || !others.length || variants.some((part) => !(part.flags & ts21.TypeFlags.Object))) {
5639
5757
  return;
5640
5758
  }
5641
5759
  const literal = (variant, name) => {
@@ -5685,7 +5803,7 @@ class Layouts {
5685
5803
  return this.enumDeclaration(type)?.members.find((member) => this.checker.getConstantValue(member) === value)?.name.getText();
5686
5804
  }
5687
5805
  isOptionalRecord(type) {
5688
- if (!type.isUnion() || !type.types.some((part) => part.flags & ts20.TypeFlags.Undefined)) {
5806
+ if (!type.isUnion() || !type.types.some((part) => part.flags & ts21.TypeFlags.Undefined)) {
5689
5807
  return false;
5690
5808
  }
5691
5809
  return !this.literalEnum(type);
@@ -5696,17 +5814,17 @@ class Layouts {
5696
5814
  if (alias && iecNames.has(alias)) {
5697
5815
  return alias;
5698
5816
  }
5699
- if (type.flags & ts20.TypeFlags.BooleanLike) {
5817
+ if (type.flags & ts21.TypeFlags.BooleanLike) {
5700
5818
  return "boolean";
5701
5819
  }
5702
5820
  const enumDeclaration = this.enumDeclaration(type);
5703
5821
  if (enumDeclaration) {
5704
5822
  return this.enumName(enumDeclaration);
5705
5823
  }
5706
- if (type.flags & ts20.TypeFlags.NumberLike) {
5824
+ if (type.flags & ts21.TypeFlags.NumberLike) {
5707
5825
  return "number";
5708
5826
  }
5709
- if (type.flags & ts20.TypeFlags.BigIntLike) {
5827
+ if (type.flags & ts21.TypeFlags.BigIntLike) {
5710
5828
  return "LINT";
5711
5829
  }
5712
5830
  const literal = this.literalEnum(type);
@@ -5717,7 +5835,7 @@ class Layouts {
5717
5835
  if (named) {
5718
5836
  return named;
5719
5837
  }
5720
- if (type.flags & ts20.TypeFlags.StringLike) {
5838
+ if (type.flags & ts21.TypeFlags.StringLike) {
5721
5839
  return "string";
5722
5840
  }
5723
5841
  const tagged = this.tagged(type);
@@ -5743,7 +5861,7 @@ class Layouts {
5743
5861
  if (enumKey) {
5744
5862
  return enumKey;
5745
5863
  }
5746
- if (type.flags & ts20.TypeFlags.Object) {
5864
+ if (type.flags & ts21.TypeFlags.Object) {
5747
5865
  return this.record(type, value, hint);
5748
5866
  }
5749
5867
  throw new Error(`${checker.typeToString(type)} has no PLC layout.`);
@@ -5751,22 +5869,22 @@ class Layouts {
5751
5869
  enumDeclaration(type) {
5752
5870
  const parts = type.isUnion() ? type.types : [type];
5753
5871
  const [first] = parts;
5754
- if (!first || !parts.every((part) => part.flags & ts20.TypeFlags.EnumLike)) {
5872
+ if (!first || !parts.every((part) => part.flags & ts21.TypeFlags.EnumLike)) {
5755
5873
  return;
5756
5874
  }
5757
5875
  const symbol = first.symbol;
5758
- const declaration = symbol?.declarations?.find(ts20.isEnumDeclaration) ?? symbol?.valueDeclaration?.parent;
5759
- return declaration && ts20.isEnumDeclaration(declaration) ? declaration : undefined;
5876
+ const declaration = symbol?.declarations?.find(ts21.isEnumDeclaration) ?? symbol?.valueDeclaration?.parent;
5877
+ return declaration && ts21.isEnumDeclaration(declaration) ? declaration : undefined;
5760
5878
  }
5761
5879
  iecName(declaration) {
5762
5880
  return iecTypeName(annotation(declaration));
5763
5881
  }
5764
5882
  elementIec(declaration) {
5765
5883
  const node = annotation(declaration);
5766
- if (node && ts20.isArrayTypeNode(node)) {
5884
+ if (node && ts21.isArrayTypeNode(node)) {
5767
5885
  return iecTypeName(node.elementType);
5768
5886
  }
5769
- if (node && ts20.isTypeReferenceNode(node)) {
5887
+ if (node && ts21.isTypeReferenceNode(node)) {
5770
5888
  return iecTypeName(node.typeArguments?.[0]);
5771
5889
  }
5772
5890
  return;
@@ -5812,7 +5930,7 @@ class Layouts {
5812
5930
  if (!symbol || !declaration) {
5813
5931
  return;
5814
5932
  }
5815
- if (!ts20.isTypeAliasDeclaration(declaration) && !ts20.isInterfaceDeclaration(declaration)) {
5933
+ if (!ts21.isTypeAliasDeclaration(declaration) && !ts21.isInterfaceDeclaration(declaration)) {
5816
5934
  return;
5817
5935
  }
5818
5936
  const file = declaration.getSourceFile().fileName;
@@ -5896,16 +6014,16 @@ var recordTypes = (type) => {
5896
6014
  };
5897
6015
  var annotation = (declaration) => declaration && declaration.type;
5898
6016
  var arrayElement = (node) => {
5899
- if (node && ts20.isArrayTypeNode(node)) {
6017
+ if (node && ts21.isArrayTypeNode(node)) {
5900
6018
  return node.elementType;
5901
6019
  }
5902
- if (node && ts20.isTypeReferenceNode(node) && ["Array", "ReadonlyArray"].includes(node.typeName.getText())) {
6020
+ if (node && ts21.isTypeReferenceNode(node) && ["Array", "ReadonlyArray"].includes(node.typeName.getText())) {
5903
6021
  return node.typeArguments?.[0];
5904
6022
  }
5905
6023
  return;
5906
6024
  };
5907
- var iecTypeName = (node) => node && ts20.isTypeReferenceNode(node) && iecNames.has(node.typeName.getText()) ? node.typeName.getText() : undefined;
5908
- var isExported = (declaration) => Boolean(ts20.getCombinedModifierFlags(declaration) & ts20.ModifierFlags.Export);
6025
+ var iecTypeName = (node) => node && ts21.isTypeReferenceNode(node) && iecNames.has(node.typeName.getText()) ? node.typeName.getText() : undefined;
6026
+ var isExported = (declaration) => Boolean(ts21.getCombinedModifierFlags(declaration) & ts21.ModifierFlags.Export);
5909
6027
  var isReadonlyArray = (type) => type.getSymbol()?.name === "ReadonlyArray";
5910
6028
  var pascalCase = (text) => text.replace(/(^|[^A-Za-z0-9]+)([A-Za-z0-9])/g, (_, __, letter) => letter.toUpperCase());
5911
6029
  var unusedName = (base, taken) => {
@@ -5925,7 +6043,7 @@ var enumMember = (value) => {
5925
6043
  };
5926
6044
 
5927
6045
  // packages/compiler/src/frontend/elaborate/writes.ts
5928
- import ts21 from "typescript";
6046
+ import ts22 from "typescript";
5929
6047
 
5930
6048
  class ScanWrites {
5931
6049
  checker;
@@ -5946,27 +6064,27 @@ class ScanWrites {
5946
6064
  });
5947
6065
  }
5948
6066
  collectAssignments(node, inConstructor) {
5949
- const constructing = inConstructor || ts21.isConstructorDeclaration(node);
6067
+ const constructing = inConstructor || ts22.isConstructorDeclaration(node);
5950
6068
  if (!constructing) {
5951
6069
  const write = (target) => {
5952
6070
  const place = unwrapped(target);
5953
- if (ts21.isPropertyAccessExpression(place)) {
6071
+ if (ts22.isPropertyAccessExpression(place)) {
5954
6072
  this.markAssigned(place.name);
5955
- } else if (ts21.isElementAccessExpression(place)) {
6073
+ } else if (ts22.isElementAccessExpression(place)) {
5956
6074
  const base = indexed(place.expression);
5957
- if (ts21.isPropertyAccessExpression(base)) {
6075
+ if (ts22.isPropertyAccessExpression(base)) {
5958
6076
  this.markAssigned(base.name);
5959
6077
  }
5960
6078
  }
5961
6079
  };
5962
- if (ts21.isBinaryExpression(node) && isAssignment(node.operatorToken.kind)) {
6080
+ if (ts22.isBinaryExpression(node) && isAssignment(node.operatorToken.kind)) {
5963
6081
  write(node.left);
5964
6082
  }
5965
6083
  if (isUpdate(node)) {
5966
6084
  write(node.operand);
5967
6085
  }
5968
6086
  }
5969
- ts21.forEachChild(node, (child) => this.collectAssignments(child, constructing));
6087
+ ts22.forEachChild(node, (child) => this.collectAssignments(child, constructing));
5970
6088
  }
5971
6089
  markAssigned(name) {
5972
6090
  const symbol = this.checker.getSymbolAtLocation(name);
@@ -5983,10 +6101,10 @@ class ScanWrites {
5983
6101
  }
5984
6102
  }
5985
6103
  var ownSymbol = (declaration) => declaration.symbol;
5986
- var unwrapped = (target) => ts21.isParenthesizedExpression(target) || ts21.isNonNullExpression(target) ? unwrapped(target.expression) : target;
5987
- var indexed = (node) => ts21.isElementAccessExpression(node) ? indexed(node.expression) : node;
5988
- var isUpdate = (node) => (ts21.isPrefixUnaryExpression(node) || ts21.isPostfixUnaryExpression(node)) && (node.operator === ts21.SyntaxKind.PlusPlusToken || node.operator === ts21.SyntaxKind.MinusMinusToken);
5989
- var isAssignment = (kind) => kind >= ts21.SyntaxKind.FirstAssignment && kind <= ts21.SyntaxKind.LastAssignment;
6104
+ var unwrapped = (target) => ts22.isParenthesizedExpression(target) || ts22.isNonNullExpression(target) ? unwrapped(target.expression) : target;
6105
+ var indexed = (node) => ts22.isElementAccessExpression(node) ? indexed(node.expression) : node;
6106
+ var isUpdate = (node) => (ts22.isPrefixUnaryExpression(node) || ts22.isPostfixUnaryExpression(node)) && (node.operator === ts22.SyntaxKind.PlusPlusToken || node.operator === ts22.SyntaxKind.MinusMinusToken);
6107
+ var isAssignment = (kind) => kind >= ts22.SyntaxKind.FirstAssignment && kind <= ts22.SyntaxKind.LastAssignment;
5990
6108
 
5991
6109
  // packages/compiler/src/frontend/elaborate/expressions.ts
5992
6110
  class ExpressionSpecializer {
@@ -6018,40 +6136,40 @@ class ExpressionSpecializer {
6018
6136
  }
6019
6137
  return {
6020
6138
  ...value,
6021
- text: from(node, ts22.isIdentifier(node) ? String(value.text) : value.text)
6139
+ text: from(node, ts23.isIdentifier(node) ? String(value.text) : value.text)
6022
6140
  };
6023
6141
  }
6024
6142
  evaluate(node, frame, expected) {
6025
- if (ts22.isParenthesizedExpression(node) || ts22.isNonNullExpression(node) || ts22.isAsExpression(node) || ts22.isSatisfiesExpression(node)) {
6143
+ if (ts23.isParenthesizedExpression(node) || ts23.isNonNullExpression(node) || ts23.isAsExpression(node) || ts23.isSatisfiesExpression(node)) {
6026
6144
  return this.expression(node.expression, frame, expected);
6027
6145
  }
6028
- if (ts22.isNumericLiteral(node)) {
6146
+ if (ts23.isNumericLiteral(node)) {
6029
6147
  return constant(Number(node.text));
6030
6148
  }
6031
- if (ts22.isStringLiteral(node) || ts22.isNoSubstitutionTemplateLiteral(node)) {
6149
+ if (ts23.isStringLiteral(node) || ts23.isNoSubstitutionTemplateLiteral(node)) {
6032
6150
  return constant(node.text);
6033
6151
  }
6034
- if (node.kind === ts22.SyntaxKind.TrueKeyword) {
6152
+ if (node.kind === ts23.SyntaxKind.TrueKeyword) {
6035
6153
  return constant(true);
6036
6154
  }
6037
- if (node.kind === ts22.SyntaxKind.FalseKeyword) {
6155
+ if (node.kind === ts23.SyntaxKind.FalseKeyword) {
6038
6156
  return constant(false);
6039
6157
  }
6040
- if (ts22.isBigIntLiteral(node)) {
6158
+ if (ts23.isBigIntLiteral(node)) {
6041
6159
  return constant(BigInt(node.text.slice(0, -1)));
6042
6160
  }
6043
- if (node.kind === ts22.SyntaxKind.ThisKeyword) {
6161
+ if (node.kind === ts23.SyntaxKind.ThisKeyword) {
6044
6162
  if (!frame.self) {
6045
6163
  throw new SpecializeError(node, "`this` outside a method.");
6046
6164
  }
6047
6165
  return { kind: "static", node: frame.self };
6048
6166
  }
6049
- if (ts22.isIdentifier(node)) {
6167
+ if (ts23.isIdentifier(node)) {
6050
6168
  return this.identifier(node, frame);
6051
6169
  }
6052
- if (ts22.isPropertyAccessExpression(node)) {
6170
+ if (ts23.isPropertyAccessExpression(node)) {
6053
6171
  const member = this.checker.getSymbolAtLocation(node.name)?.valueDeclaration;
6054
- if (member && ts22.isEnumMember(member)) {
6172
+ if (member && ts23.isEnumMember(member)) {
6055
6173
  return constant(this.checker.getConstantValue(member));
6056
6174
  }
6057
6175
  const object = this.expression(node.expression, frame);
@@ -6060,15 +6178,15 @@ class ExpressionSpecializer {
6060
6178
  }
6061
6179
  return this.narrowed(this.member(object, node.name.text, node, frame), node);
6062
6180
  }
6063
- if (ts22.isElementAccessExpression(node)) {
6181
+ if (ts23.isElementAccessExpression(node)) {
6064
6182
  const object = this.expression(node.expression, frame);
6065
6183
  const index = this.expression(node.argumentExpression, frame);
6066
6184
  return this.element(object, index, node, frame);
6067
6185
  }
6068
- if (ts22.isCallExpression(node)) {
6186
+ if (ts23.isCallExpression(node)) {
6069
6187
  return this.calls.call(node, frame, expected);
6070
6188
  }
6071
- if (ts22.isAwaitExpression(node)) {
6189
+ if (ts23.isAwaitExpression(node)) {
6072
6190
  const value = this.expression(node.expression, frame);
6073
6191
  return {
6074
6192
  kind: "code",
@@ -6076,13 +6194,13 @@ class ExpressionSpecializer {
6076
6194
  declared: this.checker.getTypeAtLocation(node)
6077
6195
  };
6078
6196
  }
6079
- if (ts22.isPrefixUnaryExpression(node)) {
6197
+ if (ts23.isPrefixUnaryExpression(node)) {
6080
6198
  return this.unary(node, frame);
6081
6199
  }
6082
- if (ts22.isBinaryExpression(node)) {
6200
+ if (ts23.isBinaryExpression(node)) {
6083
6201
  return this.binary(node, frame, expected);
6084
6202
  }
6085
- if (ts22.isConditionalExpression(node)) {
6203
+ if (ts23.isConditionalExpression(node)) {
6086
6204
  const condition = this.expression(node.condition, frame);
6087
6205
  if (condition.kind === "const") {
6088
6206
  return this.expression(condition.value ? node.whenTrue : node.whenFalse, frame, expected);
@@ -6096,7 +6214,7 @@ class ExpressionSpecializer {
6096
6214
  declared
6097
6215
  };
6098
6216
  }
6099
- if (ts22.isArrowFunction(node) || ts22.isFunctionExpression(node)) {
6217
+ if (ts23.isArrowFunction(node) || ts23.isFunctionExpression(node)) {
6100
6218
  return {
6101
6219
  kind: "function",
6102
6220
  declaration: node,
@@ -6104,13 +6222,13 @@ class ExpressionSpecializer {
6104
6222
  env: frame.env
6105
6223
  };
6106
6224
  }
6107
- if (ts22.isObjectLiteralExpression(node)) {
6225
+ if (ts23.isObjectLiteralExpression(node)) {
6108
6226
  return this.objectLiteral(node, frame);
6109
6227
  }
6110
- if (ts22.isArrayLiteralExpression(node)) {
6228
+ if (ts23.isArrayLiteralExpression(node)) {
6111
6229
  const items = [];
6112
6230
  for (const element of node.elements) {
6113
- if (ts22.isSpreadElement(element)) {
6231
+ if (ts23.isSpreadElement(element)) {
6114
6232
  const spread = this.items(this.expression(element.expression, frame));
6115
6233
  if (!spread) {
6116
6234
  throw new SpecializeError(element, "Spread an array setup built.");
@@ -6122,10 +6240,10 @@ class ExpressionSpecializer {
6122
6240
  }
6123
6241
  return { kind: "virtual", items };
6124
6242
  }
6125
- if (ts22.isTemplateExpression(node)) {
6243
+ if (ts23.isTemplateExpression(node)) {
6126
6244
  throw new SpecializeError(node, "Template strings are not supported in scan code.");
6127
6245
  }
6128
- throw new SpecializeError(node, `${ts22.SyntaxKind[node.kind]} is not supported in scan code.`);
6246
+ throw new SpecializeError(node, `${ts23.SyntaxKind[node.kind]} is not supported in scan code.`);
6129
6247
  }
6130
6248
  identifier(node, frame) {
6131
6249
  if (node.text === "undefined") {
@@ -6148,25 +6266,25 @@ class ExpressionSpecializer {
6148
6266
  if (!declaration) {
6149
6267
  throw new SpecializeError(node, `${node.text} has no declaration.`);
6150
6268
  }
6151
- if (ts22.isFunctionDeclaration(declaration)) {
6269
+ if (ts23.isFunctionDeclaration(declaration)) {
6152
6270
  return { kind: "function", declaration };
6153
6271
  }
6154
- if (ts22.isVariableDeclaration(declaration)) {
6272
+ if (ts23.isVariableDeclaration(declaration)) {
6155
6273
  const initializer = declaration.initializer;
6156
- if (initializer && (ts22.isArrowFunction(initializer) || ts22.isFunctionExpression(initializer))) {
6274
+ if (initializer && (ts23.isArrowFunction(initializer) || ts23.isFunctionExpression(initializer))) {
6157
6275
  return { kind: "function", declaration: initializer };
6158
6276
  }
6159
6277
  const root = this.model.roots.find((item) => item.declaration === declaration);
6160
6278
  if (root) {
6161
6279
  return this.storage.rootValue(root);
6162
6280
  }
6163
- if (ts22.isVariableStatement(declaration.parent.parent) && declaration.parent.parent.parent && ts22.isSourceFile(declaration.parent.parent.parent)) {
6281
+ if (ts23.isVariableStatement(declaration.parent.parent) && declaration.parent.parent.parent && ts23.isSourceFile(declaration.parent.parent.parent)) {
6164
6282
  if (initializer) {
6165
6283
  return this.expression(initializer, { ...frame, env: new Map });
6166
6284
  }
6167
6285
  }
6168
6286
  }
6169
- if (ts22.isEnumMember(declaration)) {
6287
+ if (ts23.isEnumMember(declaration)) {
6170
6288
  return constant(this.checker.getConstantValue(declaration));
6171
6289
  }
6172
6290
  throw new SpecializeError(node, `${node.text} is not available in scan code.`);
@@ -6183,11 +6301,11 @@ class ExpressionSpecializer {
6183
6301
  }
6184
6302
  if (captured.kind === "instance") {
6185
6303
  const declaration = this.model.classOf(node);
6186
- const accessor = declaration.members.find((member) => ts22.isGetAccessorDeclaration(member) && member.name.getText() === name);
6304
+ const accessor = declaration.members.find((member) => ts23.isGetAccessorDeclaration(member) && member.name.getText() === name);
6187
6305
  if (accessor) {
6188
6306
  return this.invoke({ kind: "function", declaration: accessor, self: node }, [], at, frame);
6189
6307
  }
6190
- const method = declaration.members.find((member) => ts22.isMethodDeclaration(member) && member.name.getText() === name);
6308
+ const method = declaration.members.find((member) => ts23.isMethodDeclaration(member) && member.name.getText() === name);
6191
6309
  if (method) {
6192
6310
  return { kind: "function", declaration: method, self: node };
6193
6311
  }
@@ -6240,10 +6358,10 @@ class ExpressionSpecializer {
6240
6358
  return value;
6241
6359
  }
6242
6360
  const type = this.checker.getTypeAtLocation(at);
6243
- if (type.isUnion() && type.types.some((part) => part.flags & ts22.TypeFlags.Undefined)) {
6361
+ if (type.isUnion() && type.types.some((part) => part.flags & ts23.TypeFlags.Undefined)) {
6244
6362
  return value;
6245
6363
  }
6246
- if (type.flags & ts22.TypeFlags.Undefined) {
6364
+ if (type.flags & ts23.TypeFlags.Undefined) {
6247
6365
  return value;
6248
6366
  }
6249
6367
  return {
@@ -6313,16 +6431,17 @@ class ExpressionSpecializer {
6313
6431
  const text = this.storage.storedNode(node) ? this.storage.pathText(node) : this.table(node, at);
6314
6432
  return {
6315
6433
  kind: "code",
6316
- text: mapped`${text}[${this.dialect.code(index, undefined)}]`,
6434
+ text: mapped`${text}[${this.dialect.code(index, node.type && recordTypes(node.type)?.key)}]`,
6317
6435
  declared,
6318
6436
  place: true
6319
6437
  };
6320
6438
  }
6321
6439
  if (object.kind === "code") {
6322
6440
  const declared = object.declared && (this.model.elementType(object.declared) ?? recordTypes(object.declared)?.value);
6441
+ const key = object.declared && recordTypes(object.declared)?.key;
6323
6442
  return {
6324
6443
  kind: "code",
6325
- text: mapped`${object.text}[${this.dialect.code(index, undefined)}]`,
6444
+ text: mapped`${object.text}[${this.dialect.code(index, key)}]`,
6326
6445
  declared,
6327
6446
  place: object.place,
6328
6447
  iec: object.elementIec
@@ -6365,9 +6484,9 @@ class ExpressionSpecializer {
6365
6484
  objectLiteral(node, frame) {
6366
6485
  const fields = new Map;
6367
6486
  for (const property of node.properties) {
6368
- if (ts22.isPropertyAssignment(property)) {
6487
+ if (ts23.isPropertyAssignment(property)) {
6369
6488
  fields.set(property.name.getText(), this.expression(property.initializer, frame, this.checker.getContextualType(property.initializer)));
6370
- } else if (ts22.isShorthandPropertyAssignment(property)) {
6489
+ } else if (ts23.isShorthandPropertyAssignment(property)) {
6371
6490
  const symbol = this.checker.getShorthandAssignmentValueSymbol(property);
6372
6491
  const local = symbol && frame.env.get(symbol);
6373
6492
  fields.set(property.name.text, local ?? this.expression(property.name, frame));
@@ -6380,7 +6499,7 @@ class ExpressionSpecializer {
6380
6499
  unary(node, frame) {
6381
6500
  const operand = this.expression(node.operand, frame);
6382
6501
  switch (node.operator) {
6383
- case ts22.SyntaxKind.ExclamationToken:
6502
+ case ts23.SyntaxKind.ExclamationToken:
6384
6503
  if (operand.kind === "const") {
6385
6504
  return constant(!operand.value);
6386
6505
  }
@@ -6392,7 +6511,7 @@ class ExpressionSpecializer {
6392
6511
  text: mapped`!${this.dialect.condition(operand, node.operand)}`,
6393
6512
  declared: this.checker.getBooleanType()
6394
6513
  };
6395
- case ts22.SyntaxKind.MinusToken:
6514
+ case ts23.SyntaxKind.MinusToken:
6396
6515
  if (operand.kind === "const" && typeof operand.value === "number") {
6397
6516
  return constant(-operand.value);
6398
6517
  }
@@ -6401,17 +6520,17 @@ class ExpressionSpecializer {
6401
6520
  text: mapped`-${this.dialect.code(operand, undefined)}`,
6402
6521
  declared: this.checker.getTypeAtLocation(node)
6403
6522
  };
6404
- case ts22.SyntaxKind.PlusToken:
6523
+ case ts23.SyntaxKind.PlusToken:
6405
6524
  return operand;
6406
6525
  default:
6407
- throw new SpecializeError(node, `${ts22.tokenToString(node.operator)} is not supported.`);
6526
+ throw new SpecializeError(node, `${ts23.tokenToString(node.operator)} is not supported.`);
6408
6527
  }
6409
6528
  }
6410
6529
  binary(node, frame, expected) {
6411
6530
  const kind = node.operatorToken.kind;
6412
- if (kind === ts22.SyntaxKind.AmpersandAmpersandToken || kind === ts22.SyntaxKind.BarBarToken) {
6531
+ if (kind === ts23.SyntaxKind.AmpersandAmpersandToken || kind === ts23.SyntaxKind.BarBarToken) {
6413
6532
  const left = this.expression(node.left, frame);
6414
- const and = kind === ts22.SyntaxKind.AmpersandAmpersandToken;
6533
+ const and = kind === ts23.SyntaxKind.AmpersandAmpersandToken;
6415
6534
  if (left.kind === "const") {
6416
6535
  if (Boolean(left.value) !== and) {
6417
6536
  return left;
@@ -6438,7 +6557,7 @@ class ExpressionSpecializer {
6438
6557
  declared: this.checker.getBooleanType()
6439
6558
  };
6440
6559
  }
6441
- if (kind === ts22.SyntaxKind.QuestionQuestionToken) {
6560
+ if (kind === ts23.SyntaxKind.QuestionQuestionToken) {
6442
6561
  const left = this.expression(node.left, frame);
6443
6562
  if (left.kind === "const") {
6444
6563
  return left.value === undefined ? this.expression(node.right, frame, expected) : left;
@@ -6458,14 +6577,14 @@ class ExpressionSpecializer {
6458
6577
  throw new SpecializeError(node, "Assign in a statement of its own.");
6459
6578
  }
6460
6579
  const equality = [
6461
- ts22.SyntaxKind.EqualsEqualsEqualsToken,
6462
- ts22.SyntaxKind.ExclamationEqualsEqualsToken,
6463
- ts22.SyntaxKind.EqualsEqualsToken,
6464
- ts22.SyntaxKind.ExclamationEqualsToken
6580
+ ts23.SyntaxKind.EqualsEqualsEqualsToken,
6581
+ ts23.SyntaxKind.ExclamationEqualsEqualsToken,
6582
+ ts23.SyntaxKind.EqualsEqualsToken,
6583
+ ts23.SyntaxKind.ExclamationEqualsToken
6465
6584
  ].includes(kind);
6466
6585
  const left = this.expression(node.left, frame);
6467
6586
  const right = this.expression(node.right, frame, left.kind === "code" ? left.declared : undefined);
6468
- const negate = kind === ts22.SyntaxKind.ExclamationEqualsEqualsToken || kind === ts22.SyntaxKind.ExclamationEqualsToken;
6587
+ const negate = kind === ts23.SyntaxKind.ExclamationEqualsEqualsToken || kind === ts23.SyntaxKind.ExclamationEqualsToken;
6469
6588
  if (equality) {
6470
6589
  const folded = this.equal(left, right);
6471
6590
  if (folded !== undefined) {
@@ -6527,7 +6646,7 @@ class ExpressionSpecializer {
6527
6646
  throw new SpecializeError(at, "Only functions can be called.");
6528
6647
  }
6529
6648
  const declaration = target.declaration;
6530
- if ((ts22.isArrowFunction(declaration) || ts22.isFunctionExpression(declaration)) && target.env && ts22.isArrowFunction(declaration) && !ts22.isBlock(declaration.body)) {
6649
+ if ((ts23.isArrowFunction(declaration) || ts23.isFunctionExpression(declaration)) && target.env && ts23.isArrowFunction(declaration) && !ts23.isBlock(declaration.body)) {
6531
6650
  const inline = {
6532
6651
  ...frame,
6533
6652
  env: new Map(target.env),
@@ -6543,8 +6662,8 @@ class ExpressionSpecializer {
6543
6662
  const called = this.routineTable.routine(declaration, target.self, args, target.env);
6544
6663
  const text = mapped`${called.name}(${joined(called.args, ", ")})`;
6545
6664
  const returns = called.returns;
6546
- if (!returns || returns.flags & ts22.TypeFlags.Void) {
6547
- if (ts22.isExpressionStatement(at.parent)) {
6665
+ if (!returns || returns.flags & ts23.TypeFlags.Void) {
6666
+ if (ts23.isExpressionStatement(at.parent)) {
6548
6667
  return { kind: "code", text, declared: returns };
6549
6668
  }
6550
6669
  frame.emitter.line(mapped`${text};`);
@@ -6562,8 +6681,8 @@ class ExpressionSpecializer {
6562
6681
  return { kind: "code", text: local, declared: value.declared, place: true };
6563
6682
  }
6564
6683
  bind(name, value, mutable, frame, declared) {
6565
- const bound = !ts22.isIdentifier(name) && value.kind === "code" && !value.place ? this.temporaryOf(value, frame) : value;
6566
- if (ts22.isObjectBindingPattern(name)) {
6684
+ const bound = !ts23.isIdentifier(name) && value.kind === "code" && !value.place ? this.temporaryOf(value, frame) : value;
6685
+ if (ts23.isObjectBindingPattern(name)) {
6567
6686
  for (const element of name.elements) {
6568
6687
  const field = (element.propertyName ?? element.name).getText();
6569
6688
  const inner = this.member(bound, field, element, frame);
@@ -6571,9 +6690,9 @@ class ExpressionSpecializer {
6571
6690
  }
6572
6691
  return;
6573
6692
  }
6574
- if (ts22.isArrayBindingPattern(name)) {
6693
+ if (ts23.isArrayBindingPattern(name)) {
6575
6694
  name.elements.forEach((element, index) => {
6576
- if (ts22.isOmittedExpression(element)) {
6695
+ if (ts23.isOmittedExpression(element)) {
6577
6696
  return;
6578
6697
  }
6579
6698
  const inner = this.element(bound, constant(index), element, frame);
@@ -6610,7 +6729,7 @@ class ExpressionSpecializer {
6610
6729
  return this.layouts.text(this.checker.getBaseTypeOfLiteralType(declared));
6611
6730
  }
6612
6731
  isAggregate(type) {
6613
- return Boolean(type.flags & ts22.TypeFlags.Object) && !this.layouts.literalEnum(type);
6732
+ return Boolean(type.flags & ts23.TypeFlags.Object) && !this.layouts.literalEnum(type);
6614
6733
  }
6615
6734
  items(value) {
6616
6735
  if (value.kind === "virtual" && value.items) {
@@ -6628,37 +6747,37 @@ class ExpressionSpecializer {
6628
6747
  }
6629
6748
  }
6630
6749
  var binaryOperators = new Map([
6631
- [ts22.SyntaxKind.PlusToken, "+"],
6632
- [ts22.SyntaxKind.MinusToken, "-"],
6633
- [ts22.SyntaxKind.AsteriskToken, "*"],
6634
- [ts22.SyntaxKind.PercentToken, "%"],
6635
- [ts22.SyntaxKind.LessThanToken, "<"],
6636
- [ts22.SyntaxKind.LessThanEqualsToken, "<="],
6637
- [ts22.SyntaxKind.GreaterThanToken, ">"],
6638
- [ts22.SyntaxKind.GreaterThanEqualsToken, ">="],
6639
- [ts22.SyntaxKind.AmpersandToken, "&"],
6640
- [ts22.SyntaxKind.BarToken, "|"],
6641
- [ts22.SyntaxKind.CaretToken, "^"],
6642
- [ts22.SyntaxKind.LessThanLessThanToken, "<<"],
6643
- [ts22.SyntaxKind.GreaterThanGreaterThanToken, ">>"]
6750
+ [ts23.SyntaxKind.PlusToken, "+"],
6751
+ [ts23.SyntaxKind.MinusToken, "-"],
6752
+ [ts23.SyntaxKind.AsteriskToken, "*"],
6753
+ [ts23.SyntaxKind.PercentToken, "%"],
6754
+ [ts23.SyntaxKind.LessThanToken, "<"],
6755
+ [ts23.SyntaxKind.LessThanEqualsToken, "<="],
6756
+ [ts23.SyntaxKind.GreaterThanToken, ">"],
6757
+ [ts23.SyntaxKind.GreaterThanEqualsToken, ">="],
6758
+ [ts23.SyntaxKind.AmpersandToken, "&"],
6759
+ [ts23.SyntaxKind.BarToken, "|"],
6760
+ [ts23.SyntaxKind.CaretToken, "^"],
6761
+ [ts23.SyntaxKind.LessThanLessThanToken, "<<"],
6762
+ [ts23.SyntaxKind.GreaterThanGreaterThanToken, ">>"]
6644
6763
  ]);
6645
6764
  var foldNumber = (kind, left, right) => {
6646
6765
  switch (kind) {
6647
- case ts22.SyntaxKind.PlusToken:
6766
+ case ts23.SyntaxKind.PlusToken:
6648
6767
  return left + right;
6649
- case ts22.SyntaxKind.MinusToken:
6768
+ case ts23.SyntaxKind.MinusToken:
6650
6769
  return left - right;
6651
- case ts22.SyntaxKind.AsteriskToken:
6770
+ case ts23.SyntaxKind.AsteriskToken:
6652
6771
  return left * right;
6653
- case ts22.SyntaxKind.PercentToken:
6772
+ case ts23.SyntaxKind.PercentToken:
6654
6773
  return right === 0 ? undefined : left % right;
6655
- case ts22.SyntaxKind.LessThanToken:
6774
+ case ts23.SyntaxKind.LessThanToken:
6656
6775
  return left < right;
6657
- case ts22.SyntaxKind.LessThanEqualsToken:
6776
+ case ts23.SyntaxKind.LessThanEqualsToken:
6658
6777
  return left <= right;
6659
- case ts22.SyntaxKind.GreaterThanToken:
6778
+ case ts23.SyntaxKind.GreaterThanToken:
6660
6779
  return left > right;
6661
- case ts22.SyntaxKind.GreaterThanEqualsToken:
6780
+ case ts23.SyntaxKind.GreaterThanEqualsToken:
6662
6781
  return left >= right;
6663
6782
  default:
6664
6783
  return;
@@ -6702,7 +6821,7 @@ class Emitter {
6702
6821
  }
6703
6822
 
6704
6823
  // packages/compiler/src/frontend/elaborate/initializers.ts
6705
- import ts23 from "typescript";
6824
+ import ts24 from "typescript";
6706
6825
  class Initializers {
6707
6826
  model;
6708
6827
  checker;
@@ -6831,13 +6950,13 @@ class Initializers {
6831
6950
  }
6832
6951
  }
6833
6952
  defaultOf(type) {
6834
- if (!type || type.flags & ts23.TypeFlags.Void) {
6953
+ if (!type || type.flags & ts24.TypeFlags.Void) {
6835
6954
  return "";
6836
6955
  }
6837
- if (type.flags & ts23.TypeFlags.BooleanLike) {
6956
+ if (type.flags & ts24.TypeFlags.BooleanLike) {
6838
6957
  return "false";
6839
6958
  }
6840
- if (type.flags & ts23.TypeFlags.NumberLike) {
6959
+ if (type.flags & ts24.TypeFlags.NumberLike) {
6841
6960
  return "0";
6842
6961
  }
6843
6962
  return `defaultValue<${this.layouts.text(type)}>()`;
@@ -6845,7 +6964,7 @@ class Initializers {
6845
6964
  }
6846
6965
 
6847
6966
  // packages/compiler/src/frontend/elaborate/statements.ts
6848
- import ts24 from "typescript";
6967
+ import ts25 from "typescript";
6849
6968
  class StatementSpecializer {
6850
6969
  expressions;
6851
6970
  checker;
@@ -6860,7 +6979,7 @@ class StatementSpecializer {
6860
6979
  this.initializers = context.initializers;
6861
6980
  }
6862
6981
  body(node, frame) {
6863
- if (ts24.isBlock(node)) {
6982
+ if (ts25.isBlock(node)) {
6864
6983
  this.statements(node.statements, frame);
6865
6984
  } else {
6866
6985
  frame.emitter.origin = node;
@@ -6884,57 +7003,57 @@ class StatementSpecializer {
6884
7003
  }
6885
7004
  specializeStatement(node, frame) {
6886
7005
  const { emitter } = frame;
6887
- if (ts24.isBlock(node)) {
7006
+ if (ts25.isBlock(node)) {
6888
7007
  emitter.open("{");
6889
7008
  const returns = this.statements(node.statements, frame);
6890
7009
  emitter.close();
6891
7010
  return returns;
6892
7011
  }
6893
- if (ts24.isVariableStatement(node)) {
6894
- const mutable = !(node.declarationList.flags & ts24.NodeFlags.Const);
7012
+ if (ts25.isVariableStatement(node)) {
7013
+ const mutable = !(node.declarationList.flags & ts25.NodeFlags.Const);
6895
7014
  for (const declaration of node.declarationList.declarations) {
6896
7015
  this.declare(declaration, mutable, frame);
6897
7016
  }
6898
7017
  return false;
6899
7018
  }
6900
- if (ts24.isExpressionStatement(node)) {
7019
+ if (ts25.isExpressionStatement(node)) {
6901
7020
  this.effect(node.expression, frame);
6902
7021
  return false;
6903
7022
  }
6904
- if (ts24.isIfStatement(node)) {
7023
+ if (ts25.isIfStatement(node)) {
6905
7024
  return this.ifStatement(node, frame);
6906
7025
  }
6907
- if (ts24.isReturnStatement(node)) {
7026
+ if (ts25.isReturnStatement(node)) {
6908
7027
  this.returnStatement(node, frame);
6909
7028
  return true;
6910
7029
  }
6911
- if (ts24.isForOfStatement(node)) {
7030
+ if (ts25.isForOfStatement(node)) {
6912
7031
  this.forOf(node, frame);
6913
7032
  return false;
6914
7033
  }
6915
- if (ts24.isSwitchStatement(node)) {
7034
+ if (ts25.isSwitchStatement(node)) {
6916
7035
  this.switch(node, frame);
6917
7036
  return false;
6918
7037
  }
6919
- if (ts24.isForStatement(node)) {
7038
+ if (ts25.isForStatement(node)) {
6920
7039
  this.forLoop(node, frame);
6921
7040
  return false;
6922
7041
  }
6923
- if (ts24.isWhileStatement(node)) {
7042
+ if (ts25.isWhileStatement(node)) {
6924
7043
  throw new SpecializeError(node, "Use a counted for loop or for…of; while loops have no bound to prove.");
6925
7044
  }
6926
- if (ts24.isTryStatement(node)) {
7045
+ if (ts25.isTryStatement(node)) {
6927
7046
  this.tryStatement(node, frame);
6928
7047
  return false;
6929
7048
  }
6930
- if (ts24.isBreakStatement(node) || ts24.isContinueStatement(node)) {
7049
+ if (ts25.isBreakStatement(node) || ts25.isContinueStatement(node)) {
6931
7050
  emitter.line(copied(node));
6932
7051
  return false;
6933
7052
  }
6934
- if (ts24.isEmptyStatement(node)) {
7053
+ if (ts25.isEmptyStatement(node)) {
6935
7054
  return false;
6936
7055
  }
6937
- throw new SpecializeError(node, `${ts24.SyntaxKind[node.kind]} is not supported in scan code.`);
7056
+ throw new SpecializeError(node, `${ts25.SyntaxKind[node.kind]} is not supported in scan code.`);
6938
7057
  }
6939
7058
  ifStatement(node, frame) {
6940
7059
  const condition = this.expressions.expression(node.expression, frame);
@@ -6960,7 +7079,7 @@ class StatementSpecializer {
6960
7079
  frame.emitter.line("return;");
6961
7080
  return;
6962
7081
  }
6963
- if (ts24.isSatisfiesExpression(node.expression) && this.isNever(node.expression.type)) {
7082
+ if (ts25.isSatisfiesExpression(node.expression) && this.isNever(node.expression.type)) {
6964
7083
  frame.emitter.line(`return ${this.initializers.defaultOf(frame.returns)};`);
6965
7084
  return;
6966
7085
  }
@@ -6975,7 +7094,7 @@ class StatementSpecializer {
6975
7094
  if (node.catchClause) {
6976
7095
  const binding = node.catchClause.variableDeclaration?.name;
6977
7096
  frame.emitter.reopen(`} catch${binding ? ` (${binding.getText()})` : ""} {`);
6978
- if (binding && ts24.isIdentifier(binding)) {
7097
+ if (binding && ts25.isIdentifier(binding)) {
6979
7098
  frame.env.set(this.checker.getSymbolAtLocation(binding), {
6980
7099
  kind: "code",
6981
7100
  text: binding.text,
@@ -6990,10 +7109,10 @@ class StatementSpecializer {
6990
7109
  frame.emitter.close();
6991
7110
  }
6992
7111
  inner(node, frame) {
6993
- return ts24.isBlock(node) ? this.statements(node.statements, frame) : this.statement(node, frame);
7112
+ return ts25.isBlock(node) ? this.statements(node.statements, frame) : this.statement(node, frame);
6994
7113
  }
6995
7114
  isNever(type) {
6996
- return type.kind === ts24.SyntaxKind.NeverKeyword;
7115
+ return type.kind === ts25.SyntaxKind.NeverKeyword;
6997
7116
  }
6998
7117
  declare(declaration, mutable, frame) {
6999
7118
  const initializer = declaration.initializer;
@@ -7005,7 +7124,7 @@ class StatementSpecializer {
7005
7124
  }
7006
7125
  forOf(node, frame) {
7007
7126
  const call = node.expression;
7008
- if (ts24.isCallExpression(call) && ts24.isPropertyAccessExpression(call.expression) && call.expression.name.text === "entries" && !call.arguments.length) {
7127
+ if (ts25.isCallExpression(call) && ts25.isPropertyAccessExpression(call.expression) && call.expression.name.text === "entries" && !call.arguments.length) {
7009
7128
  const array = this.expressions.expression(call.expression.expression, frame);
7010
7129
  if (array.kind === "code") {
7011
7130
  this.forEntries(node, array.text, frame);
@@ -7032,7 +7151,7 @@ class StatementSpecializer {
7032
7151
  if (iterable.kind !== "code") {
7033
7152
  throw new SpecializeError(node.expression, "for…of needs an array.");
7034
7153
  }
7035
- if (!ts24.isIdentifier(name)) {
7154
+ if (!ts25.isIdentifier(name)) {
7036
7155
  throw new SpecializeError(name, "Destructure a runtime element inside the loop.");
7037
7156
  }
7038
7157
  const local = frame.emitter.local(name.text);
@@ -7048,7 +7167,7 @@ class StatementSpecializer {
7048
7167
  }
7049
7168
  forEntries(node, array, frame) {
7050
7169
  const binding = onlyDeclaration(node.initializer)?.name;
7051
- const names = binding && ts24.isArrayBindingPattern(binding) ? binding.elements.map((element) => ts24.isBindingElement(element) && ts24.isIdentifier(element.name) ? element.name : undefined) : [];
7170
+ const names = binding && ts25.isArrayBindingPattern(binding) ? binding.elements.map((element) => ts25.isBindingElement(element) && ts25.isIdentifier(element.name) ? element.name : undefined) : [];
7052
7171
  const [indexName, itemName] = names;
7053
7172
  if (names.length !== 2 || !indexName || !itemName) {
7054
7173
  throw new SpecializeError(node.initializer, "Destructure [index, item] from array.entries().");
@@ -7070,14 +7189,14 @@ class StatementSpecializer {
7070
7189
  forLoop(node, frame) {
7071
7190
  const { condition, incrementor, initializer } = node;
7072
7191
  const declaration = onlyDeclaration(initializer);
7073
- if (!declaration || !(declaration.parent.flags & ts24.NodeFlags.Let)) {
7192
+ if (!declaration || !(declaration.parent.flags & ts25.NodeFlags.Let)) {
7074
7193
  throw new SpecializeError(node, "Declare one let counter in the for header.");
7075
7194
  }
7076
7195
  const name = declaration.name;
7077
- if (!ts24.isIdentifier(name) || !declaration.initializer) {
7196
+ if (!ts25.isIdentifier(name) || !declaration.initializer) {
7078
7197
  throw new SpecializeError(declaration, "Initialize the loop counter.");
7079
7198
  }
7080
- if (!condition || !ts24.isBinaryExpression(condition) || !incrementor) {
7199
+ if (!condition || !ts25.isBinaryExpression(condition) || !incrementor) {
7081
7200
  throw new SpecializeError(node, "Compare the counter to a bound and step it in the for header.");
7082
7201
  }
7083
7202
  const declared = this.checker.getTypeAtLocation(name);
@@ -7098,10 +7217,10 @@ class StatementSpecializer {
7098
7217
  frame.emitter.close();
7099
7218
  }
7100
7219
  loopStep(incrementor, local, declared, frame) {
7101
- if (ts24.isPrefixUnaryExpression(incrementor) || ts24.isPostfixUnaryExpression(incrementor)) {
7102
- return `${local}${ts24.tokenToString(incrementor.operator)}`;
7220
+ if (ts25.isPrefixUnaryExpression(incrementor) || ts25.isPostfixUnaryExpression(incrementor)) {
7221
+ return `${local}${ts25.tokenToString(incrementor.operator)}`;
7103
7222
  }
7104
- if (ts24.isBinaryExpression(incrementor)) {
7223
+ if (ts25.isBinaryExpression(incrementor)) {
7105
7224
  return mapped`${local} ${incrementor.operatorToken.getText()} ${this.dialect.code(this.expressions.expression(incrementor.right, frame), declared)}`;
7106
7225
  }
7107
7226
  throw new SpecializeError(incrementor, "Use i++, i--, i += step or i -= step in the for header.");
@@ -7115,11 +7234,11 @@ class StatementSpecializer {
7115
7234
  }
7116
7235
  frame.emitter.open(mapped`switch (${this.dialect.code(subject, declared)}) {`);
7117
7236
  for (const clause of node.caseBlock.clauses) {
7118
- if (ts24.isDefaultClause(clause)) {
7119
- const unreachable = clause.statements.some((statement) => ts24.isReturnStatement(statement) && statement.expression && ts24.isSatisfiesExpression(statement.expression) && this.isNever(statement.expression.type));
7237
+ if (ts25.isDefaultClause(clause)) {
7238
+ const unreachable = clause.statements.some((statement) => ts25.isReturnStatement(statement) && statement.expression && ts25.isSatisfiesExpression(statement.expression) && this.isNever(statement.expression.type));
7120
7239
  frame.emitter.open("default: {");
7121
7240
  if (unreachable) {
7122
- frame.emitter.line(frame.returns && !(frame.returns.flags & ts24.TypeFlags.Void) ? `return ${this.initializers.defaultOf(frame.returns)};` : "break;");
7241
+ frame.emitter.line(frame.returns && !(frame.returns.flags & ts25.TypeFlags.Void) ? `return ${this.initializers.defaultOf(frame.returns)};` : "break;");
7123
7242
  } else {
7124
7243
  for (const statement of clause.statements) {
7125
7244
  this.statement(statement, frame);
@@ -7140,7 +7259,7 @@ class StatementSpecializer {
7140
7259
  constantSwitch(node, subject, frame) {
7141
7260
  const clauses = node.caseBlock.clauses;
7142
7261
  const start = clauses.findIndex((clause) => {
7143
- if (ts24.isDefaultClause(clause)) {
7262
+ if (ts25.isDefaultClause(clause)) {
7144
7263
  return true;
7145
7264
  }
7146
7265
  const label = this.expressions.expression(clause.expression, frame);
@@ -7151,32 +7270,32 @@ class StatementSpecializer {
7151
7270
  }
7152
7271
  for (const clause of clauses.slice(start)) {
7153
7272
  for (const statement of clause.statements) {
7154
- if (ts24.isBreakStatement(statement)) {
7273
+ if (ts25.isBreakStatement(statement)) {
7155
7274
  return;
7156
7275
  }
7157
7276
  this.statement(statement, frame);
7158
7277
  }
7159
- if (clause.statements.some((statement) => ts24.isReturnStatement(statement))) {
7278
+ if (clause.statements.some((statement) => ts25.isReturnStatement(statement))) {
7160
7279
  return;
7161
7280
  }
7162
7281
  }
7163
7282
  }
7164
7283
  effect(node, frame) {
7165
- if (ts24.isVoidExpression(node)) {
7284
+ if (ts25.isVoidExpression(node)) {
7166
7285
  const value = this.expressions.expression(node.expression, frame);
7167
7286
  if (value.kind === "code") {
7168
7287
  frame.emitter.line(mapped`void ${value.text};`);
7169
7288
  }
7170
7289
  return;
7171
7290
  }
7172
- if (ts24.isBinaryExpression(node) && isAssignment(node.operatorToken.kind)) {
7291
+ if (ts25.isBinaryExpression(node) && isAssignment(node.operatorToken.kind)) {
7173
7292
  this.assign(node, frame);
7174
7293
  return;
7175
7294
  }
7176
7295
  if (isUpdate(node)) {
7177
7296
  const target = this.expressions.expression(node.operand, frame);
7178
7297
  const text = this.placeText(target, node.operand);
7179
- frame.emitter.line(this.store(target, mapped`${text} ${node.operator === ts24.SyntaxKind.PlusPlusToken ? "+" : "-"} 1`));
7298
+ frame.emitter.line(this.store(target, mapped`${text} ${node.operator === ts25.SyntaxKind.PlusPlusToken ? "+" : "-"} 1`));
7180
7299
  return;
7181
7300
  }
7182
7301
  const value = this.expressions.expression(node, frame);
@@ -7189,7 +7308,7 @@ class StatementSpecializer {
7189
7308
  const text = this.placeText(target, node.left);
7190
7309
  const declared = target.kind === "code" ? target.declared : undefined;
7191
7310
  const operator = node.operatorToken.kind;
7192
- if (operator === ts24.SyntaxKind.QuestionQuestionEqualsToken) {
7311
+ if (operator === ts25.SyntaxKind.QuestionQuestionEqualsToken) {
7193
7312
  const value = this.expressions.expression(node.right, frame, declared && this.checker.getNonNullableType(declared));
7194
7313
  frame.emitter.open(mapped`if (${this.dialect.isUndefinedText(text, declared)}) {`);
7195
7314
  frame.emitter.line(this.store(target, this.dialect.wrapDefined(this.dialect.code(value, declared && this.checker.getNonNullableType(declared)), declared)));
@@ -7197,7 +7316,7 @@ class StatementSpecializer {
7197
7316
  return;
7198
7317
  }
7199
7318
  const value = this.expressions.expression(node.right, frame, declared);
7200
- if (operator === ts24.SyntaxKind.EqualsToken) {
7319
+ if (operator === ts25.SyntaxKind.EqualsToken) {
7201
7320
  frame.emitter.line(this.store(target, this.dialect.assignmentText(value, declared, target.kind === "code" ? target.iec : undefined)));
7202
7321
  return;
7203
7322
  }
@@ -7221,14 +7340,14 @@ class StatementSpecializer {
7221
7340
  }
7222
7341
  }
7223
7342
  var compoundOperators = new Map([
7224
- [ts24.SyntaxKind.PlusEqualsToken, "+"],
7225
- [ts24.SyntaxKind.MinusEqualsToken, "-"],
7226
- [ts24.SyntaxKind.AsteriskEqualsToken, "*"],
7227
- [ts24.SyntaxKind.BarEqualsToken, "|"],
7228
- [ts24.SyntaxKind.AmpersandEqualsToken, "&"]
7343
+ [ts25.SyntaxKind.PlusEqualsToken, "+"],
7344
+ [ts25.SyntaxKind.MinusEqualsToken, "-"],
7345
+ [ts25.SyntaxKind.AsteriskEqualsToken, "*"],
7346
+ [ts25.SyntaxKind.BarEqualsToken, "|"],
7347
+ [ts25.SyntaxKind.AmpersandEqualsToken, "&"]
7229
7348
  ]);
7230
7349
  var onlyDeclaration = (initializer) => {
7231
- if (!initializer || !ts24.isVariableDeclarationList(initializer)) {
7350
+ if (!initializer || !ts25.isVariableDeclarationList(initializer)) {
7232
7351
  return;
7233
7352
  }
7234
7353
  const [declaration, ...others] = initializer.declarations;
@@ -7236,7 +7355,7 @@ var onlyDeclaration = (initializer) => {
7236
7355
  };
7237
7356
 
7238
7357
  // packages/compiler/src/frontend/elaborate/storage.ts
7239
- import ts25 from "typescript";
7358
+ import ts26 from "typescript";
7240
7359
  class Storage {
7241
7360
  model;
7242
7361
  checker;
@@ -7441,8 +7560,8 @@ class Storage {
7441
7560
  }
7442
7561
  return { kind: "static", node };
7443
7562
  }
7444
- if (this.kept(root.file) || root.declaration.parent.flags & ts25.NodeFlags.Const) {
7445
- return primitive(value);
7563
+ if (this.kept(root.file) || root.declaration.parent.flags & ts26.NodeFlags.Const) {
7564
+ return primitive2(value);
7446
7565
  }
7447
7566
  const namespace = this.namespace(root);
7448
7567
  this.storedRoots.add(root);
@@ -7461,7 +7580,7 @@ class Storage {
7461
7580
  kind: "code",
7462
7581
  text: root.name,
7463
7582
  declared: this.checker.getTypeAtLocation(root.declaration.name),
7464
- place: !(root.declaration.parent.flags & ts25.NodeFlags.Const)
7583
+ place: !(root.declaration.parent.flags & ts26.NodeFlags.Const)
7465
7584
  };
7466
7585
  }
7467
7586
  fromCaptured(value, holder, step) {
@@ -7482,7 +7601,7 @@ class Storage {
7482
7601
  steps: [...holder.owner.steps, step]
7483
7602
  }));
7484
7603
  }
7485
- return primitive(value);
7604
+ return primitive2(value);
7486
7605
  }
7487
7606
  fieldDeclaration(holder, name) {
7488
7607
  return holder.captured.kind === "instance" ? this.model.member(this.model.classOf(holder), name) : this.fieldSymbol(holder, name)?.valueDeclaration;
@@ -7564,7 +7683,7 @@ class Storage {
7564
7683
  return node.captured.kind === "array" ? this.storedArray(node) : this.storedWhole(node);
7565
7684
  }
7566
7685
  }
7567
- var primitive = (value) => {
7686
+ var primitive2 = (value) => {
7568
7687
  switch (value.kind) {
7569
7688
  case "undefined":
7570
7689
  return constant(undefined);
@@ -7648,7 +7767,7 @@ class Specializer {
7648
7767
  routine(declaration, self, args, closure) {
7649
7768
  const signature = this.checker.getSignatureFromDeclaration(declaration);
7650
7769
  const returnType = signature && this.checker.getReturnTypeOfSignature(signature);
7651
- const isAsync = Boolean(ts26.canHaveModifiers(declaration) && ts26.getModifiers(declaration)?.some((modifier) => modifier.kind === ts26.SyntaxKind.AsyncKeyword));
7770
+ const isAsync = Boolean(ts27.canHaveModifiers(declaration) && ts27.getModifiers(declaration)?.some((modifier) => modifier.kind === ts27.SyntaxKind.AsyncKeyword));
7652
7771
  const frame = {
7653
7772
  emitter: new Emitter(declaration),
7654
7773
  env: new Map(closure),
@@ -7659,7 +7778,7 @@ class Specializer {
7659
7778
  const parameters = [];
7660
7779
  const runtimeArgs = [];
7661
7780
  const keys = [];
7662
- const parameterList = ts26.isGetAccessorDeclaration(declaration) ? [] : declaration.parameters;
7781
+ const parameterList = ts27.isGetAccessorDeclaration(declaration) ? [] : declaration.parameters;
7663
7782
  parameterList.forEach((parameter, index) => {
7664
7783
  const arg = args[index] ?? constant(undefined);
7665
7784
  const declared = this.checker.getTypeAtLocation(parameter);
@@ -7687,17 +7806,17 @@ class Specializer {
7687
7806
  }
7688
7807
  const name = this.routineName(declaration, self);
7689
7808
  this.specialized.set(key, name);
7690
- if (ts26.isArrowFunction(declaration) && !ts26.isBlock(declaration.body)) {
7809
+ if (ts27.isArrowFunction(declaration) && !ts27.isBlock(declaration.body)) {
7691
7810
  frame.emitter.origin = declaration.body;
7692
7811
  const result = this.expressions.expression(declaration.body, frame, frame.returns);
7693
7812
  frame.emitter.line(mapped`return ${this.dialect.code(result, frame.returns)};`);
7694
7813
  } else {
7695
7814
  this.statements.body(declaration.body, frame);
7696
7815
  }
7697
- const resultText = frame.returns && !(frame.returns.flags & ts26.TypeFlags.Void) ? this.layouts.text(frame.returns) : "void";
7816
+ const resultText = frame.returns && !(frame.returns.flags & ts27.TypeFlags.Void) ? this.layouts.text(frame.returns) : "void";
7698
7817
  const head = `${frame.async ? "async " : ""}function ${name}(${parameters.join(", ")}): ${frame.async ? `Promise<${resultText}>` : resultText} {`;
7699
7818
  const instance = self?.owner && tsPath(self.owner);
7700
- if (self?.captured.kind === "instance" && (ts26.isMethodDeclaration(declaration) || ts26.isGetAccessorDeclaration(declaration))) {
7819
+ if (self?.captured.kind === "instance" && (ts27.isMethodDeclaration(declaration) || ts27.isGetAccessorDeclaration(declaration))) {
7701
7820
  this.origins.set(name, {
7702
7821
  name: `${self.captured.name}.${declaration.name.getText()}`,
7703
7822
  ...instance && { instance }
@@ -7712,8 +7831,8 @@ class Specializer {
7712
7831
  return { name, args: runtimeArgs, returns: frame.returns };
7713
7832
  }
7714
7833
  routineName(declaration, self) {
7715
- const own = declaration.name && ts26.isIdentifier(declaration.name) ? declaration.name.text : undefined;
7716
- const variable = !own && declaration.parent && ts26.isVariableDeclaration(declaration.parent) && ts26.isIdentifier(declaration.parent.name) ? declaration.parent.name.text : undefined;
7834
+ const own = declaration.name && ts27.isIdentifier(declaration.name) ? declaration.name.text : undefined;
7835
+ const variable = !own && declaration.parent && ts27.isVariableDeclaration(declaration.parent) && ts27.isIdentifier(declaration.parent.name) ? declaration.parent.name.text : undefined;
7717
7836
  const owner = self?.captured.kind === "instance" ? self.captured.name : undefined;
7718
7837
  const base = [owner, own ?? variable ?? "callback"].filter(Boolean).join("_");
7719
7838
  const name = unusedName(base, (candidate) => this.routineNames.has(candidate));
@@ -7721,7 +7840,7 @@ class Specializer {
7721
7840
  return name;
7722
7841
  }
7723
7842
  bindParameter(name, arg, declared, frame, parameters, runtimeArgs, keys) {
7724
- if (ts26.isObjectBindingPattern(name)) {
7843
+ if (ts27.isObjectBindingPattern(name)) {
7725
7844
  for (const element of name.elements) {
7726
7845
  const field = (element.propertyName ?? element.name).getText();
7727
7846
  const inner = this.expressions.member(arg, field, element, frame);
@@ -7729,7 +7848,7 @@ class Specializer {
7729
7848
  }
7730
7849
  return;
7731
7850
  }
7732
- if (ts26.isArrayBindingPattern(name)) {
7851
+ if (ts27.isArrayBindingPattern(name)) {
7733
7852
  throw new SpecializeError(name, "Array patterns are not supported in parameters.");
7734
7853
  }
7735
7854
  const symbol = this.checker.getSymbolAtLocation(name);
@@ -7749,7 +7868,7 @@ class Specializer {
7749
7868
  keys.push(`${name.text}=code${layout ? `:${layout}` : ""}`);
7750
7869
  return;
7751
7870
  }
7752
- if (arg.kind === "const" && !(declared.flags & ts26.TypeFlags.Undefined) && typeof arg.value !== "undefined") {
7871
+ if (arg.kind === "const" && !(declared.flags & ts27.TypeFlags.Undefined) && typeof arg.value !== "undefined") {
7753
7872
  const local = frame.emitter.local(name.text);
7754
7873
  parameters.push(`${local}: ${this.layouts.text(declared)}`);
7755
7874
  runtimeArgs.push(this.dialect.code(arg, declared));
@@ -7769,7 +7888,7 @@ class Specializer {
7769
7888
  return value.kind === "virtual" && [...value.fields?.values() ?? [], ...value.items ?? []].some((inner) => inner.kind === "static" || inner.kind === "function");
7770
7889
  }
7771
7890
  }
7772
- var closingBrace = (declaration) => declaration.body && ts26.isBlock(declaration.body) ? declaration.body.getLastToken() : declaration;
7891
+ var closingBrace = (declaration) => declaration.body && ts27.isBlock(declaration.body) ? declaration.body.getLastToken() : declaration;
7773
7892
  var declarationKey = (declaration) => `${declaration.getSourceFile().fileName}:${declaration.pos}`;
7774
7893
  var valueKey = (value) => {
7775
7894
  switch (value.kind) {
@@ -7788,42 +7907,42 @@ var valueKey = (value) => {
7788
7907
 
7789
7908
  // packages/compiler/src/frontend/elaborate/index.ts
7790
7909
  var keptModule = (source, checker, sdk) => source.statements.every((statement) => {
7791
- if (ts27.isImportDeclaration(statement) || ts27.isExportDeclaration(statement) || ts27.isInterfaceDeclaration(statement) || ts27.isTypeAliasDeclaration(statement) || ts27.isEnumDeclaration(statement)) {
7910
+ if (ts28.isImportDeclaration(statement) || ts28.isExportDeclaration(statement) || ts28.isInterfaceDeclaration(statement) || ts28.isTypeAliasDeclaration(statement) || ts28.isEnumDeclaration(statement)) {
7792
7911
  return true;
7793
7912
  }
7794
- if (!ts27.isVariableStatement(statement)) {
7913
+ if (!ts28.isVariableStatement(statement)) {
7795
7914
  return false;
7796
7915
  }
7797
7916
  return statement.declarationList.declarations.every((declaration) => declaration.initializer && constantInitializer(declaration.initializer, checker, sdk));
7798
7917
  });
7799
7918
  var constantInitializer = (node, checker, sdk) => {
7800
- if (ts27.isNumericLiteral(node) || ts27.isStringLiteral(node) || ts27.isNoSubstitutionTemplateLiteral(node) || ts27.isBigIntLiteral(node) || node.kind === ts27.SyntaxKind.TrueKeyword || node.kind === ts27.SyntaxKind.FalseKeyword) {
7919
+ if (ts28.isNumericLiteral(node) || ts28.isStringLiteral(node) || ts28.isNoSubstitutionTemplateLiteral(node) || ts28.isBigIntLiteral(node) || node.kind === ts28.SyntaxKind.TrueKeyword || node.kind === ts28.SyntaxKind.FalseKeyword) {
7801
7920
  return true;
7802
7921
  }
7803
- if (ts27.isPrefixUnaryExpression(node)) {
7922
+ if (ts28.isPrefixUnaryExpression(node)) {
7804
7923
  return constantInitializer(node.operand, checker, sdk);
7805
7924
  }
7806
- if (ts27.isAsExpression(node) || ts27.isSatisfiesExpression(node) || ts27.isParenthesizedExpression(node)) {
7925
+ if (ts28.isAsExpression(node) || ts28.isSatisfiesExpression(node) || ts28.isParenthesizedExpression(node)) {
7807
7926
  return constantInitializer(node.expression, checker, sdk);
7808
7927
  }
7809
- if (ts27.isPropertyAccessExpression(node)) {
7810
- return ts27.isIdentifier(node.expression);
7928
+ if (ts28.isPropertyAccessExpression(node)) {
7929
+ return ts28.isIdentifier(node.expression);
7811
7930
  }
7812
- if (ts27.isIdentifier(node)) {
7931
+ if (ts28.isIdentifier(node)) {
7813
7932
  return true;
7814
7933
  }
7815
- if (ts27.isObjectLiteralExpression(node)) {
7816
- return node.properties.every((property) => ts27.isPropertyAssignment(property) && constantInitializer(property.initializer, checker, sdk) || ts27.isShorthandPropertyAssignment(property));
7934
+ if (ts28.isObjectLiteralExpression(node)) {
7935
+ return node.properties.every((property) => ts28.isPropertyAssignment(property) && constantInitializer(property.initializer, checker, sdk) || ts28.isShorthandPropertyAssignment(property));
7817
7936
  }
7818
- if (ts27.isArrayLiteralExpression(node)) {
7937
+ if (ts28.isArrayLiteralExpression(node)) {
7819
7938
  return node.elements.every((element) => constantInitializer(element, checker, sdk));
7820
7939
  }
7821
- if (ts27.isCallExpression(node)) {
7940
+ if (ts28.isCallExpression(node)) {
7822
7941
  return namesSdk(checker, sdk, node.expression, "createServiceClient");
7823
7942
  }
7824
7943
  return false;
7825
7944
  };
7826
- var needsElaboration = (sources, kept, checker, sdk) => sources.some((source) => !kept(source.fileName) && source.statements.some((statement) => ts27.isClassDeclaration(statement) && !statement.heritageClauses?.some((clause) => clause.types.some((type) => namesSdk(checker, sdk, type.expression, "FunctionBlock")))));
7945
+ var needsElaboration = (sources, kept, checker, sdk) => sources.some((source) => !kept(source.fileName) && source.statements.some((statement) => ts28.isClassDeclaration(statement) && !statement.heritageClauses?.some((clause) => clause.types.some((type) => namesSdk(checker, sdk, type.expression, "FunctionBlock")))));
7827
7946
  var constant2 = (value, iec) => {
7828
7947
  switch (value.kind) {
7829
7948
  case "number":
@@ -7875,6 +7994,7 @@ var lowerElaboration = (program, sdk, entries, root, positions, debug) => {
7875
7994
  const directory = join2(dirname5(entryFile), generatedDirectory).replace(/\\/g, "/");
7876
7995
  const rootModule = (item) => `${directory}/${item.name}.ts`;
7877
7996
  try {
7997
+ const declarations = retainedDeclarations(runtime, checker, sdk);
7878
7998
  const graph = captureGraph(entryFile, runtime);
7879
7999
  const model = new Model(graph, checker, program, entryFile);
7880
8000
  const specializer = new Specializer(model, checker, sdk, runtime, isKept, rootModule);
@@ -7885,9 +8005,14 @@ var lowerElaboration = (program, sdk, entries, root, positions, debug) => {
7885
8005
  specializer.storage.use(item);
7886
8006
  }
7887
8007
  }
8008
+ const retention = new Retention(model, specializer.storage, declarations);
7888
8009
  const globals = new Map;
7889
8010
  for (const item of specializer.storage.roots) {
7890
- globals.set(item, storageGlobals(specializer, item));
8011
+ globals.set(item, storageGlobals(specializer, retention, item));
8012
+ }
8013
+ const [unretained] = retention.unclaimed();
8014
+ if (unretained) {
8015
+ throw unretained;
7891
8016
  }
7892
8017
  const typesFile = `${directory}/types.ts`;
7893
8018
  const typeImports = (file) => [
@@ -7955,12 +8080,18 @@ var lowerElaboration = (program, sdk, entries, root, positions, debug) => {
7955
8080
  }
7956
8081
  return result;
7957
8082
  };
7958
- var storageGlobals = (specializer, item) => {
8083
+ var storageGlobals = (specializer, retention, item) => {
7959
8084
  const { model, checker, layouts, storage, initializers } = specializer;
7960
8085
  const lines = [];
8086
+ const retained = [];
7961
8087
  const global = (name, layout, initial, declaration) => {
7962
8088
  const origin = declaration ?? item.declaration;
7963
- lines.push(from(origin, `export let ${name}: ${layout} = ${initial};`), from(origin, `export function ${setterName(name)}(value: ${layout}): void { ${name} = value; }`));
8089
+ const kept = retention.global(item, storage.flattened(item) ? name : null);
8090
+ if (kept) {
8091
+ retained.push(name);
8092
+ }
8093
+ const value = kept ? `retain(${initial})` : initial;
8094
+ lines.push(from(origin, `export let ${name}: ${layout} = ${value};`), from(origin, `export function ${setterName(name)}(value: ${layout}): void { ${name} = value; }`));
7964
8095
  };
7965
8096
  const node = model.node(item.value);
7966
8097
  if (!node || !storage.flattened(item)) {
@@ -7994,10 +8125,13 @@ var storageGlobals = (specializer, item) => {
7994
8125
  global(name, layout, initializers.valueText(field, declared, layout), property);
7995
8126
  }
7996
8127
  }
7997
- return lines;
8128
+ return retained.length ? [
8129
+ from(item.declaration, 'import { retain } from "@tsplc/compiler/types";'),
8130
+ ...lines
8131
+ ] : lines;
7998
8132
  };
7999
8133
  var typesOnly = (source) => joined([
8000
- ...source.statements.filter((statement) => ts27.isInterfaceDeclaration(statement) || ts27.isTypeAliasDeclaration(statement) || ts27.isImportDeclaration(statement) && statement.importClause?.isTypeOnly).map(copied),
8134
+ ...source.statements.filter((statement) => ts28.isInterfaceDeclaration(statement) || ts28.isTypeAliasDeclaration(statement) || ts28.isImportDeclaration(statement) && statement.importClause?.isTypeOnly).map(copied),
8001
8135
  "export {};"
8002
8136
  ], `
8003
8137
  `);
@@ -8012,12 +8146,12 @@ var failure = (cause, positions, debug) => {
8012
8146
  };
8013
8147
  var findEntry = (source, name) => {
8014
8148
  for (const statement of source.statements) {
8015
- if (ts27.isFunctionDeclaration(statement) && statement.name?.text === name && statement.body) {
8149
+ if (ts28.isFunctionDeclaration(statement) && statement.name?.text === name && statement.body) {
8016
8150
  return statement;
8017
8151
  }
8018
- if (ts27.isVariableStatement(statement)) {
8152
+ if (ts28.isVariableStatement(statement)) {
8019
8153
  for (const declaration of statement.declarationList.declarations) {
8020
- if (ts27.isIdentifier(declaration.name) && declaration.name.text === name && declaration.initializer && ts27.isArrowFunction(declaration.initializer)) {
8154
+ if (ts28.isIdentifier(declaration.name) && declaration.name.text === name && declaration.initializer && ts28.isArrowFunction(declaration.initializer)) {
8021
8155
  return declaration.initializer;
8022
8156
  }
8023
8157
  }
@@ -8030,7 +8164,7 @@ var findEntry = (source, name) => {
8030
8164
  import { createHash } from "node:crypto";
8031
8165
  import { error as error7 } from "@tsplc/compiler/ir";
8032
8166
  import { elementaryType as elementaryType2, isIntegerValued } from "@tsplc/iec";
8033
- import ts28 from "typescript";
8167
+ import ts29 from "typescript";
8034
8168
  var telemetryType = (annotation) => {
8035
8169
  const type = elementaryType2(annotation);
8036
8170
  return type?.family === "bool" || isIntegerValued(type) && type.bits <= 32 || /^STRING<\d+>$/.test(annotation);
@@ -8048,21 +8182,21 @@ var lowerExposure = (program, sdk, positions) => {
8048
8182
  const edits = [];
8049
8183
  const extra = [];
8050
8184
  const visit = (node) => {
8051
- if (!ts28.isCallExpression(node) || !namesSdk(checker, sdk, node.expression, "expose")) {
8052
- ts28.forEachChild(node, visit);
8185
+ if (!ts29.isCallExpression(node) || !namesSdk(checker, sdk, node.expression, "expose")) {
8186
+ ts29.forEachChild(node, visit);
8053
8187
  return;
8054
8188
  }
8055
8189
  const fail = (message) => diagnostics.push(error7("PLC1014", message, positions.node(node)));
8056
8190
  const [label, values] = node.arguments;
8057
- if (!label || !ts28.isStringLiteral(label) || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(label.text) || label.text === "__proto__" || !values || !ts28.isObjectLiteralExpression(values) || !ts28.isExpressionStatement(node.parent)) {
8191
+ if (!label || !ts29.isStringLiteral(label) || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(label.text) || label.text === "__proto__" || !values || !ts29.isObjectLiteralExpression(values) || !ts29.isExpressionStatement(node.parent)) {
8058
8192
  fail("expose requires a literal machine name and a flat telemetry object in a synchronous cyclic routine.");
8059
8193
  return;
8060
8194
  }
8061
8195
  let owner = node.parent;
8062
- while (owner && !ts28.isFunctionLike(owner)) {
8196
+ while (owner && !ts29.isFunctionLike(owner)) {
8063
8197
  owner = owner.parent;
8064
8198
  }
8065
- if (!owner || ts28.canHaveModifiers(owner) && ts28.getModifiers(owner)?.some((value) => value.kind === ts28.SyntaxKind.AsyncKeyword)) {
8199
+ if (!owner || ts29.canHaveModifiers(owner) && ts29.getModifiers(owner)?.some((value) => value.kind === ts29.SyntaxKind.AsyncKeyword)) {
8066
8200
  fail("Sample telemetry from a synchronous cyclic routine, outside async continuations.");
8067
8201
  return;
8068
8202
  }
@@ -8073,18 +8207,18 @@ var lowerExposure = (program, sdk, positions) => {
8073
8207
  names.add(label.text);
8074
8208
  const fields = [];
8075
8209
  for (const property of values.properties) {
8076
- if (!ts28.isPropertyAssignment(property) || !ts28.isIdentifier(property.name) || ["contractVersion", "__proto__"].includes(property.name.text)) {
8210
+ if (!ts29.isPropertyAssignment(property) || !ts29.isIdentifier(property.name) || ["contractVersion", "__proto__"].includes(property.name.text)) {
8077
8211
  fail("Telemetry uses named scalar fields; contractVersion and __proto__ are reserved.");
8078
8212
  return;
8079
8213
  }
8080
8214
  const value = property.initializer;
8081
8215
  const type = checker.getTypeAtLocation(value);
8082
8216
  let annotation;
8083
- if (type.flags & ts28.TypeFlags.BooleanLike) {
8217
+ if (type.flags & ts29.TypeFlags.BooleanLike) {
8084
8218
  annotation = "BOOL";
8085
8219
  }
8086
- const declaration = symbolAt(checker, ts28.isPropertyAccessExpression(value) ? value.name : value)?.valueDeclaration;
8087
- if (declaration && (ts28.isPropertySignature(declaration) || ts28.isPropertyDeclaration(declaration) || ts28.isVariableDeclaration(declaration) || ts28.isParameter(declaration)) && declaration.type) {
8220
+ const declaration = symbolAt(checker, ts29.isPropertyAccessExpression(value) ? value.name : value)?.valueDeclaration;
8221
+ if (declaration && (ts29.isPropertySignature(declaration) || ts29.isPropertyDeclaration(declaration) || ts29.isVariableDeclaration(declaration) || ts29.isParameter(declaration)) && declaration.type) {
8088
8222
  const text = declaration.type.getText(declaration.getSourceFile());
8089
8223
  if (telemetryType(text)) {
8090
8224
  annotation = text;
@@ -8134,33 +8268,33 @@ export let ${name}:${record}=defaultValue<${record}>();`));
8134
8268
 
8135
8269
  // packages/compiler/src/frontend/promises.ts
8136
8270
  import { error as error8 } from "@tsplc/compiler/ir";
8137
- import ts30 from "typescript";
8271
+ import ts31 from "typescript";
8138
8272
 
8139
8273
  // packages/compiler/src/frontend/promise-chains.ts
8140
- import ts29 from "typescript";
8274
+ import ts30 from "typescript";
8141
8275
  var asyncRoutine = (context, node) => {
8142
8276
  const fn = context.routines.get(context.symbol(node));
8143
- return fn && hasModifier(fn, ts29.SyntaxKind.AsyncKeyword) ? fn : undefined;
8277
+ return fn && hasModifier(fn, ts30.SyntaxKind.AsyncKeyword) ? fn : undefined;
8144
8278
  };
8145
8279
  var job = (context, node) => {
8146
- const declaration = context.symbol(node)?.declarations?.find((value) => ts29.isVariableDeclaration(value) || ts29.isPropertyDeclaration(value));
8147
- if (!declaration || !ts29.isVariableDeclaration(declaration) && !ts29.isPropertyDeclaration(declaration)) {
8280
+ const declaration = context.symbol(node)?.declarations?.find((value) => ts30.isVariableDeclaration(value) || ts30.isPropertyDeclaration(value));
8281
+ if (!declaration || !ts30.isVariableDeclaration(declaration) && !ts30.isPropertyDeclaration(declaration)) {
8148
8282
  return;
8149
8283
  }
8150
8284
  const init = declaration.initializer;
8151
- if (!init || !ts29.isCallExpression(init) || !ts29.isPropertyAccessExpression(init.expression) || !context.namesSdk(init.expression.expression, "backgroundTasks") || init.expression.name.text !== "define") {
8285
+ if (!init || !ts30.isCallExpression(init) || !ts30.isPropertyAccessExpression(init.expression) || !context.namesSdk(init.expression.expression, "backgroundTasks") || init.expression.name.text !== "define") {
8152
8286
  return;
8153
8287
  }
8154
8288
  return asyncRoutine(context, init.arguments[0]);
8155
8289
  };
8156
- var callee = (call) => ts29.isPropertyAccessExpression(call.expression) ? call.expression.name : call.expression;
8290
+ var callee = (call) => ts30.isPropertyAccessExpression(call.expression) ? call.expression.name : call.expression;
8157
8291
  var operation = (context, call) => asyncRoutine(context, callee(call)) ?? job(context, callee(call));
8158
8292
  var isSdk = (context, call, name) => context.namesSdk(callee(call), name);
8159
8293
  var chainOf = (context, expression) => {
8160
- if (!ts29.isCallExpression(expression)) {
8294
+ if (!ts30.isCallExpression(expression)) {
8161
8295
  return;
8162
8296
  }
8163
- if (ts29.isPropertyAccessExpression(expression.expression) && ["then", "catch"].includes(expression.expression.name.text)) {
8297
+ if (ts30.isPropertyAccessExpression(expression.expression) && ["then", "catch"].includes(expression.expression.name.text)) {
8164
8298
  const prefix = chainOf(context, expression.expression.expression);
8165
8299
  if (!prefix) {
8166
8300
  return;
@@ -8181,7 +8315,7 @@ var chainOf = (context, expression) => {
8181
8315
  }
8182
8316
  };
8183
8317
  var lowerChain = (context, expression, owner, detached) => new PromiseChain(context, expression, owner).lower(detached);
8184
- var isAggregate = (type) => Boolean(type && type.flags & ts29.TypeFlags.Object);
8318
+ var isAggregate = (type) => Boolean(type && type.flags & ts30.TypeFlags.Object);
8185
8319
  var helperFinish = (call, type, discard = false) => type === "void" || discard ? `await ${call};return;` : `return await ${call};`;
8186
8320
 
8187
8321
  class PromiseChain {
@@ -8208,15 +8342,15 @@ class PromiseChain {
8208
8342
  }
8209
8343
  this.chain = chain;
8210
8344
  this.source = expression.getSourceFile();
8211
- this.classOwner = ts29.isMethodDeclaration(owner) && ts29.isClassDeclaration(owner.parent) ? owner.parent : undefined;
8345
+ this.classOwner = ts30.isMethodDeclaration(owner) && ts30.isClassDeclaration(owner.parent) ? owner.parent : undefined;
8212
8346
  context.ensureImports(this.source, expression);
8213
8347
  context.useDiagnostics(expression);
8214
8348
  for (const link of chain.links) {
8215
8349
  for (const value of link.handlers) {
8216
- if (value.kind === ts29.SyntaxKind.UndefinedKeyword || value.kind === ts29.SyntaxKind.NullKeyword) {
8350
+ if (value.kind === ts30.SyntaxKind.UndefinedKeyword || value.kind === ts30.SyntaxKind.NullKeyword) {
8217
8351
  continue;
8218
8352
  }
8219
- if (ts29.isArrowFunction(value) || ts29.isFunctionExpression(value)) {
8353
+ if (ts30.isArrowFunction(value) || ts30.isFunctionExpression(value)) {
8220
8354
  this.collectCaptures(value);
8221
8355
  }
8222
8356
  }
@@ -8238,21 +8372,21 @@ class PromiseChain {
8238
8372
  }
8239
8373
  collectCaptures(handler) {
8240
8374
  const visit = (node) => {
8241
- if (ts29.isIdentifier(node) && !(ts29.isPropertyAccessExpression(node.parent) && node.parent.name === node) && !(ts29.isPropertyAssignment(node.parent) && node.parent.name === node)) {
8375
+ if (ts30.isIdentifier(node) && !(ts30.isPropertyAccessExpression(node.parent) && node.parent.name === node) && !(ts30.isPropertyAssignment(node.parent) && node.parent.name === node)) {
8242
8376
  this.capture(node);
8243
8377
  }
8244
- ts29.forEachChild(node, visit);
8378
+ ts30.forEachChild(node, visit);
8245
8379
  };
8246
8380
  visit(handler.body);
8247
8381
  }
8248
8382
  capture(node) {
8249
8383
  const { context } = this;
8250
- const key = ts29.isShorthandPropertyAssignment(node.parent) ? context.checker.getShorthandAssignmentValueSymbol(node.parent) : context.symbol(node);
8384
+ const key = ts30.isShorthandPropertyAssignment(node.parent) ? context.checker.getShorthandAssignmentValueSymbol(node.parent) : context.symbol(node);
8251
8385
  const declaration = key?.valueDeclaration;
8252
- if (!key || !declaration || !(ts29.isVariableDeclaration(declaration) || ts29.isParameter(declaration)) || ts29.findAncestor(declaration.parent, ts29.isFunctionLike) !== this.owner || this.captures.has(key)) {
8386
+ if (!key || !declaration || !(ts30.isVariableDeclaration(declaration) || ts30.isParameter(declaration)) || ts30.findAncestor(declaration.parent, ts30.isFunctionLike) !== this.owner || this.captures.has(key)) {
8253
8387
  return;
8254
8388
  }
8255
- if (ts29.isVariableDeclaration(declaration) && (!ts29.isVariableDeclarationList(declaration.parent) || !(declaration.parent.flags & ts29.NodeFlags.Const))) {
8389
+ if (ts30.isVariableDeclaration(declaration) && (!ts30.isVariableDeclarationList(declaration.parent) || !(declaration.parent.flags & ts30.NodeFlags.Const))) {
8256
8390
  this.context.fail(node, "Continuation captures must be const values; store mutable state on the controller instead.");
8257
8391
  }
8258
8392
  if (!declaration.type) {
@@ -8269,7 +8403,7 @@ class PromiseChain {
8269
8403
  }
8270
8404
  hasBorrow(node, seen = new Set) {
8271
8405
  const { context } = this;
8272
- if (ts29.isTypeReferenceNode(node)) {
8406
+ if (ts30.isTypeReferenceNode(node)) {
8273
8407
  if (context.namesSdk(node.typeName, "InOut")) {
8274
8408
  return true;
8275
8409
  }
@@ -8277,16 +8411,16 @@ class PromiseChain {
8277
8411
  if (key && !seen.has(key)) {
8278
8412
  seen.add(key);
8279
8413
  for (const declaration of key.declarations ?? []) {
8280
- if (ts29.isInterfaceDeclaration(declaration) && declaration.members.some((member) => ts29.isPropertySignature(member) && member.type && this.hasBorrow(member.type, seen))) {
8414
+ if (ts30.isInterfaceDeclaration(declaration) && declaration.members.some((member) => ts30.isPropertySignature(member) && member.type && this.hasBorrow(member.type, seen))) {
8281
8415
  return true;
8282
8416
  }
8283
- if (ts29.isTypeAliasDeclaration(declaration) && this.hasBorrow(declaration.type, seen)) {
8417
+ if (ts30.isTypeAliasDeclaration(declaration) && this.hasBorrow(declaration.type, seen)) {
8284
8418
  return true;
8285
8419
  }
8286
8420
  }
8287
8421
  }
8288
8422
  }
8289
- return node.getChildren().some((child) => ts29.isTypeNode(child) && this.hasBorrow(child, seen));
8423
+ return node.getChildren().some((child) => ts30.isTypeNode(child) && this.hasBorrow(child, seen));
8290
8424
  }
8291
8425
  rootCall() {
8292
8426
  const { context, source } = this;
@@ -8294,7 +8428,7 @@ class PromiseChain {
8294
8428
  const fn = operation(context, root);
8295
8429
  if (fn) {
8296
8430
  const node = fn.type;
8297
- if (!node || !ts29.isTypeReferenceNode(node) || !node.typeArguments?.[0]) {
8431
+ if (!node || !ts30.isTypeReferenceNode(node) || !node.typeArguments?.[0]) {
8298
8432
  this.context.fail(fn, "Async calls need an explicit Promise<T> result.");
8299
8433
  }
8300
8434
  const type = context.typeText(node.typeArguments[0], source);
@@ -8343,12 +8477,12 @@ class PromiseChain {
8343
8477
  }
8344
8478
  const type = context.typeText(response, source);
8345
8479
  const options = root.arguments[1];
8346
- if (options && !ts29.isObjectLiteralExpression(options)) {
8480
+ if (options && !ts30.isObjectLiteralExpression(options)) {
8347
8481
  this.context.fail(options, "fetch options must be an inline object.");
8348
8482
  }
8349
8483
  const parameters = [];
8350
- const optionText = options && ts29.isObjectLiteralExpression(options) ? options.properties.map((property) => {
8351
- if (!ts29.isPropertyAssignment(property)) {
8484
+ const optionText = options && ts30.isObjectLiteralExpression(options) ? options.properties.map((property) => {
8485
+ if (!ts30.isPropertyAssignment(property)) {
8352
8486
  this.context.fail(property, "fetch requires named options.");
8353
8487
  }
8354
8488
  if (property.name.getText(source) !== "json") {
@@ -8370,23 +8504,23 @@ class PromiseChain {
8370
8504
  expressionType(node) {
8371
8505
  const { context, source } = this;
8372
8506
  const { checker } = context;
8373
- if (ts29.isCallExpression(node) && node.typeArguments?.[0] && (context.namesSdk(node.expression, "defaultValue") || context.namesSdk(node.expression, "copy") || ["exact", "wrap", "wrapAdd", "wrapMultiply", "saturate"].some((name) => context.namesSdk(node.expression, name)))) {
8507
+ if (ts30.isCallExpression(node) && node.typeArguments?.[0] && (context.namesSdk(node.expression, "defaultValue") || context.namesSdk(node.expression, "copy") || ["exact", "wrap", "wrapAdd", "wrapMultiply", "saturate"].some((name) => context.namesSdk(node.expression, name)))) {
8374
8508
  return context.typeText(node.typeArguments[0], source);
8375
8509
  }
8376
- const name = ts29.isPropertyAccessExpression(node) ? node.name : node;
8377
- const declaration = context.symbol(name)?.declarations?.find((value) => (ts29.isVariableDeclaration(value) || ts29.isParameter(value) || ts29.isPropertyDeclaration(value) || ts29.isPropertySignature(value)) && value.type);
8378
- if (declaration && (ts29.isVariableDeclaration(declaration) || ts29.isParameter(declaration) || ts29.isPropertyDeclaration(declaration) || ts29.isPropertySignature(declaration)) && declaration.type) {
8510
+ const name = ts30.isPropertyAccessExpression(node) ? node.name : node;
8511
+ const declaration = context.symbol(name)?.declarations?.find((value) => (ts30.isVariableDeclaration(value) || ts30.isParameter(value) || ts30.isPropertyDeclaration(value) || ts30.isPropertySignature(value)) && value.type);
8512
+ if (declaration && (ts30.isVariableDeclaration(declaration) || ts30.isParameter(declaration) || ts30.isPropertyDeclaration(declaration) || ts30.isPropertySignature(declaration)) && declaration.type) {
8379
8513
  return context.typeText(declaration.type, source);
8380
8514
  }
8381
8515
  const type = checker.getTypeAtLocation(node);
8382
- if (type.flags & ts29.TypeFlags.BooleanLike) {
8516
+ if (type.flags & ts30.TypeFlags.BooleanLike) {
8383
8517
  return "BOOL";
8384
8518
  }
8385
- if (type.flags & ts29.TypeFlags.Void) {
8519
+ if (type.flags & ts30.TypeFlags.Void) {
8386
8520
  return "void";
8387
8521
  }
8388
- if (type.symbol && type.symbol.name !== "__type" && type.flags & ts29.TypeFlags.Object) {
8389
- return checker.typeToString(type, node, ts29.TypeFormatFlags.NoTruncation | ts29.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope);
8522
+ if (type.symbol && type.symbol.name !== "__type" && type.flags & ts30.TypeFlags.Object) {
8523
+ return checker.typeToString(type, node, ts30.TypeFormatFlags.NoTruncation | ts30.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope);
8390
8524
  }
8391
8525
  this.context.fail(node, "Annotate this value with its concrete PLC type before using it in an async continuation.");
8392
8526
  }
@@ -8445,7 +8579,7 @@ class PromiseChain {
8445
8579
  };
8446
8580
  }
8447
8581
  callback(expression, inputType, input) {
8448
- if (!expression || expression.kind === ts29.SyntaxKind.NullKeyword || ts29.isIdentifier(expression) && expression.text === "undefined") {
8582
+ if (!expression || expression.kind === ts30.SyntaxKind.NullKeyword || ts30.isIdentifier(expression) && expression.text === "undefined") {
8449
8583
  return;
8450
8584
  }
8451
8585
  const { context, source } = this;
@@ -8465,7 +8599,7 @@ class PromiseChain {
8465
8599
  const names = new Map(this.captureNames);
8466
8600
  const parameter = declaration.parameters[0];
8467
8601
  if (parameter) {
8468
- if (!ts29.isIdentifier(parameter.name)) {
8602
+ if (!ts30.isIdentifier(parameter.name)) {
8469
8603
  this.context.fail(parameter, "Promise callback parameters need names.");
8470
8604
  }
8471
8605
  names.set(context.symbol(parameter.name), "promiseValue");
@@ -8489,12 +8623,12 @@ class PromiseChain {
8489
8623
  };
8490
8624
  }
8491
8625
  handlerDeclaration(expression) {
8492
- if (ts29.isArrowFunction(expression) || ts29.isFunctionExpression(expression)) {
8626
+ if (ts30.isArrowFunction(expression) || ts30.isFunctionExpression(expression)) {
8493
8627
  return expression;
8494
8628
  }
8495
8629
  const key = this.context.symbol(expression);
8496
8630
  const named = key && this.context.routines.get(key);
8497
- if (!named || !ts29.isFunctionDeclaration(named)) {
8631
+ if (!named || !ts30.isFunctionDeclaration(named)) {
8498
8632
  this.context.fail(expression, "Use a named function or inline arrow; bind instance methods with an arrow.");
8499
8633
  }
8500
8634
  return named;
@@ -8509,11 +8643,11 @@ class PromiseChain {
8509
8643
  if (!result) {
8510
8644
  this.context.fail(declaration, "Annotate callback results with their concrete PLC type.");
8511
8645
  }
8512
- const output = ts29.isTypeReferenceNode(result) && result.typeName.getText(declaration.getSourceFile()) === "Promise" ? result.typeArguments[0] : result;
8646
+ const output = ts30.isTypeReferenceNode(result) && result.typeName.getText(declaration.getSourceFile()) === "Promise" ? result.typeArguments[0] : result;
8513
8647
  const callbackType = context.typeText(output, source);
8514
8648
  const name = expression.getText(source);
8515
8649
  const takesInput = declaration.parameters.length > 0;
8516
- if (hasModifier(declaration, ts29.SyntaxKind.AsyncKeyword)) {
8650
+ if (hasModifier(declaration, ts30.SyntaxKind.AsyncKeyword)) {
8517
8651
  return {
8518
8652
  call: `${name}(${takesInput ? input : ""})`,
8519
8653
  type: callbackType,
@@ -8533,24 +8667,24 @@ class PromiseChain {
8533
8667
  const { context, source } = this;
8534
8668
  const annotation = declaration.type;
8535
8669
  if (annotation) {
8536
- return ts29.isTypeReferenceNode(annotation) && annotation.typeName.getText(source) === "Promise" ? context.typeText(annotation.typeArguments[0], source) : context.typeText(annotation, source);
8670
+ return ts30.isTypeReferenceNode(annotation) && annotation.typeName.getText(source) === "Promise" ? context.typeText(annotation.typeArguments[0], source) : context.typeText(annotation, source);
8537
8671
  }
8538
8672
  const resolved = context.checker.getSignatureFromDeclaration(declaration);
8539
8673
  const inferred = resolved && context.checker.getAwaitedType(context.checker.getReturnTypeOfSignature(resolved));
8540
- if (inferred?.flags && inferred.flags & ts29.TypeFlags.Void) {
8674
+ if (inferred?.flags && inferred.flags & ts30.TypeFlags.Void) {
8541
8675
  return "void";
8542
8676
  }
8543
- if (ts29.isBlock(body)) {
8677
+ if (ts30.isBlock(body)) {
8544
8678
  this.context.fail(declaration, "Annotate a callback that returns a value with its concrete PLC type.");
8545
8679
  }
8546
- if (ts29.isIdentifier(body) && parameter && context.symbol(body) === context.symbol(parameter.name)) {
8680
+ if (ts30.isIdentifier(body) && parameter && context.symbol(body) === context.symbol(parameter.name)) {
8547
8681
  return inputType;
8548
8682
  }
8549
- const returned = ts29.isCallExpression(body) ? operation(context, body) : undefined;
8550
- return returned?.type && ts29.isTypeReferenceNode(returned.type) ? context.typeText(returned.type.typeArguments[0], source) : this.expressionType(body);
8683
+ const returned = ts30.isCallExpression(body) ? operation(context, body) : undefined;
8684
+ return returned?.type && ts30.isTypeReferenceNode(returned.type) ? context.typeText(returned.type.typeArguments[0], source) : this.expressionType(body);
8551
8685
  }
8552
8686
  callbackCode(body, printed, type) {
8553
- if (ts29.isBlock(body)) {
8687
+ if (ts30.isBlock(body)) {
8554
8688
  return printed.slice(1, -1);
8555
8689
  }
8556
8690
  if (type === "void") {
@@ -8560,37 +8694,37 @@ class PromiseChain {
8560
8694
  }
8561
8695
  replaceNames(node, names) {
8562
8696
  const { context } = this;
8563
- const transformed = ts29.transform(node, [
8697
+ const transformed = ts30.transform(node, [
8564
8698
  (transformation) => (root) => {
8565
8699
  const visit = (value) => {
8566
- if (ts29.isReturnStatement(value) && value.expression && !ts29.isAwaitExpression(value.expression) && this.isPromise(value.expression)) {
8567
- return ts29.factory.updateReturnStatement(value, ts29.factory.createAwaitExpression(ts29.visitNode(value.expression, visit)));
8700
+ if (ts30.isReturnStatement(value) && value.expression && !ts30.isAwaitExpression(value.expression) && this.isPromise(value.expression)) {
8701
+ return ts30.factory.updateReturnStatement(value, ts30.factory.createAwaitExpression(ts30.visitNode(value.expression, visit)));
8568
8702
  }
8569
- if (ts29.isShorthandPropertyAssignment(value)) {
8703
+ if (ts30.isShorthandPropertyAssignment(value)) {
8570
8704
  const key = context.checker.getShorthandAssignmentValueSymbol(value);
8571
8705
  const name = key && names.get(key);
8572
8706
  if (name) {
8573
- return ts29.factory.createPropertyAssignment(value.name, ts29.factory.createIdentifier(name));
8707
+ return ts30.factory.createPropertyAssignment(value.name, ts30.factory.createIdentifier(name));
8574
8708
  }
8575
8709
  }
8576
- if (ts29.isIdentifier(value) && !(ts29.isPropertyAccessExpression(value.parent) && value.parent.name === value) && !(ts29.isPropertyAssignment(value.parent) && value.parent.name === value)) {
8710
+ if (ts30.isIdentifier(value) && !(ts30.isPropertyAccessExpression(value.parent) && value.parent.name === value) && !(ts30.isPropertyAssignment(value.parent) && value.parent.name === value)) {
8577
8711
  const key = context.symbol(value);
8578
8712
  const name = key && names.get(key);
8579
8713
  if (name) {
8580
- return ts29.factory.createIdentifier(name);
8714
+ return ts30.factory.createIdentifier(name);
8581
8715
  }
8582
8716
  }
8583
- return ts29.visitEachChild(value, visit, transformation);
8717
+ return ts30.visitEachChild(value, visit, transformation);
8584
8718
  };
8585
- return ts29.visitNode(root, visit);
8719
+ return ts30.visitNode(root, visit);
8586
8720
  }
8587
8721
  ]);
8588
- const printed = printer.printNode(ts29.EmitHint.Unspecified, transformed.transformed[0], node.getSourceFile());
8722
+ const printed = printer.printNode(ts30.EmitHint.Unspecified, transformed.transformed[0], node.getSourceFile());
8589
8723
  transformed.dispose();
8590
8724
  return printed;
8591
8725
  }
8592
8726
  }
8593
- var printer = ts29.createPrinter();
8727
+ var printer = ts30.createPrinter();
8594
8728
  function linkBody(previous, {
8595
8729
  fulfilled,
8596
8730
  rejected,
@@ -8665,29 +8799,29 @@ function rewriteChains(rewrite, files, diagnostics) {
8665
8799
  };
8666
8800
  for (const source of files) {
8667
8801
  const visit = (node, owner) => {
8668
- if (ts30.isFunctionDeclaration(node) || ts30.isMethodDeclaration(node)) {
8802
+ if (ts31.isFunctionDeclaration(node) || ts31.isMethodDeclaration(node)) {
8669
8803
  if (node.body) {
8670
- ts30.forEachChild(node.body, (child) => visit(child, node));
8804
+ ts31.forEachChild(node.body, (child) => visit(child, node));
8671
8805
  }
8672
8806
  return;
8673
8807
  }
8674
8808
  if (!owner) {
8675
- ts30.forEachChild(node, (child) => visit(child));
8809
+ ts31.forEachChild(node, (child) => visit(child));
8676
8810
  return;
8677
8811
  }
8678
- if (ts30.isCallExpression(node) && rewrite.namesSdk(node.expression, "asyncDiagnostics")) {
8812
+ if (ts31.isCallExpression(node) && rewrite.namesSdk(node.expression, "asyncDiagnostics")) {
8679
8813
  rewrite.useDiagnostics(node);
8680
8814
  diagnosticsCalls.push(node);
8681
8815
  return;
8682
8816
  }
8683
- if (ts30.isCallExpression(node) && rewrite.namesSdk(node.expression, "cancelAsync")) {
8817
+ if (ts31.isCallExpression(node) && rewrite.namesSdk(node.expression, "cancelAsync")) {
8684
8818
  cancelCalls.push({ node, owner });
8685
8819
  return;
8686
8820
  }
8687
- if (ts30.isExpressionStatement(node)) {
8688
- const expression = ts30.isVoidExpression(node.expression) ? node.expression.expression : node.expression;
8821
+ if (ts31.isExpressionStatement(node)) {
8822
+ const expression = ts31.isVoidExpression(node.expression) ? node.expression.expression : node.expression;
8689
8823
  if (chainOf(rewrite, expression)) {
8690
- if (hasModifier(owner, ts30.SyntaxKind.AsyncKeyword)) {
8824
+ if (hasModifier(owner, ts31.SyntaxKind.AsyncKeyword)) {
8691
8825
  diagnostics.push(rewrite.diagnostic(node, "Await async work inside an async routine; detached calls belong in synchronous controllers."));
8692
8826
  return;
8693
8827
  }
@@ -8695,23 +8829,23 @@ function rewriteChains(rewrite, files, diagnostics) {
8695
8829
  return;
8696
8830
  }
8697
8831
  }
8698
- if (ts30.isCallExpression(node) && chainOf(rewrite, node)?.links.length) {
8832
+ if (ts31.isCallExpression(node) && chainOf(rewrite, node)?.links.length) {
8699
8833
  lower(node, node, owner, { detached: false });
8700
8834
  return;
8701
8835
  }
8702
- ts30.forEachChild(node, (child) => visit(child, owner));
8836
+ ts31.forEachChild(node, (child) => visit(child, owner));
8703
8837
  };
8704
8838
  visit(source);
8705
8839
  }
8706
8840
  return { diagnosticsCalls, cancelCalls };
8707
8841
  }
8708
8842
  function cancelScope(rewrite, node, owner, diagnostics) {
8709
- const scope = ts30.isMethodDeclaration(owner) && ts30.isClassDeclaration(owner.parent) ? owner.parent : owner.getSourceFile();
8710
- if (node.arguments.length && (node.arguments.length !== 1 || node.arguments[0].kind !== ts30.SyntaxKind.ThisKeyword)) {
8843
+ const scope = ts31.isMethodDeclaration(owner) && ts31.isClassDeclaration(owner.parent) ? owner.parent : owner.getSourceFile();
8844
+ if (node.arguments.length && (node.arguments.length !== 1 || node.arguments[0].kind !== ts31.SyntaxKind.ThisKeyword)) {
8711
8845
  diagnostics.push(rewrite.diagnostic(node, "cancelAsync takes this in a controller, or no argument in a module."));
8712
8846
  }
8713
8847
  const name = `tsplcCancelScope${rewrite.sequence()}`;
8714
- const member = ts30.isClassDeclaration(scope);
8848
+ const member = ts31.isClassDeclaration(scope);
8715
8849
  const body = (rewrite.sites.get(scope) ?? []).map((site) => `${member ? "this." : ""}${site}.cancel();`).join("");
8716
8850
  rewrite.append(scope, node, member ? `private ${name}():void{${body}}` : `function ${name}():void{${body}}`);
8717
8851
  rewrite.edit(node, `${member ? "this." : ""}${name}()`);
@@ -8737,9 +8871,9 @@ class PromiseRewrite {
8737
8871
  this.positions = positions;
8738
8872
  for (const source of files) {
8739
8873
  for (const statement of source.statements) {
8740
- const candidates = ts30.isClassDeclaration(statement) ? statement.members.filter(ts30.isMethodDeclaration) : [statement];
8874
+ const candidates = ts31.isClassDeclaration(statement) ? statement.members.filter(ts31.isMethodDeclaration) : [statement];
8741
8875
  for (const candidate of candidates) {
8742
- if ((ts30.isFunctionDeclaration(candidate) || ts30.isMethodDeclaration(candidate)) && candidate.name) {
8876
+ if ((ts31.isFunctionDeclaration(candidate) || ts31.isMethodDeclaration(candidate)) && candidate.name) {
8743
8877
  this.routines.set(this.symbol(candidate.name), candidate);
8744
8878
  }
8745
8879
  }
@@ -8762,7 +8896,7 @@ class PromiseRewrite {
8762
8896
  return this.nextName++;
8763
8897
  }
8764
8898
  append(scope, origin, text) {
8765
- if (ts30.isClassDeclaration(scope)) {
8899
+ if (ts31.isClassDeclaration(scope)) {
8766
8900
  this.members.set(scope, [
8767
8901
  ...this.members.get(scope) ?? [],
8768
8902
  from(origin, text)
@@ -8785,7 +8919,7 @@ class PromiseRewrite {
8785
8919
  return this.additions.keys();
8786
8920
  }
8787
8921
  typeText(node, source) {
8788
- if (node.kind === ts30.SyntaxKind.VoidKeyword) {
8922
+ if (node.kind === ts31.SyntaxKind.VoidKeyword) {
8789
8923
  return "void";
8790
8924
  }
8791
8925
  if (node.getSourceFile() === source) {
@@ -8854,7 +8988,7 @@ import {
8854
8988
  wireLayout,
8855
8989
  wireRecord
8856
8990
  } from "@tsplc/server";
8857
- import ts31 from "typescript";
8991
+ import ts32 from "typescript";
8858
8992
  var property = (checker, type, name) => {
8859
8993
  const symbol = type.getProperty(name);
8860
8994
  return symbol && checker.getTypeOfSymbol(symbol);
@@ -8871,12 +9005,12 @@ var layoutNumber = (checker, type, name, label) => {
8871
9005
  return value.value;
8872
9006
  };
8873
9007
  var scalarLayout = (checker, type, label) => {
8874
- if (type.flags & ts31.TypeFlags.Boolean) {
9008
+ if (type.flags & ts32.TypeFlags.Boolean) {
8875
9009
  return { field: { kind: "boolean" } };
8876
9010
  }
8877
9011
  const first = type.isUnion() ? type.types[0] : type;
8878
9012
  const member = first?.symbol?.valueDeclaration;
8879
- if (first && first.flags & ts31.TypeFlags.EnumLiteral && member && ts31.isEnumMember(member)) {
9013
+ if (first && first.flags & ts32.TypeFlags.EnumLiteral && member && ts32.isEnumMember(member)) {
8880
9014
  const members = {};
8881
9015
  for (const item of member.parent.members) {
8882
9016
  const value = checker.getConstantValue(item);
@@ -8905,13 +9039,13 @@ var scalarLayout = (checker, type, label) => {
8905
9039
  var recordLayout = (checker, type, label, output) => {
8906
9040
  const fields = {};
8907
9041
  const enums = {};
8908
- if (!(type.flags & ts31.TypeFlags.Void)) {
8909
- if (!(type.flags & ts31.TypeFlags.Object) || type.getStringIndexType() || type.getNumberIndexType() || type.getCallSignatures().length) {
9042
+ if (!(type.flags & ts32.TypeFlags.Void)) {
9043
+ if (!(type.flags & ts32.TypeFlags.Object) || type.getStringIndexType() || type.getNumberIndexType() || type.getCallSignatures().length) {
8910
9044
  throw new Error(`${label}: PLC procedures exchange one closed z.strictObject() record.`);
8911
9045
  }
8912
9046
  for (const field of type.getProperties()) {
8913
9047
  const key = `${label}.${field.name}`;
8914
- if (field.flags & ts31.SymbolFlags.Optional) {
9048
+ if (field.flags & ts32.SymbolFlags.Optional) {
8915
9049
  throw new Error(`${key}: optional wire fields are unsupported.`);
8916
9050
  }
8917
9051
  const value = checker.getTypeOfSymbol(field);
@@ -8975,17 +9109,17 @@ var lowerServices = (program, sdk, positions, options) => {
8975
9109
  const sourceFiles = runtimeSources(program).filter((source) => !source.isDeclarationFile);
8976
9110
  for (const source of sourceFiles) {
8977
9111
  for (const statement of source.statements) {
8978
- if (!ts31.isVariableStatement(statement)) {
9112
+ if (!ts32.isVariableStatement(statement)) {
8979
9113
  continue;
8980
9114
  }
8981
9115
  for (const declaration of statement.declarationList.declarations) {
8982
9116
  const call = declaration.initializer;
8983
- if (!call || !ts31.isCallExpression(call) || !namesSdk(checker, sdk, call.expression, "createServiceClient")) {
9117
+ if (!call || !ts32.isCallExpression(call) || !namesSdk(checker, sdk, call.expression, "createServiceClient")) {
8984
9118
  continue;
8985
9119
  }
8986
9120
  const router = call.typeArguments?.[0];
8987
9121
  const client = symbolAt(checker, declaration.name);
8988
- if (!router || !client || !(statement.declarationList.flags & ts31.NodeFlags.Const)) {
9122
+ if (!router || !client || !(statement.declarationList.flags & ts32.NodeFlags.Const)) {
8989
9123
  fail(declaration, "PLC1013", "Create a service client as a module constant: const services = createServiceClient<AppRouter>().");
8990
9124
  } else if (!options) {
8991
9125
  fail(call, "PLC1013", "Configure server in tsplc.config.ts to call the server.");
@@ -9005,11 +9139,11 @@ var lowerServices = (program, sdk, positions, options) => {
9005
9139
  const edits = [];
9006
9140
  const imports = new Map;
9007
9141
  const visit = (node) => {
9008
- if (ts31.isImportDeclaration(node) && ts31.isStringLiteral(node.moduleSpecifier)) {
9142
+ if (ts32.isImportDeclaration(node) && ts32.isStringLiteral(node.moduleSpecifier)) {
9009
9143
  const clause = node.importClause;
9010
9144
  const bindings = clause?.namedBindings;
9011
- const typeOnly = clause?.isTypeOnly || !clause?.name && bindings && ts31.isNamedImports(bindings) && bindings.elements.every((element) => element.isTypeOnly);
9012
- if (!typeOnly && clause && bindings && ts31.isNamedImports(bindings)) {
9145
+ const typeOnly = clause?.isTypeOnly || !clause?.name && bindings && ts32.isNamedImports(bindings) && bindings.elements.every((element) => element.isTypeOnly);
9146
+ if (!typeOnly && clause && bindings && ts32.isNamedImports(bindings)) {
9013
9147
  const elements = bindings.elements.filter((element) => {
9014
9148
  const imported = symbolAt(checker, element.name);
9015
9149
  return !imported || !clients.has(imported);
@@ -9018,7 +9152,7 @@ var lowerServices = (program, sdk, positions, options) => {
9018
9152
  edits.push({
9019
9153
  start: node.getStart(source),
9020
9154
  end: node.end,
9021
- text: elements.length || clause.name ? ts31.createPrinter().printNode(ts31.EmitHint.Unspecified, ts31.factory.updateImportDeclaration(node, node.modifiers, ts31.factory.updateImportClause(clause, clause.isTypeOnly, clause.name, ts31.factory.updateNamedImports(bindings, elements)), node.moduleSpecifier, node.attributes), source) : ""
9155
+ text: elements.length || clause.name ? ts32.createPrinter().printNode(ts32.EmitHint.Unspecified, ts32.factory.updateImportDeclaration(node, node.modifiers, ts32.factory.updateImportClause(clause, clause.isTypeOnly, clause.name, ts32.factory.updateNamedImports(bindings, elements)), node.moduleSpecifier, node.attributes), source) : ""
9022
9156
  });
9023
9157
  }
9024
9158
  }
@@ -9035,7 +9169,7 @@ var lowerServices = (program, sdk, positions, options) => {
9035
9169
  fail(node, "PLC1013", `Server runtime import ${node.moduleSpecifier.text} cannot execute in PLC code. Expose a PLC procedure on the server router and call it through createServiceClient instead.`);
9036
9170
  }
9037
9171
  }
9038
- if (ts31.isVariableStatement(node)) {
9172
+ if (ts32.isVariableStatement(node)) {
9039
9173
  const clientStatement = node.declarationList.declarations.some((declaration) => {
9040
9174
  const declared = symbolAt(checker, declaration.name);
9041
9175
  return declared && clients.has(declared);
@@ -9045,10 +9179,10 @@ var lowerServices = (program, sdk, positions, options) => {
9045
9179
  return;
9046
9180
  }
9047
9181
  }
9048
- if (clients.size && ts31.isPropertyAccessExpression(node)) {
9182
+ if (clients.size && ts32.isPropertyAccessExpression(node)) {
9049
9183
  const parts = [];
9050
9184
  let root = node;
9051
- while (ts31.isPropertyAccessExpression(root)) {
9185
+ while (ts32.isPropertyAccessExpression(root)) {
9052
9186
  parts.unshift(root.name.text);
9053
9187
  root = root.expression;
9054
9188
  }
@@ -9091,7 +9225,7 @@ var lowerServices = (program, sdk, positions, options) => {
9091
9225
  return;
9092
9226
  }
9093
9227
  }
9094
- ts31.forEachChild(node, visit);
9228
+ ts32.forEachChild(node, visit);
9095
9229
  };
9096
9230
  visit(source);
9097
9231
  if (!edits.length) {
@@ -9167,7 +9301,7 @@ var serviceRecords = (program, lowering) => {
9167
9301
  return;
9168
9302
  }
9169
9303
  const checker = program.getTypeChecker();
9170
- const declarations = new Map(source.statements.filter(ts31.isInterfaceDeclaration).map((value) => [value.name.text, value]));
9304
+ const declarations = new Map(source.statements.filter(ts32.isInterfaceDeclaration).map((value) => [value.name.text, value]));
9171
9305
  return (type) => {
9172
9306
  let key;
9173
9307
  try {
@@ -9190,8 +9324,8 @@ function tsDiagnostic(diagnostic, locate = sourceSpan) {
9190
9324
  const result = {
9191
9325
  origin: "typescript",
9192
9326
  code: `TS${diagnostic.code}`,
9193
- severity: diagnostic.category === ts32.DiagnosticCategory.Error ? "error" : "warning",
9194
- message: ts32.flattenDiagnosticMessageText(diagnostic.messageText, `
9327
+ severity: diagnostic.category === ts33.DiagnosticCategory.Error ? "error" : "warning",
9328
+ message: ts33.flattenDiagnosticMessageText(diagnostic.messageText, `
9195
9329
  `)
9196
9330
  };
9197
9331
  if (diagnostic.file && diagnostic.start !== undefined) {
@@ -9212,11 +9346,11 @@ function analyze(options) {
9212
9346
  const environment = options.environment ?? { ...process.env };
9213
9347
  const debug = compileDebug(environment);
9214
9348
  const filename = resolve7(options.tsconfig);
9215
- const config = ts32.readConfigFile(filename, ts32.sys.readFile);
9349
+ const config = ts33.readConfigFile(filename, ts33.sys.readFile);
9216
9350
  if (config.error) {
9217
9351
  return { diagnostics: [tsDiagnostic(config.error)] };
9218
9352
  }
9219
- const parsed = ts32.parseJsonConfigFileContent(config.config, ts32.sys, dirname7(filename), undefined, filename);
9353
+ const parsed = ts33.parseJsonConfigFileContent(config.config, ts33.sys, dirname7(filename), undefined, filename);
9220
9354
  if (parsed.errors.length) {
9221
9355
  return {
9222
9356
  diagnostics: parsed.errors.map((diagnostic) => tsDiagnostic(diagnostic))
@@ -9240,8 +9374,8 @@ function analyze(options) {
9240
9374
  skipLibCheck: false,
9241
9375
  types: [],
9242
9376
  lib: ["lib.es2022.d.ts"],
9243
- module: ts32.ModuleKind.ESNext,
9244
- moduleResolution: ts32.ModuleResolutionKind.Bundler
9377
+ module: ts33.ModuleKind.ESNext,
9378
+ moduleResolution: ts33.ModuleResolutionKind.Bundler
9245
9379
  };
9246
9380
  delete compilerOptions.rootDir;
9247
9381
  delete compilerOptions.outDir;
@@ -9249,7 +9383,7 @@ function analyze(options) {
9249
9383
  const rootNames = [...new Set([...projectFiles, ...programFiles, sdk])];
9250
9384
  const virtualSources = new Map;
9251
9385
  const host = loweringHost(compilerOptions, virtualSources);
9252
- let program = ts32.createProgram(rootNames, compilerOptions, host);
9386
+ let program = ts33.createProgram(rootNames, compilerOptions, host);
9253
9387
  const plcFiles = (program) => {
9254
9388
  const files = new Set(runtimeSources(program));
9255
9389
  for (const source of program.getSourceFiles()) {
@@ -9295,7 +9429,7 @@ function analyze(options) {
9295
9429
  writeFileSync2(target, text.text);
9296
9430
  }
9297
9431
  }
9298
- program = ts32.createProgram({
9432
+ program = ts33.createProgram({
9299
9433
  rootNames,
9300
9434
  options: compilerOptions,
9301
9435
  host,
@@ -9344,7 +9478,7 @@ function analyze(options) {
9344
9478
  return hasErrors(diagnostics) ? { diagnostics } : { module, diagnostics };
9345
9479
  }
9346
9480
  function loweringHost(options, virtualSources) {
9347
- const host = ts32.createCompilerHost(options);
9481
+ const host = ts33.createCompilerHost(options);
9348
9482
  const read = host.readFile;
9349
9483
  const exists = host.fileExists;
9350
9484
  const directoryExists = host.directoryExists?.bind(host);
@@ -9426,17 +9560,17 @@ function attachLowerings(module, root, {
9426
9560
  }
9427
9561
  function checkHostConfig(file) {
9428
9562
  const bunTypes = createRequire2(import.meta.url).resolve("@types/bun/index.d.ts");
9429
- const program = ts32.createProgram([file], {
9563
+ const program = ts33.createProgram([file], {
9430
9564
  strict: true,
9431
9565
  noEmit: true,
9432
- target: ts32.ScriptTarget.ES2022,
9433
- module: ts32.ModuleKind.ESNext,
9434
- moduleResolution: ts32.ModuleResolutionKind.Bundler,
9566
+ target: ts33.ScriptTarget.ES2022,
9567
+ module: ts33.ModuleKind.ESNext,
9568
+ moduleResolution: ts33.ModuleResolutionKind.Bundler,
9435
9569
  allowImportingTsExtensions: true,
9436
9570
  skipLibCheck: true,
9437
9571
  types: [bunTypes]
9438
9572
  });
9439
- return ts32.getPreEmitDiagnostics(program).map((diagnostic) => tsDiagnostic(diagnostic));
9573
+ return ts33.getPreEmitDiagnostics(program).map((diagnostic) => tsDiagnostic(diagnostic));
9440
9574
  }
9441
9575
  export {
9442
9576
  analyze,
@@ -9444,5 +9578,5 @@ export {
9444
9578
  typeCheckOnly
9445
9579
  };
9446
9580
 
9447
- //# debugId=EE7BA4F34B7B2DD664756E2164756E21
9581
+ //# debugId=7EC924FE8B27B74364756E2164756E21
9448
9582
  //# sourceMappingURL=index.js.map