@atscript/core 0.1.87 → 0.1.89

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.cjs +734 -678
  2. package/dist/index.mjs +637 -588
  3. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -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,25 @@ 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
1463
  if (isInterface(def)) {
1446
1464
  const resolved = doc.resolveInterfaceExtends(def);
1447
1465
  if (resolved) def = resolved;
1448
- else def = def.getDefinition() || def;
1466
+ else def = def.getDefinition() || def;
1449
1467
  }
1450
1468
  if (isStructure(def) || isInterface(def)) return Array.from(def.props.values());
1451
1469
  return [];
1452
1470
  }
1453
- function getQueryCompletionScope(queryArgToken, doc) {
1471
+ /**
1472
+ * Get completion scope data for a query context.
1473
+ */ function getQueryCompletionScope(queryArgToken, doc) {
1454
1474
  const scope = getQueryScope(queryArgToken, doc);
1455
- if (!scope) return undefined;
1475
+ if (!scope) return;
1456
1476
  return {
1457
1477
  typeNames: scope.allowedTypes,
1458
1478
  unqualifiedTarget: scope.unqualifiedTarget,
@@ -1483,7 +1503,12 @@ const VALUE_KEYWORDS$1 = new Set([
1483
1503
  "null",
1484
1504
  "undefined"
1485
1505
  ]);
1486
- function analyzeQueryCursorContext(textBeforeCursor) {
1506
+ /**
1507
+ * Analyze text inside backticks up to cursor position
1508
+ * to determine what kind of completions to offer.
1509
+ * Uses lightweight text scanning, not full AST parsing,
1510
+ * so it works on incomplete/mid-typing input.
1511
+ */ function analyzeQueryCursorContext(textBeforeCursor) {
1487
1512
  const trimmed = textBeforeCursor.trimEnd();
1488
1513
  const hasTrailingSpace = textBeforeCursor.length > trimmed.length;
1489
1514
  if (trimmed.length === 0) return { type: "field-start" };
@@ -1496,17 +1521,17 @@ function analyzeQueryCursorContext(textBeforeCursor) {
1496
1521
  };
1497
1522
  return { type: "field-start" };
1498
1523
  }
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];
1524
+ const tokens = tokenizeQueryText(trimmed);
1525
+ if (tokens.length === 0) return { type: "field-start" };
1526
+ const last = tokens[tokens.length - 1];
1502
1527
  if (LOGICAL_KEYWORDS.has(last) || last === "(") return { type: "field-start" };
1503
1528
  if (SYMBOLIC_OPS$1.has(last)) return { type: "after-operator" };
1504
1529
  if (last === "in" || last === "matches") return { type: "after-operator" };
1505
1530
  if (last === "exists") return { type: "after-comparison" };
1506
1531
  if (VALUE_KEYWORDS$1.has(last)) return { type: "after-comparison" };
1507
1532
  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];
1533
+ if (tokens.length >= 2) {
1534
+ const prev = tokens[tokens.length - 2];
1510
1535
  if (SYMBOLIC_OPS$1.has(prev) || KEYWORD_OPS.has(prev)) return { type: "after-comparison" };
1511
1536
  }
1512
1537
  if (/^\w+$/u.test(last)) {
@@ -1518,53 +1543,53 @@ function analyzeQueryCursorContext(textBeforeCursor) {
1518
1543
  /**
1519
1544
  * Simple tokenizer for query text — splits into identifiers, operators, and punctuation.
1520
1545
  * Does NOT need to handle all edge cases; just enough for cursor context analysis.
1521
- */ function tokenizeQueryText(text$2) {
1522
- const tokens$1 = [];
1546
+ */ function tokenizeQueryText(text) {
1547
+ const tokens = [];
1523
1548
  let i = 0;
1524
- while (i < text$2.length) {
1525
- if (/\s/.test(text$2[i])) {
1549
+ while (i < text.length) {
1550
+ if (/\s/.test(text[i])) {
1526
1551
  i++;
1527
1552
  continue;
1528
1553
  }
1529
- if (text$2[i] === "'" || text$2[i] === "\"") {
1530
- const quote = text$2[i];
1554
+ if (text[i] === "'" || text[i] === "\"") {
1555
+ const quote = text[i];
1531
1556
  let j = i + 1;
1532
- while (j < text$2.length && text$2[j] !== quote) {
1533
- if (text$2[j] === "\\") j++;
1557
+ while (j < text.length && text[j] !== quote) {
1558
+ if (text[j] === "\\") j++;
1534
1559
  j++;
1535
1560
  }
1536
- tokens$1.push(text$2.slice(i, j + 1));
1561
+ tokens.push(text.slice(i, j + 1));
1537
1562
  i = j + 1;
1538
1563
  continue;
1539
1564
  }
1540
- if (i + 1 < text$2.length) {
1541
- const two = text$2.slice(i, i + 2);
1565
+ if (i + 1 < text.length) {
1566
+ const two = text.slice(i, i + 2);
1542
1567
  if (two === "!=" || two === ">=" || two === "<=") {
1543
- tokens$1.push(two);
1568
+ tokens.push(two);
1544
1569
  i += 2;
1545
1570
  continue;
1546
1571
  }
1547
1572
  }
1548
- if ("=><(),".includes(text$2[i])) {
1549
- tokens$1.push(text$2[i]);
1573
+ if ("=><(),".includes(text[i])) {
1574
+ tokens.push(text[i]);
1550
1575
  i++;
1551
1576
  continue;
1552
1577
  }
1553
- if (text$2[i] === ".") {
1554
- tokens$1.push(".");
1578
+ if (text[i] === ".") {
1579
+ tokens.push(".");
1555
1580
  i++;
1556
1581
  continue;
1557
1582
  }
1558
- if (/[\w]/u.test(text$2[i])) {
1583
+ if (/[\w]/u.test(text[i])) {
1559
1584
  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));
1585
+ while (j < text.length && /[\w]/u.test(text[j])) j++;
1586
+ tokens.push(text.slice(i, j));
1562
1587
  i = j;
1563
1588
  continue;
1564
1589
  }
1565
1590
  i++;
1566
1591
  }
1567
- return tokens$1;
1592
+ return tokens;
1568
1593
  }
1569
1594
 
1570
1595
  //#endregion
@@ -1576,7 +1601,7 @@ function _define_property$7(obj, key, value) {
1576
1601
  configurable: true,
1577
1602
  writable: true
1578
1603
  });
1579
- else obj[key] = value;
1604
+ else obj[key] = value;
1580
1605
  return obj;
1581
1606
  }
1582
1607
  var IdRegistry = class {
@@ -1588,12 +1613,12 @@ var IdRegistry = class {
1588
1613
  registerDefinition(token) {
1589
1614
  if (!token) return;
1590
1615
  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);
1616
+ else if (this.definitions.has(token.text)) this.duplicates.add(token);
1617
+ else this.definitions.set(token.text, token);
1593
1618
  }
1594
1619
  isDefined(t) {
1595
- const text$2 = typeof t === "string" ? t : t.text;
1596
- return this.definitions.has(text$2) || this.globalTypes.has(text$2);
1620
+ const text = typeof t === "string" ? t : t.text;
1621
+ return this.definitions.has(text) || this.globalTypes.has(text);
1597
1622
  }
1598
1623
  getErrors() {
1599
1624
  return [...Array.from(this.duplicates, (t) => ({
@@ -1609,9 +1634,9 @@ else this.definitions.set(token.text, token);
1609
1634
  constructor(globalTypes = []) {
1610
1635
  _define_property$7(this, "reserved", void 0);
1611
1636
  _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());
1637
+ _define_property$7(this, "definitions", /* @__PURE__ */ new Map());
1638
+ _define_property$7(this, "duplicates", /* @__PURE__ */ new Set());
1639
+ _define_property$7(this, "forbidden", /* @__PURE__ */ new Set());
1615
1640
  this.reserved = new Set([
1616
1641
  "interface",
1617
1642
  "type",
@@ -1634,7 +1659,7 @@ function _define_property$6(obj, key, value) {
1634
1659
  configurable: true,
1635
1660
  writable: true
1636
1661
  });
1637
- else obj[key] = value;
1662
+ else obj[key] = value;
1638
1663
  return obj;
1639
1664
  }
1640
1665
  var NodeIterator = class NodeIterator {
@@ -1675,14 +1700,14 @@ var NodeIterator = class NodeIterator {
1675
1700
  fork(nodes) {
1676
1701
  return new NodeIterator(nodes || this.nodes, this.messages, this.badNodes, this.issues, nodes ? this.$ : this.parent, nodes ? 0 : this.i).update();
1677
1702
  }
1678
- skip(pun$1) {
1679
- while (this.$?.type === "comment" || this.$?.type === "punctuation" && pun$1?.length && pun$1.includes(this.$.text)) this.move();
1703
+ skip(pun) {
1704
+ while (this.$?.type === "comment" || this.$?.type === "punctuation" && pun?.length && pun.includes(this.$.text)) this.move();
1680
1705
  return this;
1681
1706
  }
1682
- skipUntil(pun$1) {
1707
+ skipUntil(pun) {
1683
1708
  while (this.$ && !this.satisfies({
1684
1709
  node: "punctuation",
1685
- text: pun$1
1710
+ text: pun
1686
1711
  })) this.move();
1687
1712
  }
1688
1713
  unexpected(force = false, msg = "Unexpected token") {
@@ -1698,15 +1723,14 @@ var NodeIterator = class NodeIterator {
1698
1723
  satisfies(...rules) {
1699
1724
  for (const rule of rules) {
1700
1725
  const passed = Array.isArray(rule.node) ? rule.node.includes(this.$?.type) : this.$?.type === rule.node;
1701
- if (passed && rule.text === undefined) return true;
1726
+ if (passed && rule.text === void 0) return true;
1702
1727
  if (passed && Array.isArray(rule.text) ? rule.text.includes(this.$?.text) : this.$?.text === rule.text) return true;
1703
1728
  }
1704
1729
  return false;
1705
1730
  }
1706
1731
  confirmIssues() {
1707
1732
  if (this.issues.unexpectedEOB) {
1708
- const node = this.lastNode || this.parent;
1709
- const pos = node?.getRange().end || {
1733
+ const pos = (this.lastNode || this.parent)?.getRange().end || {
1710
1734
  character: 1,
1711
1735
  line: 1
1712
1736
  };
@@ -1740,7 +1764,7 @@ var NodeIterator = class NodeIterator {
1740
1764
  }
1741
1765
  })).concat(this.messages);
1742
1766
  }
1743
- constructor(nodes, messages = [], badNodes = new Map(), issues = {}, parent, i = -1) {
1767
+ constructor(nodes, messages = [], badNodes = /* @__PURE__ */ new Map(), issues = {}, parent, i = -1) {
1744
1768
  _define_property$6(this, "nodes", void 0);
1745
1769
  _define_property$6(this, "messages", void 0);
1746
1770
  _define_property$6(this, "badNodes", void 0);
@@ -1759,7 +1783,9 @@ var NodeIterator = class NodeIterator {
1759
1783
 
1760
1784
  //#endregion
1761
1785
  //#region packages/core/src/tokenizer/tokens/a-identifier.token.ts
1762
- const AIdentifierToken = new Node({
1786
+ /**
1787
+ * Annotation (@) Identifier node
1788
+ */ const AIdentifierToken = new Node({
1763
1789
  name: "annotation",
1764
1790
  start: { token: RegExp("@[\\p{ID_Continue}$.]*", "u") },
1765
1791
  end: {
@@ -1781,7 +1807,9 @@ const pairs = {
1781
1807
  "(": ")",
1782
1808
  "[": "]"
1783
1809
  };
1784
- const BlockToken = new Node({
1810
+ /**
1811
+ * Block node
1812
+ */ const BlockToken = new Node({
1785
1813
  name: "block",
1786
1814
  start: {
1787
1815
  token: RegExp("(?<text>[([{])", "u"),
@@ -1835,7 +1863,9 @@ const block$1 = new Node({
1835
1863
  },
1836
1864
  mapContent: "text"
1837
1865
  });
1838
- const commentNodes = {
1866
+ /**
1867
+ * Block and inline comments
1868
+ */ const commentNodes = {
1839
1869
  inline,
1840
1870
  block: block$1,
1841
1871
  all: [inline, block$1]
@@ -1843,7 +1873,9 @@ const commentNodes = {
1843
1873
 
1844
1874
  //#endregion
1845
1875
  //#region packages/core/src/tokenizer/tokens/identifier.token.ts
1846
- const IdentifierToken = new Node({
1876
+ /**
1877
+ * Identifier node
1878
+ */ const IdentifierToken = new Node({
1847
1879
  name: "identifier",
1848
1880
  start: { token: RegExp("[\\p{ID_Start}$_][\\p{ID_Continue}$]*", "u") },
1849
1881
  end: {
@@ -1860,7 +1892,9 @@ const IdentifierToken = new Node({
1860
1892
 
1861
1893
  //#endregion
1862
1894
  //#region packages/core/src/tokenizer/tokens/number.token.ts
1863
- const NumberToken = new Node({
1895
+ /**
1896
+ * Number node
1897
+ */ const NumberToken = new Node({
1864
1898
  name: "number",
1865
1899
  start: { token: /[-+]?(?:\d*\.\d+|\d+)(?:[eE][-+]?\d+)?/u },
1866
1900
  end: {
@@ -1877,7 +1911,9 @@ const NumberToken = new Node({
1877
1911
 
1878
1912
  //#endregion
1879
1913
  //#region packages/core/src/tokenizer/tokens/punctuation.token.ts
1880
- const PunctuationToken = new Node({
1914
+ /**
1915
+ * Punctuation node
1916
+ */ const PunctuationToken = new Node({
1881
1917
  name: "punctuation",
1882
1918
  start: {
1883
1919
  token: RegExp("(?<text>[\\n!&+,./:;=?|])", "u"),
@@ -1896,7 +1932,13 @@ const PunctuationToken = new Node({
1896
1932
 
1897
1933
  //#endregion
1898
1934
  //#region packages/core/src/tokenizer/tokens/query-operator.token.ts
1899
- const QueryOperatorToken = new Node({
1935
+ /**
1936
+ * Query operator token — matches symbolic comparison operators
1937
+ * inside backtick-delimited query expressions.
1938
+ *
1939
+ * Multi-character operators (!=, >=, <=) are matched as single tokens.
1940
+ * Only recognized inside QueryToken — not in root or BlockToken.
1941
+ */ const QueryOperatorToken = new Node({
1900
1942
  name: "punctuation",
1901
1943
  start: {
1902
1944
  token: RegExp("(?<text>!=|>=|<=|[=><])", "u"),
@@ -1915,7 +1957,10 @@ const QueryOperatorToken = new Node({
1915
1957
 
1916
1958
  //#endregion
1917
1959
  //#region packages/core/src/tokenizer/tokens/query.token.ts
1918
- const QueryToken = new Node({
1960
+ /**
1961
+ * Query node — backtick-delimited filter expressions
1962
+ * Content inside backticks is tokenized into children.
1963
+ */ const QueryToken = new Node({
1919
1964
  name: "query",
1920
1965
  start: {
1921
1966
  token: /`/u,
@@ -1936,7 +1981,11 @@ const QueryToken = new Node({
1936
1981
  //#endregion
1937
1982
  //#region packages/core/src/tokenizer/tokens/regexp.token.ts
1938
1983
  const REGEXP_LITERAL_RE = /\/(?![/*])(?:\\.|\[.*?]|[^/\\\n\r[])*\/[dgimsuy]*/;
1939
- const RegExpToken = new Node({
1984
+ /**
1985
+ * RegExp literal – `/pattern/flags`
1986
+ * • Starts with `/` but *not* `//` or `/*`
1987
+ * • Ends with `/` followed by zero-or-more valid flags
1988
+ */ const RegExpToken = new Node({
1940
1989
  name: "regexp",
1941
1990
  start: {
1942
1991
  token: REGEXP_LITERAL_RE,
@@ -1957,7 +2006,9 @@ const RegExpToken = new Node({
1957
2006
 
1958
2007
  //#endregion
1959
2008
  //#region packages/core/src/tokenizer/tokens/text.node.ts
1960
- const TextToken = new Node({
2009
+ /**
2010
+ * Text node single or doublequoted
2011
+ */ const TextToken = new Node({
1961
2012
  name: "text",
1962
2013
  start: {
1963
2014
  token: RegExp("(?<quote>[\"'])", "u"),
@@ -1994,7 +2045,7 @@ const tokens = {
1994
2045
  text: TextToken,
1995
2046
  regexp: RegExpToken,
1996
2047
  query: QueryToken,
1997
- root: undefined
2048
+ root: void 0
1998
2049
  };
1999
2050
  const root = new Node({
2000
2051
  name: "root",
@@ -2014,7 +2065,14 @@ const root = new Node({
2014
2065
  tokens.root = root;
2015
2066
  BlockToken.recognize(RegExpToken, ...commentNodes.all, BlockToken, QueryToken, AIdentifierToken, IdentifierToken, TextToken, NumberToken, PunctuationToken);
2016
2067
  QueryToken.recognize(RegExpToken, QueryOperatorToken, BlockToken, IdentifierToken, TextToken, NumberToken, PunctuationToken);
2017
- function extractTokens(node) {
2068
+ /**
2069
+ * Recursively extract TLexicalToken[] from a ParsedNode tree.
2070
+ * Replaces the v0.5 mapContent('children', callback) + global loop.
2071
+ *
2072
+ * v0.6 Position has { offset, line, column }.
2073
+ * line is 1-based, column is 1-based.
2074
+ * VSCode expects 0-based line, 0-based character.
2075
+ */ function extractTokens(node) {
2018
2076
  return node.content.map((item) => {
2019
2077
  if (typeof item === "string") return {
2020
2078
  type: "unknown",
@@ -2046,23 +2104,23 @@ function tokenize(source, debug = false) {
2046
2104
 
2047
2105
  //#endregion
2048
2106
  //#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) {
2107
+ const identifier = (...text) => $token("identifier", text.length > 0 ? text : void 0);
2108
+ const text = (...text) => $token("text", text.length > 0 ? text : void 0);
2109
+ const block = (...text) => $token("block", text.length > 0 ? text.map((v) => v[0]) : void 0);
2110
+ const pun = (...text) => $token("punctuation", text.length > 0 ? text : void 0);
2111
+ function $token(name, text) {
2054
2112
  const opts = {
2055
2113
  optional: false,
2056
- saveAs: undefined,
2057
- skip: undefined,
2114
+ saveAs: void 0,
2115
+ skip: void 0,
2058
2116
  expect: [{
2059
2117
  node: name,
2060
- text: text$2
2118
+ text
2061
2119
  }],
2062
- contains: undefined,
2120
+ contains: void 0,
2063
2121
  isGlobal: false,
2064
2122
  empty: false,
2065
- wrapper: undefined,
2123
+ wrapper: void 0,
2066
2124
  wrapMultiple: false,
2067
2125
  debug: false,
2068
2126
  eob: false,
@@ -2072,7 +2130,7 @@ function $token(name, text$2) {
2072
2130
  return {
2073
2131
  expect: [{
2074
2132
  node: name,
2075
- text: text$2
2133
+ text
2076
2134
  }],
2077
2135
  handler(ni, target) {
2078
2136
  if (opts.debug) debugger;
@@ -2113,7 +2171,7 @@ function $token(name, text$2) {
2113
2171
  ni.move();
2114
2172
  if (opts.skip) ni.skip(opts.skip);
2115
2173
  if (opts.wrapMultiple) continue;
2116
- else return true;
2174
+ else return true;
2117
2175
  } else {
2118
2176
  if (!opts.optional) ni.unexpected();
2119
2177
  return opts.optional;
@@ -2198,7 +2256,7 @@ function $pipe(entity, pipe = []) {
2198
2256
  pipe,
2199
2257
  toString: () => entity,
2200
2258
  skipTokens: [],
2201
- stopCondition: undefined,
2259
+ stopCondition: void 0,
2202
2260
  skip(...s) {
2203
2261
  this.skipTokens.push(...s);
2204
2262
  return this;
@@ -2213,12 +2271,12 @@ function $pipe(entity, pipe = []) {
2213
2271
  }
2214
2272
  };
2215
2273
  }
2216
- function runPipes(pipes$1, ni, singlePass = false) {
2274
+ function runPipes(pipes, ni, singlePass = false) {
2217
2275
  const nodes = [];
2218
2276
  while (ni.$) {
2219
2277
  let matched = true;
2220
2278
  let depth = ni.index;
2221
- for (const { targetFactory, pipe, skipTokens: skip, stopCondition } of pipes$1) {
2279
+ for (const { targetFactory, pipe, skipTokens: skip, stopCondition } of pipes) {
2222
2280
  const target = { node: targetFactory() };
2223
2281
  const fork = ni.fork();
2224
2282
  fork.skip(skip);
@@ -2253,15 +2311,15 @@ function runPipes(pipes$1, ni, singlePass = false) {
2253
2311
  }
2254
2312
  return nodes;
2255
2313
  }
2256
- function runPipesOnce(pipes$1, ni) {
2257
- return runPipes(pipes$1, ni, true)[0];
2314
+ function runPipesOnce(pipes, ni) {
2315
+ return runPipes(pipes, ni, true)[0];
2258
2316
  }
2259
2317
 
2260
2318
  //#endregion
2261
2319
  //#region packages/core/src/parser/grouping.ts
2262
2320
  function groupByPriority(nodes, priority) {
2263
2321
  if (nodes.length === 1) return nodes[0];
2264
- if (nodes.length === 0) return undefined;
2322
+ if (nodes.length === 0) return;
2265
2323
  if (nodes.length % 2 === 0) throw new Error(`Invalid number of nodes ${nodes.length}. Odd number expected`);
2266
2324
  let currentPass = nodes;
2267
2325
  let temporaryResult = [];
@@ -2270,7 +2328,7 @@ function groupByPriority(nodes, priority) {
2270
2328
  for (const [i, node] of currentPass.entries()) {
2271
2329
  const isOperator = i % 2 === 1;
2272
2330
  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}`);
2331
+ else if (isOperator && !(node instanceof Token)) throw new Error(`Unexpected token ${isGroup(node) ? node.op : node.token.toString()} at ${i}`);
2274
2332
  if (isOperator) {
2275
2333
  if (node.text !== p) temporaryResult.push(node);
2276
2334
  continue;
@@ -2312,12 +2370,15 @@ const VALUE_KEYWORDS = new Set([
2312
2370
  "null",
2313
2371
  "undefined"
2314
2372
  ]);
2315
- function parseQueryExpression(children, messages, sourceToken) {
2316
- if (children.length === 0) return undefined;
2373
+ /**
2374
+ * Parse a backtick-delimited query expression from its child tokens.
2375
+ * Returns a SemanticQueryNode or undefined if the content is empty.
2376
+ */ function parseQueryExpression(children, messages, sourceToken) {
2377
+ if (children.length === 0) return;
2317
2378
  const ni = new NodeIterator(children, messages);
2318
2379
  ni.move();
2319
2380
  const expr = parseOrExpr(ni, messages);
2320
- if (!expr) return undefined;
2381
+ if (!expr) return;
2321
2382
  if (ni.$) messages.push({
2322
2383
  severity: 1,
2323
2384
  message: `Unexpected token in query expression: "${ni.$.text}"`,
@@ -2339,7 +2400,7 @@ function parseQueryExpression(children, messages, sourceToken) {
2339
2400
  }
2340
2401
  function parseOrExpr(ni, messages) {
2341
2402
  const left = parseAndExpr(ni, messages);
2342
- if (!left) return undefined;
2403
+ if (!left) return;
2343
2404
  const operands = [left];
2344
2405
  while (ni.$?.type === "identifier" && ni.$.text === "or") {
2345
2406
  ni.move();
@@ -2358,7 +2419,7 @@ function parseOrExpr(ni, messages) {
2358
2419
  }
2359
2420
  function parseAndExpr(ni, messages) {
2360
2421
  const left = parseUnaryExpr(ni, messages);
2361
- if (!left) return undefined;
2422
+ if (!left) return;
2362
2423
  const operands = [left];
2363
2424
  while (ni.$?.type === "identifier" && ni.$.text === "and") {
2364
2425
  ni.move();
@@ -2381,7 +2442,7 @@ function parseUnaryExpr(ni, messages) {
2381
2442
  const operand = parseUnaryExpr(ni, messages);
2382
2443
  if (!operand) {
2383
2444
  pushError(ni, messages, "Expected expression after \"not\"");
2384
- return undefined;
2445
+ return;
2385
2446
  }
2386
2447
  const node = new SemanticQueryLogicalNode();
2387
2448
  node.operator = "not";
@@ -2393,7 +2454,7 @@ function parseUnaryExpr(ni, messages) {
2393
2454
  ni.move();
2394
2455
  if (blockChildren.length === 0) {
2395
2456
  pushError(ni, messages, "Empty parenthesized expression");
2396
- return undefined;
2457
+ return;
2397
2458
  }
2398
2459
  const subNi = new NodeIterator(blockChildren, messages);
2399
2460
  subNi.move();
@@ -2405,14 +2466,14 @@ function parseUnaryExpr(ni, messages) {
2405
2466
  }
2406
2467
  function parseComparison(ni, messages) {
2407
2468
  const left = parseFieldRef(ni, messages);
2408
- if (!left) return undefined;
2469
+ if (!left) return;
2409
2470
  if (ni.$?.type === "punctuation" && SYMBOLIC_OPS.has(ni.$.text)) {
2410
2471
  const opText = ni.$.text;
2411
2472
  ni.move();
2412
2473
  const right = parseValueOrFieldRef(ni, messages);
2413
2474
  if (!right) {
2414
2475
  pushError(ni, messages, `Expected value or field reference after "${opText}"`);
2415
- return undefined;
2476
+ return;
2416
2477
  }
2417
2478
  const node = new SemanticQueryComparisonNode();
2418
2479
  node.left = left;
@@ -2425,7 +2486,7 @@ function parseComparison(ni, messages) {
2425
2486
  if (opText === "in") {
2426
2487
  ni.move();
2427
2488
  const right = parseValueList(ni, messages);
2428
- if (!right) return undefined;
2489
+ if (!right) return;
2429
2490
  const node = new SemanticQueryComparisonNode();
2430
2491
  node.left = left;
2431
2492
  node.operator = "in";
@@ -2437,7 +2498,7 @@ function parseComparison(ni, messages) {
2437
2498
  const right = parseValueOrFieldRef(ni, messages);
2438
2499
  if (!right) {
2439
2500
  pushError(ni, messages, "Expected value after \"matches\"");
2440
- return undefined;
2501
+ return;
2441
2502
  }
2442
2503
  const node = new SemanticQueryComparisonNode();
2443
2504
  node.left = left;
@@ -2454,17 +2515,16 @@ function parseComparison(ni, messages) {
2454
2515
  }
2455
2516
  if (opText === "not") return parseNotComparison(ni, messages, left);
2456
2517
  pushError(ni, messages, `Unknown operator "${opText}"`);
2457
- return undefined;
2518
+ return;
2458
2519
  }
2459
2520
  pushError(ni, messages, "Expected operator after field reference");
2460
- return undefined;
2461
2521
  }
2462
2522
  function parseNotComparison(ni, messages, left) {
2463
2523
  ni.move();
2464
2524
  if (ni.$?.type === "identifier" && ni.$.text === "in") {
2465
2525
  ni.move();
2466
2526
  const right = parseValueList(ni, messages);
2467
- if (!right) return undefined;
2527
+ if (!right) return;
2468
2528
  const node = new SemanticQueryComparisonNode();
2469
2529
  node.left = left;
2470
2530
  node.operator = "not in";
@@ -2479,12 +2539,11 @@ function parseNotComparison(ni, messages, left) {
2479
2539
  return node;
2480
2540
  }
2481
2541
  pushError(ni, messages, "Expected \"in\" or \"exists\" after \"not\"");
2482
- return undefined;
2483
2542
  }
2484
2543
  function parseFieldRef(ni, messages) {
2485
2544
  if (ni.$?.type !== "identifier") {
2486
2545
  pushError(ni, messages, "Expected field reference");
2487
- return undefined;
2546
+ return;
2488
2547
  }
2489
2548
  const firstToken = new Token(ni.$);
2490
2549
  ni.move();
@@ -2504,35 +2563,34 @@ function parseFieldRef(ni, messages) {
2504
2563
  break;
2505
2564
  }
2506
2565
  }
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;
2566
+ const node = new SemanticQueryFieldRefNode();
2567
+ node.typeRef = firstToken;
2568
+ if (fieldText !== secondToken.text) node.fieldRef = secondToken.clone({ text: fieldText });
2569
+ else node.fieldRef = secondToken;
2570
+ return node;
2512
2571
  }
2513
2572
  pushError(ni, messages, "Expected identifier after \".\"");
2514
- const node$1 = new SemanticQueryFieldRefNode();
2515
- node$1.fieldRef = firstToken;
2516
- return node$1;
2573
+ const node = new SemanticQueryFieldRefNode();
2574
+ node.fieldRef = firstToken;
2575
+ return node;
2517
2576
  }
2518
2577
  const node = new SemanticQueryFieldRefNode();
2519
2578
  node.fieldRef = firstToken;
2520
2579
  return node;
2521
2580
  }
2522
2581
  function parseValueOrFieldRef(ni, messages) {
2523
- if (!ni.$) return undefined;
2582
+ if (!ni.$) return;
2524
2583
  if (ni.$.type === "text" || ni.$.type === "number" || ni.$.type === "regexp") return parseValue(ni, messages);
2525
2584
  if (ni.$.type === "identifier") {
2526
2585
  if (VALUE_KEYWORDS.has(ni.$.text)) return parseValue(ni, messages);
2527
2586
  return parseFieldRef(ni, messages);
2528
2587
  }
2529
2588
  pushError(ni, messages, "Expected value or field reference");
2530
- return undefined;
2531
2589
  }
2532
2590
  function parseValue(ni, messages) {
2533
2591
  if (!ni.$) {
2534
2592
  pushError(ni, messages, "Expected value");
2535
- return undefined;
2593
+ return;
2536
2594
  }
2537
2595
  const token = ni.$;
2538
2596
  if (token.type === "text" || token.type === "number" || token.type === "regexp" || token.type === "identifier" && VALUE_KEYWORDS.has(token.text)) {
@@ -2542,7 +2600,6 @@ function parseValue(ni, messages) {
2542
2600
  return node;
2543
2601
  }
2544
2602
  pushError(ni, messages, `Unexpected token "${token.text}" where value expected`);
2545
- return undefined;
2546
2603
  }
2547
2604
  function parseValueList(ni, messages) {
2548
2605
  if (ni.$?.type === "block" && ni.$.text === "(") {
@@ -2551,7 +2608,7 @@ function parseValueList(ni, messages) {
2551
2608
  const values = [];
2552
2609
  if (blockChildren.length === 0) {
2553
2610
  pushError(ni, messages, "Empty value list in \"in\" expression");
2554
- return undefined;
2611
+ return;
2555
2612
  }
2556
2613
  const subNi = new NodeIterator(blockChildren, messages);
2557
2614
  subNi.move();
@@ -2568,7 +2625,6 @@ function parseValueList(ni, messages) {
2568
2625
  return node;
2569
2626
  }
2570
2627
  pushError(ni, messages, "Expected parenthesized value list after \"in\"");
2571
- return undefined;
2572
2628
  }
2573
2629
  function pushError(ni, messages, message) {
2574
2630
  const range = ni.$?.getRange?.() ?? {
@@ -2634,7 +2690,7 @@ function refWithChain() {
2634
2690
  } else if (fork.$.children?.length === 1 && fork.$.children[0].type === "text") {
2635
2691
  if (isRef(target.node)) target.node.addChain(new Token(fork.$.children[0]));
2636
2692
  } else return true;
2637
- else {
2693
+ else {
2638
2694
  fork.skip(["\n"]);
2639
2695
  if (fork.next().satisfies(s.id)) {
2640
2696
  if (isRef(target.node)) target.node.addDot(new Token(fork.$));
@@ -2741,7 +2797,7 @@ function annotations() {
2741
2797
  } else break;
2742
2798
  }
2743
2799
  if (ni.satisfies(opts.end)) ni.skip([";", "\n"]);
2744
- else if (ni.$) {
2800
+ else if (ni.$) {
2745
2801
  ni.unexpected(false, `Unexpected token in annotation ${ni.toString()}`);
2746
2802
  ni.skipUntil([";", "\n"]);
2747
2803
  ni.skip([";", "\n"]);
@@ -2750,12 +2806,12 @@ else if (ni.$) {
2750
2806
  return true;
2751
2807
  } };
2752
2808
  }
2753
- function definition(pipes$1) {
2809
+ function definition(pipes) {
2754
2810
  const opts = {
2755
2811
  sep: [],
2756
2812
  priority: false,
2757
2813
  multiple: false,
2758
- from: undefined,
2814
+ from: void 0,
2759
2815
  debug: false,
2760
2816
  skip: []
2761
2817
  };
@@ -2773,7 +2829,7 @@ function definition(pipes$1) {
2773
2829
  targetNode.define(new $n.SemanticGroup());
2774
2830
  return true;
2775
2831
  }
2776
- const resolvedPipes = pipes$1.map((p) => typeof p === "function" ? p() : p);
2832
+ const resolvedPipes = pipes.map((p) => typeof p === "function" ? p() : p);
2777
2833
  const node = runPipesOnce(resolvedPipes, fork);
2778
2834
  if (node) {
2779
2835
  fork.accepted();
@@ -2794,7 +2850,7 @@ function definition(pipes$1) {
2794
2850
  text: opts.sep
2795
2851
  })) {
2796
2852
  if (opts.priority) if (fork.next(opts.skip).$) nodes.push(new Token(fork.$));
2797
- else {
2853
+ else {
2798
2854
  fork.unexpected(false, "Unexpected end of group");
2799
2855
  break;
2800
2856
  }
@@ -2817,7 +2873,7 @@ else {
2817
2873
  }
2818
2874
  }
2819
2875
  if (nodes.length === 1) targetNode.define(nodes[0]);
2820
- else if (opts.priority && opts.sep.length > 0) {
2876
+ else if (opts.priority && opts.sep.length > 0) {
2821
2877
  if (nodes.length % 2 === 0) {
2822
2878
  fork.next().unexpected(false, "Error in group definition");
2823
2879
  return false;
@@ -2864,8 +2920,8 @@ function unwrap(attr) {
2864
2920
  target.node.define(new $n.SemanticGroup(nodes));
2865
2921
  return true;
2866
2922
  },
2867
- with(pipes$1) {
2868
- opts.pipes = pipes$1;
2923
+ with(pipes) {
2924
+ opts.pipes = pipes;
2869
2925
  return this;
2870
2926
  }
2871
2927
  };
@@ -2874,13 +2930,12 @@ function propName() {
2874
2930
  return { handler(ni, target) {
2875
2931
  switch (ni.$?.type) {
2876
2932
  case "identifier":
2877
- case "text": {
2933
+ case "text":
2878
2934
  target.node.saveToken(new Token(ni.$), "identifier");
2879
2935
  ni.accepted();
2880
2936
  ni.move();
2881
2937
  ni.skip(["\n"]);
2882
2938
  return true;
2883
- }
2884
2939
  case "block": {
2885
2940
  const childrenLength = ni.$.children?.length || 0;
2886
2941
  const firstText = ni.$.children?.[0]?.text;
@@ -2903,13 +2958,12 @@ function propName() {
2903
2958
  }
2904
2959
  if (ni.$.text === "[" && !childrenLength) ni.unexpected(false, "Wildcard \"*\" or a Regular Expression expected");
2905
2960
  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");
2961
+ else ni.unexpected(false, "Unexpected identifier at property name");
2907
2962
  return false;
2908
2963
  }
2909
- default: {
2964
+ default:
2910
2965
  ni.unexpected(false, "Unexpected identifier at property name");
2911
2966
  return false;
2912
- }
2913
2967
  }
2914
2968
  } };
2915
2969
  }
@@ -2956,9 +3010,8 @@ function extendsClause() {
2956
3010
  //#region packages/core/src/parser/pipes/pipes.ts
2957
3011
  const ref = $pipe("ref", [refWithChain()]);
2958
3012
  const constText = defineValuePipe("const", "text", false);
2959
- const constNumber = defineValuePipe("const", "number", false);
2960
3013
  const allowedValuesPipeArray = [
2961
- constNumber,
3014
+ defineValuePipe("const", "number", false),
2962
3015
  ref,
2963
3016
  constText
2964
3017
  ];
@@ -3021,14 +3074,13 @@ const importPipe = $pipe("import", [
3021
3074
  text().saveAs("path").skip(";", "\n"),
3022
3075
  definition([$pipe("ref", [identifier().saveAs("identifier").skip("\n")])]).from("inner").separatedBy(",").skip("\n").respectPriority()
3023
3076
  ]).skip("\n", ";");
3024
- const skipComments = { handler(ni) {
3025
- ni.skip();
3026
- return true;
3027
- } };
3028
3077
  const annotateEntry = $pipe("ref", [
3029
3078
  annotations(),
3030
3079
  refWithChain(),
3031
- skipComments,
3080
+ { handler(ni) {
3081
+ ni.skip();
3082
+ return true;
3083
+ } },
3032
3084
  pun(";", ",", "\n").orEob().lookBehind()
3033
3085
  ]).skip("\n", ";", ",");
3034
3086
  const annotatePipe = $pipe("annotate", [
@@ -3052,12 +3104,12 @@ const pipes = {
3052
3104
 
3053
3105
  //#endregion
3054
3106
  //#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;
3107
+ var TSeverity = /* @__PURE__ */ function(TSeverity) {
3108
+ TSeverity[TSeverity["Error"] = 1] = "Error";
3109
+ TSeverity[TSeverity["Warning"] = 2] = "Warning";
3110
+ TSeverity[TSeverity["Info"] = 3] = "Info";
3111
+ TSeverity[TSeverity["Hint"] = 4] = "Hint";
3112
+ return TSeverity;
3061
3113
  }({});
3062
3114
 
3063
3115
  //#endregion
@@ -3069,7 +3121,7 @@ function _define_property$5(obj, key, value) {
3069
3121
  configurable: true,
3070
3122
  writable: true
3071
3123
  });
3072
- else obj[key] = value;
3124
+ else obj[key] = value;
3073
3125
  return obj;
3074
3126
  }
3075
3127
  /**
@@ -3111,19 +3163,22 @@ else obj[key] = value;
3111
3163
  const endCmp = comparePos(a.range.end, b.range.end);
3112
3164
  return startCmp >= 0 && endCmp <= 0;
3113
3165
  }
3114
- var BlocksIndex = class {
3166
+ /**
3167
+ * Implementation of `IBlocksIndex` that manages a collection of tokens and provides efficient methods to add tokens
3168
+ * and query the most nested token at a specific position.
3169
+ */ var BlocksIndex = class {
3115
3170
  /**
3116
3171
  * Adds a new token to the index. The token collection is maintained in sorted order by start position.
3117
3172
  * @param block - The token to add.
3118
- */ add(block$2) {
3173
+ */ add(block) {
3119
3174
  let left = 0;
3120
3175
  let right = this.blocks.length;
3121
3176
  while (left < right) {
3122
3177
  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;
3178
+ if (comparePos(this.blocks[mid].range.start, block.range.start) < 0) left = mid + 1;
3179
+ else right = mid;
3125
3180
  }
3126
- this.blocks.splice(left, 0, block$2);
3181
+ this.blocks.splice(left, 0, block);
3127
3182
  }
3128
3183
  /**
3129
3184
  * Finds the most nested token at a specific position.
@@ -3132,14 +3187,14 @@ else right = mid;
3132
3187
  * @returns The most nested token at the given position, or `undefined` if no token is found.
3133
3188
  */ at(line, character) {
3134
3189
  const candidates = [];
3135
- for (const block$2 of this.blocks) {
3136
- if (comparePos(block$2.range.start, {
3190
+ for (const block of this.blocks) {
3191
+ if (comparePos(block.range.start, {
3137
3192
  line,
3138
3193
  character
3139
3194
  }) > 0) break;
3140
- if (contains(block$2, line, character)) candidates.push(block$2);
3195
+ if (contains(block, line, character)) candidates.push(block);
3141
3196
  }
3142
- if (candidates.length === 0) return undefined;
3197
+ if (candidates.length === 0) return;
3143
3198
  let result = candidates[0];
3144
3199
  for (let i = 1; i < candidates.length; i++) if (moreNested(candidates[i], result)) result = candidates[i];
3145
3200
  return result;
@@ -3161,17 +3216,20 @@ function _define_property$4(obj, key, value) {
3161
3216
  configurable: true,
3162
3217
  writable: true
3163
3218
  });
3164
- else obj[key] = value;
3219
+ else obj[key] = value;
3165
3220
  return obj;
3166
3221
  }
3167
- var TokensIndex = class {
3222
+ /**
3223
+ * A class that implements a flat index for tokens, allowing quick access to tokens
3224
+ * at a specific line and character. Tokens in this index are not nested.
3225
+ */ var TokensIndex = class {
3168
3226
  /**
3169
3227
  * Adds a token to the index. The token is stored based on its starting line.
3170
3228
  * @param token - The token to add to the index.
3171
3229
  */ add(token) {
3172
3230
  if (!token?.range) return;
3173
3231
  const line = token.range.start.line;
3174
- this.tokensMap[line] = this.tokensMap[line] ?? new Set();
3232
+ this.tokensMap[line] = this.tokensMap[line] ?? /* @__PURE__ */ new Set();
3175
3233
  this.tokensMap[line].add(token);
3176
3234
  }
3177
3235
  /**
@@ -3180,10 +3238,10 @@ var TokensIndex = class {
3180
3238
  * @param character - The character position within the line to search for.
3181
3239
  * @returns The token at the specified line and character, or `undefined` if none exists.
3182
3240
  */ at(line, character) {
3183
- const tokens$1 = this.tokensMap[line];
3184
- if (!tokens$1) return undefined;
3241
+ const tokens = this.tokensMap[line];
3242
+ if (!tokens) return;
3185
3243
  let best;
3186
- for (const t of tokens$1) if (t.range.start.character <= character && t.range.end.character >= character) {
3244
+ for (const t of tokens) if (t.range.start.character <= character && t.range.end.character >= character) {
3187
3245
  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
3246
  }
3189
3247
  return best;
@@ -3207,14 +3265,13 @@ var TokensIndex = class {
3207
3265
  if (candidate) return candidate;
3208
3266
  }
3209
3267
  for (let l = line - 1; l >= 0; l--) {
3210
- const tokens$1 = this.tokensMap[l];
3211
- if (tokens$1 && tokens$1.size > 0) {
3268
+ const tokens = this.tokensMap[l];
3269
+ if (tokens && tokens.size > 0) {
3212
3270
  let candidate;
3213
- for (const t of tokens$1) if (!candidate || t.range.end.character > candidate.range.end.character) candidate = t;
3271
+ for (const t of tokens) if (!candidate || t.range.end.character > candidate.range.end.character) candidate = t;
3214
3272
  if (candidate) return candidate;
3215
3273
  }
3216
3274
  }
3217
- return undefined;
3218
3275
  }
3219
3276
  constructor() {
3220
3277
  /**
@@ -3233,7 +3290,7 @@ function _define_property$3(obj, key, value) {
3233
3290
  configurable: true,
3234
3291
  writable: true
3235
3292
  });
3236
- else obj[key] = value;
3293
+ else obj[key] = value;
3237
3294
  return obj;
3238
3295
  }
3239
3296
  var AtscriptDoc = class {
@@ -3248,7 +3305,7 @@ var AtscriptDoc = class {
3248
3305
  }
3249
3306
  resolveAnnotation(name) {
3250
3307
  let spec = this._annotationSpecCache.get(name);
3251
- if (spec === undefined && !this._annotationSpecCache.has(name)) {
3308
+ if (spec === void 0 && !this._annotationSpecCache.has(name)) {
3252
3309
  spec = resolveAnnotation(name, this.config.annotations);
3253
3310
  this._annotationSpecCache.set(name, spec);
3254
3311
  }
@@ -3287,11 +3344,10 @@ var AtscriptDoc = class {
3287
3344
  get text() {
3288
3345
  return this._text;
3289
3346
  }
3290
- update(text$2, debug = false) {
3291
- this._text = text$2;
3347
+ update(text, debug = false) {
3348
+ this._text = text;
3292
3349
  this.cleanup();
3293
- const rawTokens = tokenize(text$2, debug);
3294
- const ni = new NodeIterator(rawTokens, []).move();
3350
+ const ni = new NodeIterator(tokenize(text, debug), []).move();
3295
3351
  this.nodes = runPipes([
3296
3352
  pipes.importPipe,
3297
3353
  pipes.type,
@@ -3311,8 +3367,8 @@ var AtscriptDoc = class {
3311
3367
  this.queryFieldRefs = [];
3312
3368
  this.imports.clear();
3313
3369
  this.resolvedImports.clear();
3314
- this._allMessages = undefined;
3315
- this._annotateNodesByTarget = undefined;
3370
+ this._allMessages = void 0;
3371
+ this._annotateNodesByTarget = void 0;
3316
3372
  this.tokensIndex = new TokensIndex();
3317
3373
  this.blocksIndex = new BlocksIndex();
3318
3374
  this.resolvedAnnotations = [];
@@ -3359,14 +3415,12 @@ var AtscriptDoc = class {
3359
3415
  } else {
3360
3416
  let severity = 1;
3361
3417
  switch (this.config.unknownAnnotation) {
3362
- case "warn": {
3418
+ case "warn":
3363
3419
  severity = 2;
3364
3420
  break;
3365
- }
3366
- case "allow": {
3421
+ case "allow":
3367
3422
  severity = 0;
3368
3423
  break;
3369
- }
3370
3424
  default:
3371
3425
  }
3372
3426
  if (severity > 0) this.registerMessage(mainToken, `Unknown annotation "${mainToken.text}"`, severity, "dim");
@@ -3393,9 +3447,9 @@ var AtscriptDoc = class {
3393
3447
  *
3394
3448
  * If the type cannot be resolved or does not exist, returns `undefined`.
3395
3449
  */ unwindType(name, chain = [], watchCb, _tracked) {
3396
- const tracked = _tracked || new Set();
3450
+ const tracked = _tracked || /* @__PURE__ */ new Set();
3397
3451
  const decl = this.getDeclarationOwnerNode(name);
3398
- if (!decl) return undefined;
3452
+ if (!decl) return;
3399
3453
  const callCb = watchCb ? () => {
3400
3454
  if (def && !tracked.has(def) && [
3401
3455
  "type",
@@ -3426,19 +3480,19 @@ var AtscriptDoc = class {
3426
3480
  }
3427
3481
  };
3428
3482
  resolveType();
3429
- if (!def) return undefined;
3483
+ if (!def) return;
3430
3484
  if (isAnnotate(def)) return doc.unwindType(def.targetName, chain, watchCb, tracked);
3431
3485
  for (const item of chain) {
3432
3486
  const itemText = typeof item === "string" ? item : item.text;
3433
- if (!def) return undefined;
3487
+ if (!def) return;
3434
3488
  if (isProp(def)) if (def.nestedProps?.get(itemText)) def = def.nestedProps.get(itemText);
3435
- else {
3489
+ else {
3436
3490
  def = def.nestedType;
3437
3491
  resolveRef();
3438
3492
  resolveType();
3439
3493
  if (isStructure(def) || isInterface(def)) def = def.props.get(itemText);
3440
3494
  }
3441
- else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.props.get(itemText);
3495
+ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.props.get(itemText);
3442
3496
  }
3443
3497
  if (_tracked) callCb();
3444
3498
  while (isProp(def)) {
@@ -3451,7 +3505,7 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
3451
3505
  def,
3452
3506
  doc,
3453
3507
  node
3454
- } : undefined;
3508
+ } : void 0;
3455
3509
  }
3456
3510
  getUsageListAt(line, character) {
3457
3511
  const token = this.tokensIndex.at(line, character);
@@ -3461,7 +3515,7 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
3461
3515
  let right = givenNode.annotations;
3462
3516
  let def = givenNode.getDefinition();
3463
3517
  if (def) {
3464
- const refDef = isRef(def) ? def : undefined;
3518
+ const refDef = isRef(def) ? def : void 0;
3465
3519
  if (refDef) {
3466
3520
  const chainNodes = [];
3467
3521
  const unwound = this.unwindType(refDef.token("identifier").text, refDef.chain, (intermediate) => {
@@ -3483,20 +3537,20 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
3483
3537
  * when folding annotations across a ref boundary. Annotations without a
3484
3538
  * resolvable spec pass through (default is to inherit). Returns the input
3485
3539
  * array unchanged when nothing is dropped.
3486
- */ filterPassedWhenReferred(annotations$1) {
3487
- if (!annotations$1?.length) return annotations$1;
3540
+ */ filterPassedWhenReferred(annotations) {
3541
+ if (!annotations?.length) return annotations;
3488
3542
  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;
3543
+ for (let i = 0; i < annotations.length; i++) if (this.resolveAnnotation(annotations[i].name)?.config.passedWhenReferred === false) filtered ?? (filtered = annotations.slice(0, i));
3544
+ else filtered?.push(annotations[i]);
3545
+ return filtered ?? annotations;
3492
3546
  }
3493
3547
  /**
3494
3548
  * If the position falls inside an `annotate` block, returns that block's node
3495
3549
  * (whose `targetName` is the annotated interface). Entry refs within the block
3496
3550
  * resolve through the target interface rather than as top-level definitions.
3497
3551
  */ 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;
3552
+ const block = this.blocksIndex.at(line, character);
3553
+ return block?.blockType === "annotate" && isAnnotate(block.parentNode) ? block.parentNode : void 0;
3500
3554
  }
3501
3555
  /**
3502
3556
  * Collects ad-hoc annotations from all `annotate` blocks targeting a given type/interface.
@@ -3504,11 +3558,11 @@ else filtered?.push(annotations$1[i]);
3504
3558
  * For entries without a chain (root-level), the key is the entry identifier.
3505
3559
  */ getAnnotateNodesFor(targetName) {
3506
3560
  if (!this._annotateNodesByTarget) {
3507
- const index = new Map();
3561
+ const index = /* @__PURE__ */ new Map();
3508
3562
  for (const node of this.nodes) if (isAnnotate(node)) {
3509
3563
  const existing = index.get(node.targetName);
3510
3564
  if (existing) existing.push(node);
3511
- else index.set(node.targetName, [node]);
3565
+ else index.set(node.targetName, [node]);
3512
3566
  }
3513
3567
  this._annotateNodesByTarget = index;
3514
3568
  }
@@ -3527,9 +3581,9 @@ else index.set(node.targetName, [node]);
3527
3581
  * the child's file apply to grandparent-inherited fields, even when the chain crosses
3528
3582
  * package boundaries (child → mid → grandparent, all in different .as files).
3529
3583
  */ 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;
3584
+ if (!node.hasExtends) return;
3585
+ const visited = _visited || /* @__PURE__ */ new Set();
3586
+ if (node.id && visited.has(node.id)) return;
3533
3587
  if (node.id) visited.add(node.id);
3534
3588
  const originDoc = _originDoc ?? this;
3535
3589
  let mergedStruct;
@@ -3538,10 +3592,8 @@ else index.set(node.targetName, [node]);
3538
3592
  if (!unwound?.def) continue;
3539
3593
  let parentDef = unwound.def;
3540
3594
  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;
3595
+ if (isInterface(parentDef) && parentDef.hasExtends) parentDef = unwound.doc.resolveInterfaceExtends(parentDef, visited, originDoc) || parentDef.getDefinition() || parentDef;
3596
+ else if (isInterface(parentDef)) parentDef = parentDef.getDefinition() || parentDef;
3545
3597
  parentDef = this.mergeIntersection(parentDef);
3546
3598
  const annotateNodes = [];
3547
3599
  const collect = (doc, name) => {
@@ -3553,16 +3605,10 @@ else index.set(node.targetName, [node]);
3553
3605
  if (originDoc !== this && originDoc !== unwound.doc) collect(originDoc, parentDeclName);
3554
3606
  if (annotateNodes.length > 0) parentDef = this.applyAnnotateBlocksToStructure(parentDef, annotateNodes);
3555
3607
  if (!mergedStruct) mergedStruct = parentDef;
3556
- else {
3557
- const merged = this.mergeDefs(mergedStruct, parentDef);
3558
- mergedStruct = merged[0];
3559
- }
3608
+ else mergedStruct = this.mergeDefs(mergedStruct, parentDef)[0];
3560
3609
  }
3561
3610
  const ownDef = node.getDefinition();
3562
- if (ownDef && mergedStruct) {
3563
- const merged = this.mergeDefs(mergedStruct, ownDef);
3564
- return merged[0];
3565
- }
3611
+ if (ownDef && mergedStruct) return this.mergeDefs(mergedStruct, ownDef)[0];
3566
3612
  return mergedStruct || ownDef;
3567
3613
  }
3568
3614
  /**
@@ -3593,19 +3639,19 @@ else {
3593
3639
  * prop. Returns a new structure with cloned props/structures along touched paths, or
3594
3640
  * `undefined` when nothing matched (so callers can reuse the original by reference).
3595
3641
  */ foldAnnotationsIntoStructure(struct, entries) {
3596
- const byHead = new Map();
3642
+ const byHead = /* @__PURE__ */ new Map();
3597
3643
  for (const entry of entries) {
3598
3644
  const head = entry.parts[0];
3599
- let group$1 = byHead.get(head);
3600
- if (!group$1) {
3601
- group$1 = {
3645
+ let group = byHead.get(head);
3646
+ if (!group) {
3647
+ group = {
3602
3648
  own: [],
3603
3649
  nested: []
3604
3650
  };
3605
- byHead.set(head, group$1);
3651
+ byHead.set(head, group);
3606
3652
  }
3607
- if (entry.parts.length === 1) group$1.own.push(...entry.anns);
3608
- else group$1.nested.push({
3653
+ if (entry.parts.length === 1) group.own.push(...entry.anns);
3654
+ else group.nested.push({
3609
3655
  parts: entry.parts.slice(1),
3610
3656
  anns: entry.anns
3611
3657
  });
@@ -3613,18 +3659,18 @@ else group$1.nested.push({
3613
3659
  const newProps = [];
3614
3660
  let changed = false;
3615
3661
  for (const [name, prop] of struct.props) {
3616
- const group$1 = byHead.get(name);
3617
- if (!group$1) {
3662
+ const group = byHead.get(name);
3663
+ if (!group) {
3618
3664
  newProps.push(prop);
3619
3665
  continue;
3620
3666
  }
3621
3667
  const propDef = prop.getDefinition();
3622
3668
  let newDef = propDef;
3623
- if (group$1.nested.length > 0 && propDef && isStructure(propDef)) {
3624
- const foldedNested = this.foldAnnotationsIntoStructure(propDef, group$1.nested);
3669
+ if (group.nested.length > 0 && propDef && isStructure(propDef)) {
3670
+ const foldedNested = this.foldAnnotationsIntoStructure(propDef, group.nested);
3625
3671
  if (foldedNested) newDef = foldedNested;
3626
3672
  }
3627
- if (group$1.own.length === 0 && newDef === propDef) {
3673
+ if (group.own.length === 0 && newDef === propDef) {
3628
3674
  newProps.push(prop);
3629
3675
  continue;
3630
3676
  }
@@ -3632,13 +3678,13 @@ else group$1.nested.push({
3632
3678
  const idToken = prop.token("identifier");
3633
3679
  if (idToken) cloned.saveToken(idToken, "identifier");
3634
3680
  if (newDef) cloned.define(newDef);
3635
- cloned.annotations = group$1.own.length > 0 ? this.mergeNodesAnnotations(prop.annotations, group$1.own) : prop.annotations;
3681
+ cloned.annotations = group.own.length > 0 ? this.mergeNodesAnnotations(prop.annotations, group.own) : prop.annotations;
3636
3682
  const optionalToken = prop.token("optional");
3637
3683
  if (optionalToken) cloned.saveToken(optionalToken, "optional");
3638
3684
  newProps.push(cloned);
3639
3685
  changed = true;
3640
3686
  }
3641
- if (!changed) return undefined;
3687
+ if (!changed) return;
3642
3688
  const newStruct = new SemanticStructureNode();
3643
3689
  newStruct.setProps(newProps);
3644
3690
  newStruct.annotations = struct.annotations;
@@ -3651,9 +3697,8 @@ else group$1.nested.push({
3651
3697
  range: r.range,
3652
3698
  token: r
3653
3699
  }));
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) => ({
3700
+ if (token.exported) {
3701
+ 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
3702
  uri: d.id,
3658
3703
  range: r.range,
3659
3704
  token: r
@@ -3662,20 +3707,20 @@ else group$1.nested.push({
3662
3707
  return refs;
3663
3708
  }
3664
3709
  if (isProp(token.parentNode)) {
3665
- const propName$1 = token.parentNode.id;
3666
- if (!propName$1) return undefined;
3710
+ const propName = token.parentNode.id;
3711
+ if (!propName) return;
3667
3712
  let parentName;
3668
- for (const node of this.nodes) if ((isInterface(node) || isStructure(node)) && node.props.get(propName$1) === token.parentNode) {
3713
+ for (const node of this.nodes) if ((isInterface(node) || isStructure(node)) && node.props.get(propName) === token.parentNode) {
3669
3714
  parentName = node.id;
3670
3715
  break;
3671
3716
  }
3672
- if (!parentName) return undefined;
3717
+ if (!parentName) return;
3673
3718
  const refs = [];
3674
3719
  const searchDoc = (doc, uri) => {
3675
3720
  for (const t of doc.referred) {
3676
3721
  if (t.text !== parentName || !isRef(t.parentNode) || !t.parentNode.hasChain) continue;
3677
3722
  const chainToken = t.parentNode.chain[0];
3678
- if (chainToken?.text === propName$1) refs.push({
3723
+ if (chainToken?.text === propName) refs.push({
3679
3724
  uri,
3680
3725
  range: chainToken.range,
3681
3726
  token: chainToken
@@ -3683,7 +3728,7 @@ else group$1.nested.push({
3683
3728
  }
3684
3729
  for (const node of doc.nodes) {
3685
3730
  if (!isAnnotate(node) || node.targetName !== parentName) continue;
3686
- for (const entry of node.entries) if (entry.id === propName$1) {
3731
+ for (const entry of node.entries) if (entry.id === propName) {
3687
3732
  const entryToken = entry.token("identifier");
3688
3733
  if (entryToken) refs.push({
3689
3734
  uri,
@@ -3693,11 +3738,10 @@ else group$1.nested.push({
3693
3738
  }
3694
3739
  }
3695
3740
  for (const qfr of doc.queryFieldRefs) {
3696
- if (!qfr.queryArgToken || qfr.fieldRef.text !== propName$1) continue;
3741
+ if (!qfr.queryArgToken || qfr.fieldRef.text !== propName) continue;
3697
3742
  const scope = getQueryScope(qfr.queryArgToken, doc);
3698
3743
  if (!scope) continue;
3699
- const resolvedTypeName = qfr.typeRef?.text ?? scope.unqualifiedTarget;
3700
- if (resolvedTypeName === parentName) refs.push({
3744
+ if ((qfr.typeRef?.text ?? scope.unqualifiedTarget) === parentName) refs.push({
3701
3745
  uri,
3702
3746
  range: qfr.fieldRef.range,
3703
3747
  token: qfr.fieldRef
@@ -3705,13 +3749,9 @@ else group$1.nested.push({
3705
3749
  }
3706
3750
  };
3707
3751
  searchDoc(this, this.id);
3708
- const parentDefToken = this.registry.definitions.get(parentName);
3709
- if (parentDefToken?.exported) {
3752
+ if (this.registry.definitions.get(parentName)?.exported) {
3710
3753
  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
- }
3754
+ for (const d of this.dependants) if (d.imports.get(this.id)?.imports.find((t) => t.text === targetName)) searchDoc(d, d.id);
3715
3755
  }
3716
3756
  return refs;
3717
3757
  }
@@ -3728,13 +3768,12 @@ else group$1.nested.push({
3728
3768
  }
3729
3769
  }
3730
3770
  }
3731
- return undefined;
3771
+ return;
3732
3772
  }
3733
3773
  {
3734
3774
  const defForToken = this.getDefinitionFor(token);
3735
3775
  if (defForToken?.token?.isDefinition && defForToken.doc) return defForToken.doc.usageListFor(defForToken.token);
3736
3776
  }
3737
- return undefined;
3738
3777
  }
3739
3778
  /**
3740
3779
  * Retrieves the definition (i.e., the “go to definition” target) for a given token.
@@ -3775,7 +3814,7 @@ else group$1.nested.push({
3775
3814
  uri: targetDoc.id,
3776
3815
  doc: targetDoc,
3777
3816
  token: target
3778
- } : undefined;
3817
+ } : void 0;
3779
3818
  }
3780
3819
  }
3781
3820
  if (token.isReference) {
@@ -3784,7 +3823,7 @@ else group$1.nested.push({
3784
3823
  uri: this.id,
3785
3824
  doc: this,
3786
3825
  token: def
3787
- } : undefined;
3826
+ } : void 0;
3788
3827
  }
3789
3828
  }
3790
3829
  getToDefinitionAt(line, character) {
@@ -3802,7 +3841,7 @@ else group$1.nested.push({
3802
3841
  targetSelectionRange: unwound.node.token("identifier")?.range ?? zeroRange,
3803
3842
  originSelectionRange: token.range
3804
3843
  }];
3805
- return undefined;
3844
+ return;
3806
3845
  }
3807
3846
  if (isQueryFieldRef(token.parentNode)) {
3808
3847
  const fieldRefNode = token.parentNode;
@@ -3817,7 +3856,7 @@ else group$1.nested.push({
3817
3856
  targetRange: result.token?.range ?? zeroRange,
3818
3857
  targetSelectionRange: result.token?.range ?? zeroRange,
3819
3858
  originSelectionRange: token.range
3820
- }] : undefined;
3859
+ }] : void 0;
3821
3860
  }
3822
3861
  if (token === fieldRefNode.fieldRef) {
3823
3862
  const resolved = resolveQueryFieldRef(fieldRefNode, this, scope);
@@ -3833,7 +3872,7 @@ else group$1.nested.push({
3833
3872
  }
3834
3873
  }
3835
3874
  }
3836
- return undefined;
3875
+ return;
3837
3876
  }
3838
3877
  if (isProp(token.parentNode)) return [{
3839
3878
  targetUri: this.id,
@@ -3857,19 +3896,19 @@ else group$1.nested.push({
3857
3896
  targetRange: result.token?.range ?? zeroRange,
3858
3897
  targetSelectionRange: result.token?.range ?? zeroRange,
3859
3898
  originSelectionRange: token.range
3860
- }] : undefined;
3899
+ }] : void 0;
3861
3900
  }
3862
3901
  }
3863
3902
  }
3864
- registerImport({ from, imports, block: block$2 }) {
3903
+ registerImport({ from, imports, block }) {
3865
3904
  const importId = resolveAtscriptFromPath(from.text, this.id);
3866
3905
  this.imports.set(importId, {
3867
3906
  from,
3868
3907
  imports
3869
3908
  });
3870
- this.blocksIndex.add(block$2);
3871
- block$2.blockType = "import";
3872
- block$2.fromPath = from.text;
3909
+ this.blocksIndex.add(block);
3910
+ block.blockType = "import";
3911
+ block.fromPath = from.text;
3873
3912
  this.tokensIndex.add(from);
3874
3913
  from.fromPath = from.text;
3875
3914
  imports.forEach((t) => {
@@ -3909,27 +3948,26 @@ else group$1.nested.push({
3909
3948
  * - `token`: The specific token for the declaration (if applicable).
3910
3949
  *
3911
3950
  * If no declaration is found, returns `undefined`.
3912
- */ getDeclarationOwnerNode(identifier$1) {
3913
- if (this.config.primitives?.has(identifier$1)) return {
3951
+ */ getDeclarationOwnerNode(identifier) {
3952
+ if (this.config.primitives?.has(identifier)) return {
3914
3953
  doc: this,
3915
- node: this.config.primitives.get(identifier$1)
3954
+ node: this.config.primitives.get(identifier)
3916
3955
  };
3917
- const def = this.registry.definitions.get(identifier$1);
3956
+ const def = this.registry.definitions.get(identifier);
3918
3957
  if (def?.imported && def.fromPath) {
3919
3958
  const absolutePath = this.resolveImportId(resolveAtscriptFromPath(def.fromPath, this.id));
3920
- const doc = this.dependenciesMap.get(absolutePath);
3921
- return doc?.getDeclarationOwnerNode(identifier$1);
3959
+ return this.dependenciesMap.get(absolutePath)?.getDeclarationOwnerNode(identifier);
3922
3960
  } else if (!def?.imported) return def ? {
3923
3961
  doc: this,
3924
3962
  node: def.parentNode,
3925
3963
  token: def
3926
- } : undefined;
3964
+ } : void 0;
3927
3965
  }
3928
3966
  registerExport(node) {
3929
3967
  if (node.id) this.exports.set(node.id, node);
3930
3968
  }
3931
3969
  registerMessage(token, message, severity = 1, tag) {
3932
- if (this._allMessages) this._allMessages = undefined;
3970
+ if (this._allMessages) this._allMessages = void 0;
3933
3971
  this.messages.push({
3934
3972
  severity,
3935
3973
  message,
@@ -3941,50 +3979,46 @@ else group$1.nested.push({
3941
3979
  if (messages) this.messages.push(...messages);
3942
3980
  }
3943
3981
  clearMessages() {
3944
- this._allMessages = undefined;
3982
+ this._allMessages = void 0;
3945
3983
  }
3946
3984
  getUnusedTokens() {
3947
3985
  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;
3986
+ const tokens = [];
3987
+ for (const [key, token] of this.registry.definitions) if (!refSet.has(key) && !this.exports.has(key)) tokens.push(token);
3988
+ return tokens;
3951
3989
  }
3952
3990
  renderDiagMessage(m, addSourceLinses = false, colors = false) {
3953
3991
  const c = {
3954
- red: colors ? __DYE_RED__ : "",
3955
- blue: colors ? __DYE_BLUE__ : "",
3956
- cyan: colors ? __DYE_CYAN__ : "",
3957
- yellow: colors ? __DYE_YELLOW__ : "",
3958
- dim: colors ? __DYE_DIM__ : "",
3959
- reset: colors ? __DYE_RESET__ : ""
3992
+ red: colors ? "\x1B[31m" : "",
3993
+ blue: colors ? "\x1B[34m" : "",
3994
+ cyan: colors ? "\x1B[36m" : "",
3995
+ yellow: colors ? "\x1B[33m" : "",
3996
+ dim: colors ? "\x1B[2m" : "",
3997
+ reset: colors ? "\x1B[0m" : ""
3960
3998
  };
3961
3999
  let sc = "";
3962
4000
  let banner = "[atscript]";
3963
4001
  switch (m.severity) {
3964
- case TSeverity.Error: {
4002
+ case TSeverity.Error:
3965
4003
  sc = c.red;
3966
4004
  banner += "[Error]";
3967
4005
  break;
3968
- }
3969
- case TSeverity.Warning: {
4006
+ case TSeverity.Warning:
3970
4007
  sc = c.yellow;
3971
4008
  banner += "[Warning]";
3972
4009
  break;
3973
- }
3974
- case TSeverity.Info: {
4010
+ case TSeverity.Info:
3975
4011
  sc = "";
3976
4012
  banner += "[Info]";
3977
4013
  break;
3978
- }
3979
- case TSeverity.Hint: {
4014
+ case TSeverity.Hint:
3980
4015
  sc = c.dim;
3981
4016
  banner += "[Hint]";
3982
4017
  break;
3983
- }
3984
4018
  default: sc = "";
3985
4019
  }
3986
4020
  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}`;
4021
+ let out = `\n${sc}${banner} ${m.message}${c.reset}\nin ${c.blue}${this.id}:${n}:${m.range.start.character + 1}${c.reset}`;
3988
4022
  if (addSourceLinses) {
3989
4023
  const lines = this.text.split("\n");
3990
4024
  const renderLines = [
@@ -4000,7 +4034,7 @@ else group$1.nested.push({
4000
4034
  l: lines[n - 1],
4001
4035
  i: n - 1
4002
4036
  }
4003
- ].filter((r) => r.l !== undefined);
4037
+ ].filter((r) => r.l !== void 0);
4004
4038
  const nl = String(n).length + 1;
4005
4039
  for (const { l, i } of renderLines) {
4006
4040
  const prefix = `${c.dim + c.cyan}${`0${i}`.slice(-nl)} | ${c.reset}`;
@@ -4026,7 +4060,7 @@ else group$1.nested.push({
4026
4060
  });
4027
4061
  const ownDef = iface.getDefinition();
4028
4062
  if (ownDef && isStructure(ownDef)) {
4029
- const parentProps = new Map();
4063
+ const parentProps = /* @__PURE__ */ new Map();
4030
4064
  for (const t of iface.extendsTokens) {
4031
4065
  if (t.text === iface.id) continue;
4032
4066
  const unwound = this.unwindType(t.text);
@@ -4064,8 +4098,7 @@ else group$1.nested.push({
4064
4098
  if (!this.registry.isDefined(targetName)) continue;
4065
4099
  const chain = isRef(t.parentNode) && t.parentNode.hasChain ? [t.text, ...t.parentNode.chain.map((c) => c.text)] : [t.text];
4066
4100
  const unwound = this.unwindType(targetName, chain);
4067
- const chainResolved = unwound?.def && !isGroup(unwound.def);
4068
- const resolvedType = chainResolved ? unwound.def : this.resolveChainWithMerge(targetName, chain);
4101
+ const resolvedType = unwound?.def && !isGroup(unwound.def) ? unwound.def : this.resolveChainWithMerge(targetName, chain);
4069
4102
  if (!resolvedType) {
4070
4103
  const lastToken = chain.length > 1 && isRef(t.parentNode) ? t.parentNode.chain[t.parentNode.chain.length - 1] || t : t;
4071
4104
  this._allMessages.push({
@@ -4079,8 +4112,7 @@ else group$1.nested.push({
4079
4112
  const token = t.parentNode.chain[i];
4080
4113
  const memberChain = [t.text, ...t.parentNode.chain.slice(0, i + 1).map((c) => c.text)];
4081
4114
  const decl = this.unwindType(targetName, memberChain);
4082
- const memberResolved = decl?.def && !isGroup(decl.def);
4083
- if (!memberResolved && !this.resolveChainWithMerge(targetName, memberChain)) this._allMessages.push({
4115
+ if (!(decl?.def && !isGroup(decl.def)) && !this.resolveChainWithMerge(targetName, memberChain)) this._allMessages.push({
4084
4116
  severity: 1,
4085
4117
  message: `Unknown property "${memberChain.join(".")}" in "${targetName}"`,
4086
4118
  range: token.range
@@ -4088,8 +4120,7 @@ else group$1.nested.push({
4088
4120
  }
4089
4121
  }
4090
4122
  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);
4123
+ const msgs = this.resolveAnnotation(a.token.text.slice(1))?.validateTargetType(resolvedType, a.token.range);
4093
4124
  if (msgs) this._allMessages.push(...msgs);
4094
4125
  }
4095
4126
  continue;
@@ -4121,8 +4152,7 @@ else group$1.nested.push({
4121
4152
  const length = t.parentNode.chain.length - 1;
4122
4153
  for (let i = length; i >= 0; i--) {
4123
4154
  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({
4155
+ if (!this.unwindType(t.parentNode.id, t.parentNode.chain.slice(0, i + 1))?.def) this._allMessages.push({
4126
4156
  severity: 1,
4127
4157
  message: `Unknown member "${token.text}"`,
4128
4158
  range: token.range
@@ -4148,7 +4178,7 @@ else group$1.nested.push({
4148
4178
  * only need a yes/no resolution check use the truthiness of the result.
4149
4179
  */ resolveChainWithMerge(targetName, chain) {
4150
4180
  let def = this.unwindType(targetName)?.def;
4151
- if (!def) return undefined;
4181
+ if (!def) return;
4152
4182
  for (const prop of chain) {
4153
4183
  def = this.mergeIntersection(def);
4154
4184
  if (isProp(def)) {
@@ -4157,30 +4187,29 @@ else group$1.nested.push({
4157
4187
  }
4158
4188
  if (isStructure(def) || isInterface(def)) {
4159
4189
  const next = def.props.get(prop);
4160
- if (!next) return undefined;
4190
+ if (!next) return;
4161
4191
  def = next.getDefinition() || next;
4162
4192
  } else if (isGroup(def)) {
4163
4193
  const found = this.findPropInGroup(def, prop);
4164
- if (!found) return undefined;
4194
+ if (!found) return;
4165
4195
  def = found;
4166
- } else return undefined;
4196
+ } else return;
4167
4197
  }
4168
4198
  if (isRef(def)) def = this.unwindType(def.id, def.chain)?.def || def;
4169
4199
  return def;
4170
4200
  }
4171
- findPropInGroup(group$1, propName$1) {
4172
- for (const item of group$1.unwrap()) {
4201
+ findPropInGroup(group, propName) {
4202
+ for (const item of group.unwrap()) {
4173
4203
  const merged = this.mergeIntersection(item);
4174
4204
  if (isStructure(merged) || isInterface(merged)) {
4175
- const prop = merged.props.get(propName$1);
4205
+ const prop = merged.props.get(propName);
4176
4206
  if (prop) return prop.getDefinition() || prop;
4177
4207
  }
4178
4208
  if (isGroup(merged)) {
4179
- const found = this.findPropInGroup(merged, propName$1);
4209
+ const found = this.findPropInGroup(merged, propName);
4180
4210
  if (found) return found;
4181
4211
  }
4182
4212
  }
4183
- return undefined;
4184
4213
  }
4185
4214
  mergeIntersection(node) {
4186
4215
  if (!isGroup(node)) return node;
@@ -4199,10 +4228,8 @@ else group$1.nested.push({
4199
4228
  } else left = merged[0];
4200
4229
  }
4201
4230
  newGroup.push(left);
4202
- if (newGroup.length > 1) {
4203
- const newNode = new SemanticGroup(newGroup, "&");
4204
- return newNode;
4205
- } else return newGroup[0];
4231
+ if (newGroup.length > 1) return new SemanticGroup(newGroup, "&");
4232
+ else return newGroup[0];
4206
4233
  }
4207
4234
  mergeDefs(_left, _right) {
4208
4235
  let left = _left;
@@ -4236,7 +4263,7 @@ else group$1.nested.push({
4236
4263
  const oldProps = [leftProp, rightProp].filter(Boolean);
4237
4264
  let optionalToken = oldProps[0]?.token("optional");
4238
4265
  for (const oldProp of oldProps) if (!oldProp.token("optional")) {
4239
- optionalToken = undefined;
4266
+ optionalToken = void 0;
4240
4267
  break;
4241
4268
  }
4242
4269
  if (optionalToken) prop.saveToken(optionalToken, "optional");
@@ -4261,18 +4288,17 @@ else group$1.nested.push({
4261
4288
  * @param right - An optional array of annotation tokens to merge (higher priority).
4262
4289
  * @returns A merged array of annotation tokens, preserving order while preventing duplicates.
4263
4290
  */ mergeNodesAnnotations(left, right) {
4264
- const annotations$1 = [];
4265
- const savedAnnotations = new Set();
4291
+ const annotations = [];
4292
+ const savedAnnotations = /* @__PURE__ */ new Set();
4266
4293
  for (const a of right || []) {
4267
- annotations$1.push(a);
4294
+ annotations.push(a);
4268
4295
  savedAnnotations.add(a.name);
4269
4296
  }
4270
4297
  for (const a of left || []) {
4271
4298
  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);
4299
+ if (spec && spec.config.multiple && spec.config.mergeStrategy === "append" || !savedAnnotations.has(a.name)) annotations.push(a);
4274
4300
  }
4275
- return annotations$1;
4301
+ return annotations;
4276
4302
  }
4277
4303
  constructor(id, config, manager) {
4278
4304
  _define_property$3(this, "id", void 0);
@@ -4330,22 +4356,22 @@ else group$1.nested.push({
4330
4356
  this.messages = [];
4331
4357
  this.tokensIndex = new TokensIndex();
4332
4358
  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();
4359
+ this.imports = /* @__PURE__ */ new Map();
4360
+ this.resolvedImports = /* @__PURE__ */ new Map();
4361
+ this.importedDefs = /* @__PURE__ */ new Map();
4362
+ this.exports = /* @__PURE__ */ new Map();
4363
+ this.dependencies = /* @__PURE__ */ new Set();
4364
+ this.dependants = /* @__PURE__ */ new Set();
4339
4365
  this.referred = [];
4340
4366
  this.queryFieldRefs = [];
4341
- this.dependenciesMap = new Map();
4342
- this._annotationSpecCache = new Map();
4367
+ this.dependenciesMap = /* @__PURE__ */ new Map();
4368
+ this._annotationSpecCache = /* @__PURE__ */ new Map();
4343
4369
  this.nodes = [];
4344
4370
  this._text = "";
4345
4371
  this.resolvedAnnotations = [];
4346
4372
  this.annotations = [];
4347
4373
  this._nextTypeId = 0;
4348
- this._allMessages = undefined;
4374
+ this._allMessages = void 0;
4349
4375
  this.registry = new IdRegistry(Array.from(config.primitives?.keys() || []));
4350
4376
  }
4351
4377
  };
@@ -4360,13 +4386,13 @@ const zeroRange = {
4360
4386
  }
4361
4387
  };
4362
4388
  function createSyntheticRef(name) {
4363
- const ref$1 = new SemanticRefNode();
4364
- ref$1.saveToken(new Token({
4389
+ const ref = new SemanticRefNode();
4390
+ ref.saveToken(new Token({
4365
4391
  text: name,
4366
4392
  type: "identifier",
4367
4393
  getRange: () => zeroRange
4368
4394
  }), "identifier");
4369
- return ref$1;
4395
+ return ref;
4370
4396
  }
4371
4397
 
4372
4398
  //#endregion
@@ -4560,13 +4586,13 @@ const expectAnnotations = {
4560
4586
  validate(token, args, doc) {
4561
4587
  const field = token.parentNode;
4562
4588
  const errors = [];
4563
- const definition$1 = field.getDefinition();
4564
- if (!definition$1) return errors;
4589
+ const definition = field.getDefinition();
4590
+ if (!definition) return errors;
4565
4591
  let wrongType = false;
4566
- if (isRef(definition$1)) {
4567
- const def = doc.unwindType(definition$1.id, definition$1.chain)?.def;
4592
+ if (isRef(definition)) {
4593
+ const def = doc.unwindType(definition.id, definition.chain)?.def;
4568
4594
  if (!isArray(def)) wrongType = true;
4569
- } else if (!isArray(definition$1)) wrongType = true;
4595
+ } else if (!isArray(definition)) wrongType = true;
4570
4596
  if (wrongType) errors.push({
4571
4597
  message: `@expect.array.uniqueItems requires an array field`,
4572
4598
  severity: 1,
@@ -4588,17 +4614,16 @@ const expectAnnotations = {
4588
4614
  validate(token, args, doc) {
4589
4615
  const field = token.parentNode;
4590
4616
  const errors = [];
4591
- const isOptional = !!field.token("optional");
4592
- if (isOptional) errors.push({
4617
+ if (!!field.token("optional")) errors.push({
4593
4618
  message: `@expect.array.key can't be optional`,
4594
4619
  severity: 1,
4595
4620
  range: field.token("identifier").range
4596
4621
  });
4597
- const definition$1 = field.getDefinition();
4598
- if (!definition$1) return errors;
4622
+ const definition = field.getDefinition();
4623
+ if (!definition) return errors;
4599
4624
  let wrongType = false;
4600
- if (isRef(definition$1)) {
4601
- const def = doc.unwindType(definition$1.id, definition$1.chain)?.def;
4625
+ if (isRef(definition)) {
4626
+ const def = doc.unwindType(definition.id, definition.chain)?.def;
4602
4627
  if (isPrimitive(def) && !["string", "number"].includes(def.config.type)) wrongType = true;
4603
4628
  } else wrongType = true;
4604
4629
  if (wrongType) errors.push({
@@ -4692,17 +4717,15 @@ const metaAnnotations = {
4692
4717
  //#region packages/core/src/defaults/primitives.ts
4693
4718
  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
4719
  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
4720
  const positiveOrNegative = {
4704
- positive,
4705
- negative
4721
+ positive: {
4722
+ documentation: "Number that greater than or equal to zero.",
4723
+ annotations: { "expect.min": 0 }
4724
+ },
4725
+ negative: {
4726
+ documentation: "Number that less than or equal to zero.",
4727
+ annotations: { "expect.max": 0 }
4728
+ }
4706
4729
  };
4707
4730
  const primitives = {
4708
4731
  never: { documentation: "Represents impossible type." },
@@ -4935,7 +4958,7 @@ const primitives = {
4935
4958
  //#endregion
4936
4959
  //#region packages/core/src/default-atscript-config.ts
4937
4960
  function getDefaultAtscriptConfig() {
4938
- const defaulTAtscriptConfig = {
4961
+ return {
4939
4962
  primitives,
4940
4963
  annotations: {
4941
4964
  meta: { ...metaAnnotations },
@@ -4943,7 +4966,6 @@ function getDefaultAtscriptConfig() {
4943
4966
  emit: { ...emitAnnotations }
4944
4967
  }
4945
4968
  };
4946
- return defaulTAtscriptConfig;
4947
4969
  }
4948
4970
 
4949
4971
  //#endregion
@@ -4955,7 +4977,7 @@ function _define_property$2(obj, key, value) {
4955
4977
  configurable: true,
4956
4978
  writable: true
4957
4979
  });
4958
- else obj[key] = value;
4980
+ else obj[key] = value;
4959
4981
  return obj;
4960
4982
  }
4961
4983
  var PluginManager = class {
@@ -4967,7 +4989,7 @@ var PluginManager = class {
4967
4989
  const raw = await this.config();
4968
4990
  this._docConfig = {};
4969
4991
  if (raw?.primitives) {
4970
- this._docConfig.primitives = new Map();
4992
+ this._docConfig.primitives = /* @__PURE__ */ new Map();
4971
4993
  for (const [key, value] of Object.entries(raw.primitives)) this._docConfig.primitives.set(key, new SemanticPrimitiveNode(key, value, "", raw.annotations));
4972
4994
  }
4973
4995
  if (raw?.annotations) this._docConfig.annotations = { ...raw.annotations };
@@ -4978,7 +5000,7 @@ var PluginManager = class {
4978
5000
  async config(config = this.cfg) {
4979
5001
  if (!this._config) {
4980
5002
  config = defu(config, getDefaultAtscriptConfig());
4981
- const seen = new Set();
5003
+ const seen = /* @__PURE__ */ new Set();
4982
5004
  for (const plugin of this.plugins) {
4983
5005
  if (seen.has(plugin.name)) continue;
4984
5006
  seen.add(plugin.name);
@@ -5020,16 +5042,15 @@ var PluginManager = class {
5020
5042
  for (const plugin of this.plugins) if (plugin.buildEnd) await plugin.buildEnd(output, format, repo);
5021
5043
  }
5022
5044
  async loopInAnnotationsSpec(cb) {
5023
- const config = await this.config();
5024
- const annotations$1 = config.annotations || {};
5025
- return this._loopInAnnotationsSpec(annotations$1, cb);
5045
+ const annotations = (await this.config()).annotations || {};
5046
+ return this._loopInAnnotationsSpec(annotations, cb);
5026
5047
  }
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)) {
5048
+ _loopInAnnotationsSpec(annotations, cb, prefix) {
5049
+ if (annotations.$self && prefix) cb(prefix, annotations.$self);
5050
+ for (const [key, value] of Object.entries(annotations)) {
5030
5051
  if (key === "$self") continue;
5031
5052
  if (isAnnotationSpec(value)) cb(prefix ? `${prefix}.${key}` : key, value);
5032
- else this._loopInAnnotationsSpec(value, cb, prefix ? `${prefix}.${key}` : key);
5053
+ else this._loopInAnnotationsSpec(value, cb, prefix ? `${prefix}.${key}` : key);
5033
5054
  }
5034
5055
  }
5035
5056
  constructor(cfg) {
@@ -5051,7 +5072,7 @@ function _define_property$1(obj, key, value) {
5051
5072
  configurable: true,
5052
5073
  writable: true
5053
5074
  });
5054
- else obj[key] = value;
5075
+ else obj[key] = value;
5055
5076
  return obj;
5056
5077
  }
5057
5078
  var AtscriptRepo = class {
@@ -5060,12 +5081,12 @@ var AtscriptRepo = class {
5060
5081
  }
5061
5082
  async getPrimitivesTags() {
5062
5083
  const manager = await this.getSharedPluginManager();
5063
- if (!manager) return undefined;
5084
+ if (!manager) return;
5064
5085
  const docConfig = await manager.getDocConfig();
5065
- const primitives$1 = Array.from(docConfig.primitives?.entries() || []);
5086
+ const primitives = Array.from(docConfig.primitives?.entries() || []);
5066
5087
  const tags = [];
5067
- const processed = new Set();
5068
- for (const [, primitive] of primitives$1) tags.push(...primitive.getAllTags(processed));
5088
+ const processed = /* @__PURE__ */ new Set();
5089
+ for (const [, primitive] of primitives) tags.push(...primitive.getAllTags(processed));
5069
5090
  return new Set(tags);
5070
5091
  }
5071
5092
  async getUsedAnnotations() {
@@ -5075,7 +5096,7 @@ var AtscriptRepo = class {
5075
5096
  };
5076
5097
  const mapArgType = (t) => ANNOTATION_TYPE_MAP[t] || t;
5077
5098
  const manager = await this.getSharedPluginManager();
5078
- const annotations$1 = {};
5099
+ const annotations = {};
5079
5100
  if (manager) await manager.loopInAnnotationsSpec((name, spec) => {
5080
5101
  const types = [];
5081
5102
  const multiple = !!spec.config.multiple;
@@ -5093,62 +5114,57 @@ var AtscriptRepo = class {
5093
5114
  type: mapArgType(spec.config.argument.type),
5094
5115
  optional: spec.config.argument.optional
5095
5116
  });
5096
- else types.push({ type: "boolean" });
5097
- annotations$1[name] = {
5117
+ else types.push({ type: "boolean" });
5118
+ annotations[name] = {
5098
5119
  multiple,
5099
5120
  fromSpec: true,
5100
- typeSet: new Set(),
5121
+ typeSet: /* @__PURE__ */ new Set(),
5101
5122
  types
5102
5123
  };
5103
5124
  });
5104
5125
  for (const doc of Array.from(this.atscripts.values())) {
5105
5126
  const awaited = await doc;
5106
5127
  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;
5128
+ if (annotations[name]?.fromSpec) continue;
5129
+ if (!annotations[name]) annotations[name] = {
5130
+ multiple: false,
5131
+ fromSpec: false,
5132
+ typeSet: /* @__PURE__ */ new Set(),
5133
+ types: []
5134
+ };
5135
+ if (token.parentNode.countAnnotations(name) > 1) annotations[name].multiple = true;
5120
5136
  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" });
5137
+ if (!annotations[name].typeSet.has("string")) {
5138
+ annotations[name].typeSet.add("string");
5139
+ annotations[name].types.push({ type: "string" });
5124
5140
  }
5125
5141
  } 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" });
5142
+ if (!annotations[name].typeSet.has("number")) {
5143
+ annotations[name].typeSet.add("number");
5144
+ annotations[name].types.push({ type: "number" });
5129
5145
  }
5130
5146
  } 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" });
5147
+ if (!annotations[name].typeSet.has("boolean")) {
5148
+ annotations[name].typeSet.add("boolean");
5149
+ annotations[name].types.push({ type: "boolean" });
5134
5150
  }
5135
- } else if (!annotations$1[name].typeSet.has("unknown")) {
5136
- annotations$1[name].typeSet.add("unknown");
5137
- annotations$1[name].types.push({ type: "unknown" });
5151
+ } else if (!annotations[name].typeSet.has("unknown")) {
5152
+ annotations[name].typeSet.add("unknown");
5153
+ annotations[name].types.push({ type: "unknown" });
5138
5154
  }
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" });
5155
+ if (args.length === 0 && !annotations[name].typeSet.has("boolean")) {
5156
+ annotations[name].typeSet.add("boolean");
5157
+ annotations[name].types.push({ type: "boolean" });
5142
5158
  }
5143
5159
  }
5144
5160
  }
5145
- return annotations$1;
5161
+ return annotations;
5146
5162
  }
5147
5163
  async loadPluginManagerFor(id) {
5148
5164
  if (this.sharedConfig) {
5149
5165
  if (!this.sharedPluginManager) this.sharedPluginManager = {
5150
5166
  manager: new PluginManager(this.sharedConfig),
5151
- dependants: new Set()
5167
+ dependants: /* @__PURE__ */ new Set()
5152
5168
  };
5153
5169
  return this.sharedPluginManager;
5154
5170
  }
@@ -5165,14 +5181,14 @@ else types.push({ type: "boolean" });
5165
5181
  return {
5166
5182
  file: configFile,
5167
5183
  manager,
5168
- dependants: new Set()
5184
+ dependants: /* @__PURE__ */ new Set()
5169
5185
  };
5170
5186
  } else {
5171
5187
  const manager = new PluginManager({ rootDir: process.cwd() });
5172
5188
  await manager.getDocConfig();
5173
5189
  return {
5174
5190
  manager,
5175
- dependants: new Set()
5191
+ dependants: /* @__PURE__ */ new Set()
5176
5192
  };
5177
5193
  }
5178
5194
  }
@@ -5187,18 +5203,18 @@ else types.push({ type: "boolean" });
5187
5203
  }
5188
5204
  return config;
5189
5205
  }
5190
- async openDocument(id, text$2) {
5206
+ async openDocument(id, text) {
5191
5207
  let atscript = this.atscripts.get(id);
5192
5208
  if (atscript) {
5193
- if (text$2) {
5209
+ if (text) {
5194
5210
  atscript = atscript.then((d) => {
5195
- d.update(text$2);
5211
+ d.update(text);
5196
5212
  return d;
5197
5213
  });
5198
5214
  this.atscripts.set(id, atscript);
5199
5215
  }
5200
5216
  } else {
5201
- atscript = this._openDocument(id, text$2);
5217
+ atscript = this._openDocument(id, text);
5202
5218
  atscript.catch(() => {
5203
5219
  this.atscripts.delete(id);
5204
5220
  });
@@ -5206,11 +5222,11 @@ else types.push({ type: "boolean" });
5206
5222
  }
5207
5223
  return atscript;
5208
5224
  }
5209
- async _openDocument(id, text$2) {
5225
+ async _openDocument(id, text) {
5210
5226
  const { manager } = await this.resolveConfig(id);
5211
5227
  const newId = await manager.resolve(id);
5212
5228
  if (!newId) throw new Error(`Document not resolved: ${id}`);
5213
- const content = text$2 || await manager.load(newId);
5229
+ const content = text || await manager.load(newId);
5214
5230
  if (typeof content !== "string") throw new TypeError(`Document not found: ${newId}`);
5215
5231
  const atscript = new AtscriptDoc(id, await manager.getDocConfig(), manager);
5216
5232
  atscript.update(content);
@@ -5221,11 +5237,10 @@ else types.push({ type: "boolean" });
5221
5237
  await this.checkImports(atscript);
5222
5238
  }
5223
5239
  async checkImports(atscript, checked) {
5224
- const _checked = checked || new Set();
5240
+ const _checked = checked || /* @__PURE__ */ new Set();
5225
5241
  if (_checked.has(atscript.id)) return;
5226
5242
  _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;
5243
+ const results = await Promise.all(Array.from(atscript.imports.values(), async ({ from, imports }) => this.checkImport(atscript, from, imports, _checked)));
5229
5244
  atscript.updateDependencies(results.filter(Boolean));
5230
5245
  }
5231
5246
  async checkImport(atscript, from, imports, checked) {
@@ -5273,7 +5288,7 @@ else types.push({ type: "boolean" });
5273
5288
  }
5274
5289
  return external;
5275
5290
  }
5276
- constructor(root$1 = process.cwd(), sharedConfig) {
5291
+ constructor(root = process.cwd(), sharedConfig) {
5277
5292
  _define_property$1(this, "root", void 0);
5278
5293
  _define_property$1(this, "sharedConfig", void 0);
5279
5294
  _define_property$1(this, "configFormat", void 0);
@@ -5290,18 +5305,35 @@ else types.push({ type: "boolean" });
5290
5305
  /**
5291
5306
  * cache for raw content of config files
5292
5307
  */ _define_property$1(this, "configFiles", void 0);
5293
- this.root = root$1;
5308
+ this.root = root;
5294
5309
  this.sharedConfig = sharedConfig;
5295
- this.configs = new Map();
5296
- this.atscripts = new Map();
5297
- this.resolvedToBare = new Map();
5298
- this.configFiles = new Map();
5310
+ this.configs = /* @__PURE__ */ new Map();
5311
+ this.atscripts = /* @__PURE__ */ new Map();
5312
+ this.resolvedToBare = /* @__PURE__ */ new Map();
5313
+ this.configFiles = /* @__PURE__ */ new Map();
5299
5314
  }
5300
5315
  };
5301
5316
 
5302
5317
  //#endregion
5303
5318
  //#region packages/core/src/plugin/types.ts
5304
- const DEFAULT_FORMAT = "__default__";
5319
+ /**
5320
+ * Well-known render format for a plugin's primary output.
5321
+ *
5322
+ * When a `.as` file is saved in an editor (VSCode, etc.), the editor
5323
+ * passes this format to `render()` and `buildEnd()`. Plugins should
5324
+ * check for this value alongside their own format strings to produce
5325
+ * output that is essential for the development experience — typically
5326
+ * type declarations for the host language.
5327
+ *
5328
+ * @example
5329
+ * ```ts
5330
+ * render(doc, format) {
5331
+ * if (format === 'dts' || format === DEFAULT_FORMAT) {
5332
+ * return [{ fileName: `${doc.name}.d.ts`, content: renderTypes(doc) }]
5333
+ * }
5334
+ * }
5335
+ * ```
5336
+ */ const DEFAULT_FORMAT = "__default__";
5305
5337
  const createAtscriptPlugin = (plugin) => plugin;
5306
5338
 
5307
5339
  //#endregion
@@ -5313,7 +5345,7 @@ function _define_property(obj, key, value) {
5313
5345
  configurable: true,
5314
5346
  writable: true
5315
5347
  });
5316
- else obj[key] = value;
5348
+ else obj[key] = value;
5317
5349
  return obj;
5318
5350
  }
5319
5351
  async function build(config) {
@@ -5322,13 +5354,11 @@ async function build(config) {
5322
5354
  const repo = new AtscriptRepo(rootDir, config);
5323
5355
  const entries = [];
5324
5356
  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, {
5357
+ else {
5358
+ const found = await glob(config.include && config.include.length > 0 ? config.include : ["**/*.as"], {
5329
5359
  cwd: rootDir,
5330
5360
  absolute: true,
5331
- ignore: excludes
5361
+ ignore: config.exclude && config.exclude.length > 0 ? config.exclude : ["node_modules"]
5332
5362
  });
5333
5363
  entries.push(...found);
5334
5364
  }
@@ -5343,7 +5373,7 @@ var BuildRepo = class {
5343
5373
  return this.docs.find((d) => d.id === id);
5344
5374
  }
5345
5375
  async diagnostics() {
5346
- const docMessages = new Map();
5376
+ const docMessages = /* @__PURE__ */ new Map();
5347
5377
  for (const document of this.docs) docMessages.set(document.id, document.getDiagMessages());
5348
5378
  return docMessages;
5349
5379
  }
@@ -5387,9 +5417,29 @@ var BuildRepo = class {
5387
5417
 
5388
5418
  //#endregion
5389
5419
  //#region packages/core/src/flatten.ts
5390
- function flattenInterfaceNode(doc, node, options) {
5391
- const flatMap = new Map();
5392
- const stack = new Set();
5420
+ /**
5421
+ * Flattens an interface node into a map of dot-notation paths to their type descriptors.
5422
+ *
5423
+ * This utility exists to improve type-safety for filter expressions and `$select`/`$sort`
5424
+ * operations in the DB layer. The generated `__flat` static property on `@db.table`
5425
+ * interfaces uses this map to provide autocomplete and compile-time checks for
5426
+ * dot-notation query paths.
5427
+ *
5428
+ * Walks the interface structure (including inherited props from `extends`) and collects
5429
+ * all reachable field paths. Nested objects are recursed into, arrays are recursed through
5430
+ * their element types, and unions/intersections are recursed through each branch (with
5431
+ * colliding paths merged into union groups).
5432
+ *
5433
+ * Fields annotated with `@db.json` are treated as leaves — their sub-paths are NOT included,
5434
+ * because `@db.json` fields are stored as a single JSON column in the database and their
5435
+ * sub-paths are not individually queryable.
5436
+ *
5437
+ * @param doc - The document owning the interface node.
5438
+ * @param node - The interface node to flatten.
5439
+ * @returns A map of dot-separated paths to their field descriptors.
5440
+ */ function flattenInterfaceNode(doc, node, options) {
5441
+ const flatMap = /* @__PURE__ */ new Map();
5442
+ const stack = /* @__PURE__ */ new Set();
5393
5443
  let struct;
5394
5444
  if (node.hasExtends) struct = doc.resolveInterfaceExtends(node);
5395
5445
  if (!struct) struct = node.getDefinition();
@@ -5424,10 +5474,10 @@ function isPhantomNode(doc, def) {
5424
5474
  }
5425
5475
  function resolveNode(doc, def) {
5426
5476
  if (isRef(def)) {
5427
- const ref$1 = def;
5428
- const unwound = doc.unwindType(ref$1.id, ref$1.chain);
5477
+ const ref = def;
5478
+ const unwound = doc.unwindType(ref.id, ref.chain);
5429
5479
  if (unwound?.def) return resolveNode(unwound.doc, unwound.def);
5430
- return undefined;
5480
+ return;
5431
5481
  }
5432
5482
  if (isInterface(def)) {
5433
5483
  const iface = def;
@@ -5438,7 +5488,7 @@ function resolveNode(doc, def) {
5438
5488
  def: struct,
5439
5489
  doc
5440
5490
  };
5441
- return undefined;
5491
+ return;
5442
5492
  }
5443
5493
  return {
5444
5494
  def,
@@ -5448,18 +5498,18 @@ function resolveNode(doc, def) {
5448
5498
  function isComplexNode(def) {
5449
5499
  return isStructure(def) || isArray(def) || isGroup(def) && def.entity !== "tuple";
5450
5500
  }
5451
- function addToFlatMap(flatMap, path$2, descriptor) {
5452
- const existing = flatMap.get(path$2);
5501
+ function addToFlatMap(flatMap, path, descriptor) {
5502
+ const existing = flatMap.get(path);
5453
5503
  if (existing) {
5454
- const group$1 = new SemanticGroup([existing.def, descriptor.def], "|");
5455
- flatMap.set(path$2, {
5456
- def: group$1,
5504
+ const group = new SemanticGroup([existing.def, descriptor.def], "|");
5505
+ flatMap.set(path, {
5506
+ def: group,
5457
5507
  doc: existing.doc,
5458
5508
  optional: existing.optional || descriptor.optional,
5459
5509
  propNode: existing.propNode,
5460
- intermediate: existing.intermediate && descriptor.intermediate ? true : undefined
5510
+ intermediate: existing.intermediate && descriptor.intermediate ? true : void 0
5461
5511
  });
5462
- } else flatMap.set(path$2, descriptor);
5512
+ } else flatMap.set(path, descriptor);
5463
5513
  }
5464
5514
  function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack, options) {
5465
5515
  for (const [name, prop] of struct.props) {
@@ -5467,11 +5517,11 @@ function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack, opti
5467
5517
  const propDef = prop.getDefinition();
5468
5518
  if (isPhantomNode(doc, propDef)) continue;
5469
5519
  if (options?.skipNavProps && hasNavPropAnnotation(prop)) continue;
5470
- const path$2 = prefix ? `${prefix}.${name}` : name;
5520
+ const path = prefix ? `${prefix}.${name}` : name;
5471
5521
  const optional = parentOptional || !!prop.token("optional");
5472
5522
  const dbJson = hasDbJsonAnnotation(prop);
5473
5523
  if (!propDef) {
5474
- addToFlatMap(flatMap, path$2, {
5524
+ addToFlatMap(flatMap, path, {
5475
5525
  def: prop,
5476
5526
  doc,
5477
5527
  optional,
@@ -5481,7 +5531,7 @@ function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack, opti
5481
5531
  }
5482
5532
  const resolved = resolveNode(doc, propDef);
5483
5533
  if (!resolved) {
5484
- addToFlatMap(flatMap, path$2, {
5534
+ addToFlatMap(flatMap, path, {
5485
5535
  def: propDef,
5486
5536
  doc,
5487
5537
  optional,
@@ -5490,7 +5540,7 @@ function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack, opti
5490
5540
  continue;
5491
5541
  }
5492
5542
  if (dbJson) {
5493
- addToFlatMap(flatMap, path$2, {
5543
+ addToFlatMap(flatMap, path, {
5494
5544
  def: resolved.def,
5495
5545
  doc: resolved.doc,
5496
5546
  optional,
@@ -5499,12 +5549,12 @@ function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack, opti
5499
5549
  });
5500
5550
  continue;
5501
5551
  }
5502
- walkNode(resolved.doc, resolved.def, path$2, optional, prop, flatMap, stack, options);
5552
+ walkNode(resolved.doc, resolved.def, path, optional, prop, flatMap, stack, options);
5503
5553
  }
5504
5554
  }
5505
- function walkNode(doc, def, path$2, optional, propNode, flatMap, stack, options) {
5555
+ function walkNode(doc, def, path, optional, propNode, flatMap, stack, options) {
5506
5556
  if (stack.has(def)) {
5507
- addToFlatMap(flatMap, path$2, {
5557
+ addToFlatMap(flatMap, path, {
5508
5558
  def,
5509
5559
  doc,
5510
5560
  optional,
@@ -5515,69 +5565,68 @@ function walkNode(doc, def, path$2, optional, propNode, flatMap, stack, options)
5515
5565
  stack.add(def);
5516
5566
  try {
5517
5567
  if (isStructure(def)) {
5518
- addToFlatMap(flatMap, path$2, {
5568
+ addToFlatMap(flatMap, path, {
5519
5569
  def,
5520
5570
  doc,
5521
5571
  optional,
5522
5572
  propNode,
5523
5573
  intermediate: true
5524
5574
  });
5525
- walkStructure(doc, def, path$2, optional, flatMap, stack, options);
5575
+ walkStructure(doc, def, path, optional, flatMap, stack, options);
5526
5576
  } else if (isArray(def)) {
5527
5577
  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, {
5578
+ const resolvedElement = elementDef ? resolveNode(doc, elementDef) : void 0;
5579
+ if (resolvedElement && (isStructure(resolvedElement.def) || isGroup(resolvedElement.def) && resolvedElement.def.entity !== "tuple" || isArray(resolvedElement.def))) {
5580
+ addToFlatMap(flatMap, path, {
5532
5581
  def,
5533
5582
  doc,
5534
5583
  optional,
5535
5584
  propNode,
5536
5585
  intermediate: true
5537
5586
  });
5538
- walkArrayElement(doc, def, path$2, optional, flatMap, stack, options);
5539
- } else addToFlatMap(flatMap, path$2, {
5587
+ walkArrayElement(doc, def, path, optional, flatMap, stack, options);
5588
+ } else addToFlatMap(flatMap, path, {
5540
5589
  def,
5541
5590
  doc,
5542
5591
  optional,
5543
5592
  propNode
5544
5593
  });
5545
5594
  } else if (isGroup(def) && def.entity !== "structure") {
5546
- const group$1 = def;
5547
- if (group$1.op === "&") {
5595
+ const group = def;
5596
+ if (group.op === "&") {
5548
5597
  const merged = doc.mergeIntersection(def);
5549
5598
  if (merged !== def && isStructure(merged)) {
5550
- addToFlatMap(flatMap, path$2, {
5599
+ addToFlatMap(flatMap, path, {
5551
5600
  def: merged,
5552
5601
  doc,
5553
5602
  optional,
5554
5603
  propNode,
5555
5604
  intermediate: true
5556
5605
  });
5557
- walkStructure(doc, merged, path$2, optional, flatMap, stack, options);
5558
- } else addToFlatMap(flatMap, path$2, {
5606
+ walkStructure(doc, merged, path, optional, flatMap, stack, options);
5607
+ } else addToFlatMap(flatMap, path, {
5559
5608
  def,
5560
5609
  doc,
5561
5610
  optional,
5562
5611
  propNode
5563
5612
  });
5564
- } else if (group$1.op === "|") {
5565
- const branches = group$1.unwrap();
5613
+ } else if (group.op === "|") {
5614
+ const branches = group.unwrap();
5566
5615
  let hasComplexBranch = false;
5567
5616
  let hasLeafBranch = false;
5568
5617
  for (const branch of branches) {
5569
5618
  const resolved = resolveNode(doc, branch);
5570
5619
  if (resolved && isComplexNode(resolved.def)) hasComplexBranch = true;
5571
- else hasLeafBranch = true;
5620
+ else hasLeafBranch = true;
5572
5621
  }
5573
5622
  if (hasComplexBranch) {
5574
- if (hasLeafBranch) addToFlatMap(flatMap, path$2, {
5623
+ if (hasLeafBranch) addToFlatMap(flatMap, path, {
5575
5624
  def,
5576
5625
  doc,
5577
5626
  optional,
5578
5627
  propNode
5579
5628
  });
5580
- else addToFlatMap(flatMap, path$2, {
5629
+ else addToFlatMap(flatMap, path, {
5581
5630
  def,
5582
5631
  doc,
5583
5632
  optional,
@@ -5586,21 +5635,21 @@ else addToFlatMap(flatMap, path$2, {
5586
5635
  });
5587
5636
  for (const branch of branches) {
5588
5637
  const resolved = resolveNode(doc, branch);
5589
- if (resolved) walkBranch(resolved.doc, resolved.def, path$2, optional, flatMap, stack, options);
5638
+ if (resolved) walkBranch(resolved.doc, resolved.def, path, optional, flatMap, stack, options);
5590
5639
  }
5591
- } else addToFlatMap(flatMap, path$2, {
5640
+ } else addToFlatMap(flatMap, path, {
5592
5641
  def,
5593
5642
  doc,
5594
5643
  optional,
5595
5644
  propNode
5596
5645
  });
5597
- } else addToFlatMap(flatMap, path$2, {
5646
+ } else addToFlatMap(flatMap, path, {
5598
5647
  def,
5599
5648
  doc,
5600
5649
  optional,
5601
5650
  propNode
5602
5651
  });
5603
- } else addToFlatMap(flatMap, path$2, {
5652
+ } else addToFlatMap(flatMap, path, {
5604
5653
  def,
5605
5654
  doc,
5606
5655
  optional,
@@ -5622,13 +5671,13 @@ function walkArrayElement(doc, arrayNode, prefix, parentOptional, flatMap, stack
5622
5671
  * Does NOT add an entry for the branch itself — the parent already did that.
5623
5672
  */ function walkBranch(doc, def, prefix, parentOptional, flatMap, stack, options) {
5624
5673
  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 === "&") {
5674
+ else if (isArray(def)) walkArrayElement(doc, def, prefix, parentOptional, flatMap, stack, options);
5675
+ else if (isGroup(def) && def.entity !== "structure") {
5676
+ const group = def;
5677
+ if (group.op === "&") {
5629
5678
  const merged = doc.mergeIntersection(def);
5630
5679
  if (isStructure(merged)) walkStructure(doc, merged, prefix, parentOptional, flatMap, stack, options);
5631
- } else if (group$1.op === "|") for (const branch of group$1.unwrap()) {
5680
+ } else if (group.op === "|") for (const branch of group.unwrap()) {
5632
5681
  const resolved = resolveNode(doc, branch);
5633
5682
  if (resolved) walkBranch(resolved.doc, resolved.def, prefix, parentOptional, flatMap, stack, options);
5634
5683
  }