@atscript/core 0.1.88 → 0.1.90

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.mjs CHANGED
@@ -7,7 +7,7 @@ import path$1 from "path";
7
7
  import { URL } from "url";
8
8
  import { Node, printTree } from "@prostojs/parser";
9
9
  import { defu } from "defu";
10
- import { mkdir, writeFile } from "fs/promises";
10
+ import { mkdir, rename, rm, writeFile } from "fs/promises";
11
11
  import { glob } from "glob";
12
12
 
13
13
  //#region packages/core/src/parser/nodes/semantic-node.ts
@@ -18,7 +18,7 @@ function _define_property$16(obj, key, value) {
18
18
  configurable: true,
19
19
  writable: true
20
20
  });
21
- else obj[key] = value;
21
+ else obj[key] = value;
22
22
  return obj;
23
23
  }
24
24
  var SemanticNode = class {
@@ -53,9 +53,9 @@ var SemanticNode = class {
53
53
  }
54
54
  annotate(name, token) {
55
55
  if (!this.annotations) this.annotations = [];
56
- if (!this.annotationsCounter) this.annotationsCounter = new Map();
56
+ if (!this.annotationsCounter) this.annotationsCounter = /* @__PURE__ */ new Map();
57
57
  if (this.annotationsCounter.has(name)) this.annotationsCounter.set(name, this.annotationsCounter.get(name) + 1);
58
- else this.annotationsCounter.set(name, 1);
58
+ else this.annotationsCounter.set(name, 1);
59
59
  token.parentNode = this;
60
60
  const a = {
61
61
  name,
@@ -85,7 +85,7 @@ else this.annotationsCounter.set(name, 1);
85
85
  return this.token("identifier")?.text;
86
86
  }
87
87
  saveToken(token, semantic) {
88
- if (!this.tokens) this.tokens = new Map();
88
+ if (!this.tokens) this.tokens = /* @__PURE__ */ new Map();
89
89
  token.parentNode = this;
90
90
  this.tokens.set(semantic, token);
91
91
  return this;
@@ -168,12 +168,12 @@ var SemanticAnnotateNode = class extends SemanticNode {
168
168
  doc.registerExport(this);
169
169
  }
170
170
  } else if (this.token("export")) doc.registerMessage(this.token("export"), "Cannot export mutating ad-hoc annotations block");
171
- const block$2 = this.token("inner");
172
- if (block$2) {
173
- block$2.blockType = "annotate";
174
- doc.blocksIndex.add(block$2);
171
+ const block = this.token("inner");
172
+ if (block) {
173
+ block.blockType = "annotate";
174
+ doc.blocksIndex.add(block);
175
175
  }
176
- const seenEntries = new Set();
176
+ const seenEntries = /* @__PURE__ */ new Set();
177
177
  for (const entry of this.entries) {
178
178
  const entryPath = entry.hasChain ? `${entry.id}.${entry.chain.map((c) => c.text).join(".")}` : entry.id;
179
179
  if (seenEntries.has(entryPath)) {
@@ -205,8 +205,8 @@ var SemanticAnnotateNode = class extends SemanticNode {
205
205
  //#region packages/core/src/parser/nodes/array-node.ts
206
206
  var SemanticArrayNode = class extends SemanticNode {
207
207
  get props() {
208
- if (this.definition) return isStructure(this.definition) ? this.definition.props : new Map();
209
- return new Map();
208
+ if (this.definition) return isStructure(this.definition) ? this.definition.props : /* @__PURE__ */ new Map();
209
+ return /* @__PURE__ */ new Map();
210
210
  }
211
211
  constructor() {
212
212
  super("array");
@@ -234,7 +234,7 @@ function _define_property$15(obj, key, value) {
234
234
  configurable: true,
235
235
  writable: true
236
236
  });
237
- else obj[key] = value;
237
+ else obj[key] = value;
238
238
  return obj;
239
239
  }
240
240
  var SemanticGroup = class extends SemanticNode {
@@ -301,7 +301,7 @@ function _define_property$14(obj, key, value) {
301
301
  configurable: true,
302
302
  writable: true
303
303
  });
304
- else obj[key] = value;
304
+ else obj[key] = value;
305
305
  return obj;
306
306
  }
307
307
  var SemanticInterfaceNode = class extends SemanticNode {
@@ -330,8 +330,8 @@ var SemanticInterfaceNode = class extends SemanticNode {
330
330
  }
331
331
  }
332
332
  get props() {
333
- if (this.definition) return isStructure(this.definition) ? this.definition.props : new Map();
334
- return new Map();
333
+ if (this.definition) return isStructure(this.definition) ? this.definition.props : /* @__PURE__ */ new Map();
334
+ return /* @__PURE__ */ new Map();
335
335
  }
336
336
  toString(level = 0, prefix = "●") {
337
337
  let s = super.toString(level, prefix);
@@ -355,7 +355,7 @@ function _define_property$13(obj, key, value) {
355
355
  configurable: true,
356
356
  writable: true
357
357
  });
358
- else obj[key] = value;
358
+ else obj[key] = value;
359
359
  return obj;
360
360
  }
361
361
  var Token = class Token {
@@ -364,11 +364,10 @@ var Token = class Token {
364
364
  return `[${this.type}] "${this.text}"${children}`;
365
365
  }
366
366
  clone(replace) {
367
- const t = {
367
+ return new Token({
368
368
  ...this._data,
369
369
  ...replace
370
- };
371
- return new Token(t);
370
+ });
372
371
  }
373
372
  get text() {
374
373
  return this._data.text || "";
@@ -440,18 +439,18 @@ function _define_property$12(obj, key, value) {
440
439
  configurable: true,
441
440
  writable: true
442
441
  });
443
- else obj[key] = value;
442
+ else obj[key] = value;
444
443
  return obj;
445
444
  }
446
445
  var SemanticPrimitiveNode = class SemanticPrimitiveNode extends SemanticNode {
447
446
  applyAnnotations() {
448
447
  this.annotations = [];
449
448
  for (const [name, value] of Object.entries(this.config.annotations || {})) {
450
- const spec = this.annotationTree ? resolveAnnotation(name, this.annotationTree) : undefined;
449
+ const spec = this.annotationTree ? resolveAnnotation(name, this.annotationTree) : void 0;
451
450
  const isMultiple = spec?.config.multiple ?? false;
452
451
  if (Array.isArray(value)) {
453
452
  if (isMultiple) for (const item of value) this.annotations.push(toAnnotationTokens(name, item, spec));
454
- else if (value.length > 0) this.annotations.push(toAnnotationTokens(name, value[0], spec));
453
+ else if (value.length > 0) this.annotations.push(toAnnotationTokens(name, value[0], spec));
455
454
  } else this.annotations.push(toAnnotationTokens(name, value, spec));
456
455
  }
457
456
  }
@@ -460,7 +459,7 @@ else if (value.length > 0) this.annotations.push(toAnnotationTokens(name, value[
460
459
  }
461
460
  getAllTags(_processed) {
462
461
  const allTags = [this._id];
463
- const processed = _processed || new Set();
462
+ const processed = _processed || /* @__PURE__ */ new Set();
464
463
  processed.add(this);
465
464
  for (const [, node] of this.props) {
466
465
  if (processed.has(node)) continue;
@@ -483,7 +482,7 @@ else if (value.length > 0) this.annotations.push(toAnnotationTokens(name, value[
483
482
  }
484
483
  constructor(_id, config, parentKey = "", annotationTree) {
485
484
  super("primitive"), _define_property$12(this, "_id", void 0), _define_property$12(this, "config", void 0), _define_property$12(this, "parentKey", void 0), _define_property$12(this, "annotationTree", void 0), _define_property$12(this, "type", void 0), _define_property$12(this, "props", void 0), _define_property$12(this, "tags", void 0), this._id = _id, this.config = config, this.parentKey = parentKey, this.annotationTree = annotationTree;
486
- this.props = new Map();
485
+ this.props = /* @__PURE__ */ new Map();
487
486
  this.tags = new Set([_id, ...config?.tags || []]);
488
487
  for (const [ext, def] of Object.entries(config.extensions || {})) {
489
488
  const node = new SemanticPrimitiveNode(ext, {
@@ -499,7 +498,7 @@ else if (value.length > 0) this.annotations.push(toAnnotationTokens(name, value[
499
498
  this.props.set(ext, node);
500
499
  }
501
500
  if (typeof config.type === "object") this.type = config.type.kind === "final" ? config.type.value : config.type.kind;
502
- else this.type = config.type;
501
+ else this.type = config.type;
503
502
  this.applyAnnotations();
504
503
  }
505
504
  };
@@ -519,18 +518,16 @@ function toAnnotationTokens(name, value, spec) {
519
518
  token: dummyToken,
520
519
  args: [num(value)]
521
520
  };
522
- const argNames = spec?.arguments.map((a) => a.name) ?? Object.keys(value);
523
- const raw = argNames.map((argName) => {
521
+ const raw = (spec?.arguments.map((a) => a.name) ?? Object.keys(value)).map((argName) => {
524
522
  const v = value[argName];
525
- if (v === undefined) return undefined;
523
+ if (v === void 0) return;
526
524
  return typeof v === "number" ? num(v) : text$1(String(v));
527
525
  });
528
- while (raw.length > 0 && raw[raw.length - 1] === undefined) raw.pop();
529
- const args = raw.map((t) => t ?? text$1(""));
526
+ while (raw.length > 0 && raw[raw.length - 1] === void 0) raw.pop();
530
527
  return {
531
528
  name,
532
529
  token: dummyToken,
533
- args
530
+ args: raw.map((t) => t ?? text$1(""))
534
531
  };
535
532
  }
536
533
  const dummyToken = new Token({
@@ -610,7 +607,7 @@ function _define_property$11(obj, key, value) {
610
607
  configurable: true,
611
608
  writable: true
612
609
  });
613
- else obj[key] = value;
610
+ else obj[key] = value;
614
611
  return obj;
615
612
  }
616
613
  var SemanticRefNode = class extends SemanticNode {
@@ -668,27 +665,27 @@ function _define_property$10(obj, key, value) {
668
665
  configurable: true,
669
666
  writable: true
670
667
  });
671
- else obj[key] = value;
668
+ else obj[key] = value;
672
669
  return obj;
673
670
  }
674
671
  var SemanticStructureNode = class extends SemanticGroup {
675
672
  /**
676
673
  * Shortcut to set props, used as utility
677
- */ setProps(props$1) {
678
- this.nodes = props$1;
679
- for (const prop of props$1) {
674
+ */ setProps(props) {
675
+ this.nodes = props;
676
+ for (const prop of props) {
680
677
  prop.ownerNode = this;
681
678
  this.props.set(prop.id, prop);
682
679
  }
683
680
  }
684
681
  registerAtDocument(doc) {
685
- const block$2 = this.token("identifier");
686
- block$2.blockType = "structure";
687
- doc.blocksIndex.add(block$2);
682
+ const block = this.token("identifier");
683
+ block.blockType = "structure";
684
+ doc.blocksIndex.add(block);
688
685
  for (const node of this.nodes) {
689
686
  const token = node.token("identifier");
690
687
  if (!token) {
691
- doc.registerMessage(block$2, "Has empty prop node");
688
+ doc.registerMessage(block, "Has empty prop node");
692
689
  continue;
693
690
  }
694
691
  const name = token.text;
@@ -719,28 +716,28 @@ var SemanticStructureNode = class extends SemanticGroup {
719
716
  if (opts.documentation) prop.setDocumentation(opts.documentation);
720
717
  prop.saveToken(propToken, "identifier");
721
718
  if (typeof opts.type === "string") {
722
- const ref$1 = new SemanticRefNode();
719
+ const ref = new SemanticRefNode();
723
720
  const [first, ...rest] = opts.type.split(".");
724
721
  const refToken = token.clone({
725
722
  type: "identifier",
726
723
  text: first
727
724
  });
728
- ref$1.saveToken(refToken, "identifier");
725
+ ref.saveToken(refToken, "identifier");
729
726
  for (const chain of rest) {
730
727
  const chainToken = token.clone({
731
728
  type: "identifier",
732
729
  text: chain
733
730
  });
734
- ref$1.addChain(chainToken);
731
+ ref.addChain(chainToken);
735
732
  }
736
- prop.define(ref$1);
733
+ prop.define(ref);
737
734
  } else prop.define(opts.type);
738
735
  prop.ownerNode = this;
739
736
  this.nodes.push(prop);
740
737
  this.props.set(opts.name, prop);
741
738
  }
742
739
  constructor() {
743
- super(), _define_property$10(this, "props", new Map());
740
+ super(), _define_property$10(this, "props", /* @__PURE__ */ new Map());
744
741
  this.entity = "structure";
745
742
  }
746
743
  };
@@ -782,7 +779,7 @@ function _define_property$9(obj, key, value) {
782
779
  configurable: true,
783
780
  writable: true
784
781
  });
785
- else obj[key] = value;
782
+ else obj[key] = value;
786
783
  return obj;
787
784
  }
788
785
  var SemanticQueryNode = class extends SemanticNode {
@@ -904,13 +901,13 @@ function isAnnotate(node) {
904
901
  return node?.entity === "annotate";
905
902
  }
906
903
  function isQueryLogical(node) {
907
- return node?.operands !== undefined;
904
+ return node?.operands !== void 0;
908
905
  }
909
906
  function isQueryComparison(node) {
910
- return node?.left !== undefined;
907
+ return node?.left !== void 0;
911
908
  }
912
909
  function isQueryFieldRef(node) {
913
- return node?.fieldRef !== undefined;
910
+ return node?.fieldRef !== void 0;
914
911
  }
915
912
 
916
913
  //#endregion
@@ -922,7 +919,7 @@ function _define_property$8(obj, key, value) {
922
919
  configurable: true,
923
920
  writable: true
924
921
  });
925
- else obj[key] = value;
922
+ else obj[key] = value;
926
923
  return obj;
927
924
  }
928
925
  var AnnotationSpec = class {
@@ -939,14 +936,14 @@ var AnnotationSpec = class {
939
936
  return `${quote}\${${placeholderIndex}:${defaultValue}}${quote}`;
940
937
  }).join(", ");
941
938
  }
942
- validateType(tokenType, type$1) {
943
- switch (type$1) {
944
- case "string": return tokenType === "text" ? undefined : "string expected.";
945
- case "number": return tokenType === "number" ? undefined : "number expected.";
946
- case "boolean": return tokenType === "identifier" ? undefined : "boolean expected.";
947
- case "ref": return tokenType === "identifier" ? undefined : "type reference expected.";
948
- case "query": return tokenType === "query" ? undefined : "query expression expected (use backticks).";
949
- default: return `unknown type "${type$1}".`;
939
+ validateType(tokenType, type) {
940
+ switch (type) {
941
+ case "string": return tokenType === "text" ? void 0 : "string expected.";
942
+ case "number": return tokenType === "number" ? void 0 : "number expected.";
943
+ case "boolean": return tokenType === "identifier" ? void 0 : "boolean expected.";
944
+ case "ref": return tokenType === "identifier" ? void 0 : "type reference expected.";
945
+ case "query": return tokenType === "query" ? void 0 : "query expression expected (use backticks).";
946
+ default: return `unknown type "${type}".`;
950
947
  }
951
948
  }
952
949
  modify(mainToken, args, doc) {
@@ -1006,7 +1003,7 @@ var AnnotationSpec = class {
1006
1003
  range: token.range
1007
1004
  });
1008
1005
  }
1009
- return messages.length > 0 ? messages : undefined;
1006
+ return messages.length > 0 ? messages : void 0;
1010
1007
  }
1011
1008
  /**
1012
1009
  * Cross-file-dependent validation, deferred to diagnostic time
@@ -1019,20 +1016,19 @@ var AnnotationSpec = class {
1019
1016
  * diagnostics. Annotate-block entries' `defType` guard is handled separately
1020
1017
  * by `getDiagMessages` (the `referred` loop) and is skipped here.
1021
1018
  */ validateDeferred(mainToken, args, doc) {
1022
- if (!mainToken.parentNode) return undefined;
1019
+ if (!mainToken.parentNode) return;
1023
1020
  const messages = [];
1024
1021
  if (this.config.defType?.length) {
1025
1022
  const parentNode = mainToken.parentNode;
1026
- const idToken = isRef(parentNode) ? parentNode.token("identifier") : undefined;
1027
- const isAnnotateEntry = !!idToken && !!doc.annotateBlockAt(idToken.range.start.line, idToken.range.start.character);
1028
- if (!isAnnotateEntry) {
1023
+ const idToken = isRef(parentNode) ? parentNode.token("identifier") : void 0;
1024
+ if (!(!!idToken && !!doc.annotateBlockAt(idToken.range.start.line, idToken.range.start.character))) {
1029
1025
  let def = parentNode.getDefinition();
1030
1026
  if (isRef(def)) def = doc.unwindType(def.id, def.chain)?.def || def;
1031
1027
  messages.push(...this.validateTargetType(def, mainToken.range) || []);
1032
1028
  }
1033
1029
  }
1034
1030
  if (this.config.validate) messages.push(...this.config.validate(mainToken, args, doc) || []);
1035
- return messages.length > 0 ? messages : undefined;
1031
+ return messages.length > 0 ? messages : void 0;
1036
1032
  }
1037
1033
  /**
1038
1034
  * Checks an already-resolved target node against this annotation's `defType`
@@ -1042,16 +1038,15 @@ var AnnotationSpec = class {
1042
1038
  * the deferred annotate-entry check in `AtscriptDoc.getDiagMessages`, where
1043
1039
  * imported target types finally resolve.
1044
1040
  */ validateTargetType(def, range) {
1045
- if (!this.config.defType?.length) return undefined;
1041
+ if (!this.config.defType?.length) return;
1046
1042
  let defEntity = def?.entity || "unknown";
1047
1043
  if (isInterface(def) || isStructure(def)) defEntity = "object";
1048
- else if (isGroup(def) && def.entity !== "tuple") defEntity = def.op === "&" ? "intersection" : "union";
1044
+ else if (isGroup(def) && def.entity !== "tuple") defEntity = def.op === "&" ? "intersection" : "union";
1049
1045
  if (!isPrimitive(def) && !this.config.defType.includes(defEntity) || isPrimitive(def) && !this.config.defType.includes(def.type)) return [{
1050
1046
  message: `Expected type is (${this.config.defType.join(" | ")}), got "${isPrimitive(def) ? def.type : def?.entity || "unknown"}"`,
1051
1047
  severity: 1,
1052
1048
  range
1053
1049
  }];
1054
- return undefined;
1055
1050
  }
1056
1051
  renderDocs(index) {
1057
1052
  if (typeof index === "number") {
@@ -1060,13 +1055,10 @@ else if (isGroup(def) && def.entity !== "tuple") defEntity = def.op === "&" ? "i
1060
1055
  const values = a.values ? `\n\nValues:\n${a.values.join(", ")}` : "";
1061
1056
  return `### \`${a.name}${a.optional ? "?" : ""}: ${a.type}\`\n\n${a.description}${values}`;
1062
1057
  }
1063
- } else {
1064
- const args = this.arguments;
1065
- return `### ${index} ${args.map((a) => `\`${a.name}${a.optional ? "?" : ""}: ${a.type}\``).join(", ")}\n\n${this.config.description}`;
1066
- }
1058
+ } else return `### ${index} ${this.arguments.map((a) => `\`${a.name}${a.optional ? "?" : ""}: ${a.type}\``).join(", ")}\n\n${this.config.description}`;
1067
1059
  }
1068
- getDefaultValueForType(name, type$1) {
1069
- switch (type$1) {
1060
+ getDefaultValueForType(name, type) {
1061
+ switch (type) {
1070
1062
  case "string": return name;
1071
1063
  case "number": return "0";
1072
1064
  case "boolean": return "true";
@@ -1089,37 +1081,50 @@ function resolveAnnotation(name, annotationsTree) {
1089
1081
  const parts = name.split(".");
1090
1082
  let current = annotationsTree;
1091
1083
  for (const part of parts) {
1092
- if (part === "$self") return undefined;
1093
- if (!current || isAnnotationSpec(current)) return undefined;
1084
+ if (part === "$self") return;
1085
+ if (!current || isAnnotationSpec(current)) return;
1094
1086
  current = current[part];
1095
1087
  }
1096
1088
  if (isAnnotationSpec(current)) return current;
1097
1089
  if (current && !isAnnotationSpec(current) && current.$self) return current.$self;
1098
- return undefined;
1099
1090
  }
1100
1091
 
1101
1092
  //#endregion
1102
1093
  //#region packages/core/src/config/define-config.ts
1103
- function defineConfig(config) {
1094
+ /**
1095
+ * Defines the configuration for the Intertation parser
1096
+ */ function defineConfig(config) {
1104
1097
  return config;
1105
1098
  }
1106
1099
 
1107
1100
  //#endregion
1108
1101
  //#region packages/core/src/resolve-bare.ts
1109
- function isBareSpecifier(specifier) {
1102
+ /**
1103
+ * Returns true if the specifier is a bare specifier (not relative or absolute).
1104
+ * Bare specifiers: 'my-lib/user', '@org/pkg/models'
1105
+ * NOT bare: './user', '../shared', '/absolute/path'
1106
+ */ function isBareSpecifier(specifier) {
1110
1107
  return specifier[0] !== "." && specifier[0] !== "/";
1111
1108
  }
1112
- function isBareId(id) {
1109
+ /**
1110
+ * Returns true if the document ID is a bare specifier placeholder.
1111
+ */ function isBareId(id) {
1113
1112
  return id.startsWith("bare:");
1114
1113
  }
1115
- function parseBareSpecifier(specifier) {
1114
+ /**
1115
+ * Parse a bare specifier into package name and subpath.
1116
+ *
1117
+ * '@scope/pkg/sub/path' → { packageName: '@scope/pkg', subpath: './sub/path' }
1118
+ * 'pkg/sub' → { packageName: 'pkg', subpath: './sub' }
1119
+ * 'pkg' → { packageName: 'pkg', subpath: '.' }
1120
+ */ function parseBareSpecifier(specifier) {
1116
1121
  if (specifier.startsWith("@")) {
1117
- const firstSlash$1 = specifier.indexOf("/");
1118
- if (firstSlash$1 === -1) return {
1122
+ const firstSlash = specifier.indexOf("/");
1123
+ if (firstSlash === -1) return {
1119
1124
  packageName: specifier,
1120
1125
  subpath: "."
1121
1126
  };
1122
- const secondSlash = specifier.indexOf("/", firstSlash$1 + 1);
1127
+ const secondSlash = specifier.indexOf("/", firstSlash + 1);
1123
1128
  if (secondSlash === -1) return {
1124
1129
  packageName: specifier,
1125
1130
  subpath: "."
@@ -1139,8 +1144,11 @@ function parseBareSpecifier(specifier) {
1139
1144
  subpath: `./${specifier.slice(firstSlash + 1)}`
1140
1145
  };
1141
1146
  }
1142
- function resolvePackageExports(exports, subpath) {
1143
- if (!exports || typeof exports !== "object") return undefined;
1147
+ /**
1148
+ * Resolve a subpath against a package.json `exports` field using the `atscript` condition.
1149
+ * Returns the resolved file path relative to the package directory, or undefined.
1150
+ */ function resolvePackageExports(exports, subpath) {
1151
+ if (!exports || typeof exports !== "object") return;
1144
1152
  const exportsMap = exports;
1145
1153
  const subpathWithExt = subpath === "." ? "." : `${subpath}.as`;
1146
1154
  const entry = exportsMap[subpathWithExt];
@@ -1148,12 +1156,11 @@ function resolvePackageExports(exports, subpath) {
1148
1156
  for (const [pattern, value] of Object.entries(exportsMap)) {
1149
1157
  if (!pattern.includes("*")) continue;
1150
1158
  const match = matchSubpathPattern(pattern, subpathWithExt);
1151
- if (match !== undefined) {
1159
+ if (match !== void 0) {
1152
1160
  const resolved = resolveExportEntry(value);
1153
1161
  if (resolved) return resolved.replaceAll("*", match);
1154
1162
  }
1155
1163
  }
1156
- return undefined;
1157
1164
  }
1158
1165
  /**
1159
1166
  * Resolve a single export entry, checking for `atscript` condition.
@@ -1164,18 +1171,16 @@ function resolvePackageExports(exports, subpath) {
1164
1171
  if (typeof obj["atscript"] === "string") return obj["atscript"];
1165
1172
  if (typeof obj["default"] === "string") return obj["default"];
1166
1173
  }
1167
- return undefined;
1168
1174
  }
1169
1175
  /**
1170
1176
  * Match a subpath against a pattern with a single `*` wildcard.
1171
1177
  * Returns the matched wildcard portion, or undefined if no match.
1172
1178
  */ function matchSubpathPattern(pattern, subpath) {
1173
1179
  const starIdx = pattern.indexOf("*");
1174
- if (starIdx === -1) return undefined;
1180
+ if (starIdx === -1) return;
1175
1181
  const prefix = pattern.slice(0, starIdx);
1176
1182
  const suffix = pattern.slice(starIdx + 1);
1177
1183
  if (subpath.startsWith(prefix) && subpath.endsWith(suffix) && subpath.length >= prefix.length + suffix.length) return subpath.slice(prefix.length, subpath.length - suffix.length);
1178
- return undefined;
1179
1184
  }
1180
1185
  /**
1181
1186
  * Check if a file exists.
@@ -1187,11 +1192,27 @@ function resolvePackageExports(exports, subpath) {
1187
1192
  return false;
1188
1193
  }
1189
1194
  }
1190
- const resolveCache = new Map();
1191
- function clearResolveBareCache() {
1195
+ const resolveCache = /* @__PURE__ */ new Map();
1196
+ /**
1197
+ * Clear the bare specifier resolution cache.
1198
+ * Call this when node_modules may have changed (e.g., after install).
1199
+ */ function clearResolveBareCache() {
1192
1200
  resolveCache.clear();
1193
1201
  }
1194
- async function resolveBareSpecifier(specifier, fromDir) {
1202
+ /**
1203
+ * Resolve a bare specifier to an absolute file path.
1204
+ *
1205
+ * Algorithm:
1206
+ * 1. Parse specifier into packageName + subpath
1207
+ * 2. Walk up from `fromDir` looking for `node_modules/<packageName>/package.json`
1208
+ * 3. Check `exports` field for subpath with `atscript` condition
1209
+ * 4. Fallback: check if file exists at `node_modules/<pkg>/<subpath>.as`
1210
+ * 5. Resolve symlinks via `fs.realpath`
1211
+ *
1212
+ * @param specifier Bare specifier, e.g. 'my-lib/user' or '@org/pkg/models'
1213
+ * @param fromDir Absolute directory of the importing file
1214
+ * @returns Resolved absolute file path, or undefined if not found
1215
+ */ async function resolveBareSpecifier(specifier, fromDir) {
1195
1216
  const cacheKey = `${fromDir}\0${specifier}`;
1196
1217
  if (resolveCache.has(cacheKey)) return resolveCache.get(cacheKey);
1197
1218
  const result = await _resolveBareSpecifier(specifier, fromDir);
@@ -1201,7 +1222,7 @@ async function resolveBareSpecifier(specifier, fromDir) {
1201
1222
  async function _resolveBareSpecifier(specifier, fromDir) {
1202
1223
  const { packageName, subpath } = parseBareSpecifier(specifier);
1203
1224
  let dir = fromDir;
1204
- const root$1 = path.parse(dir).root;
1225
+ const root = path.parse(dir).root;
1205
1226
  while (true) {
1206
1227
  const pkgDir = path.join(dir, "node_modules", packageName);
1207
1228
  const pkgJsonPath = path.join(pkgDir, "package.json");
@@ -1220,10 +1241,9 @@ async function _resolveBareSpecifier(specifier, fromDir) {
1220
1241
  if (await fileExists(directPath)) return resolveRealPath(directPath);
1221
1242
  }
1222
1243
  const parentDir = path.dirname(dir);
1223
- if (parentDir === dir || dir === root$1) break;
1244
+ if (parentDir === dir || dir === root) break;
1224
1245
  dir = parentDir;
1225
1246
  }
1226
- return undefined;
1227
1247
  }
1228
1248
  /**
1229
1249
  * Resolve symlinks to get the canonical path (important for pnpm).
@@ -1255,8 +1275,7 @@ function getRelPath(fromUri, toUri) {
1255
1275
  const toPath = new URL(toUri).pathname;
1256
1276
  const relPath = path$1.relative(path$1.dirname(fromPath), toPath);
1257
1277
  const { dir, name } = path$1.parse(relPath);
1258
- const prefix = dir.startsWith("..") ? "" : "./";
1259
- return `${prefix}${dir ? `${dir}/` : ""}${name}`;
1278
+ return `${dir.startsWith("..") ? "" : "./"}${dir ? `${dir}/` : ""}${name}`;
1260
1279
  }
1261
1280
 
1262
1281
  //#endregion
@@ -1284,9 +1303,8 @@ async function bundleTsConfig(configFile, forceFormat) {
1284
1303
  transform: {
1285
1304
  filter: { id: /\.[cm]?[jt]s$/u },
1286
1305
  handler(code, id) {
1287
- const injectValues = `const ${dirnameVarName} = ${JSON.stringify(path.dirname(id))};` + `const ${filenameVarName} = ${JSON.stringify(id)};` + `const ${importMetaUrlVarName} = ${JSON.stringify(pathToFileURL(id).href)};`;
1288
1306
  return {
1289
- code: injectValues + code,
1307
+ code: `const ${dirnameVarName} = ${JSON.stringify(path.dirname(id))};const ${filenameVarName} = ${JSON.stringify(id)};const ${importMetaUrlVarName} = ${JSON.stringify(pathToFileURL(id).href)};` + code,
1290
1308
  map: null
1291
1309
  };
1292
1310
  }
@@ -1294,13 +1312,12 @@ async function bundleTsConfig(configFile, forceFormat) {
1294
1312
  }]
1295
1313
  });
1296
1314
  const outputDir = path.dirname(configFile);
1297
- const result = await bundle.write({
1315
+ const fileName = (await bundle.write({
1298
1316
  dir: outputDir,
1299
1317
  format: forceFormat || "esm",
1300
1318
  sourcemap: "inline",
1301
1319
  entryFileNames: forceFormat === "cjs" ? "atscript.config.[hash].cjs" : "atscript.config.[hash].mjs"
1302
- });
1303
- const fileName = result.output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
1320
+ })).output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
1304
1321
  return path.join(outputDir, fileName);
1305
1322
  }
1306
1323
  const SUPPORTED_JS_CONFIG_FORMATS = [
@@ -1315,11 +1332,13 @@ const SUPPORTED_TS_CONFIG_FORMATS = [
1315
1332
  ];
1316
1333
  const SUPPORTED_CONFIG_FORMATS = [...SUPPORTED_JS_CONFIG_FORMATS, ...SUPPORTED_TS_CONFIG_FORMATS];
1317
1334
  const DEFAULT_CONFIG_BASE = "atscript.config";
1318
- async function resolveConfigFile(docUri, _root) {
1335
+ /**
1336
+ * Resolves nearest config file
1337
+ */ async function resolveConfigFile(docUri, _root) {
1319
1338
  const startDir = docUri.endsWith(".as") ? path.dirname(docUri) : docUri;
1320
- const root$1 = _root || startDir;
1339
+ const root = _root || startDir;
1321
1340
  let currentDir = startDir;
1322
- const rootId = `file://${root$1}`;
1341
+ const rootId = `file://${root}`;
1323
1342
  while (true) {
1324
1343
  const candidate = await findConfigFileName(currentDir);
1325
1344
  if (candidate) return path.join(currentDir, candidate).replace(/^file:/, "");
@@ -1327,7 +1346,6 @@ async function resolveConfigFile(docUri, _root) {
1327
1346
  if (currentDir === rootId || parentDir === currentDir) break;
1328
1347
  currentDir = parentDir;
1329
1348
  }
1330
- return undefined;
1331
1349
  }
1332
1350
  async function findConfigFileName(d) {
1333
1351
  const filesInWorkingDirectory = new Set(await readdir(fileUriToPath(d)));
@@ -1359,10 +1377,8 @@ async function loadConfig(configPath, forceFormat) {
1359
1377
  /* @vite-ignore */
1360
1378
  pathToFileURL(configPath).href
1361
1379
  )).default;
1362
- else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) {
1363
- const rawConfigPath = path.resolve(configPath);
1364
- return await loadTsConfig(rawConfigPath, forceFormat);
1365
- } else throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${ext}\``);
1380
+ else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) return await loadTsConfig(path.resolve(configPath), forceFormat);
1381
+ else throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${ext}\``);
1366
1382
  } catch (error) {
1367
1383
  console.error(error);
1368
1384
  throw new Error("Error happened while loading config.");
@@ -1371,21 +1387,22 @@ else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) {
1371
1387
 
1372
1388
  //#endregion
1373
1389
  //#region packages/core/src/defaults/db-query-lsp.ts
1374
- function getQueryScope(queryArgToken, doc) {
1390
+ /**
1391
+ * Determine the allowed type scope for a query arg token
1392
+ * by reading sibling annotations on the owner node.
1393
+ */ function getQueryScope(queryArgToken, doc) {
1375
1394
  const annotationRef = queryArgToken.annotationRef;
1376
- if (!annotationRef) return undefined;
1395
+ if (!annotationRef) return;
1377
1396
  const owner = queryArgToken.parentNode;
1378
- if (!owner) return undefined;
1397
+ if (!owner) return;
1379
1398
  const annotationName = annotationRef.text.slice(1);
1380
1399
  if (annotationName === "db.view.filter") return getViewFilterScope(owner);
1381
1400
  if (annotationName === "db.view.joins") return getViewJoinsScope(owner, queryArgToken);
1382
1401
  if (annotationName === "db.rel.filter") return getRelFilterScope(owner);
1383
- return undefined;
1384
1402
  }
1385
1403
  function getViewFilterScope(owner) {
1386
- const forAnnotations = owner.annotations?.filter((a) => a.name === "db.view.for");
1387
- const entryTypeName = forAnnotations?.[0]?.args[0]?.text;
1388
- if (!entryTypeName) return undefined;
1404
+ const entryTypeName = (owner.annotations?.filter((a) => a.name === "db.view.for"))?.[0]?.args[0]?.text;
1405
+ if (!entryTypeName) return;
1389
1406
  const allowedTypes = [entryTypeName];
1390
1407
  const joinsAnnotations = owner.annotations?.filter((a) => a.name === "db.view.joins");
1391
1408
  if (joinsAnnotations) {
@@ -1397,12 +1414,10 @@ function getViewFilterScope(owner) {
1397
1414
  };
1398
1415
  }
1399
1416
  function getViewJoinsScope(owner, queryArgToken) {
1400
- const forAnnotations = owner.annotations?.filter((a) => a.name === "db.view.for");
1401
- const entryTypeName = forAnnotations?.[0]?.args[0]?.text;
1402
- if (!entryTypeName) return undefined;
1403
- const joinsAnnotation = owner.annotations?.find((a) => a.name === "db.view.joins" && a.args.includes(queryArgToken));
1404
- const joinTargetName = joinsAnnotation?.args[0]?.text;
1405
- if (!joinTargetName) return undefined;
1417
+ const entryTypeName = (owner.annotations?.filter((a) => a.name === "db.view.for"))?.[0]?.args[0]?.text;
1418
+ if (!entryTypeName) return;
1419
+ const joinTargetName = (owner.annotations?.find((a) => a.name === "db.view.joins" && a.args.includes(queryArgToken)))?.args[0]?.text;
1420
+ if (!joinTargetName) return;
1406
1421
  return {
1407
1422
  allowedTypes: [joinTargetName, entryTypeName],
1408
1423
  unqualifiedTarget: entryTypeName
@@ -1411,7 +1426,7 @@ function getViewJoinsScope(owner, queryArgToken) {
1411
1426
  function getRelFilterScope(owner) {
1412
1427
  let def = owner.getDefinition();
1413
1428
  if (isArray(def)) def = def?.getDefinition();
1414
- if (!isRef(def)) return undefined;
1429
+ if (!isRef(def)) return;
1415
1430
  const targetTypeName = def.id;
1416
1431
  const allowedTypes = [targetTypeName];
1417
1432
  const viaAnnotation = owner.annotations?.find((a) => a.name === "db.rel.via");
@@ -1421,16 +1436,17 @@ function getRelFilterScope(owner) {
1421
1436
  unqualifiedTarget: targetTypeName
1422
1437
  };
1423
1438
  }
1424
- function resolveQueryFieldRef(fieldRefNode, doc, scope) {
1439
+ /**
1440
+ * Resolve a query field ref node to a property definition.
1441
+ */ function resolveQueryFieldRef(fieldRefNode, doc, scope) {
1425
1442
  const typeName = fieldRefNode.typeRef?.text ?? scope.unqualifiedTarget;
1426
- if (!typeName) return undefined;
1427
- const fieldPath = fieldRefNode.fieldRef.text;
1428
- const chain = fieldPath.split(".");
1443
+ if (!typeName) return;
1444
+ const chain = fieldRefNode.fieldRef.text.split(".");
1429
1445
  const parentChain = chain.slice(0, -1);
1430
1446
  const parentUnwound = doc.unwindType(typeName, parentChain);
1431
- if (!parentUnwound?.def) return undefined;
1447
+ if (!parentUnwound?.def) return;
1432
1448
  const unwound = doc.unwindType(typeName, chain);
1433
- if (!unwound?.node) return undefined;
1449
+ if (!unwound?.node) return;
1434
1450
  const prop = unwound.node;
1435
1451
  return {
1436
1452
  targetUri: parentUnwound.doc.id,
@@ -1438,21 +1454,21 @@ function resolveQueryFieldRef(fieldRefNode, doc, scope) {
1438
1454
  prop
1439
1455
  };
1440
1456
  }
1441
- function getFieldsForType(doc, typeName) {
1457
+ /**
1458
+ * Get fields available for a type (resolving extends/intersections).
1459
+ */ function getFieldsForType(doc, typeName) {
1442
1460
  const unwound = doc.unwindType(typeName);
1443
1461
  if (!unwound?.def) return [];
1444
1462
  let def = doc.mergeIntersection(unwound.def);
1445
- if (isInterface(def)) {
1446
- const resolved = doc.resolveInterfaceExtends(def);
1447
- if (resolved) def = resolved;
1448
- else def = def.getDefinition() || def;
1449
- }
1463
+ if (isInterface(def)) def = doc.resolveInterfaceExtends(def) || def.getDefinition() || def;
1450
1464
  if (isStructure(def) || isInterface(def)) return Array.from(def.props.values());
1451
1465
  return [];
1452
1466
  }
1453
- function getQueryCompletionScope(queryArgToken, doc) {
1467
+ /**
1468
+ * Get completion scope data for a query context.
1469
+ */ function getQueryCompletionScope(queryArgToken, doc) {
1454
1470
  const scope = getQueryScope(queryArgToken, doc);
1455
- if (!scope) return undefined;
1471
+ if (!scope) return;
1456
1472
  return {
1457
1473
  typeNames: scope.allowedTypes,
1458
1474
  unqualifiedTarget: scope.unqualifiedTarget,
@@ -1483,7 +1499,12 @@ const VALUE_KEYWORDS$1 = new Set([
1483
1499
  "null",
1484
1500
  "undefined"
1485
1501
  ]);
1486
- function analyzeQueryCursorContext(textBeforeCursor) {
1502
+ /**
1503
+ * Analyze text inside backticks up to cursor position
1504
+ * to determine what kind of completions to offer.
1505
+ * Uses lightweight text scanning, not full AST parsing,
1506
+ * so it works on incomplete/mid-typing input.
1507
+ */ function analyzeQueryCursorContext(textBeforeCursor) {
1487
1508
  const trimmed = textBeforeCursor.trimEnd();
1488
1509
  const hasTrailingSpace = textBeforeCursor.length > trimmed.length;
1489
1510
  if (trimmed.length === 0) return { type: "field-start" };
@@ -1496,17 +1517,17 @@ function analyzeQueryCursorContext(textBeforeCursor) {
1496
1517
  };
1497
1518
  return { type: "field-start" };
1498
1519
  }
1499
- const tokens$1 = tokenizeQueryText(trimmed);
1500
- if (tokens$1.length === 0) return { type: "field-start" };
1501
- const last = tokens$1[tokens$1.length - 1];
1520
+ const tokens = tokenizeQueryText(trimmed);
1521
+ if (tokens.length === 0) return { type: "field-start" };
1522
+ const last = tokens[tokens.length - 1];
1502
1523
  if (LOGICAL_KEYWORDS.has(last) || last === "(") return { type: "field-start" };
1503
1524
  if (SYMBOLIC_OPS$1.has(last)) return { type: "after-operator" };
1504
1525
  if (last === "in" || last === "matches") return { type: "after-operator" };
1505
1526
  if (last === "exists") return { type: "after-comparison" };
1506
1527
  if (VALUE_KEYWORDS$1.has(last)) return { type: "after-comparison" };
1507
1528
  if (/^['"]/.test(last) || /^\d/.test(last)) return { type: "after-comparison" };
1508
- if (tokens$1.length >= 2) {
1509
- const prev = tokens$1[tokens$1.length - 2];
1529
+ if (tokens.length >= 2) {
1530
+ const prev = tokens[tokens.length - 2];
1510
1531
  if (SYMBOLIC_OPS$1.has(prev) || KEYWORD_OPS.has(prev)) return { type: "after-comparison" };
1511
1532
  }
1512
1533
  if (/^\w+$/u.test(last)) {
@@ -1518,53 +1539,53 @@ function analyzeQueryCursorContext(textBeforeCursor) {
1518
1539
  /**
1519
1540
  * Simple tokenizer for query text — splits into identifiers, operators, and punctuation.
1520
1541
  * Does NOT need to handle all edge cases; just enough for cursor context analysis.
1521
- */ function tokenizeQueryText(text$2) {
1522
- const tokens$1 = [];
1542
+ */ function tokenizeQueryText(text) {
1543
+ const tokens = [];
1523
1544
  let i = 0;
1524
- while (i < text$2.length) {
1525
- if (/\s/.test(text$2[i])) {
1545
+ while (i < text.length) {
1546
+ if (/\s/.test(text[i])) {
1526
1547
  i++;
1527
1548
  continue;
1528
1549
  }
1529
- if (text$2[i] === "'" || text$2[i] === "\"") {
1530
- const quote = text$2[i];
1550
+ if (text[i] === "'" || text[i] === "\"") {
1551
+ const quote = text[i];
1531
1552
  let j = i + 1;
1532
- while (j < text$2.length && text$2[j] !== quote) {
1533
- if (text$2[j] === "\\") j++;
1553
+ while (j < text.length && text[j] !== quote) {
1554
+ if (text[j] === "\\") j++;
1534
1555
  j++;
1535
1556
  }
1536
- tokens$1.push(text$2.slice(i, j + 1));
1557
+ tokens.push(text.slice(i, j + 1));
1537
1558
  i = j + 1;
1538
1559
  continue;
1539
1560
  }
1540
- if (i + 1 < text$2.length) {
1541
- const two = text$2.slice(i, i + 2);
1561
+ if (i + 1 < text.length) {
1562
+ const two = text.slice(i, i + 2);
1542
1563
  if (two === "!=" || two === ">=" || two === "<=") {
1543
- tokens$1.push(two);
1564
+ tokens.push(two);
1544
1565
  i += 2;
1545
1566
  continue;
1546
1567
  }
1547
1568
  }
1548
- if ("=><(),".includes(text$2[i])) {
1549
- tokens$1.push(text$2[i]);
1569
+ if ("=><(),".includes(text[i])) {
1570
+ tokens.push(text[i]);
1550
1571
  i++;
1551
1572
  continue;
1552
1573
  }
1553
- if (text$2[i] === ".") {
1554
- tokens$1.push(".");
1574
+ if (text[i] === ".") {
1575
+ tokens.push(".");
1555
1576
  i++;
1556
1577
  continue;
1557
1578
  }
1558
- if (/[\w]/u.test(text$2[i])) {
1579
+ if (/[\w]/u.test(text[i])) {
1559
1580
  let j = i;
1560
- while (j < text$2.length && /[\w]/u.test(text$2[j])) j++;
1561
- tokens$1.push(text$2.slice(i, j));
1581
+ while (j < text.length && /[\w]/u.test(text[j])) j++;
1582
+ tokens.push(text.slice(i, j));
1562
1583
  i = j;
1563
1584
  continue;
1564
1585
  }
1565
1586
  i++;
1566
1587
  }
1567
- return tokens$1;
1588
+ return tokens;
1568
1589
  }
1569
1590
 
1570
1591
  //#endregion
@@ -1576,7 +1597,7 @@ function _define_property$7(obj, key, value) {
1576
1597
  configurable: true,
1577
1598
  writable: true
1578
1599
  });
1579
- else obj[key] = value;
1600
+ else obj[key] = value;
1580
1601
  return obj;
1581
1602
  }
1582
1603
  var IdRegistry = class {
@@ -1588,12 +1609,12 @@ var IdRegistry = class {
1588
1609
  registerDefinition(token) {
1589
1610
  if (!token) return;
1590
1611
  if (this.reserved.has(token.text)) this.forbidden.add(token);
1591
- else if (this.definitions.has(token.text)) this.duplicates.add(token);
1592
- else this.definitions.set(token.text, token);
1612
+ else if (this.definitions.has(token.text)) this.duplicates.add(token);
1613
+ else this.definitions.set(token.text, token);
1593
1614
  }
1594
1615
  isDefined(t) {
1595
- const text$2 = typeof t === "string" ? t : t.text;
1596
- return this.definitions.has(text$2) || this.globalTypes.has(text$2);
1616
+ const text = typeof t === "string" ? t : t.text;
1617
+ return this.definitions.has(text) || this.globalTypes.has(text);
1597
1618
  }
1598
1619
  getErrors() {
1599
1620
  return [...Array.from(this.duplicates, (t) => ({
@@ -1609,9 +1630,9 @@ else this.definitions.set(token.text, token);
1609
1630
  constructor(globalTypes = []) {
1610
1631
  _define_property$7(this, "reserved", void 0);
1611
1632
  _define_property$7(this, "globalTypes", void 0);
1612
- _define_property$7(this, "definitions", new Map());
1613
- _define_property$7(this, "duplicates", new Set());
1614
- _define_property$7(this, "forbidden", new Set());
1633
+ _define_property$7(this, "definitions", /* @__PURE__ */ new Map());
1634
+ _define_property$7(this, "duplicates", /* @__PURE__ */ new Set());
1635
+ _define_property$7(this, "forbidden", /* @__PURE__ */ new Set());
1615
1636
  this.reserved = new Set([
1616
1637
  "interface",
1617
1638
  "type",
@@ -1634,7 +1655,7 @@ function _define_property$6(obj, key, value) {
1634
1655
  configurable: true,
1635
1656
  writable: true
1636
1657
  });
1637
- else obj[key] = value;
1658
+ else obj[key] = value;
1638
1659
  return obj;
1639
1660
  }
1640
1661
  var NodeIterator = class NodeIterator {
@@ -1675,14 +1696,14 @@ var NodeIterator = class NodeIterator {
1675
1696
  fork(nodes) {
1676
1697
  return new NodeIterator(nodes || this.nodes, this.messages, this.badNodes, this.issues, nodes ? this.$ : this.parent, nodes ? 0 : this.i).update();
1677
1698
  }
1678
- skip(pun$1) {
1679
- while (this.$?.type === "comment" || this.$?.type === "punctuation" && pun$1?.length && pun$1.includes(this.$.text)) this.move();
1699
+ skip(pun) {
1700
+ while (this.$?.type === "comment" || this.$?.type === "punctuation" && pun?.length && pun.includes(this.$.text)) this.move();
1680
1701
  return this;
1681
1702
  }
1682
- skipUntil(pun$1) {
1703
+ skipUntil(pun) {
1683
1704
  while (this.$ && !this.satisfies({
1684
1705
  node: "punctuation",
1685
- text: pun$1
1706
+ text: pun
1686
1707
  })) this.move();
1687
1708
  }
1688
1709
  unexpected(force = false, msg = "Unexpected token") {
@@ -1698,15 +1719,14 @@ var NodeIterator = class NodeIterator {
1698
1719
  satisfies(...rules) {
1699
1720
  for (const rule of rules) {
1700
1721
  const passed = Array.isArray(rule.node) ? rule.node.includes(this.$?.type) : this.$?.type === rule.node;
1701
- if (passed && rule.text === undefined) return true;
1722
+ if (passed && rule.text === void 0) return true;
1702
1723
  if (passed && Array.isArray(rule.text) ? rule.text.includes(this.$?.text) : this.$?.text === rule.text) return true;
1703
1724
  }
1704
1725
  return false;
1705
1726
  }
1706
1727
  confirmIssues() {
1707
1728
  if (this.issues.unexpectedEOB) {
1708
- const node = this.lastNode || this.parent;
1709
- const pos = node?.getRange().end || {
1729
+ const pos = (this.lastNode || this.parent)?.getRange().end || {
1710
1730
  character: 1,
1711
1731
  line: 1
1712
1732
  };
@@ -1740,7 +1760,7 @@ var NodeIterator = class NodeIterator {
1740
1760
  }
1741
1761
  })).concat(this.messages);
1742
1762
  }
1743
- constructor(nodes, messages = [], badNodes = new Map(), issues = {}, parent, i = -1) {
1763
+ constructor(nodes, messages = [], badNodes = /* @__PURE__ */ new Map(), issues = {}, parent, i = -1) {
1744
1764
  _define_property$6(this, "nodes", void 0);
1745
1765
  _define_property$6(this, "messages", void 0);
1746
1766
  _define_property$6(this, "badNodes", void 0);
@@ -1759,7 +1779,9 @@ var NodeIterator = class NodeIterator {
1759
1779
 
1760
1780
  //#endregion
1761
1781
  //#region packages/core/src/tokenizer/tokens/a-identifier.token.ts
1762
- const AIdentifierToken = new Node({
1782
+ /**
1783
+ * Annotation (@) Identifier node
1784
+ */ const AIdentifierToken = new Node({
1763
1785
  name: "annotation",
1764
1786
  start: { token: RegExp("@[\\p{ID_Continue}$.]*", "u") },
1765
1787
  end: {
@@ -1781,7 +1803,9 @@ const pairs = {
1781
1803
  "(": ")",
1782
1804
  "[": "]"
1783
1805
  };
1784
- const BlockToken = new Node({
1806
+ /**
1807
+ * Block node
1808
+ */ const BlockToken = new Node({
1785
1809
  name: "block",
1786
1810
  start: {
1787
1811
  token: RegExp("(?<text>[([{])", "u"),
@@ -1835,7 +1859,9 @@ const block$1 = new Node({
1835
1859
  },
1836
1860
  mapContent: "text"
1837
1861
  });
1838
- const commentNodes = {
1862
+ /**
1863
+ * Block and inline comments
1864
+ */ const commentNodes = {
1839
1865
  inline,
1840
1866
  block: block$1,
1841
1867
  all: [inline, block$1]
@@ -1843,7 +1869,9 @@ const commentNodes = {
1843
1869
 
1844
1870
  //#endregion
1845
1871
  //#region packages/core/src/tokenizer/tokens/identifier.token.ts
1846
- const IdentifierToken = new Node({
1872
+ /**
1873
+ * Identifier node
1874
+ */ const IdentifierToken = new Node({
1847
1875
  name: "identifier",
1848
1876
  start: { token: RegExp("[\\p{ID_Start}$_][\\p{ID_Continue}$]*", "u") },
1849
1877
  end: {
@@ -1860,7 +1888,9 @@ const IdentifierToken = new Node({
1860
1888
 
1861
1889
  //#endregion
1862
1890
  //#region packages/core/src/tokenizer/tokens/number.token.ts
1863
- const NumberToken = new Node({
1891
+ /**
1892
+ * Number node
1893
+ */ const NumberToken = new Node({
1864
1894
  name: "number",
1865
1895
  start: { token: /[-+]?(?:\d*\.\d+|\d+)(?:[eE][-+]?\d+)?/u },
1866
1896
  end: {
@@ -1877,7 +1907,9 @@ const NumberToken = new Node({
1877
1907
 
1878
1908
  //#endregion
1879
1909
  //#region packages/core/src/tokenizer/tokens/punctuation.token.ts
1880
- const PunctuationToken = new Node({
1910
+ /**
1911
+ * Punctuation node
1912
+ */ const PunctuationToken = new Node({
1881
1913
  name: "punctuation",
1882
1914
  start: {
1883
1915
  token: RegExp("(?<text>[\\n!&+,./:;=?|])", "u"),
@@ -1894,9 +1926,47 @@ const PunctuationToken = new Node({
1894
1926
  }
1895
1927
  });
1896
1928
 
1929
+ //#endregion
1930
+ //#region packages/core/src/tokenizer/tokens/query-block.token.ts
1931
+ /**
1932
+ * Query block node — parenthesized sub-expressions inside backtick queries.
1933
+ *
1934
+ * Produces exactly the same token shape as `BlockToken` (`type: 'block'`,
1935
+ * `text: '('`) so every consumer keeps working, but it recognizes
1936
+ * `QueryOperatorToken` inside, which makes `!=`, `>=`, `<=`, `>`, `<`
1937
+ * work within parentheses (the generic block only knows `PunctuationToken`,
1938
+ * whose charset has no `<` / `>`).
1939
+ *
1940
+ * Only registered inside `QueryToken` (and itself, for nested parens) —
1941
+ * the generic `BlockToken` is left untouched so tokenization of `(`/`[`/`{`
1942
+ * outside queries does not change.
1943
+ */ const QueryBlockToken = new Node({
1944
+ name: "block",
1945
+ start: {
1946
+ token: RegExp("(?<text>\\()", "u"),
1947
+ omit: true
1948
+ },
1949
+ end: {
1950
+ token: ")",
1951
+ omit: true
1952
+ },
1953
+ skip: /\s/u,
1954
+ eofClose: true,
1955
+ data: {
1956
+ type: "block",
1957
+ text: ""
1958
+ }
1959
+ });
1960
+
1897
1961
  //#endregion
1898
1962
  //#region packages/core/src/tokenizer/tokens/query-operator.token.ts
1899
- const QueryOperatorToken = new Node({
1963
+ /**
1964
+ * Query operator token — matches symbolic comparison operators
1965
+ * inside backtick-delimited query expressions.
1966
+ *
1967
+ * Multi-character operators (!=, >=, <=) are matched as single tokens.
1968
+ * Only recognized inside QueryToken — not in root or BlockToken.
1969
+ */ const QueryOperatorToken = new Node({
1900
1970
  name: "punctuation",
1901
1971
  start: {
1902
1972
  token: RegExp("(?<text>!=|>=|<=|[=><])", "u"),
@@ -1915,7 +1985,10 @@ const QueryOperatorToken = new Node({
1915
1985
 
1916
1986
  //#endregion
1917
1987
  //#region packages/core/src/tokenizer/tokens/query.token.ts
1918
- const QueryToken = new Node({
1988
+ /**
1989
+ * Query node — backtick-delimited filter expressions
1990
+ * Content inside backticks is tokenized into children.
1991
+ */ const QueryToken = new Node({
1919
1992
  name: "query",
1920
1993
  start: {
1921
1994
  token: /`/u,
@@ -1936,7 +2009,11 @@ const QueryToken = new Node({
1936
2009
  //#endregion
1937
2010
  //#region packages/core/src/tokenizer/tokens/regexp.token.ts
1938
2011
  const REGEXP_LITERAL_RE = /\/(?![/*])(?:\\.|\[.*?]|[^/\\\n\r[])*\/[dgimsuy]*/;
1939
- const RegExpToken = new Node({
2012
+ /**
2013
+ * RegExp literal – `/pattern/flags`
2014
+ * • Starts with `/` but *not* `//` or `/*`
2015
+ * • Ends with `/` followed by zero-or-more valid flags
2016
+ */ const RegExpToken = new Node({
1940
2017
  name: "regexp",
1941
2018
  start: {
1942
2019
  token: REGEXP_LITERAL_RE,
@@ -1957,7 +2034,9 @@ const RegExpToken = new Node({
1957
2034
 
1958
2035
  //#endregion
1959
2036
  //#region packages/core/src/tokenizer/tokens/text.node.ts
1960
- const TextToken = new Node({
2037
+ /**
2038
+ * Text node single or doublequoted
2039
+ */ const TextToken = new Node({
1961
2040
  name: "text",
1962
2041
  start: {
1963
2042
  token: RegExp("(?<quote>[\"'])", "u"),
@@ -1994,7 +2073,8 @@ const tokens = {
1994
2073
  text: TextToken,
1995
2074
  regexp: RegExpToken,
1996
2075
  query: QueryToken,
1997
- root: undefined
2076
+ queryBlock: QueryBlockToken,
2077
+ root: void 0
1998
2078
  };
1999
2079
  const root = new Node({
2000
2080
  name: "root",
@@ -2013,13 +2093,38 @@ const root = new Node({
2013
2093
  });
2014
2094
  tokens.root = root;
2015
2095
  BlockToken.recognize(RegExpToken, ...commentNodes.all, BlockToken, QueryToken, AIdentifierToken, IdentifierToken, TextToken, NumberToken, PunctuationToken);
2016
- QueryToken.recognize(RegExpToken, QueryOperatorToken, BlockToken, IdentifierToken, TextToken, NumberToken, PunctuationToken);
2017
- function extractTokens(node) {
2018
- return node.content.map((item) => {
2019
- if (typeof item === "string") return {
2020
- type: "unknown",
2021
- text: item
2022
- };
2096
+ QueryToken.recognize(RegExpToken, QueryOperatorToken, QueryBlockToken, BlockToken, IdentifierToken, TextToken, NumberToken, PunctuationToken);
2097
+ QueryBlockToken.recognize(RegExpToken, QueryOperatorToken, QueryBlockToken, IdentifierToken, TextToken, NumberToken, PunctuationToken);
2098
+ /**
2099
+ * Recursively extract TLexicalToken[] from a ParsedNode tree.
2100
+ * Replaces the v0.5 mapContent('children', callback) + global loop.
2101
+ *
2102
+ * v0.6 Position has { offset, line, column }.
2103
+ * line is 1-based, column is 1-based.
2104
+ * VSCode expects 0-based line, 0-based character.
2105
+ */ function extractTokens(node) {
2106
+ const content = node.content;
2107
+ return content.map((item, index) => {
2108
+ if (typeof item === "string") {
2109
+ const prev = content[index - 1];
2110
+ const next = content[index + 1];
2111
+ const start = typeof prev === "object" ? prev.end : node.start;
2112
+ const end = typeof next === "object" ? next.start : node.end;
2113
+ return {
2114
+ type: "unknown",
2115
+ text: item,
2116
+ getRange: () => ({
2117
+ start: {
2118
+ line: start.line - 1,
2119
+ character: start.column - 1
2120
+ },
2121
+ end: {
2122
+ line: end.line - 1,
2123
+ character: end.column - 1
2124
+ }
2125
+ })
2126
+ };
2127
+ }
2023
2128
  const data = item.data;
2024
2129
  data.getRange = () => ({
2025
2130
  start: {
@@ -2046,23 +2151,23 @@ function tokenize(source, debug = false) {
2046
2151
 
2047
2152
  //#endregion
2048
2153
  //#region packages/core/src/parser/pipes/tokens.pipe.ts
2049
- const identifier = (...text$2) => $token("identifier", text$2.length > 0 ? text$2 : undefined);
2050
- const text = (...text$2) => $token("text", text$2.length > 0 ? text$2 : undefined);
2051
- const block = (...text$2) => $token("block", text$2.length > 0 ? text$2.map((v) => v[0]) : undefined);
2052
- const pun = (...text$2) => $token("punctuation", text$2.length > 0 ? text$2 : undefined);
2053
- function $token(name, text$2) {
2154
+ const identifier = (...text) => $token("identifier", text.length > 0 ? text : void 0);
2155
+ const text = (...text) => $token("text", text.length > 0 ? text : void 0);
2156
+ const block = (...text) => $token("block", text.length > 0 ? text.map((v) => v[0]) : void 0);
2157
+ const pun = (...text) => $token("punctuation", text.length > 0 ? text : void 0);
2158
+ function $token(name, text) {
2054
2159
  const opts = {
2055
2160
  optional: false,
2056
- saveAs: undefined,
2057
- skip: undefined,
2161
+ saveAs: void 0,
2162
+ skip: void 0,
2058
2163
  expect: [{
2059
2164
  node: name,
2060
- text: text$2
2165
+ text
2061
2166
  }],
2062
- contains: undefined,
2167
+ contains: void 0,
2063
2168
  isGlobal: false,
2064
2169
  empty: false,
2065
- wrapper: undefined,
2170
+ wrapper: void 0,
2066
2171
  wrapMultiple: false,
2067
2172
  debug: false,
2068
2173
  eob: false,
@@ -2072,7 +2177,7 @@ function $token(name, text$2) {
2072
2177
  return {
2073
2178
  expect: [{
2074
2179
  node: name,
2075
- text: text$2
2180
+ text
2076
2181
  }],
2077
2182
  handler(ni, target) {
2078
2183
  if (opts.debug) debugger;
@@ -2113,7 +2218,7 @@ function $token(name, text$2) {
2113
2218
  ni.move();
2114
2219
  if (opts.skip) ni.skip(opts.skip);
2115
2220
  if (opts.wrapMultiple) continue;
2116
- else return true;
2221
+ else return true;
2117
2222
  } else {
2118
2223
  if (!opts.optional) ni.unexpected();
2119
2224
  return opts.optional;
@@ -2198,7 +2303,7 @@ function $pipe(entity, pipe = []) {
2198
2303
  pipe,
2199
2304
  toString: () => entity,
2200
2305
  skipTokens: [],
2201
- stopCondition: undefined,
2306
+ stopCondition: void 0,
2202
2307
  skip(...s) {
2203
2308
  this.skipTokens.push(...s);
2204
2309
  return this;
@@ -2213,12 +2318,12 @@ function $pipe(entity, pipe = []) {
2213
2318
  }
2214
2319
  };
2215
2320
  }
2216
- function runPipes(pipes$1, ni, singlePass = false) {
2321
+ function runPipes(pipes, ni, singlePass = false) {
2217
2322
  const nodes = [];
2218
2323
  while (ni.$) {
2219
2324
  let matched = true;
2220
2325
  let depth = ni.index;
2221
- for (const { targetFactory, pipe, skipTokens: skip, stopCondition } of pipes$1) {
2326
+ for (const { targetFactory, pipe, skipTokens: skip, stopCondition } of pipes) {
2222
2327
  const target = { node: targetFactory() };
2223
2328
  const fork = ni.fork();
2224
2329
  fork.skip(skip);
@@ -2253,15 +2358,15 @@ function runPipes(pipes$1, ni, singlePass = false) {
2253
2358
  }
2254
2359
  return nodes;
2255
2360
  }
2256
- function runPipesOnce(pipes$1, ni) {
2257
- return runPipes(pipes$1, ni, true)[0];
2361
+ function runPipesOnce(pipes, ni) {
2362
+ return runPipes(pipes, ni, true)[0];
2258
2363
  }
2259
2364
 
2260
2365
  //#endregion
2261
2366
  //#region packages/core/src/parser/grouping.ts
2262
2367
  function groupByPriority(nodes, priority) {
2263
2368
  if (nodes.length === 1) return nodes[0];
2264
- if (nodes.length === 0) return undefined;
2369
+ if (nodes.length === 0) return;
2265
2370
  if (nodes.length % 2 === 0) throw new Error(`Invalid number of nodes ${nodes.length}. Odd number expected`);
2266
2371
  let currentPass = nodes;
2267
2372
  let temporaryResult = [];
@@ -2270,7 +2375,7 @@ function groupByPriority(nodes, priority) {
2270
2375
  for (const [i, node] of currentPass.entries()) {
2271
2376
  const isOperator = i % 2 === 1;
2272
2377
  if (!isOperator && node instanceof Token) throw new Error(`Unexpected token ${node.toString()} at ${i}`);
2273
- else if (isOperator && !(node instanceof Token)) throw new Error(`Unexpected token ${isGroup(node) ? node.op : node.token.toString()} at ${i}`);
2378
+ else if (isOperator && !(node instanceof Token)) throw new Error(`Unexpected token ${isGroup(node) ? node.op : node.token.toString()} at ${i}`);
2274
2379
  if (isOperator) {
2275
2380
  if (node.text !== p) temporaryResult.push(node);
2276
2381
  continue;
@@ -2312,40 +2417,34 @@ const VALUE_KEYWORDS = new Set([
2312
2417
  "null",
2313
2418
  "undefined"
2314
2419
  ]);
2315
- function parseQueryExpression(children, messages, sourceToken) {
2316
- if (children.length === 0) return undefined;
2420
+ /**
2421
+ * Parse a backtick-delimited query expression from its child tokens.
2422
+ * Returns a SemanticQueryNode or undefined if the content is empty.
2423
+ */ function parseQueryExpression(children, messages, sourceToken) {
2424
+ if (children.length === 0) return;
2425
+ const ctx = {
2426
+ messages,
2427
+ fallback: sourceToken.range
2428
+ };
2317
2429
  const ni = new NodeIterator(children, messages);
2318
2430
  ni.move();
2319
- const expr = parseOrExpr(ni, messages);
2320
- if (!expr) return undefined;
2321
- if (ni.$) messages.push({
2322
- severity: 1,
2323
- message: `Unexpected token in query expression: "${ni.$.text}"`,
2324
- range: ni.$.getRange?.() ?? {
2325
- start: {
2326
- line: 0,
2327
- character: 0
2328
- },
2329
- end: {
2330
- line: 0,
2331
- character: 0
2332
- }
2333
- }
2334
- });
2431
+ const expr = parseOrExpr(ni, ctx);
2432
+ if (!expr) return;
2433
+ if (ni.$) pushError(ni, ctx, `Unexpected token in query expression: "${ni.$.text}"`);
2335
2434
  const node = new SemanticQueryNode();
2336
2435
  node.expression = expr;
2337
2436
  node.sourceToken = sourceToken;
2338
2437
  return node;
2339
2438
  }
2340
- function parseOrExpr(ni, messages) {
2341
- const left = parseAndExpr(ni, messages);
2342
- if (!left) return undefined;
2439
+ function parseOrExpr(ni, ctx) {
2440
+ const left = parseAndExpr(ni, ctx);
2441
+ if (!left) return;
2343
2442
  const operands = [left];
2344
2443
  while (ni.$?.type === "identifier" && ni.$.text === "or") {
2345
2444
  ni.move();
2346
- const right = parseAndExpr(ni, messages);
2445
+ const right = parseAndExpr(ni, ctx);
2347
2446
  if (!right) {
2348
- pushError(ni, messages, "Expected expression after \"or\"");
2447
+ pushError(ni, ctx, "Expected expression after \"or\"");
2349
2448
  break;
2350
2449
  }
2351
2450
  operands.push(right);
@@ -2356,15 +2455,15 @@ function parseOrExpr(ni, messages) {
2356
2455
  node.operands = operands;
2357
2456
  return node;
2358
2457
  }
2359
- function parseAndExpr(ni, messages) {
2360
- const left = parseUnaryExpr(ni, messages);
2361
- if (!left) return undefined;
2458
+ function parseAndExpr(ni, ctx) {
2459
+ const left = parseUnaryExpr(ni, ctx);
2460
+ if (!left) return;
2362
2461
  const operands = [left];
2363
2462
  while (ni.$?.type === "identifier" && ni.$.text === "and") {
2364
2463
  ni.move();
2365
- const right = parseUnaryExpr(ni, messages);
2464
+ const right = parseUnaryExpr(ni, ctx);
2366
2465
  if (!right) {
2367
- pushError(ni, messages, "Expected expression after \"and\"");
2466
+ pushError(ni, ctx, "Expected expression after \"and\"");
2368
2467
  break;
2369
2468
  }
2370
2469
  operands.push(right);
@@ -2375,13 +2474,13 @@ function parseAndExpr(ni, messages) {
2375
2474
  node.operands = operands;
2376
2475
  return node;
2377
2476
  }
2378
- function parseUnaryExpr(ni, messages) {
2477
+ function parseUnaryExpr(ni, ctx) {
2379
2478
  if (ni.$?.type === "identifier" && ni.$.text === "not") {
2380
2479
  ni.move();
2381
- const operand = parseUnaryExpr(ni, messages);
2480
+ const operand = parseUnaryExpr(ni, ctx);
2382
2481
  if (!operand) {
2383
- pushError(ni, messages, "Expected expression after \"not\"");
2384
- return undefined;
2482
+ pushError(ni, ctx, "Expected expression after \"not\"");
2483
+ return;
2385
2484
  }
2386
2485
  const node = new SemanticQueryLogicalNode();
2387
2486
  node.operator = "not";
@@ -2389,30 +2488,35 @@ function parseUnaryExpr(ni, messages) {
2389
2488
  return node;
2390
2489
  }
2391
2490
  if (ni.$?.type === "block" && ni.$.text === "(") {
2392
- const blockChildren = ni.$.children || [];
2491
+ const blockToken = ni.$;
2492
+ const blockChildren = blockToken.children || [];
2393
2493
  ni.move();
2494
+ const subCtx = {
2495
+ messages: ctx.messages,
2496
+ fallback: rangeOf(blockToken, ctx)
2497
+ };
2394
2498
  if (blockChildren.length === 0) {
2395
- pushError(ni, messages, "Empty parenthesized expression");
2396
- return undefined;
2499
+ pushErrorAt(subCtx.fallback, ctx, "Empty parenthesized expression");
2500
+ return;
2397
2501
  }
2398
- const subNi = new NodeIterator(blockChildren, messages);
2502
+ const subNi = new NodeIterator(blockChildren, ctx.messages);
2399
2503
  subNi.move();
2400
- const expr = parseOrExpr(subNi, messages);
2401
- if (subNi.$) pushError(subNi, messages, `Unexpected token in parenthesized expression: "${subNi.$.text}"`);
2504
+ const expr = parseOrExpr(subNi, subCtx);
2505
+ if (subNi.$) pushError(subNi, subCtx, `Unexpected token in parenthesized expression: "${subNi.$.text}"`);
2402
2506
  return expr;
2403
2507
  }
2404
- return parseComparison(ni, messages);
2508
+ return parseComparison(ni, ctx);
2405
2509
  }
2406
- function parseComparison(ni, messages) {
2407
- const left = parseFieldRef(ni, messages);
2408
- if (!left) return undefined;
2510
+ function parseComparison(ni, ctx) {
2511
+ const left = parseFieldRef(ni, ctx);
2512
+ if (!left) return;
2409
2513
  if (ni.$?.type === "punctuation" && SYMBOLIC_OPS.has(ni.$.text)) {
2410
2514
  const opText = ni.$.text;
2411
2515
  ni.move();
2412
- const right = parseValueOrFieldRef(ni, messages);
2516
+ const right = parseValueOrFieldRef(ni, ctx);
2413
2517
  if (!right) {
2414
- pushError(ni, messages, `Expected value or field reference after "${opText}"`);
2415
- return undefined;
2518
+ pushError(ni, ctx, `Expected value or field reference after "${opText}"`);
2519
+ return;
2416
2520
  }
2417
2521
  const node = new SemanticQueryComparisonNode();
2418
2522
  node.left = left;
@@ -2424,8 +2528,8 @@ function parseComparison(ni, messages) {
2424
2528
  const opText = ni.$.text;
2425
2529
  if (opText === "in") {
2426
2530
  ni.move();
2427
- const right = parseValueList(ni, messages);
2428
- if (!right) return undefined;
2531
+ const right = parseValueList(ni, ctx);
2532
+ if (!right) return;
2429
2533
  const node = new SemanticQueryComparisonNode();
2430
2534
  node.left = left;
2431
2535
  node.operator = "in";
@@ -2434,10 +2538,10 @@ function parseComparison(ni, messages) {
2434
2538
  }
2435
2539
  if (opText === "matches") {
2436
2540
  ni.move();
2437
- const right = parseValueOrFieldRef(ni, messages);
2541
+ const right = parseValueOrFieldRef(ni, ctx);
2438
2542
  if (!right) {
2439
- pushError(ni, messages, "Expected value after \"matches\"");
2440
- return undefined;
2543
+ pushError(ni, ctx, "Expected value after \"matches\"");
2544
+ return;
2441
2545
  }
2442
2546
  const node = new SemanticQueryComparisonNode();
2443
2547
  node.left = left;
@@ -2452,19 +2556,18 @@ function parseComparison(ni, messages) {
2452
2556
  node.operator = "exists";
2453
2557
  return node;
2454
2558
  }
2455
- if (opText === "not") return parseNotComparison(ni, messages, left);
2456
- pushError(ni, messages, `Unknown operator "${opText}"`);
2457
- return undefined;
2559
+ if (opText === "not") return parseNotComparison(ni, ctx, left);
2560
+ pushError(ni, ctx, `Unknown operator "${opText}"`);
2561
+ return;
2458
2562
  }
2459
- pushError(ni, messages, "Expected operator after field reference");
2460
- return undefined;
2563
+ pushError(ni, ctx, "Expected operator after field reference");
2461
2564
  }
2462
- function parseNotComparison(ni, messages, left) {
2565
+ function parseNotComparison(ni, ctx, left) {
2463
2566
  ni.move();
2464
2567
  if (ni.$?.type === "identifier" && ni.$.text === "in") {
2465
2568
  ni.move();
2466
- const right = parseValueList(ni, messages);
2467
- if (!right) return undefined;
2569
+ const right = parseValueList(ni, ctx);
2570
+ if (!right) return;
2468
2571
  const node = new SemanticQueryComparisonNode();
2469
2572
  node.left = left;
2470
2573
  node.operator = "not in";
@@ -2478,13 +2581,12 @@ function parseNotComparison(ni, messages, left) {
2478
2581
  node.operator = "not exists";
2479
2582
  return node;
2480
2583
  }
2481
- pushError(ni, messages, "Expected \"in\" or \"exists\" after \"not\"");
2482
- return undefined;
2584
+ pushError(ni, ctx, "Expected \"in\" or \"exists\" after \"not\"");
2483
2585
  }
2484
- function parseFieldRef(ni, messages) {
2586
+ function parseFieldRef(ni, ctx) {
2485
2587
  if (ni.$?.type !== "identifier") {
2486
- pushError(ni, messages, "Expected field reference");
2487
- return undefined;
2588
+ pushError(ni, ctx, "Expected field reference");
2589
+ return;
2488
2590
  }
2489
2591
  const firstToken = new Token(ni.$);
2490
2592
  ni.move();
@@ -2500,39 +2602,37 @@ function parseFieldRef(ni, messages) {
2500
2602
  fieldText += `.${ni.$.text}`;
2501
2603
  ni.move();
2502
2604
  } else {
2503
- pushError(ni, messages, "Expected identifier after \".\"");
2605
+ pushError(ni, ctx, "Expected identifier after \".\"");
2504
2606
  break;
2505
2607
  }
2506
2608
  }
2507
- const node$2 = new SemanticQueryFieldRefNode();
2508
- node$2.typeRef = firstToken;
2509
- if (fieldText !== secondToken.text) node$2.fieldRef = secondToken.clone({ text: fieldText });
2510
- else node$2.fieldRef = secondToken;
2511
- return node$2;
2609
+ const node = new SemanticQueryFieldRefNode();
2610
+ node.typeRef = firstToken;
2611
+ node.fieldRef = fieldText === secondToken.text ? secondToken : secondToken.clone({ text: fieldText });
2612
+ return node;
2512
2613
  }
2513
- pushError(ni, messages, "Expected identifier after \".\"");
2514
- const node$1 = new SemanticQueryFieldRefNode();
2515
- node$1.fieldRef = firstToken;
2516
- return node$1;
2614
+ pushError(ni, ctx, "Expected identifier after \".\"");
2615
+ const node = new SemanticQueryFieldRefNode();
2616
+ node.fieldRef = firstToken;
2617
+ return node;
2517
2618
  }
2518
2619
  const node = new SemanticQueryFieldRefNode();
2519
2620
  node.fieldRef = firstToken;
2520
2621
  return node;
2521
2622
  }
2522
- function parseValueOrFieldRef(ni, messages) {
2523
- if (!ni.$) return undefined;
2524
- if (ni.$.type === "text" || ni.$.type === "number" || ni.$.type === "regexp") return parseValue(ni, messages);
2623
+ function parseValueOrFieldRef(ni, ctx) {
2624
+ if (!ni.$) return;
2625
+ if (ni.$.type === "text" || ni.$.type === "number" || ni.$.type === "regexp") return parseValue(ni, ctx);
2525
2626
  if (ni.$.type === "identifier") {
2526
- if (VALUE_KEYWORDS.has(ni.$.text)) return parseValue(ni, messages);
2527
- return parseFieldRef(ni, messages);
2627
+ if (VALUE_KEYWORDS.has(ni.$.text)) return parseValue(ni, ctx);
2628
+ return parseFieldRef(ni, ctx);
2528
2629
  }
2529
- pushError(ni, messages, "Expected value or field reference");
2530
- return undefined;
2630
+ pushError(ni, ctx, "Expected value or field reference");
2531
2631
  }
2532
- function parseValue(ni, messages) {
2632
+ function parseValue(ni, ctx) {
2533
2633
  if (!ni.$) {
2534
- pushError(ni, messages, "Expected value");
2535
- return undefined;
2634
+ pushError(ni, ctx, "Expected value");
2635
+ return;
2536
2636
  }
2537
2637
  const token = ni.$;
2538
2638
  if (token.type === "text" || token.type === "number" || token.type === "regexp" || token.type === "identifier" && VALUE_KEYWORDS.has(token.text)) {
@@ -2541,47 +2641,49 @@ function parseValue(ni, messages) {
2541
2641
  ni.move();
2542
2642
  return node;
2543
2643
  }
2544
- pushError(ni, messages, `Unexpected token "${token.text}" where value expected`);
2545
- return undefined;
2644
+ pushError(ni, ctx, `Unexpected token "${token.text}" where value expected`);
2546
2645
  }
2547
- function parseValueList(ni, messages) {
2646
+ function parseValueList(ni, ctx) {
2548
2647
  if (ni.$?.type === "block" && ni.$.text === "(") {
2549
- const blockChildren = ni.$.children || [];
2648
+ const blockToken = ni.$;
2649
+ const blockChildren = blockToken.children || [];
2550
2650
  ni.move();
2651
+ const subCtx = {
2652
+ messages: ctx.messages,
2653
+ fallback: rangeOf(blockToken, ctx)
2654
+ };
2551
2655
  const values = [];
2552
2656
  if (blockChildren.length === 0) {
2553
- pushError(ni, messages, "Empty value list in \"in\" expression");
2554
- return undefined;
2657
+ pushErrorAt(subCtx.fallback, ctx, "Empty value list in \"in\" expression");
2658
+ return;
2555
2659
  }
2556
- const subNi = new NodeIterator(blockChildren, messages);
2660
+ const subNi = new NodeIterator(blockChildren, ctx.messages);
2557
2661
  subNi.move();
2558
- const first = parseValue(subNi, messages);
2662
+ const first = parseValue(subNi, subCtx);
2559
2663
  if (first) values.push(first);
2560
2664
  while (subNi.$?.type === "punctuation" && subNi.$.text === ",") {
2561
2665
  subNi.move();
2562
- const v = parseValue(subNi, messages);
2666
+ const v = parseValue(subNi, subCtx);
2563
2667
  if (v) values.push(v);
2564
2668
  }
2565
- if (subNi.$) pushError(subNi, messages, `Unexpected token in value list: "${subNi.$.text}"`);
2669
+ if (subNi.$) pushError(subNi, subCtx, `Unexpected token in value list: "${subNi.$.text}"`);
2566
2670
  const node = new SemanticQueryValueListNode();
2567
2671
  node.values = values;
2568
2672
  return node;
2569
2673
  }
2570
- pushError(ni, messages, "Expected parenthesized value list after \"in\"");
2571
- return undefined;
2674
+ pushError(ni, ctx, "Expected parenthesized value list after \"in\"");
2572
2675
  }
2573
- function pushError(ni, messages, message) {
2574
- const range = ni.$?.getRange?.() ?? {
2575
- start: {
2576
- line: 0,
2577
- character: 0
2578
- },
2579
- end: {
2580
- line: 0,
2581
- character: 0
2582
- }
2583
- };
2584
- messages.push({
2676
+ /**
2677
+ * Range of a token, falling back to the enclosing query/paren range when the
2678
+ * token carries no position of its own.
2679
+ */ function rangeOf(token, ctx) {
2680
+ return token?.getRange?.() ?? ctx.fallback;
2681
+ }
2682
+ function pushError(ni, ctx, message) {
2683
+ pushErrorAt(rangeOf(ni.$, ctx), ctx, message);
2684
+ }
2685
+ function pushErrorAt(range, ctx, message) {
2686
+ ctx.messages.push({
2585
2687
  severity: 1,
2586
2688
  message,
2587
2689
  range
@@ -2634,7 +2736,7 @@ function refWithChain() {
2634
2736
  } else if (fork.$.children?.length === 1 && fork.$.children[0].type === "text") {
2635
2737
  if (isRef(target.node)) target.node.addChain(new Token(fork.$.children[0]));
2636
2738
  } else return true;
2637
- else {
2739
+ else {
2638
2740
  fork.skip(["\n"]);
2639
2741
  if (fork.next().satisfies(s.id)) {
2640
2742
  if (isRef(target.node)) target.node.addDot(new Token(fork.$));
@@ -2741,7 +2843,7 @@ function annotations() {
2741
2843
  } else break;
2742
2844
  }
2743
2845
  if (ni.satisfies(opts.end)) ni.skip([";", "\n"]);
2744
- else if (ni.$) {
2846
+ else if (ni.$) {
2745
2847
  ni.unexpected(false, `Unexpected token in annotation ${ni.toString()}`);
2746
2848
  ni.skipUntil([";", "\n"]);
2747
2849
  ni.skip([";", "\n"]);
@@ -2750,12 +2852,12 @@ else if (ni.$) {
2750
2852
  return true;
2751
2853
  } };
2752
2854
  }
2753
- function definition(pipes$1) {
2855
+ function definition(pipes) {
2754
2856
  const opts = {
2755
2857
  sep: [],
2756
2858
  priority: false,
2757
2859
  multiple: false,
2758
- from: undefined,
2860
+ from: void 0,
2759
2861
  debug: false,
2760
2862
  skip: []
2761
2863
  };
@@ -2773,7 +2875,7 @@ function definition(pipes$1) {
2773
2875
  targetNode.define(new $n.SemanticGroup());
2774
2876
  return true;
2775
2877
  }
2776
- const resolvedPipes = pipes$1.map((p) => typeof p === "function" ? p() : p);
2878
+ const resolvedPipes = pipes.map((p) => typeof p === "function" ? p() : p);
2777
2879
  const node = runPipesOnce(resolvedPipes, fork);
2778
2880
  if (node) {
2779
2881
  fork.accepted();
@@ -2794,7 +2896,7 @@ function definition(pipes$1) {
2794
2896
  text: opts.sep
2795
2897
  })) {
2796
2898
  if (opts.priority) if (fork.next(opts.skip).$) nodes.push(new Token(fork.$));
2797
- else {
2899
+ else {
2798
2900
  fork.unexpected(false, "Unexpected end of group");
2799
2901
  break;
2800
2902
  }
@@ -2817,7 +2919,7 @@ else {
2817
2919
  }
2818
2920
  }
2819
2921
  if (nodes.length === 1) targetNode.define(nodes[0]);
2820
- else if (opts.priority && opts.sep.length > 0) {
2922
+ else if (opts.priority && opts.sep.length > 0) {
2821
2923
  if (nodes.length % 2 === 0) {
2822
2924
  fork.next().unexpected(false, "Error in group definition");
2823
2925
  return false;
@@ -2864,8 +2966,8 @@ function unwrap(attr) {
2864
2966
  target.node.define(new $n.SemanticGroup(nodes));
2865
2967
  return true;
2866
2968
  },
2867
- with(pipes$1) {
2868
- opts.pipes = pipes$1;
2969
+ with(pipes) {
2970
+ opts.pipes = pipes;
2869
2971
  return this;
2870
2972
  }
2871
2973
  };
@@ -2874,13 +2976,12 @@ function propName() {
2874
2976
  return { handler(ni, target) {
2875
2977
  switch (ni.$?.type) {
2876
2978
  case "identifier":
2877
- case "text": {
2979
+ case "text":
2878
2980
  target.node.saveToken(new Token(ni.$), "identifier");
2879
2981
  ni.accepted();
2880
2982
  ni.move();
2881
2983
  ni.skip(["\n"]);
2882
2984
  return true;
2883
- }
2884
2985
  case "block": {
2885
2986
  const childrenLength = ni.$.children?.length || 0;
2886
2987
  const firstText = ni.$.children?.[0]?.text;
@@ -2903,13 +3004,12 @@ function propName() {
2903
3004
  }
2904
3005
  if (ni.$.text === "[" && !childrenLength) ni.unexpected(false, "Wildcard \"*\" or a Regular Expression expected");
2905
3006
  if (ni.$.text === "[" && childrenLength > 1) ni.unexpected(false, firstText?.startsWith("/") ? "Invalid Regular Expression" : "To many arguments in prop pattern []");
2906
- else ni.unexpected(false, "Unexpected identifier at property name");
3007
+ else ni.unexpected(false, "Unexpected identifier at property name");
2907
3008
  return false;
2908
3009
  }
2909
- default: {
3010
+ default:
2910
3011
  ni.unexpected(false, "Unexpected identifier at property name");
2911
3012
  return false;
2912
- }
2913
3013
  }
2914
3014
  } };
2915
3015
  }
@@ -2956,9 +3056,8 @@ function extendsClause() {
2956
3056
  //#region packages/core/src/parser/pipes/pipes.ts
2957
3057
  const ref = $pipe("ref", [refWithChain()]);
2958
3058
  const constText = defineValuePipe("const", "text", false);
2959
- const constNumber = defineValuePipe("const", "number", false);
2960
3059
  const allowedValuesPipeArray = [
2961
- constNumber,
3060
+ defineValuePipe("const", "number", false),
2962
3061
  ref,
2963
3062
  constText
2964
3063
  ];
@@ -3021,14 +3120,13 @@ const importPipe = $pipe("import", [
3021
3120
  text().saveAs("path").skip(";", "\n"),
3022
3121
  definition([$pipe("ref", [identifier().saveAs("identifier").skip("\n")])]).from("inner").separatedBy(",").skip("\n").respectPriority()
3023
3122
  ]).skip("\n", ";");
3024
- const skipComments = { handler(ni) {
3025
- ni.skip();
3026
- return true;
3027
- } };
3028
3123
  const annotateEntry = $pipe("ref", [
3029
3124
  annotations(),
3030
3125
  refWithChain(),
3031
- skipComments,
3126
+ { handler(ni) {
3127
+ ni.skip();
3128
+ return true;
3129
+ } },
3032
3130
  pun(";", ",", "\n").orEob().lookBehind()
3033
3131
  ]).skip("\n", ";", ",");
3034
3132
  const annotatePipe = $pipe("annotate", [
@@ -3052,12 +3150,12 @@ const pipes = {
3052
3150
 
3053
3151
  //#endregion
3054
3152
  //#region packages/core/src/parser/types.ts
3055
- var TSeverity = /*#__PURE__*/ function(TSeverity$1) {
3056
- TSeverity$1[TSeverity$1["Error"] = 1] = "Error";
3057
- TSeverity$1[TSeverity$1["Warning"] = 2] = "Warning";
3058
- TSeverity$1[TSeverity$1["Info"] = 3] = "Info";
3059
- TSeverity$1[TSeverity$1["Hint"] = 4] = "Hint";
3060
- return TSeverity$1;
3153
+ var TSeverity = /* @__PURE__ */ function(TSeverity) {
3154
+ TSeverity[TSeverity["Error"] = 1] = "Error";
3155
+ TSeverity[TSeverity["Warning"] = 2] = "Warning";
3156
+ TSeverity[TSeverity["Info"] = 3] = "Info";
3157
+ TSeverity[TSeverity["Hint"] = 4] = "Hint";
3158
+ return TSeverity;
3061
3159
  }({});
3062
3160
 
3063
3161
  //#endregion
@@ -3069,7 +3167,7 @@ function _define_property$5(obj, key, value) {
3069
3167
  configurable: true,
3070
3168
  writable: true
3071
3169
  });
3072
- else obj[key] = value;
3170
+ else obj[key] = value;
3073
3171
  return obj;
3074
3172
  }
3075
3173
  /**
@@ -3111,19 +3209,22 @@ else obj[key] = value;
3111
3209
  const endCmp = comparePos(a.range.end, b.range.end);
3112
3210
  return startCmp >= 0 && endCmp <= 0;
3113
3211
  }
3114
- var BlocksIndex = class {
3212
+ /**
3213
+ * Implementation of `IBlocksIndex` that manages a collection of tokens and provides efficient methods to add tokens
3214
+ * and query the most nested token at a specific position.
3215
+ */ var BlocksIndex = class {
3115
3216
  /**
3116
3217
  * Adds a new token to the index. The token collection is maintained in sorted order by start position.
3117
3218
  * @param block - The token to add.
3118
- */ add(block$2) {
3219
+ */ add(block) {
3119
3220
  let left = 0;
3120
3221
  let right = this.blocks.length;
3121
3222
  while (left < right) {
3122
3223
  const mid = left + right >> 1;
3123
- if (comparePos(this.blocks[mid].range.start, block$2.range.start) < 0) left = mid + 1;
3124
- else right = mid;
3224
+ if (comparePos(this.blocks[mid].range.start, block.range.start) < 0) left = mid + 1;
3225
+ else right = mid;
3125
3226
  }
3126
- this.blocks.splice(left, 0, block$2);
3227
+ this.blocks.splice(left, 0, block);
3127
3228
  }
3128
3229
  /**
3129
3230
  * Finds the most nested token at a specific position.
@@ -3132,14 +3233,14 @@ else right = mid;
3132
3233
  * @returns The most nested token at the given position, or `undefined` if no token is found.
3133
3234
  */ at(line, character) {
3134
3235
  const candidates = [];
3135
- for (const block$2 of this.blocks) {
3136
- if (comparePos(block$2.range.start, {
3236
+ for (const block of this.blocks) {
3237
+ if (comparePos(block.range.start, {
3137
3238
  line,
3138
3239
  character
3139
3240
  }) > 0) break;
3140
- if (contains(block$2, line, character)) candidates.push(block$2);
3241
+ if (contains(block, line, character)) candidates.push(block);
3141
3242
  }
3142
- if (candidates.length === 0) return undefined;
3243
+ if (candidates.length === 0) return;
3143
3244
  let result = candidates[0];
3144
3245
  for (let i = 1; i < candidates.length; i++) if (moreNested(candidates[i], result)) result = candidates[i];
3145
3246
  return result;
@@ -3161,17 +3262,20 @@ function _define_property$4(obj, key, value) {
3161
3262
  configurable: true,
3162
3263
  writable: true
3163
3264
  });
3164
- else obj[key] = value;
3265
+ else obj[key] = value;
3165
3266
  return obj;
3166
3267
  }
3167
- var TokensIndex = class {
3268
+ /**
3269
+ * A class that implements a flat index for tokens, allowing quick access to tokens
3270
+ * at a specific line and character. Tokens in this index are not nested.
3271
+ */ var TokensIndex = class {
3168
3272
  /**
3169
3273
  * Adds a token to the index. The token is stored based on its starting line.
3170
3274
  * @param token - The token to add to the index.
3171
3275
  */ add(token) {
3172
3276
  if (!token?.range) return;
3173
3277
  const line = token.range.start.line;
3174
- this.tokensMap[line] = this.tokensMap[line] ?? new Set();
3278
+ this.tokensMap[line] = this.tokensMap[line] ?? /* @__PURE__ */ new Set();
3175
3279
  this.tokensMap[line].add(token);
3176
3280
  }
3177
3281
  /**
@@ -3180,10 +3284,10 @@ var TokensIndex = class {
3180
3284
  * @param character - The character position within the line to search for.
3181
3285
  * @returns The token at the specified line and character, or `undefined` if none exists.
3182
3286
  */ at(line, character) {
3183
- const tokens$1 = this.tokensMap[line];
3184
- if (!tokens$1) return undefined;
3287
+ const tokens = this.tokensMap[line];
3288
+ if (!tokens) return;
3185
3289
  let best;
3186
- for (const t of tokens$1) if (t.range.start.character <= character && t.range.end.character >= character) {
3290
+ for (const t of tokens) if (t.range.start.character <= character && t.range.end.character >= character) {
3187
3291
  if (!best || t.range.start.character > best.range.start.character || t.range.start.character === best.range.start.character && t.range.end.character < best.range.end.character) best = t;
3188
3292
  }
3189
3293
  return best;
@@ -3207,14 +3311,13 @@ var TokensIndex = class {
3207
3311
  if (candidate) return candidate;
3208
3312
  }
3209
3313
  for (let l = line - 1; l >= 0; l--) {
3210
- const tokens$1 = this.tokensMap[l];
3211
- if (tokens$1 && tokens$1.size > 0) {
3314
+ const tokens = this.tokensMap[l];
3315
+ if (tokens && tokens.size > 0) {
3212
3316
  let candidate;
3213
- for (const t of tokens$1) if (!candidate || t.range.end.character > candidate.range.end.character) candidate = t;
3317
+ for (const t of tokens) if (!candidate || t.range.end.character > candidate.range.end.character) candidate = t;
3214
3318
  if (candidate) return candidate;
3215
3319
  }
3216
3320
  }
3217
- return undefined;
3218
3321
  }
3219
3322
  constructor() {
3220
3323
  /**
@@ -3233,7 +3336,7 @@ function _define_property$3(obj, key, value) {
3233
3336
  configurable: true,
3234
3337
  writable: true
3235
3338
  });
3236
- else obj[key] = value;
3339
+ else obj[key] = value;
3237
3340
  return obj;
3238
3341
  }
3239
3342
  var AtscriptDoc = class {
@@ -3248,7 +3351,7 @@ var AtscriptDoc = class {
3248
3351
  }
3249
3352
  resolveAnnotation(name) {
3250
3353
  let spec = this._annotationSpecCache.get(name);
3251
- if (spec === undefined && !this._annotationSpecCache.has(name)) {
3354
+ if (spec === void 0 && !this._annotationSpecCache.has(name)) {
3252
3355
  spec = resolveAnnotation(name, this.config.annotations);
3253
3356
  this._annotationSpecCache.set(name, spec);
3254
3357
  }
@@ -3287,11 +3390,10 @@ var AtscriptDoc = class {
3287
3390
  get text() {
3288
3391
  return this._text;
3289
3392
  }
3290
- update(text$2, debug = false) {
3291
- this._text = text$2;
3393
+ update(text, debug = false) {
3394
+ this._text = text;
3292
3395
  this.cleanup();
3293
- const rawTokens = tokenize(text$2, debug);
3294
- const ni = new NodeIterator(rawTokens, []).move();
3396
+ const ni = new NodeIterator(tokenize(text, debug), []).move();
3295
3397
  this.nodes = runPipes([
3296
3398
  pipes.importPipe,
3297
3399
  pipes.type,
@@ -3311,8 +3413,8 @@ var AtscriptDoc = class {
3311
3413
  this.queryFieldRefs = [];
3312
3414
  this.imports.clear();
3313
3415
  this.resolvedImports.clear();
3314
- this._allMessages = undefined;
3315
- this._annotateNodesByTarget = undefined;
3416
+ this._allMessages = void 0;
3417
+ this._annotateNodesByTarget = void 0;
3316
3418
  this.tokensIndex = new TokensIndex();
3317
3419
  this.blocksIndex = new BlocksIndex();
3318
3420
  this.resolvedAnnotations = [];
@@ -3359,14 +3461,12 @@ var AtscriptDoc = class {
3359
3461
  } else {
3360
3462
  let severity = 1;
3361
3463
  switch (this.config.unknownAnnotation) {
3362
- case "warn": {
3464
+ case "warn":
3363
3465
  severity = 2;
3364
3466
  break;
3365
- }
3366
- case "allow": {
3467
+ case "allow":
3367
3468
  severity = 0;
3368
3469
  break;
3369
- }
3370
3470
  default:
3371
3471
  }
3372
3472
  if (severity > 0) this.registerMessage(mainToken, `Unknown annotation "${mainToken.text}"`, severity, "dim");
@@ -3393,9 +3493,9 @@ var AtscriptDoc = class {
3393
3493
  *
3394
3494
  * If the type cannot be resolved or does not exist, returns `undefined`.
3395
3495
  */ unwindType(name, chain = [], watchCb, _tracked) {
3396
- const tracked = _tracked || new Set();
3496
+ const tracked = _tracked || /* @__PURE__ */ new Set();
3397
3497
  const decl = this.getDeclarationOwnerNode(name);
3398
- if (!decl) return undefined;
3498
+ if (!decl) return;
3399
3499
  const callCb = watchCb ? () => {
3400
3500
  if (def && !tracked.has(def) && [
3401
3501
  "type",
@@ -3426,19 +3526,19 @@ var AtscriptDoc = class {
3426
3526
  }
3427
3527
  };
3428
3528
  resolveType();
3429
- if (!def) return undefined;
3529
+ if (!def) return;
3430
3530
  if (isAnnotate(def)) return doc.unwindType(def.targetName, chain, watchCb, tracked);
3431
3531
  for (const item of chain) {
3432
3532
  const itemText = typeof item === "string" ? item : item.text;
3433
- if (!def) return undefined;
3533
+ if (!def) return;
3434
3534
  if (isProp(def)) if (def.nestedProps?.get(itemText)) def = def.nestedProps.get(itemText);
3435
- else {
3535
+ else {
3436
3536
  def = def.nestedType;
3437
3537
  resolveRef();
3438
3538
  resolveType();
3439
3539
  if (isStructure(def) || isInterface(def)) def = def.props.get(itemText);
3440
3540
  }
3441
- else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.props.get(itemText);
3541
+ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.props.get(itemText);
3442
3542
  }
3443
3543
  if (_tracked) callCb();
3444
3544
  while (isProp(def)) {
@@ -3451,7 +3551,7 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
3451
3551
  def,
3452
3552
  doc,
3453
3553
  node
3454
- } : undefined;
3554
+ } : void 0;
3455
3555
  }
3456
3556
  getUsageListAt(line, character) {
3457
3557
  const token = this.tokensIndex.at(line, character);
@@ -3461,7 +3561,7 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
3461
3561
  let right = givenNode.annotations;
3462
3562
  let def = givenNode.getDefinition();
3463
3563
  if (def) {
3464
- const refDef = isRef(def) ? def : undefined;
3564
+ const refDef = isRef(def) ? def : void 0;
3465
3565
  if (refDef) {
3466
3566
  const chainNodes = [];
3467
3567
  const unwound = this.unwindType(refDef.token("identifier").text, refDef.chain, (intermediate) => {
@@ -3483,20 +3583,20 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
3483
3583
  * when folding annotations across a ref boundary. Annotations without a
3484
3584
  * resolvable spec pass through (default is to inherit). Returns the input
3485
3585
  * array unchanged when nothing is dropped.
3486
- */ filterPassedWhenReferred(annotations$1) {
3487
- if (!annotations$1?.length) return annotations$1;
3586
+ */ filterPassedWhenReferred(annotations) {
3587
+ if (!annotations?.length) return annotations;
3488
3588
  let filtered;
3489
- for (let i = 0; i < annotations$1.length; i++) if (this.resolveAnnotation(annotations$1[i].name)?.config.passedWhenReferred === false) filtered ?? (filtered = annotations$1.slice(0, i));
3490
- else filtered?.push(annotations$1[i]);
3491
- return filtered ?? annotations$1;
3589
+ for (let i = 0; i < annotations.length; i++) if (this.resolveAnnotation(annotations[i].name)?.config.passedWhenReferred === false) filtered ?? (filtered = annotations.slice(0, i));
3590
+ else filtered?.push(annotations[i]);
3591
+ return filtered ?? annotations;
3492
3592
  }
3493
3593
  /**
3494
3594
  * If the position falls inside an `annotate` block, returns that block's node
3495
3595
  * (whose `targetName` is the annotated interface). Entry refs within the block
3496
3596
  * resolve through the target interface rather than as top-level definitions.
3497
3597
  */ annotateBlockAt(line, character) {
3498
- const block$2 = this.blocksIndex.at(line, character);
3499
- return block$2?.blockType === "annotate" && isAnnotate(block$2.parentNode) ? block$2.parentNode : undefined;
3598
+ const block = this.blocksIndex.at(line, character);
3599
+ return block?.blockType === "annotate" && isAnnotate(block.parentNode) ? block.parentNode : void 0;
3500
3600
  }
3501
3601
  /**
3502
3602
  * Collects ad-hoc annotations from all `annotate` blocks targeting a given type/interface.
@@ -3504,11 +3604,11 @@ else filtered?.push(annotations$1[i]);
3504
3604
  * For entries without a chain (root-level), the key is the entry identifier.
3505
3605
  */ getAnnotateNodesFor(targetName) {
3506
3606
  if (!this._annotateNodesByTarget) {
3507
- const index = new Map();
3607
+ const index = /* @__PURE__ */ new Map();
3508
3608
  for (const node of this.nodes) if (isAnnotate(node)) {
3509
3609
  const existing = index.get(node.targetName);
3510
3610
  if (existing) existing.push(node);
3511
- else index.set(node.targetName, [node]);
3611
+ else index.set(node.targetName, [node]);
3512
3612
  }
3513
3613
  this._annotateNodesByTarget = index;
3514
3614
  }
@@ -3527,9 +3627,9 @@ else index.set(node.targetName, [node]);
3527
3627
  * the child's file apply to grandparent-inherited fields, even when the chain crosses
3528
3628
  * package boundaries (child → mid → grandparent, all in different .as files).
3529
3629
  */ resolveInterfaceExtends(node, _visited, _originDoc) {
3530
- if (!node.hasExtends) return undefined;
3531
- const visited = _visited || new Set();
3532
- if (node.id && visited.has(node.id)) return undefined;
3630
+ if (!node.hasExtends) return;
3631
+ const visited = _visited || /* @__PURE__ */ new Set();
3632
+ if (node.id && visited.has(node.id)) return;
3533
3633
  if (node.id) visited.add(node.id);
3534
3634
  const originDoc = _originDoc ?? this;
3535
3635
  let mergedStruct;
@@ -3538,10 +3638,8 @@ else index.set(node.targetName, [node]);
3538
3638
  if (!unwound?.def) continue;
3539
3639
  let parentDef = unwound.def;
3540
3640
  const parentDeclName = unwound.node?.id ?? parentDef.id;
3541
- if (isInterface(parentDef) && parentDef.hasExtends) {
3542
- const resolved = unwound.doc.resolveInterfaceExtends(parentDef, visited, originDoc);
3543
- parentDef = resolved || parentDef.getDefinition() || parentDef;
3544
- } else if (isInterface(parentDef)) parentDef = parentDef.getDefinition() || parentDef;
3641
+ if (isInterface(parentDef) && parentDef.hasExtends) parentDef = unwound.doc.resolveInterfaceExtends(parentDef, visited, originDoc) || parentDef.getDefinition() || parentDef;
3642
+ else if (isInterface(parentDef)) parentDef = parentDef.getDefinition() || parentDef;
3545
3643
  parentDef = this.mergeIntersection(parentDef);
3546
3644
  const annotateNodes = [];
3547
3645
  const collect = (doc, name) => {
@@ -3553,16 +3651,10 @@ else index.set(node.targetName, [node]);
3553
3651
  if (originDoc !== this && originDoc !== unwound.doc) collect(originDoc, parentDeclName);
3554
3652
  if (annotateNodes.length > 0) parentDef = this.applyAnnotateBlocksToStructure(parentDef, annotateNodes);
3555
3653
  if (!mergedStruct) mergedStruct = parentDef;
3556
- else {
3557
- const merged = this.mergeDefs(mergedStruct, parentDef);
3558
- mergedStruct = merged[0];
3559
- }
3654
+ else mergedStruct = this.mergeDefs(mergedStruct, parentDef)[0];
3560
3655
  }
3561
3656
  const ownDef = node.getDefinition();
3562
- if (ownDef && mergedStruct) {
3563
- const merged = this.mergeDefs(mergedStruct, ownDef);
3564
- return merged[0];
3565
- }
3657
+ if (ownDef && mergedStruct) return this.mergeDefs(mergedStruct, ownDef)[0];
3566
3658
  return mergedStruct || ownDef;
3567
3659
  }
3568
3660
  /**
@@ -3593,19 +3685,19 @@ else {
3593
3685
  * prop. Returns a new structure with cloned props/structures along touched paths, or
3594
3686
  * `undefined` when nothing matched (so callers can reuse the original by reference).
3595
3687
  */ foldAnnotationsIntoStructure(struct, entries) {
3596
- const byHead = new Map();
3688
+ const byHead = /* @__PURE__ */ new Map();
3597
3689
  for (const entry of entries) {
3598
3690
  const head = entry.parts[0];
3599
- let group$1 = byHead.get(head);
3600
- if (!group$1) {
3601
- group$1 = {
3691
+ let group = byHead.get(head);
3692
+ if (!group) {
3693
+ group = {
3602
3694
  own: [],
3603
3695
  nested: []
3604
3696
  };
3605
- byHead.set(head, group$1);
3697
+ byHead.set(head, group);
3606
3698
  }
3607
- if (entry.parts.length === 1) group$1.own.push(...entry.anns);
3608
- else group$1.nested.push({
3699
+ if (entry.parts.length === 1) group.own.push(...entry.anns);
3700
+ else group.nested.push({
3609
3701
  parts: entry.parts.slice(1),
3610
3702
  anns: entry.anns
3611
3703
  });
@@ -3613,18 +3705,18 @@ else group$1.nested.push({
3613
3705
  const newProps = [];
3614
3706
  let changed = false;
3615
3707
  for (const [name, prop] of struct.props) {
3616
- const group$1 = byHead.get(name);
3617
- if (!group$1) {
3708
+ const group = byHead.get(name);
3709
+ if (!group) {
3618
3710
  newProps.push(prop);
3619
3711
  continue;
3620
3712
  }
3621
3713
  const propDef = prop.getDefinition();
3622
3714
  let newDef = propDef;
3623
- if (group$1.nested.length > 0 && propDef && isStructure(propDef)) {
3624
- const foldedNested = this.foldAnnotationsIntoStructure(propDef, group$1.nested);
3715
+ if (group.nested.length > 0 && propDef && isStructure(propDef)) {
3716
+ const foldedNested = this.foldAnnotationsIntoStructure(propDef, group.nested);
3625
3717
  if (foldedNested) newDef = foldedNested;
3626
3718
  }
3627
- if (group$1.own.length === 0 && newDef === propDef) {
3719
+ if (group.own.length === 0 && newDef === propDef) {
3628
3720
  newProps.push(prop);
3629
3721
  continue;
3630
3722
  }
@@ -3632,13 +3724,13 @@ else group$1.nested.push({
3632
3724
  const idToken = prop.token("identifier");
3633
3725
  if (idToken) cloned.saveToken(idToken, "identifier");
3634
3726
  if (newDef) cloned.define(newDef);
3635
- cloned.annotations = group$1.own.length > 0 ? this.mergeNodesAnnotations(prop.annotations, group$1.own) : prop.annotations;
3727
+ cloned.annotations = group.own.length > 0 ? this.mergeNodesAnnotations(prop.annotations, group.own) : prop.annotations;
3636
3728
  const optionalToken = prop.token("optional");
3637
3729
  if (optionalToken) cloned.saveToken(optionalToken, "optional");
3638
3730
  newProps.push(cloned);
3639
3731
  changed = true;
3640
3732
  }
3641
- if (!changed) return undefined;
3733
+ if (!changed) return;
3642
3734
  const newStruct = new SemanticStructureNode();
3643
3735
  newStruct.setProps(newProps);
3644
3736
  newStruct.annotations = struct.annotations;
@@ -3651,9 +3743,8 @@ else group$1.nested.push({
3651
3743
  range: r.range,
3652
3744
  token: r
3653
3745
  }));
3654
- if (token.exported) for (const d of this.dependants) {
3655
- const imp = d.imports.get(this.id);
3656
- if (imp?.imports.find((t) => t.text === token.text)) refs.push(...d.referred.filter((t) => t.text === token.text).map((r) => ({
3746
+ if (token.exported) {
3747
+ for (const d of this.dependants) if (d.imports.get(this.id)?.imports.find((t) => t.text === token.text)) refs.push(...d.referred.filter((t) => t.text === token.text).map((r) => ({
3657
3748
  uri: d.id,
3658
3749
  range: r.range,
3659
3750
  token: r
@@ -3662,20 +3753,20 @@ else group$1.nested.push({
3662
3753
  return refs;
3663
3754
  }
3664
3755
  if (isProp(token.parentNode)) {
3665
- const propName$1 = token.parentNode.id;
3666
- if (!propName$1) return undefined;
3756
+ const propName = token.parentNode.id;
3757
+ if (!propName) return;
3667
3758
  let parentName;
3668
- for (const node of this.nodes) if ((isInterface(node) || isStructure(node)) && node.props.get(propName$1) === token.parentNode) {
3759
+ for (const node of this.nodes) if ((isInterface(node) || isStructure(node)) && node.props.get(propName) === token.parentNode) {
3669
3760
  parentName = node.id;
3670
3761
  break;
3671
3762
  }
3672
- if (!parentName) return undefined;
3763
+ if (!parentName) return;
3673
3764
  const refs = [];
3674
3765
  const searchDoc = (doc, uri) => {
3675
3766
  for (const t of doc.referred) {
3676
3767
  if (t.text !== parentName || !isRef(t.parentNode) || !t.parentNode.hasChain) continue;
3677
3768
  const chainToken = t.parentNode.chain[0];
3678
- if (chainToken?.text === propName$1) refs.push({
3769
+ if (chainToken?.text === propName) refs.push({
3679
3770
  uri,
3680
3771
  range: chainToken.range,
3681
3772
  token: chainToken
@@ -3683,7 +3774,7 @@ else group$1.nested.push({
3683
3774
  }
3684
3775
  for (const node of doc.nodes) {
3685
3776
  if (!isAnnotate(node) || node.targetName !== parentName) continue;
3686
- for (const entry of node.entries) if (entry.id === propName$1) {
3777
+ for (const entry of node.entries) if (entry.id === propName) {
3687
3778
  const entryToken = entry.token("identifier");
3688
3779
  if (entryToken) refs.push({
3689
3780
  uri,
@@ -3693,11 +3784,10 @@ else group$1.nested.push({
3693
3784
  }
3694
3785
  }
3695
3786
  for (const qfr of doc.queryFieldRefs) {
3696
- if (!qfr.queryArgToken || qfr.fieldRef.text !== propName$1) continue;
3787
+ if (!qfr.queryArgToken || qfr.fieldRef.text !== propName) continue;
3697
3788
  const scope = getQueryScope(qfr.queryArgToken, doc);
3698
3789
  if (!scope) continue;
3699
- const resolvedTypeName = qfr.typeRef?.text ?? scope.unqualifiedTarget;
3700
- if (resolvedTypeName === parentName) refs.push({
3790
+ if ((qfr.typeRef?.text ?? scope.unqualifiedTarget) === parentName) refs.push({
3701
3791
  uri,
3702
3792
  range: qfr.fieldRef.range,
3703
3793
  token: qfr.fieldRef
@@ -3705,13 +3795,9 @@ else group$1.nested.push({
3705
3795
  }
3706
3796
  };
3707
3797
  searchDoc(this, this.id);
3708
- const parentDefToken = this.registry.definitions.get(parentName);
3709
- if (parentDefToken?.exported) {
3798
+ if (this.registry.definitions.get(parentName)?.exported) {
3710
3799
  const targetName = parentName;
3711
- for (const d of this.dependants) {
3712
- const imp = d.imports.get(this.id);
3713
- if (imp?.imports.find((t) => t.text === targetName)) searchDoc(d, d.id);
3714
- }
3800
+ for (const d of this.dependants) if (d.imports.get(this.id)?.imports.find((t) => t.text === targetName)) searchDoc(d, d.id);
3715
3801
  }
3716
3802
  return refs;
3717
3803
  }
@@ -3728,13 +3814,12 @@ else group$1.nested.push({
3728
3814
  }
3729
3815
  }
3730
3816
  }
3731
- return undefined;
3817
+ return;
3732
3818
  }
3733
3819
  {
3734
3820
  const defForToken = this.getDefinitionFor(token);
3735
3821
  if (defForToken?.token?.isDefinition && defForToken.doc) return defForToken.doc.usageListFor(defForToken.token);
3736
3822
  }
3737
- return undefined;
3738
3823
  }
3739
3824
  /**
3740
3825
  * Retrieves the definition (i.e., the “go to definition” target) for a given token.
@@ -3775,7 +3860,7 @@ else group$1.nested.push({
3775
3860
  uri: targetDoc.id,
3776
3861
  doc: targetDoc,
3777
3862
  token: target
3778
- } : undefined;
3863
+ } : void 0;
3779
3864
  }
3780
3865
  }
3781
3866
  if (token.isReference) {
@@ -3784,7 +3869,7 @@ else group$1.nested.push({
3784
3869
  uri: this.id,
3785
3870
  doc: this,
3786
3871
  token: def
3787
- } : undefined;
3872
+ } : void 0;
3788
3873
  }
3789
3874
  }
3790
3875
  getToDefinitionAt(line, character) {
@@ -3802,7 +3887,7 @@ else group$1.nested.push({
3802
3887
  targetSelectionRange: unwound.node.token("identifier")?.range ?? zeroRange,
3803
3888
  originSelectionRange: token.range
3804
3889
  }];
3805
- return undefined;
3890
+ return;
3806
3891
  }
3807
3892
  if (isQueryFieldRef(token.parentNode)) {
3808
3893
  const fieldRefNode = token.parentNode;
@@ -3817,7 +3902,7 @@ else group$1.nested.push({
3817
3902
  targetRange: result.token?.range ?? zeroRange,
3818
3903
  targetSelectionRange: result.token?.range ?? zeroRange,
3819
3904
  originSelectionRange: token.range
3820
- }] : undefined;
3905
+ }] : void 0;
3821
3906
  }
3822
3907
  if (token === fieldRefNode.fieldRef) {
3823
3908
  const resolved = resolveQueryFieldRef(fieldRefNode, this, scope);
@@ -3833,7 +3918,7 @@ else group$1.nested.push({
3833
3918
  }
3834
3919
  }
3835
3920
  }
3836
- return undefined;
3921
+ return;
3837
3922
  }
3838
3923
  if (isProp(token.parentNode)) return [{
3839
3924
  targetUri: this.id,
@@ -3857,19 +3942,19 @@ else group$1.nested.push({
3857
3942
  targetRange: result.token?.range ?? zeroRange,
3858
3943
  targetSelectionRange: result.token?.range ?? zeroRange,
3859
3944
  originSelectionRange: token.range
3860
- }] : undefined;
3945
+ }] : void 0;
3861
3946
  }
3862
3947
  }
3863
3948
  }
3864
- registerImport({ from, imports, block: block$2 }) {
3949
+ registerImport({ from, imports, block }) {
3865
3950
  const importId = resolveAtscriptFromPath(from.text, this.id);
3866
3951
  this.imports.set(importId, {
3867
3952
  from,
3868
3953
  imports
3869
3954
  });
3870
- this.blocksIndex.add(block$2);
3871
- block$2.blockType = "import";
3872
- block$2.fromPath = from.text;
3955
+ this.blocksIndex.add(block);
3956
+ block.blockType = "import";
3957
+ block.fromPath = from.text;
3873
3958
  this.tokensIndex.add(from);
3874
3959
  from.fromPath = from.text;
3875
3960
  imports.forEach((t) => {
@@ -3909,27 +3994,26 @@ else group$1.nested.push({
3909
3994
  * - `token`: The specific token for the declaration (if applicable).
3910
3995
  *
3911
3996
  * If no declaration is found, returns `undefined`.
3912
- */ getDeclarationOwnerNode(identifier$1) {
3913
- if (this.config.primitives?.has(identifier$1)) return {
3997
+ */ getDeclarationOwnerNode(identifier) {
3998
+ if (this.config.primitives?.has(identifier)) return {
3914
3999
  doc: this,
3915
- node: this.config.primitives.get(identifier$1)
4000
+ node: this.config.primitives.get(identifier)
3916
4001
  };
3917
- const def = this.registry.definitions.get(identifier$1);
4002
+ const def = this.registry.definitions.get(identifier);
3918
4003
  if (def?.imported && def.fromPath) {
3919
4004
  const absolutePath = this.resolveImportId(resolveAtscriptFromPath(def.fromPath, this.id));
3920
- const doc = this.dependenciesMap.get(absolutePath);
3921
- return doc?.getDeclarationOwnerNode(identifier$1);
4005
+ return this.dependenciesMap.get(absolutePath)?.getDeclarationOwnerNode(identifier);
3922
4006
  } else if (!def?.imported) return def ? {
3923
4007
  doc: this,
3924
4008
  node: def.parentNode,
3925
4009
  token: def
3926
- } : undefined;
4010
+ } : void 0;
3927
4011
  }
3928
4012
  registerExport(node) {
3929
4013
  if (node.id) this.exports.set(node.id, node);
3930
4014
  }
3931
4015
  registerMessage(token, message, severity = 1, tag) {
3932
- if (this._allMessages) this._allMessages = undefined;
4016
+ if (this._allMessages) this._allMessages = void 0;
3933
4017
  this.messages.push({
3934
4018
  severity,
3935
4019
  message,
@@ -3941,13 +4025,13 @@ else group$1.nested.push({
3941
4025
  if (messages) this.messages.push(...messages);
3942
4026
  }
3943
4027
  clearMessages() {
3944
- this._allMessages = undefined;
4028
+ this._allMessages = void 0;
3945
4029
  }
3946
4030
  getUnusedTokens() {
3947
4031
  const refSet = new Set(this.referred.filter((r) => !r.imported).map((r) => r.text));
3948
- const tokens$1 = [];
3949
- for (const [key, token] of this.registry.definitions) if (!refSet.has(key) && !this.exports.has(key)) tokens$1.push(token);
3950
- return tokens$1;
4032
+ const tokens = [];
4033
+ for (const [key, token] of this.registry.definitions) if (!refSet.has(key) && !this.exports.has(key)) tokens.push(token);
4034
+ return tokens;
3951
4035
  }
3952
4036
  renderDiagMessage(m, addSourceLinses = false, colors = false) {
3953
4037
  const c = {
@@ -3961,30 +4045,26 @@ else group$1.nested.push({
3961
4045
  let sc = "";
3962
4046
  let banner = "[atscript]";
3963
4047
  switch (m.severity) {
3964
- case TSeverity.Error: {
4048
+ case TSeverity.Error:
3965
4049
  sc = c.red;
3966
4050
  banner += "[Error]";
3967
4051
  break;
3968
- }
3969
- case TSeverity.Warning: {
4052
+ case TSeverity.Warning:
3970
4053
  sc = c.yellow;
3971
4054
  banner += "[Warning]";
3972
4055
  break;
3973
- }
3974
- case TSeverity.Info: {
4056
+ case TSeverity.Info:
3975
4057
  sc = "";
3976
4058
  banner += "[Info]";
3977
4059
  break;
3978
- }
3979
- case TSeverity.Hint: {
4060
+ case TSeverity.Hint:
3980
4061
  sc = c.dim;
3981
4062
  banner += "[Hint]";
3982
4063
  break;
3983
- }
3984
4064
  default: sc = "";
3985
4065
  }
3986
4066
  const n = m.range.start.line + 1;
3987
- let out = `\n${sc}${banner} ${m.message}${c.reset}` + `\nin ${c.blue}${this.id}:${n}:${m.range.start.character + 1}${c.reset}`;
4067
+ let out = `\n${sc}${banner} ${m.message}${c.reset}\nin ${c.blue}${this.id}:${n}:${m.range.start.character + 1}${c.reset}`;
3988
4068
  if (addSourceLinses) {
3989
4069
  const lines = this.text.split("\n");
3990
4070
  const renderLines = [
@@ -4000,7 +4080,7 @@ else group$1.nested.push({
4000
4080
  l: lines[n - 1],
4001
4081
  i: n - 1
4002
4082
  }
4003
- ].filter((r) => r.l !== undefined);
4083
+ ].filter((r) => r.l !== void 0);
4004
4084
  const nl = String(n).length + 1;
4005
4085
  for (const { l, i } of renderLines) {
4006
4086
  const prefix = `${c.dim + c.cyan}${`0${i}`.slice(-nl)} | ${c.reset}`;
@@ -4026,7 +4106,7 @@ else group$1.nested.push({
4026
4106
  });
4027
4107
  const ownDef = iface.getDefinition();
4028
4108
  if (ownDef && isStructure(ownDef)) {
4029
- const parentProps = new Map();
4109
+ const parentProps = /* @__PURE__ */ new Map();
4030
4110
  for (const t of iface.extendsTokens) {
4031
4111
  if (t.text === iface.id) continue;
4032
4112
  const unwound = this.unwindType(t.text);
@@ -4064,8 +4144,7 @@ else group$1.nested.push({
4064
4144
  if (!this.registry.isDefined(targetName)) continue;
4065
4145
  const chain = isRef(t.parentNode) && t.parentNode.hasChain ? [t.text, ...t.parentNode.chain.map((c) => c.text)] : [t.text];
4066
4146
  const unwound = this.unwindType(targetName, chain);
4067
- const chainResolved = unwound?.def && !isGroup(unwound.def);
4068
- const resolvedType = chainResolved ? unwound.def : this.resolveChainWithMerge(targetName, chain);
4147
+ const resolvedType = unwound?.def && !isGroup(unwound.def) ? unwound.def : this.resolveChainWithMerge(targetName, chain);
4069
4148
  if (!resolvedType) {
4070
4149
  const lastToken = chain.length > 1 && isRef(t.parentNode) ? t.parentNode.chain[t.parentNode.chain.length - 1] || t : t;
4071
4150
  this._allMessages.push({
@@ -4079,8 +4158,7 @@ else group$1.nested.push({
4079
4158
  const token = t.parentNode.chain[i];
4080
4159
  const memberChain = [t.text, ...t.parentNode.chain.slice(0, i + 1).map((c) => c.text)];
4081
4160
  const decl = this.unwindType(targetName, memberChain);
4082
- const memberResolved = decl?.def && !isGroup(decl.def);
4083
- if (!memberResolved && !this.resolveChainWithMerge(targetName, memberChain)) this._allMessages.push({
4161
+ if (!(decl?.def && !isGroup(decl.def)) && !this.resolveChainWithMerge(targetName, memberChain)) this._allMessages.push({
4084
4162
  severity: 1,
4085
4163
  message: `Unknown property "${memberChain.join(".")}" in "${targetName}"`,
4086
4164
  range: token.range
@@ -4088,8 +4166,7 @@ else group$1.nested.push({
4088
4166
  }
4089
4167
  }
4090
4168
  if (resolvedType && isRef(t.parentNode) && t.parentNode.annotations) for (const a of t.parentNode.annotations) {
4091
- const spec = this.resolveAnnotation(a.token.text.slice(1));
4092
- const msgs = spec?.validateTargetType(resolvedType, a.token.range);
4169
+ const msgs = this.resolveAnnotation(a.token.text.slice(1))?.validateTargetType(resolvedType, a.token.range);
4093
4170
  if (msgs) this._allMessages.push(...msgs);
4094
4171
  }
4095
4172
  continue;
@@ -4121,8 +4198,7 @@ else group$1.nested.push({
4121
4198
  const length = t.parentNode.chain.length - 1;
4122
4199
  for (let i = length; i >= 0; i--) {
4123
4200
  const token = t.parentNode.chain[i];
4124
- const decl = this.unwindType(t.parentNode.id, t.parentNode.chain.slice(0, i + 1));
4125
- if (!decl?.def) this._allMessages.push({
4201
+ if (!this.unwindType(t.parentNode.id, t.parentNode.chain.slice(0, i + 1))?.def) this._allMessages.push({
4126
4202
  severity: 1,
4127
4203
  message: `Unknown member "${token.text}"`,
4128
4204
  range: token.range
@@ -4148,7 +4224,7 @@ else group$1.nested.push({
4148
4224
  * only need a yes/no resolution check use the truthiness of the result.
4149
4225
  */ resolveChainWithMerge(targetName, chain) {
4150
4226
  let def = this.unwindType(targetName)?.def;
4151
- if (!def) return undefined;
4227
+ if (!def) return;
4152
4228
  for (const prop of chain) {
4153
4229
  def = this.mergeIntersection(def);
4154
4230
  if (isProp(def)) {
@@ -4157,30 +4233,29 @@ else group$1.nested.push({
4157
4233
  }
4158
4234
  if (isStructure(def) || isInterface(def)) {
4159
4235
  const next = def.props.get(prop);
4160
- if (!next) return undefined;
4236
+ if (!next) return;
4161
4237
  def = next.getDefinition() || next;
4162
4238
  } else if (isGroup(def)) {
4163
4239
  const found = this.findPropInGroup(def, prop);
4164
- if (!found) return undefined;
4240
+ if (!found) return;
4165
4241
  def = found;
4166
- } else return undefined;
4242
+ } else return;
4167
4243
  }
4168
4244
  if (isRef(def)) def = this.unwindType(def.id, def.chain)?.def || def;
4169
4245
  return def;
4170
4246
  }
4171
- findPropInGroup(group$1, propName$1) {
4172
- for (const item of group$1.unwrap()) {
4247
+ findPropInGroup(group, propName) {
4248
+ for (const item of group.unwrap()) {
4173
4249
  const merged = this.mergeIntersection(item);
4174
4250
  if (isStructure(merged) || isInterface(merged)) {
4175
- const prop = merged.props.get(propName$1);
4251
+ const prop = merged.props.get(propName);
4176
4252
  if (prop) return prop.getDefinition() || prop;
4177
4253
  }
4178
4254
  if (isGroup(merged)) {
4179
- const found = this.findPropInGroup(merged, propName$1);
4255
+ const found = this.findPropInGroup(merged, propName);
4180
4256
  if (found) return found;
4181
4257
  }
4182
4258
  }
4183
- return undefined;
4184
4259
  }
4185
4260
  mergeIntersection(node) {
4186
4261
  if (!isGroup(node)) return node;
@@ -4199,10 +4274,8 @@ else group$1.nested.push({
4199
4274
  } else left = merged[0];
4200
4275
  }
4201
4276
  newGroup.push(left);
4202
- if (newGroup.length > 1) {
4203
- const newNode = new SemanticGroup(newGroup, "&");
4204
- return newNode;
4205
- } else return newGroup[0];
4277
+ if (newGroup.length > 1) return new SemanticGroup(newGroup, "&");
4278
+ else return newGroup[0];
4206
4279
  }
4207
4280
  mergeDefs(_left, _right) {
4208
4281
  let left = _left;
@@ -4236,7 +4309,7 @@ else group$1.nested.push({
4236
4309
  const oldProps = [leftProp, rightProp].filter(Boolean);
4237
4310
  let optionalToken = oldProps[0]?.token("optional");
4238
4311
  for (const oldProp of oldProps) if (!oldProp.token("optional")) {
4239
- optionalToken = undefined;
4312
+ optionalToken = void 0;
4240
4313
  break;
4241
4314
  }
4242
4315
  if (optionalToken) prop.saveToken(optionalToken, "optional");
@@ -4261,18 +4334,17 @@ else group$1.nested.push({
4261
4334
  * @param right - An optional array of annotation tokens to merge (higher priority).
4262
4335
  * @returns A merged array of annotation tokens, preserving order while preventing duplicates.
4263
4336
  */ mergeNodesAnnotations(left, right) {
4264
- const annotations$1 = [];
4265
- const savedAnnotations = new Set();
4337
+ const annotations = [];
4338
+ const savedAnnotations = /* @__PURE__ */ new Set();
4266
4339
  for (const a of right || []) {
4267
- annotations$1.push(a);
4340
+ annotations.push(a);
4268
4341
  savedAnnotations.add(a.name);
4269
4342
  }
4270
4343
  for (const a of left || []) {
4271
4344
  const spec = this.resolveAnnotation(a.name);
4272
- const append = spec && spec.config.multiple && spec.config.mergeStrategy === "append";
4273
- if (append || !savedAnnotations.has(a.name)) annotations$1.push(a);
4345
+ if (spec && spec.config.multiple && spec.config.mergeStrategy === "append" || !savedAnnotations.has(a.name)) annotations.push(a);
4274
4346
  }
4275
- return annotations$1;
4347
+ return annotations;
4276
4348
  }
4277
4349
  constructor(id, config, manager) {
4278
4350
  _define_property$3(this, "id", void 0);
@@ -4330,22 +4402,22 @@ else group$1.nested.push({
4330
4402
  this.messages = [];
4331
4403
  this.tokensIndex = new TokensIndex();
4332
4404
  this.blocksIndex = new BlocksIndex();
4333
- this.imports = new Map();
4334
- this.resolvedImports = new Map();
4335
- this.importedDefs = new Map();
4336
- this.exports = new Map();
4337
- this.dependencies = new Set();
4338
- this.dependants = new Set();
4405
+ this.imports = /* @__PURE__ */ new Map();
4406
+ this.resolvedImports = /* @__PURE__ */ new Map();
4407
+ this.importedDefs = /* @__PURE__ */ new Map();
4408
+ this.exports = /* @__PURE__ */ new Map();
4409
+ this.dependencies = /* @__PURE__ */ new Set();
4410
+ this.dependants = /* @__PURE__ */ new Set();
4339
4411
  this.referred = [];
4340
4412
  this.queryFieldRefs = [];
4341
- this.dependenciesMap = new Map();
4342
- this._annotationSpecCache = new Map();
4413
+ this.dependenciesMap = /* @__PURE__ */ new Map();
4414
+ this._annotationSpecCache = /* @__PURE__ */ new Map();
4343
4415
  this.nodes = [];
4344
4416
  this._text = "";
4345
4417
  this.resolvedAnnotations = [];
4346
4418
  this.annotations = [];
4347
4419
  this._nextTypeId = 0;
4348
- this._allMessages = undefined;
4420
+ this._allMessages = void 0;
4349
4421
  this.registry = new IdRegistry(Array.from(config.primitives?.keys() || []));
4350
4422
  }
4351
4423
  };
@@ -4360,13 +4432,13 @@ const zeroRange = {
4360
4432
  }
4361
4433
  };
4362
4434
  function createSyntheticRef(name) {
4363
- const ref$1 = new SemanticRefNode();
4364
- ref$1.saveToken(new Token({
4435
+ const ref = new SemanticRefNode();
4436
+ ref.saveToken(new Token({
4365
4437
  text: name,
4366
4438
  type: "identifier",
4367
4439
  getRange: () => zeroRange
4368
4440
  }), "identifier");
4369
- return ref$1;
4441
+ return ref;
4370
4442
  }
4371
4443
 
4372
4444
  //#endregion
@@ -4560,13 +4632,13 @@ const expectAnnotations = {
4560
4632
  validate(token, args, doc) {
4561
4633
  const field = token.parentNode;
4562
4634
  const errors = [];
4563
- const definition$1 = field.getDefinition();
4564
- if (!definition$1) return errors;
4635
+ const definition = field.getDefinition();
4636
+ if (!definition) return errors;
4565
4637
  let wrongType = false;
4566
- if (isRef(definition$1)) {
4567
- const def = doc.unwindType(definition$1.id, definition$1.chain)?.def;
4638
+ if (isRef(definition)) {
4639
+ const def = doc.unwindType(definition.id, definition.chain)?.def;
4568
4640
  if (!isArray(def)) wrongType = true;
4569
- } else if (!isArray(definition$1)) wrongType = true;
4641
+ } else if (!isArray(definition)) wrongType = true;
4570
4642
  if (wrongType) errors.push({
4571
4643
  message: `@expect.array.uniqueItems requires an array field`,
4572
4644
  severity: 1,
@@ -4588,17 +4660,16 @@ const expectAnnotations = {
4588
4660
  validate(token, args, doc) {
4589
4661
  const field = token.parentNode;
4590
4662
  const errors = [];
4591
- const isOptional = !!field.token("optional");
4592
- if (isOptional) errors.push({
4663
+ if (!!field.token("optional")) errors.push({
4593
4664
  message: `@expect.array.key can't be optional`,
4594
4665
  severity: 1,
4595
4666
  range: field.token("identifier").range
4596
4667
  });
4597
- const definition$1 = field.getDefinition();
4598
- if (!definition$1) return errors;
4668
+ const definition = field.getDefinition();
4669
+ if (!definition) return errors;
4599
4670
  let wrongType = false;
4600
- if (isRef(definition$1)) {
4601
- const def = doc.unwindType(definition$1.id, definition$1.chain)?.def;
4671
+ if (isRef(definition)) {
4672
+ const def = doc.unwindType(definition.id, definition.chain)?.def;
4602
4673
  if (isPrimitive(def) && !["string", "number"].includes(def.config.type)) wrongType = true;
4603
4674
  } else wrongType = true;
4604
4675
  if (wrongType) errors.push({
@@ -4692,17 +4763,15 @@ const metaAnnotations = {
4692
4763
  //#region packages/core/src/defaults/primitives.ts
4693
4764
  const IPV4_PATTERN = "^((25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]\\d|\\d)\\.){3}(25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]\\d|\\d)$";
4694
4765
  const IPV6_PATTERN = "^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$";
4695
- const positive = {
4696
- documentation: "Number that greater than or equal to zero.",
4697
- annotations: { "expect.min": 0 }
4698
- };
4699
- const negative = {
4700
- documentation: "Number that less than or equal to zero.",
4701
- annotations: { "expect.max": 0 }
4702
- };
4703
4766
  const positiveOrNegative = {
4704
- positive,
4705
- negative
4767
+ positive: {
4768
+ documentation: "Number that greater than or equal to zero.",
4769
+ annotations: { "expect.min": 0 }
4770
+ },
4771
+ negative: {
4772
+ documentation: "Number that less than or equal to zero.",
4773
+ annotations: { "expect.max": 0 }
4774
+ }
4706
4775
  };
4707
4776
  const primitives = {
4708
4777
  never: { documentation: "Represents impossible type." },
@@ -4935,7 +5004,7 @@ const primitives = {
4935
5004
  //#endregion
4936
5005
  //#region packages/core/src/default-atscript-config.ts
4937
5006
  function getDefaultAtscriptConfig() {
4938
- const defaulTAtscriptConfig = {
5007
+ return {
4939
5008
  primitives,
4940
5009
  annotations: {
4941
5010
  meta: { ...metaAnnotations },
@@ -4943,7 +5012,6 @@ function getDefaultAtscriptConfig() {
4943
5012
  emit: { ...emitAnnotations }
4944
5013
  }
4945
5014
  };
4946
- return defaulTAtscriptConfig;
4947
5015
  }
4948
5016
 
4949
5017
  //#endregion
@@ -4955,7 +5023,7 @@ function _define_property$2(obj, key, value) {
4955
5023
  configurable: true,
4956
5024
  writable: true
4957
5025
  });
4958
- else obj[key] = value;
5026
+ else obj[key] = value;
4959
5027
  return obj;
4960
5028
  }
4961
5029
  var PluginManager = class {
@@ -4967,7 +5035,7 @@ var PluginManager = class {
4967
5035
  const raw = await this.config();
4968
5036
  this._docConfig = {};
4969
5037
  if (raw?.primitives) {
4970
- this._docConfig.primitives = new Map();
5038
+ this._docConfig.primitives = /* @__PURE__ */ new Map();
4971
5039
  for (const [key, value] of Object.entries(raw.primitives)) this._docConfig.primitives.set(key, new SemanticPrimitiveNode(key, value, "", raw.annotations));
4972
5040
  }
4973
5041
  if (raw?.annotations) this._docConfig.annotations = { ...raw.annotations };
@@ -4978,7 +5046,7 @@ var PluginManager = class {
4978
5046
  async config(config = this.cfg) {
4979
5047
  if (!this._config) {
4980
5048
  config = defu(config, getDefaultAtscriptConfig());
4981
- const seen = new Set();
5049
+ const seen = /* @__PURE__ */ new Set();
4982
5050
  for (const plugin of this.plugins) {
4983
5051
  if (seen.has(plugin.name)) continue;
4984
5052
  seen.add(plugin.name);
@@ -5020,16 +5088,15 @@ var PluginManager = class {
5020
5088
  for (const plugin of this.plugins) if (plugin.buildEnd) await plugin.buildEnd(output, format, repo);
5021
5089
  }
5022
5090
  async loopInAnnotationsSpec(cb) {
5023
- const config = await this.config();
5024
- const annotations$1 = config.annotations || {};
5025
- return this._loopInAnnotationsSpec(annotations$1, cb);
5091
+ const annotations = (await this.config()).annotations || {};
5092
+ return this._loopInAnnotationsSpec(annotations, cb);
5026
5093
  }
5027
- _loopInAnnotationsSpec(annotations$1, cb, prefix) {
5028
- if (annotations$1.$self && prefix) cb(prefix, annotations$1.$self);
5029
- for (const [key, value] of Object.entries(annotations$1)) {
5094
+ _loopInAnnotationsSpec(annotations, cb, prefix) {
5095
+ if (annotations.$self && prefix) cb(prefix, annotations.$self);
5096
+ for (const [key, value] of Object.entries(annotations)) {
5030
5097
  if (key === "$self") continue;
5031
5098
  if (isAnnotationSpec(value)) cb(prefix ? `${prefix}.${key}` : key, value);
5032
- else this._loopInAnnotationsSpec(value, cb, prefix ? `${prefix}.${key}` : key);
5099
+ else this._loopInAnnotationsSpec(value, cb, prefix ? `${prefix}.${key}` : key);
5033
5100
  }
5034
5101
  }
5035
5102
  constructor(cfg) {
@@ -5051,7 +5118,7 @@ function _define_property$1(obj, key, value) {
5051
5118
  configurable: true,
5052
5119
  writable: true
5053
5120
  });
5054
- else obj[key] = value;
5121
+ else obj[key] = value;
5055
5122
  return obj;
5056
5123
  }
5057
5124
  var AtscriptRepo = class {
@@ -5060,12 +5127,12 @@ var AtscriptRepo = class {
5060
5127
  }
5061
5128
  async getPrimitivesTags() {
5062
5129
  const manager = await this.getSharedPluginManager();
5063
- if (!manager) return undefined;
5130
+ if (!manager) return;
5064
5131
  const docConfig = await manager.getDocConfig();
5065
- const primitives$1 = Array.from(docConfig.primitives?.entries() || []);
5132
+ const primitives = Array.from(docConfig.primitives?.entries() || []);
5066
5133
  const tags = [];
5067
- const processed = new Set();
5068
- for (const [, primitive] of primitives$1) tags.push(...primitive.getAllTags(processed));
5134
+ const processed = /* @__PURE__ */ new Set();
5135
+ for (const [, primitive] of primitives) tags.push(...primitive.getAllTags(processed));
5069
5136
  return new Set(tags);
5070
5137
  }
5071
5138
  async getUsedAnnotations() {
@@ -5075,7 +5142,7 @@ var AtscriptRepo = class {
5075
5142
  };
5076
5143
  const mapArgType = (t) => ANNOTATION_TYPE_MAP[t] || t;
5077
5144
  const manager = await this.getSharedPluginManager();
5078
- const annotations$1 = {};
5145
+ const annotations = {};
5079
5146
  if (manager) await manager.loopInAnnotationsSpec((name, spec) => {
5080
5147
  const types = [];
5081
5148
  const multiple = !!spec.config.multiple;
@@ -5093,62 +5160,57 @@ var AtscriptRepo = class {
5093
5160
  type: mapArgType(spec.config.argument.type),
5094
5161
  optional: spec.config.argument.optional
5095
5162
  });
5096
- else types.push({ type: "boolean" });
5097
- annotations$1[name] = {
5163
+ else types.push({ type: "boolean" });
5164
+ annotations[name] = {
5098
5165
  multiple,
5099
5166
  fromSpec: true,
5100
- typeSet: new Set(),
5167
+ typeSet: /* @__PURE__ */ new Set(),
5101
5168
  types
5102
5169
  };
5103
5170
  });
5104
5171
  for (const doc of Array.from(this.atscripts.values())) {
5105
5172
  const awaited = await doc;
5106
5173
  for (const { name, token, args } of awaited.annotations) {
5107
- if (annotations$1[name]?.fromSpec) continue;
5108
- if (!annotations$1[name]) {
5109
- const types = [];
5110
- const multiple = false;
5111
- annotations$1[name] = {
5112
- multiple,
5113
- fromSpec: false,
5114
- typeSet: new Set(),
5115
- types
5116
- };
5117
- }
5118
- const isArray$1 = token.parentNode.countAnnotations(name) > 1;
5119
- if (isArray$1) annotations$1[name].multiple = true;
5174
+ if (annotations[name]?.fromSpec) continue;
5175
+ if (!annotations[name]) annotations[name] = {
5176
+ multiple: false,
5177
+ fromSpec: false,
5178
+ typeSet: /* @__PURE__ */ new Set(),
5179
+ types: []
5180
+ };
5181
+ if (token.parentNode.countAnnotations(name) > 1) annotations[name].multiple = true;
5120
5182
  for (const arg of args) if (arg.type === "text") {
5121
- if (!annotations$1[name].typeSet.has("string")) {
5122
- annotations$1[name].typeSet.add("string");
5123
- annotations$1[name].types.push({ type: "string" });
5183
+ if (!annotations[name].typeSet.has("string")) {
5184
+ annotations[name].typeSet.add("string");
5185
+ annotations[name].types.push({ type: "string" });
5124
5186
  }
5125
5187
  } else if (arg.type === "number") {
5126
- if (!annotations$1[name].typeSet.has("number")) {
5127
- annotations$1[name].typeSet.add("number");
5128
- annotations$1[name].types.push({ type: "number" });
5188
+ if (!annotations[name].typeSet.has("number")) {
5189
+ annotations[name].typeSet.add("number");
5190
+ annotations[name].types.push({ type: "number" });
5129
5191
  }
5130
5192
  } else if (arg.type === "identifier" && ["true", "false"].includes(arg.text)) {
5131
- if (!annotations$1[name].typeSet.has("boolean")) {
5132
- annotations$1[name].typeSet.add("boolean");
5133
- annotations$1[name].types.push({ type: "boolean" });
5193
+ if (!annotations[name].typeSet.has("boolean")) {
5194
+ annotations[name].typeSet.add("boolean");
5195
+ annotations[name].types.push({ type: "boolean" });
5134
5196
  }
5135
- } else if (!annotations$1[name].typeSet.has("unknown")) {
5136
- annotations$1[name].typeSet.add("unknown");
5137
- annotations$1[name].types.push({ type: "unknown" });
5197
+ } else if (!annotations[name].typeSet.has("unknown")) {
5198
+ annotations[name].typeSet.add("unknown");
5199
+ annotations[name].types.push({ type: "unknown" });
5138
5200
  }
5139
- if (args.length === 0 && !annotations$1[name].typeSet.has("boolean")) {
5140
- annotations$1[name].typeSet.add("boolean");
5141
- annotations$1[name].types.push({ type: "boolean" });
5201
+ if (args.length === 0 && !annotations[name].typeSet.has("boolean")) {
5202
+ annotations[name].typeSet.add("boolean");
5203
+ annotations[name].types.push({ type: "boolean" });
5142
5204
  }
5143
5205
  }
5144
5206
  }
5145
- return annotations$1;
5207
+ return annotations;
5146
5208
  }
5147
5209
  async loadPluginManagerFor(id) {
5148
5210
  if (this.sharedConfig) {
5149
5211
  if (!this.sharedPluginManager) this.sharedPluginManager = {
5150
5212
  manager: new PluginManager(this.sharedConfig),
5151
- dependants: new Set()
5213
+ dependants: /* @__PURE__ */ new Set()
5152
5214
  };
5153
5215
  return this.sharedPluginManager;
5154
5216
  }
@@ -5165,14 +5227,14 @@ else types.push({ type: "boolean" });
5165
5227
  return {
5166
5228
  file: configFile,
5167
5229
  manager,
5168
- dependants: new Set()
5230
+ dependants: /* @__PURE__ */ new Set()
5169
5231
  };
5170
5232
  } else {
5171
5233
  const manager = new PluginManager({ rootDir: process.cwd() });
5172
5234
  await manager.getDocConfig();
5173
5235
  return {
5174
5236
  manager,
5175
- dependants: new Set()
5237
+ dependants: /* @__PURE__ */ new Set()
5176
5238
  };
5177
5239
  }
5178
5240
  }
@@ -5187,18 +5249,18 @@ else types.push({ type: "boolean" });
5187
5249
  }
5188
5250
  return config;
5189
5251
  }
5190
- async openDocument(id, text$2) {
5252
+ async openDocument(id, text) {
5191
5253
  let atscript = this.atscripts.get(id);
5192
5254
  if (atscript) {
5193
- if (text$2) {
5255
+ if (text) {
5194
5256
  atscript = atscript.then((d) => {
5195
- d.update(text$2);
5257
+ d.update(text);
5196
5258
  return d;
5197
5259
  });
5198
5260
  this.atscripts.set(id, atscript);
5199
5261
  }
5200
5262
  } else {
5201
- atscript = this._openDocument(id, text$2);
5263
+ atscript = this._openDocument(id, text);
5202
5264
  atscript.catch(() => {
5203
5265
  this.atscripts.delete(id);
5204
5266
  });
@@ -5206,11 +5268,11 @@ else types.push({ type: "boolean" });
5206
5268
  }
5207
5269
  return atscript;
5208
5270
  }
5209
- async _openDocument(id, text$2) {
5271
+ async _openDocument(id, text) {
5210
5272
  const { manager } = await this.resolveConfig(id);
5211
5273
  const newId = await manager.resolve(id);
5212
5274
  if (!newId) throw new Error(`Document not resolved: ${id}`);
5213
- const content = text$2 || await manager.load(newId);
5275
+ const content = text || await manager.load(newId);
5214
5276
  if (typeof content !== "string") throw new TypeError(`Document not found: ${newId}`);
5215
5277
  const atscript = new AtscriptDoc(id, await manager.getDocConfig(), manager);
5216
5278
  atscript.update(content);
@@ -5221,11 +5283,10 @@ else types.push({ type: "boolean" });
5221
5283
  await this.checkImports(atscript);
5222
5284
  }
5223
5285
  async checkImports(atscript, checked) {
5224
- const _checked = checked || new Set();
5286
+ const _checked = checked || /* @__PURE__ */ new Set();
5225
5287
  if (_checked.has(atscript.id)) return;
5226
5288
  _checked.add(atscript.id);
5227
- const promise = Promise.all(Array.from(atscript.imports.values(), async ({ from, imports }) => this.checkImport(atscript, from, imports, _checked)));
5228
- const results = await promise;
5289
+ const results = await Promise.all(Array.from(atscript.imports.values(), async ({ from, imports }) => this.checkImport(atscript, from, imports, _checked)));
5229
5290
  atscript.updateDependencies(results.filter(Boolean));
5230
5291
  }
5231
5292
  async checkImport(atscript, from, imports, checked) {
@@ -5273,7 +5334,7 @@ else types.push({ type: "boolean" });
5273
5334
  }
5274
5335
  return external;
5275
5336
  }
5276
- constructor(root$1 = process.cwd(), sharedConfig) {
5337
+ constructor(root = process.cwd(), sharedConfig) {
5277
5338
  _define_property$1(this, "root", void 0);
5278
5339
  _define_property$1(this, "sharedConfig", void 0);
5279
5340
  _define_property$1(this, "configFormat", void 0);
@@ -5290,18 +5351,35 @@ else types.push({ type: "boolean" });
5290
5351
  /**
5291
5352
  * cache for raw content of config files
5292
5353
  */ _define_property$1(this, "configFiles", void 0);
5293
- this.root = root$1;
5354
+ this.root = root;
5294
5355
  this.sharedConfig = sharedConfig;
5295
- this.configs = new Map();
5296
- this.atscripts = new Map();
5297
- this.resolvedToBare = new Map();
5298
- this.configFiles = new Map();
5356
+ this.configs = /* @__PURE__ */ new Map();
5357
+ this.atscripts = /* @__PURE__ */ new Map();
5358
+ this.resolvedToBare = /* @__PURE__ */ new Map();
5359
+ this.configFiles = /* @__PURE__ */ new Map();
5299
5360
  }
5300
5361
  };
5301
5362
 
5302
5363
  //#endregion
5303
5364
  //#region packages/core/src/plugin/types.ts
5304
- const DEFAULT_FORMAT = "__default__";
5365
+ /**
5366
+ * Well-known render format for a plugin's primary output.
5367
+ *
5368
+ * When a `.as` file is saved in an editor (VSCode, etc.), the editor
5369
+ * passes this format to `render()` and `buildEnd()`. Plugins should
5370
+ * check for this value alongside their own format strings to produce
5371
+ * output that is essential for the development experience — typically
5372
+ * type declarations for the host language.
5373
+ *
5374
+ * @example
5375
+ * ```ts
5376
+ * render(doc, format) {
5377
+ * if (format === 'dts' || format === DEFAULT_FORMAT) {
5378
+ * return [{ fileName: `${doc.name}.d.ts`, content: renderTypes(doc) }]
5379
+ * }
5380
+ * }
5381
+ * ```
5382
+ */ const DEFAULT_FORMAT = "__default__";
5305
5383
  const createAtscriptPlugin = (plugin) => plugin;
5306
5384
 
5307
5385
  //#endregion
@@ -5313,7 +5391,7 @@ function _define_property(obj, key, value) {
5313
5391
  configurable: true,
5314
5392
  writable: true
5315
5393
  });
5316
- else obj[key] = value;
5394
+ else obj[key] = value;
5317
5395
  return obj;
5318
5396
  }
5319
5397
  async function build(config) {
@@ -5322,13 +5400,11 @@ async function build(config) {
5322
5400
  const repo = new AtscriptRepo(rootDir, config);
5323
5401
  const entries = [];
5324
5402
  if (config.entries && config.entries.length > 0) for (const entry of config.entries) entries.push(path$1.join(rootDir, entry));
5325
- else {
5326
- const includes = config.include && config.include.length > 0 ? config.include : ["**/*.as"];
5327
- const excludes = config.exclude && config.exclude.length > 0 ? config.exclude : ["node_modules"];
5328
- const found = await glob(includes, {
5403
+ else {
5404
+ const found = await glob(config.include && config.include.length > 0 ? config.include : ["**/*.as"], {
5329
5405
  cwd: rootDir,
5330
5406
  absolute: true,
5331
- ignore: excludes
5407
+ ignore: config.exclude && config.exclude.length > 0 ? config.exclude : ["node_modules"]
5332
5408
  });
5333
5409
  entries.push(...found);
5334
5410
  }
@@ -5343,7 +5419,7 @@ var BuildRepo = class {
5343
5419
  return this.docs.find((d) => d.id === id);
5344
5420
  }
5345
5421
  async diagnostics() {
5346
- const docMessages = new Map();
5422
+ const docMessages = /* @__PURE__ */ new Map();
5347
5423
  for (const document of this.docs) docMessages.set(document.id, document.getDiagMessages());
5348
5424
  return docMessages;
5349
5425
  }
@@ -5367,11 +5443,18 @@ var BuildRepo = class {
5367
5443
  }
5368
5444
  return outFiles;
5369
5445
  }
5370
- async write(config, docs = this.docs) {
5446
+ /**
5447
+ * Renders every document and writes the outputs to disk.
5448
+ *
5449
+ * Each write is awaited and atomic (temp file + rename), because a consumer
5450
+ * watching the output — a dev server, a type checker, another build — must
5451
+ * never observe a half-written file, and an un-awaited write can be
5452
+ * truncated when the process exits.
5453
+ */ async write(config, docs = this.docs) {
5371
5454
  const outFiles = await this.generate(config, docs);
5372
5455
  for (const o of outFiles) if (o.target) {
5373
5456
  await mkdir(path$1.dirname(o.target), { recursive: true });
5374
- writeFile(o.target, o.content);
5457
+ await writeFileAtomic(o.target, o.content);
5375
5458
  }
5376
5459
  return outFiles;
5377
5460
  }
@@ -5384,12 +5467,49 @@ var BuildRepo = class {
5384
5467
  this.docs = docs;
5385
5468
  }
5386
5469
  };
5470
+ let tmpSeq = 0;
5471
+ /**
5472
+ * Writes `content` to a sibling temp file and renames it over `target`, so the
5473
+ * target is either the old file or the new one — never a partial write.
5474
+ * The temp file is removed if anything goes wrong.
5475
+ */ async function writeFileAtomic(target, content) {
5476
+ const tmp = `${target}.${process.pid}.${tmpSeq++}.tmp`;
5477
+ try {
5478
+ await writeFile(tmp, content);
5479
+ await rename(tmp, target);
5480
+ } catch (error) {
5481
+ try {
5482
+ await rm(tmp, { force: true });
5483
+ } catch {}
5484
+ throw error;
5485
+ }
5486
+ }
5387
5487
 
5388
5488
  //#endregion
5389
5489
  //#region packages/core/src/flatten.ts
5390
- function flattenInterfaceNode(doc, node, options) {
5391
- const flatMap = new Map();
5392
- const stack = new Set();
5490
+ /**
5491
+ * Flattens an interface node into a map of dot-notation paths to their type descriptors.
5492
+ *
5493
+ * This utility exists to improve type-safety for filter expressions and `$select`/`$sort`
5494
+ * operations in the DB layer. The generated `__flat` static property on `@db.table`
5495
+ * interfaces uses this map to provide autocomplete and compile-time checks for
5496
+ * dot-notation query paths.
5497
+ *
5498
+ * Walks the interface structure (including inherited props from `extends`) and collects
5499
+ * all reachable field paths. Nested objects are recursed into, arrays are recursed through
5500
+ * their element types, and unions/intersections are recursed through each branch (with
5501
+ * colliding paths merged into union groups).
5502
+ *
5503
+ * Fields annotated with `@db.json` are treated as leaves — their sub-paths are NOT included,
5504
+ * because `@db.json` fields are stored as a single JSON column in the database and their
5505
+ * sub-paths are not individually queryable.
5506
+ *
5507
+ * @param doc - The document owning the interface node.
5508
+ * @param node - The interface node to flatten.
5509
+ * @returns A map of dot-separated paths to their field descriptors.
5510
+ */ function flattenInterfaceNode(doc, node, options) {
5511
+ const flatMap = /* @__PURE__ */ new Map();
5512
+ const stack = /* @__PURE__ */ new Set();
5393
5513
  let struct;
5394
5514
  if (node.hasExtends) struct = doc.resolveInterfaceExtends(node);
5395
5515
  if (!struct) struct = node.getDefinition();
@@ -5424,10 +5544,10 @@ function isPhantomNode(doc, def) {
5424
5544
  }
5425
5545
  function resolveNode(doc, def) {
5426
5546
  if (isRef(def)) {
5427
- const ref$1 = def;
5428
- const unwound = doc.unwindType(ref$1.id, ref$1.chain);
5547
+ const ref = def;
5548
+ const unwound = doc.unwindType(ref.id, ref.chain);
5429
5549
  if (unwound?.def) return resolveNode(unwound.doc, unwound.def);
5430
- return undefined;
5550
+ return;
5431
5551
  }
5432
5552
  if (isInterface(def)) {
5433
5553
  const iface = def;
@@ -5438,7 +5558,7 @@ function resolveNode(doc, def) {
5438
5558
  def: struct,
5439
5559
  doc
5440
5560
  };
5441
- return undefined;
5561
+ return;
5442
5562
  }
5443
5563
  return {
5444
5564
  def,
@@ -5448,18 +5568,18 @@ function resolveNode(doc, def) {
5448
5568
  function isComplexNode(def) {
5449
5569
  return isStructure(def) || isArray(def) || isGroup(def) && def.entity !== "tuple";
5450
5570
  }
5451
- function addToFlatMap(flatMap, path$2, descriptor) {
5452
- const existing = flatMap.get(path$2);
5571
+ function addToFlatMap(flatMap, path, descriptor) {
5572
+ const existing = flatMap.get(path);
5453
5573
  if (existing) {
5454
- const group$1 = new SemanticGroup([existing.def, descriptor.def], "|");
5455
- flatMap.set(path$2, {
5456
- def: group$1,
5574
+ const group = new SemanticGroup([existing.def, descriptor.def], "|");
5575
+ flatMap.set(path, {
5576
+ def: group,
5457
5577
  doc: existing.doc,
5458
5578
  optional: existing.optional || descriptor.optional,
5459
5579
  propNode: existing.propNode,
5460
- intermediate: existing.intermediate && descriptor.intermediate ? true : undefined
5580
+ intermediate: existing.intermediate && descriptor.intermediate ? true : void 0
5461
5581
  });
5462
- } else flatMap.set(path$2, descriptor);
5582
+ } else flatMap.set(path, descriptor);
5463
5583
  }
5464
5584
  function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack, options) {
5465
5585
  for (const [name, prop] of struct.props) {
@@ -5467,11 +5587,11 @@ function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack, opti
5467
5587
  const propDef = prop.getDefinition();
5468
5588
  if (isPhantomNode(doc, propDef)) continue;
5469
5589
  if (options?.skipNavProps && hasNavPropAnnotation(prop)) continue;
5470
- const path$2 = prefix ? `${prefix}.${name}` : name;
5590
+ const path = prefix ? `${prefix}.${name}` : name;
5471
5591
  const optional = parentOptional || !!prop.token("optional");
5472
5592
  const dbJson = hasDbJsonAnnotation(prop);
5473
5593
  if (!propDef) {
5474
- addToFlatMap(flatMap, path$2, {
5594
+ addToFlatMap(flatMap, path, {
5475
5595
  def: prop,
5476
5596
  doc,
5477
5597
  optional,
@@ -5481,7 +5601,7 @@ function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack, opti
5481
5601
  }
5482
5602
  const resolved = resolveNode(doc, propDef);
5483
5603
  if (!resolved) {
5484
- addToFlatMap(flatMap, path$2, {
5604
+ addToFlatMap(flatMap, path, {
5485
5605
  def: propDef,
5486
5606
  doc,
5487
5607
  optional,
@@ -5490,7 +5610,7 @@ function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack, opti
5490
5610
  continue;
5491
5611
  }
5492
5612
  if (dbJson) {
5493
- addToFlatMap(flatMap, path$2, {
5613
+ addToFlatMap(flatMap, path, {
5494
5614
  def: resolved.def,
5495
5615
  doc: resolved.doc,
5496
5616
  optional,
@@ -5499,12 +5619,12 @@ function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack, opti
5499
5619
  });
5500
5620
  continue;
5501
5621
  }
5502
- walkNode(resolved.doc, resolved.def, path$2, optional, prop, flatMap, stack, options);
5622
+ walkNode(resolved.doc, resolved.def, path, optional, prop, flatMap, stack, options);
5503
5623
  }
5504
5624
  }
5505
- function walkNode(doc, def, path$2, optional, propNode, flatMap, stack, options) {
5625
+ function walkNode(doc, def, path, optional, propNode, flatMap, stack, options) {
5506
5626
  if (stack.has(def)) {
5507
- addToFlatMap(flatMap, path$2, {
5627
+ addToFlatMap(flatMap, path, {
5508
5628
  def,
5509
5629
  doc,
5510
5630
  optional,
@@ -5515,69 +5635,68 @@ function walkNode(doc, def, path$2, optional, propNode, flatMap, stack, options)
5515
5635
  stack.add(def);
5516
5636
  try {
5517
5637
  if (isStructure(def)) {
5518
- addToFlatMap(flatMap, path$2, {
5638
+ addToFlatMap(flatMap, path, {
5519
5639
  def,
5520
5640
  doc,
5521
5641
  optional,
5522
5642
  propNode,
5523
5643
  intermediate: true
5524
5644
  });
5525
- walkStructure(doc, def, path$2, optional, flatMap, stack, options);
5645
+ walkStructure(doc, def, path, optional, flatMap, stack, options);
5526
5646
  } else if (isArray(def)) {
5527
5647
  const elementDef = def.getDefinition();
5528
- const resolvedElement = elementDef ? resolveNode(doc, elementDef) : undefined;
5529
- const isComplexElement = resolvedElement && (isStructure(resolvedElement.def) || isGroup(resolvedElement.def) && resolvedElement.def.entity !== "tuple" || isArray(resolvedElement.def));
5530
- if (isComplexElement) {
5531
- addToFlatMap(flatMap, path$2, {
5648
+ const resolvedElement = elementDef ? resolveNode(doc, elementDef) : void 0;
5649
+ if (resolvedElement && (isStructure(resolvedElement.def) || isGroup(resolvedElement.def) && resolvedElement.def.entity !== "tuple" || isArray(resolvedElement.def))) {
5650
+ addToFlatMap(flatMap, path, {
5532
5651
  def,
5533
5652
  doc,
5534
5653
  optional,
5535
5654
  propNode,
5536
5655
  intermediate: true
5537
5656
  });
5538
- walkArrayElement(doc, def, path$2, optional, flatMap, stack, options);
5539
- } else addToFlatMap(flatMap, path$2, {
5657
+ walkArrayElement(doc, def, path, optional, flatMap, stack, options);
5658
+ } else addToFlatMap(flatMap, path, {
5540
5659
  def,
5541
5660
  doc,
5542
5661
  optional,
5543
5662
  propNode
5544
5663
  });
5545
5664
  } else if (isGroup(def) && def.entity !== "structure") {
5546
- const group$1 = def;
5547
- if (group$1.op === "&") {
5665
+ const group = def;
5666
+ if (group.op === "&") {
5548
5667
  const merged = doc.mergeIntersection(def);
5549
5668
  if (merged !== def && isStructure(merged)) {
5550
- addToFlatMap(flatMap, path$2, {
5669
+ addToFlatMap(flatMap, path, {
5551
5670
  def: merged,
5552
5671
  doc,
5553
5672
  optional,
5554
5673
  propNode,
5555
5674
  intermediate: true
5556
5675
  });
5557
- walkStructure(doc, merged, path$2, optional, flatMap, stack, options);
5558
- } else addToFlatMap(flatMap, path$2, {
5676
+ walkStructure(doc, merged, path, optional, flatMap, stack, options);
5677
+ } else addToFlatMap(flatMap, path, {
5559
5678
  def,
5560
5679
  doc,
5561
5680
  optional,
5562
5681
  propNode
5563
5682
  });
5564
- } else if (group$1.op === "|") {
5565
- const branches = group$1.unwrap();
5683
+ } else if (group.op === "|") {
5684
+ const branches = group.unwrap();
5566
5685
  let hasComplexBranch = false;
5567
5686
  let hasLeafBranch = false;
5568
5687
  for (const branch of branches) {
5569
5688
  const resolved = resolveNode(doc, branch);
5570
5689
  if (resolved && isComplexNode(resolved.def)) hasComplexBranch = true;
5571
- else hasLeafBranch = true;
5690
+ else hasLeafBranch = true;
5572
5691
  }
5573
5692
  if (hasComplexBranch) {
5574
- if (hasLeafBranch) addToFlatMap(flatMap, path$2, {
5693
+ if (hasLeafBranch) addToFlatMap(flatMap, path, {
5575
5694
  def,
5576
5695
  doc,
5577
5696
  optional,
5578
5697
  propNode
5579
5698
  });
5580
- else addToFlatMap(flatMap, path$2, {
5699
+ else addToFlatMap(flatMap, path, {
5581
5700
  def,
5582
5701
  doc,
5583
5702
  optional,
@@ -5586,21 +5705,21 @@ else addToFlatMap(flatMap, path$2, {
5586
5705
  });
5587
5706
  for (const branch of branches) {
5588
5707
  const resolved = resolveNode(doc, branch);
5589
- if (resolved) walkBranch(resolved.doc, resolved.def, path$2, optional, flatMap, stack, options);
5708
+ if (resolved) walkBranch(resolved.doc, resolved.def, path, optional, flatMap, stack, options);
5590
5709
  }
5591
- } else addToFlatMap(flatMap, path$2, {
5710
+ } else addToFlatMap(flatMap, path, {
5592
5711
  def,
5593
5712
  doc,
5594
5713
  optional,
5595
5714
  propNode
5596
5715
  });
5597
- } else addToFlatMap(flatMap, path$2, {
5716
+ } else addToFlatMap(flatMap, path, {
5598
5717
  def,
5599
5718
  doc,
5600
5719
  optional,
5601
5720
  propNode
5602
5721
  });
5603
- } else addToFlatMap(flatMap, path$2, {
5722
+ } else addToFlatMap(flatMap, path, {
5604
5723
  def,
5605
5724
  doc,
5606
5725
  optional,
@@ -5622,13 +5741,13 @@ function walkArrayElement(doc, arrayNode, prefix, parentOptional, flatMap, stack
5622
5741
  * Does NOT add an entry for the branch itself — the parent already did that.
5623
5742
  */ function walkBranch(doc, def, prefix, parentOptional, flatMap, stack, options) {
5624
5743
  if (isStructure(def)) walkStructure(doc, def, prefix, parentOptional, flatMap, stack, options);
5625
- else if (isArray(def)) walkArrayElement(doc, def, prefix, parentOptional, flatMap, stack, options);
5626
- else if (isGroup(def) && def.entity !== "structure") {
5627
- const group$1 = def;
5628
- if (group$1.op === "&") {
5744
+ else if (isArray(def)) walkArrayElement(doc, def, prefix, parentOptional, flatMap, stack, options);
5745
+ else if (isGroup(def) && def.entity !== "structure") {
5746
+ const group = def;
5747
+ if (group.op === "&") {
5629
5748
  const merged = doc.mergeIntersection(def);
5630
5749
  if (isStructure(merged)) walkStructure(doc, merged, prefix, parentOptional, flatMap, stack, options);
5631
- } else if (group$1.op === "|") for (const branch of group$1.unwrap()) {
5750
+ } else if (group.op === "|") for (const branch of group.unwrap()) {
5632
5751
  const resolved = resolveNode(doc, branch);
5633
5752
  if (resolved) walkBranch(resolved.doc, resolved.def, prefix, parentOptional, flatMap, stack, options);
5634
5753
  }