@atscript/core 0.1.88 → 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 +728 -672
  2. package/dist/index.mjs +631 -582
  3. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";
2
- //#region rolldown:runtime
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ //#region \0rolldown/runtime.js
3
3
  var __create = Object.create;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -7,12 +7,16 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
- key = keys[i];
12
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
- get: ((k) => from[k]).bind(null, key),
14
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
- });
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) {
14
+ __defProp(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ }
16
20
  }
17
21
  return to;
18
22
  };
@@ -22,17 +26,20 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
26
  }) : target, mod));
23
27
 
24
28
  //#endregion
25
- const node_fs = __toESM(require("node:fs"));
26
- const node_fs_promises = __toESM(require("node:fs/promises"));
27
- const node_path = __toESM(require("node:path"));
28
- const node_url = __toESM(require("node:url"));
29
- const rolldown = __toESM(require("rolldown"));
30
- const path = __toESM(require("path"));
31
- const url = __toESM(require("url"));
32
- const __prostojs_parser = __toESM(require("@prostojs/parser"));
33
- const defu = __toESM(require("defu"));
34
- const fs_promises = __toESM(require("fs/promises"));
35
- const glob = __toESM(require("glob"));
29
+ let node_fs = require("node:fs");
30
+ node_fs = __toESM(node_fs);
31
+ let node_fs_promises = require("node:fs/promises");
32
+ let node_path = require("node:path");
33
+ node_path = __toESM(node_path);
34
+ let node_url = require("node:url");
35
+ let rolldown = require("rolldown");
36
+ let path = require("path");
37
+ path = __toESM(path);
38
+ let url = require("url");
39
+ let _prostojs_parser = require("@prostojs/parser");
40
+ let defu = require("defu");
41
+ let fs_promises = require("fs/promises");
42
+ let glob = require("glob");
36
43
 
37
44
  //#region packages/core/src/parser/nodes/semantic-node.ts
38
45
  function _define_property$16(obj, key, value) {
@@ -42,7 +49,7 @@ function _define_property$16(obj, key, value) {
42
49
  configurable: true,
43
50
  writable: true
44
51
  });
45
- else obj[key] = value;
52
+ else obj[key] = value;
46
53
  return obj;
47
54
  }
48
55
  var SemanticNode = class {
@@ -77,9 +84,9 @@ var SemanticNode = class {
77
84
  }
78
85
  annotate(name, token) {
79
86
  if (!this.annotations) this.annotations = [];
80
- if (!this.annotationsCounter) this.annotationsCounter = new Map();
87
+ if (!this.annotationsCounter) this.annotationsCounter = /* @__PURE__ */ new Map();
81
88
  if (this.annotationsCounter.has(name)) this.annotationsCounter.set(name, this.annotationsCounter.get(name) + 1);
82
- else this.annotationsCounter.set(name, 1);
89
+ else this.annotationsCounter.set(name, 1);
83
90
  token.parentNode = this;
84
91
  const a = {
85
92
  name,
@@ -109,7 +116,7 @@ else this.annotationsCounter.set(name, 1);
109
116
  return this.token("identifier")?.text;
110
117
  }
111
118
  saveToken(token, semantic) {
112
- if (!this.tokens) this.tokens = new Map();
119
+ if (!this.tokens) this.tokens = /* @__PURE__ */ new Map();
113
120
  token.parentNode = this;
114
121
  this.tokens.set(semantic, token);
115
122
  return this;
@@ -192,12 +199,12 @@ var SemanticAnnotateNode = class extends SemanticNode {
192
199
  doc.registerExport(this);
193
200
  }
194
201
  } else if (this.token("export")) doc.registerMessage(this.token("export"), "Cannot export mutating ad-hoc annotations block");
195
- const block$2 = this.token("inner");
196
- if (block$2) {
197
- block$2.blockType = "annotate";
198
- doc.blocksIndex.add(block$2);
202
+ const block = this.token("inner");
203
+ if (block) {
204
+ block.blockType = "annotate";
205
+ doc.blocksIndex.add(block);
199
206
  }
200
- const seenEntries = new Set();
207
+ const seenEntries = /* @__PURE__ */ new Set();
201
208
  for (const entry of this.entries) {
202
209
  const entryPath = entry.hasChain ? `${entry.id}.${entry.chain.map((c) => c.text).join(".")}` : entry.id;
203
210
  if (seenEntries.has(entryPath)) {
@@ -229,8 +236,8 @@ var SemanticAnnotateNode = class extends SemanticNode {
229
236
  //#region packages/core/src/parser/nodes/array-node.ts
230
237
  var SemanticArrayNode = class extends SemanticNode {
231
238
  get props() {
232
- if (this.definition) return isStructure(this.definition) ? this.definition.props : new Map();
233
- return new Map();
239
+ if (this.definition) return isStructure(this.definition) ? this.definition.props : /* @__PURE__ */ new Map();
240
+ return /* @__PURE__ */ new Map();
234
241
  }
235
242
  constructor() {
236
243
  super("array");
@@ -258,7 +265,7 @@ function _define_property$15(obj, key, value) {
258
265
  configurable: true,
259
266
  writable: true
260
267
  });
261
- else obj[key] = value;
268
+ else obj[key] = value;
262
269
  return obj;
263
270
  }
264
271
  var SemanticGroup = class extends SemanticNode {
@@ -325,7 +332,7 @@ function _define_property$14(obj, key, value) {
325
332
  configurable: true,
326
333
  writable: true
327
334
  });
328
- else obj[key] = value;
335
+ else obj[key] = value;
329
336
  return obj;
330
337
  }
331
338
  var SemanticInterfaceNode = class extends SemanticNode {
@@ -354,8 +361,8 @@ var SemanticInterfaceNode = class extends SemanticNode {
354
361
  }
355
362
  }
356
363
  get props() {
357
- if (this.definition) return isStructure(this.definition) ? this.definition.props : new Map();
358
- return new Map();
364
+ if (this.definition) return isStructure(this.definition) ? this.definition.props : /* @__PURE__ */ new Map();
365
+ return /* @__PURE__ */ new Map();
359
366
  }
360
367
  toString(level = 0, prefix = "●") {
361
368
  let s = super.toString(level, prefix);
@@ -379,7 +386,7 @@ function _define_property$13(obj, key, value) {
379
386
  configurable: true,
380
387
  writable: true
381
388
  });
382
- else obj[key] = value;
389
+ else obj[key] = value;
383
390
  return obj;
384
391
  }
385
392
  var Token = class Token {
@@ -388,11 +395,10 @@ var Token = class Token {
388
395
  return `[${this.type}] "${this.text}"${children}`;
389
396
  }
390
397
  clone(replace) {
391
- const t = {
398
+ return new Token({
392
399
  ...this._data,
393
400
  ...replace
394
- };
395
- return new Token(t);
401
+ });
396
402
  }
397
403
  get text() {
398
404
  return this._data.text || "";
@@ -464,18 +470,18 @@ function _define_property$12(obj, key, value) {
464
470
  configurable: true,
465
471
  writable: true
466
472
  });
467
- else obj[key] = value;
473
+ else obj[key] = value;
468
474
  return obj;
469
475
  }
470
476
  var SemanticPrimitiveNode = class SemanticPrimitiveNode extends SemanticNode {
471
477
  applyAnnotations() {
472
478
  this.annotations = [];
473
479
  for (const [name, value] of Object.entries(this.config.annotations || {})) {
474
- const spec = this.annotationTree ? resolveAnnotation(name, this.annotationTree) : undefined;
480
+ const spec = this.annotationTree ? resolveAnnotation(name, this.annotationTree) : void 0;
475
481
  const isMultiple = spec?.config.multiple ?? false;
476
482
  if (Array.isArray(value)) {
477
483
  if (isMultiple) for (const item of value) this.annotations.push(toAnnotationTokens(name, item, spec));
478
- else if (value.length > 0) this.annotations.push(toAnnotationTokens(name, value[0], spec));
484
+ else if (value.length > 0) this.annotations.push(toAnnotationTokens(name, value[0], spec));
479
485
  } else this.annotations.push(toAnnotationTokens(name, value, spec));
480
486
  }
481
487
  }
@@ -484,7 +490,7 @@ else if (value.length > 0) this.annotations.push(toAnnotationTokens(name, value[
484
490
  }
485
491
  getAllTags(_processed) {
486
492
  const allTags = [this._id];
487
- const processed = _processed || new Set();
493
+ const processed = _processed || /* @__PURE__ */ new Set();
488
494
  processed.add(this);
489
495
  for (const [, node] of this.props) {
490
496
  if (processed.has(node)) continue;
@@ -507,7 +513,7 @@ else if (value.length > 0) this.annotations.push(toAnnotationTokens(name, value[
507
513
  }
508
514
  constructor(_id, config, parentKey = "", annotationTree) {
509
515
  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;
510
- this.props = new Map();
516
+ this.props = /* @__PURE__ */ new Map();
511
517
  this.tags = new Set([_id, ...config?.tags || []]);
512
518
  for (const [ext, def] of Object.entries(config.extensions || {})) {
513
519
  const node = new SemanticPrimitiveNode(ext, {
@@ -523,7 +529,7 @@ else if (value.length > 0) this.annotations.push(toAnnotationTokens(name, value[
523
529
  this.props.set(ext, node);
524
530
  }
525
531
  if (typeof config.type === "object") this.type = config.type.kind === "final" ? config.type.value : config.type.kind;
526
- else this.type = config.type;
532
+ else this.type = config.type;
527
533
  this.applyAnnotations();
528
534
  }
529
535
  };
@@ -543,18 +549,16 @@ function toAnnotationTokens(name, value, spec) {
543
549
  token: dummyToken,
544
550
  args: [num(value)]
545
551
  };
546
- const argNames = spec?.arguments.map((a) => a.name) ?? Object.keys(value);
547
- const raw = argNames.map((argName) => {
552
+ const raw = (spec?.arguments.map((a) => a.name) ?? Object.keys(value)).map((argName) => {
548
553
  const v = value[argName];
549
- if (v === undefined) return undefined;
554
+ if (v === void 0) return;
550
555
  return typeof v === "number" ? num(v) : text$1(String(v));
551
556
  });
552
- while (raw.length > 0 && raw[raw.length - 1] === undefined) raw.pop();
553
- const args = raw.map((t) => t ?? text$1(""));
557
+ while (raw.length > 0 && raw[raw.length - 1] === void 0) raw.pop();
554
558
  return {
555
559
  name,
556
560
  token: dummyToken,
557
- args
561
+ args: raw.map((t) => t ?? text$1(""))
558
562
  };
559
563
  }
560
564
  const dummyToken = new Token({
@@ -634,7 +638,7 @@ function _define_property$11(obj, key, value) {
634
638
  configurable: true,
635
639
  writable: true
636
640
  });
637
- else obj[key] = value;
641
+ else obj[key] = value;
638
642
  return obj;
639
643
  }
640
644
  var SemanticRefNode = class extends SemanticNode {
@@ -692,27 +696,27 @@ function _define_property$10(obj, key, value) {
692
696
  configurable: true,
693
697
  writable: true
694
698
  });
695
- else obj[key] = value;
699
+ else obj[key] = value;
696
700
  return obj;
697
701
  }
698
702
  var SemanticStructureNode = class extends SemanticGroup {
699
703
  /**
700
704
  * Shortcut to set props, used as utility
701
- */ setProps(props$1) {
702
- this.nodes = props$1;
703
- for (const prop of props$1) {
705
+ */ setProps(props) {
706
+ this.nodes = props;
707
+ for (const prop of props) {
704
708
  prop.ownerNode = this;
705
709
  this.props.set(prop.id, prop);
706
710
  }
707
711
  }
708
712
  registerAtDocument(doc) {
709
- const block$2 = this.token("identifier");
710
- block$2.blockType = "structure";
711
- doc.blocksIndex.add(block$2);
713
+ const block = this.token("identifier");
714
+ block.blockType = "structure";
715
+ doc.blocksIndex.add(block);
712
716
  for (const node of this.nodes) {
713
717
  const token = node.token("identifier");
714
718
  if (!token) {
715
- doc.registerMessage(block$2, "Has empty prop node");
719
+ doc.registerMessage(block, "Has empty prop node");
716
720
  continue;
717
721
  }
718
722
  const name = token.text;
@@ -743,28 +747,28 @@ var SemanticStructureNode = class extends SemanticGroup {
743
747
  if (opts.documentation) prop.setDocumentation(opts.documentation);
744
748
  prop.saveToken(propToken, "identifier");
745
749
  if (typeof opts.type === "string") {
746
- const ref$1 = new SemanticRefNode();
750
+ const ref = new SemanticRefNode();
747
751
  const [first, ...rest] = opts.type.split(".");
748
752
  const refToken = token.clone({
749
753
  type: "identifier",
750
754
  text: first
751
755
  });
752
- ref$1.saveToken(refToken, "identifier");
756
+ ref.saveToken(refToken, "identifier");
753
757
  for (const chain of rest) {
754
758
  const chainToken = token.clone({
755
759
  type: "identifier",
756
760
  text: chain
757
761
  });
758
- ref$1.addChain(chainToken);
762
+ ref.addChain(chainToken);
759
763
  }
760
- prop.define(ref$1);
764
+ prop.define(ref);
761
765
  } else prop.define(opts.type);
762
766
  prop.ownerNode = this;
763
767
  this.nodes.push(prop);
764
768
  this.props.set(opts.name, prop);
765
769
  }
766
770
  constructor() {
767
- super(), _define_property$10(this, "props", new Map());
771
+ super(), _define_property$10(this, "props", /* @__PURE__ */ new Map());
768
772
  this.entity = "structure";
769
773
  }
770
774
  };
@@ -806,7 +810,7 @@ function _define_property$9(obj, key, value) {
806
810
  configurable: true,
807
811
  writable: true
808
812
  });
809
- else obj[key] = value;
813
+ else obj[key] = value;
810
814
  return obj;
811
815
  }
812
816
  var SemanticQueryNode = class extends SemanticNode {
@@ -928,13 +932,13 @@ function isAnnotate(node) {
928
932
  return node?.entity === "annotate";
929
933
  }
930
934
  function isQueryLogical(node) {
931
- return node?.operands !== undefined;
935
+ return node?.operands !== void 0;
932
936
  }
933
937
  function isQueryComparison(node) {
934
- return node?.left !== undefined;
938
+ return node?.left !== void 0;
935
939
  }
936
940
  function isQueryFieldRef(node) {
937
- return node?.fieldRef !== undefined;
941
+ return node?.fieldRef !== void 0;
938
942
  }
939
943
 
940
944
  //#endregion
@@ -946,7 +950,7 @@ function _define_property$8(obj, key, value) {
946
950
  configurable: true,
947
951
  writable: true
948
952
  });
949
- else obj[key] = value;
953
+ else obj[key] = value;
950
954
  return obj;
951
955
  }
952
956
  var AnnotationSpec = class {
@@ -963,14 +967,14 @@ var AnnotationSpec = class {
963
967
  return `${quote}\${${placeholderIndex}:${defaultValue}}${quote}`;
964
968
  }).join(", ");
965
969
  }
966
- validateType(tokenType, type$1) {
967
- switch (type$1) {
968
- case "string": return tokenType === "text" ? undefined : "string expected.";
969
- case "number": return tokenType === "number" ? undefined : "number expected.";
970
- case "boolean": return tokenType === "identifier" ? undefined : "boolean expected.";
971
- case "ref": return tokenType === "identifier" ? undefined : "type reference expected.";
972
- case "query": return tokenType === "query" ? undefined : "query expression expected (use backticks).";
973
- default: return `unknown type "${type$1}".`;
970
+ validateType(tokenType, type) {
971
+ switch (type) {
972
+ case "string": return tokenType === "text" ? void 0 : "string expected.";
973
+ case "number": return tokenType === "number" ? void 0 : "number expected.";
974
+ case "boolean": return tokenType === "identifier" ? void 0 : "boolean expected.";
975
+ case "ref": return tokenType === "identifier" ? void 0 : "type reference expected.";
976
+ case "query": return tokenType === "query" ? void 0 : "query expression expected (use backticks).";
977
+ default: return `unknown type "${type}".`;
974
978
  }
975
979
  }
976
980
  modify(mainToken, args, doc) {
@@ -1030,7 +1034,7 @@ var AnnotationSpec = class {
1030
1034
  range: token.range
1031
1035
  });
1032
1036
  }
1033
- return messages.length > 0 ? messages : undefined;
1037
+ return messages.length > 0 ? messages : void 0;
1034
1038
  }
1035
1039
  /**
1036
1040
  * Cross-file-dependent validation, deferred to diagnostic time
@@ -1043,20 +1047,19 @@ var AnnotationSpec = class {
1043
1047
  * diagnostics. Annotate-block entries' `defType` guard is handled separately
1044
1048
  * by `getDiagMessages` (the `referred` loop) and is skipped here.
1045
1049
  */ validateDeferred(mainToken, args, doc) {
1046
- if (!mainToken.parentNode) return undefined;
1050
+ if (!mainToken.parentNode) return;
1047
1051
  const messages = [];
1048
1052
  if (this.config.defType?.length) {
1049
1053
  const parentNode = mainToken.parentNode;
1050
- const idToken = isRef(parentNode) ? parentNode.token("identifier") : undefined;
1051
- const isAnnotateEntry = !!idToken && !!doc.annotateBlockAt(idToken.range.start.line, idToken.range.start.character);
1052
- if (!isAnnotateEntry) {
1054
+ const idToken = isRef(parentNode) ? parentNode.token("identifier") : void 0;
1055
+ if (!(!!idToken && !!doc.annotateBlockAt(idToken.range.start.line, idToken.range.start.character))) {
1053
1056
  let def = parentNode.getDefinition();
1054
1057
  if (isRef(def)) def = doc.unwindType(def.id, def.chain)?.def || def;
1055
1058
  messages.push(...this.validateTargetType(def, mainToken.range) || []);
1056
1059
  }
1057
1060
  }
1058
1061
  if (this.config.validate) messages.push(...this.config.validate(mainToken, args, doc) || []);
1059
- return messages.length > 0 ? messages : undefined;
1062
+ return messages.length > 0 ? messages : void 0;
1060
1063
  }
1061
1064
  /**
1062
1065
  * Checks an already-resolved target node against this annotation's `defType`
@@ -1066,16 +1069,15 @@ var AnnotationSpec = class {
1066
1069
  * the deferred annotate-entry check in `AtscriptDoc.getDiagMessages`, where
1067
1070
  * imported target types finally resolve.
1068
1071
  */ validateTargetType(def, range) {
1069
- if (!this.config.defType?.length) return undefined;
1072
+ if (!this.config.defType?.length) return;
1070
1073
  let defEntity = def?.entity || "unknown";
1071
1074
  if (isInterface(def) || isStructure(def)) defEntity = "object";
1072
- else if (isGroup(def) && def.entity !== "tuple") defEntity = def.op === "&" ? "intersection" : "union";
1075
+ else if (isGroup(def) && def.entity !== "tuple") defEntity = def.op === "&" ? "intersection" : "union";
1073
1076
  if (!isPrimitive(def) && !this.config.defType.includes(defEntity) || isPrimitive(def) && !this.config.defType.includes(def.type)) return [{
1074
1077
  message: `Expected type is (${this.config.defType.join(" | ")}), got "${isPrimitive(def) ? def.type : def?.entity || "unknown"}"`,
1075
1078
  severity: 1,
1076
1079
  range
1077
1080
  }];
1078
- return undefined;
1079
1081
  }
1080
1082
  renderDocs(index) {
1081
1083
  if (typeof index === "number") {
@@ -1084,13 +1086,10 @@ else if (isGroup(def) && def.entity !== "tuple") defEntity = def.op === "&" ? "i
1084
1086
  const values = a.values ? `\n\nValues:\n${a.values.join(", ")}` : "";
1085
1087
  return `### \`${a.name}${a.optional ? "?" : ""}: ${a.type}\`\n\n${a.description}${values}`;
1086
1088
  }
1087
- } else {
1088
- const args = this.arguments;
1089
- return `### ${index} ${args.map((a) => `\`${a.name}${a.optional ? "?" : ""}: ${a.type}\``).join(", ")}\n\n${this.config.description}`;
1090
- }
1089
+ } else return `### ${index} ${this.arguments.map((a) => `\`${a.name}${a.optional ? "?" : ""}: ${a.type}\``).join(", ")}\n\n${this.config.description}`;
1091
1090
  }
1092
- getDefaultValueForType(name, type$1) {
1093
- switch (type$1) {
1091
+ getDefaultValueForType(name, type) {
1092
+ switch (type) {
1094
1093
  case "string": return name;
1095
1094
  case "number": return "0";
1096
1095
  case "boolean": return "true";
@@ -1113,37 +1112,50 @@ function resolveAnnotation(name, annotationsTree) {
1113
1112
  const parts = name.split(".");
1114
1113
  let current = annotationsTree;
1115
1114
  for (const part of parts) {
1116
- if (part === "$self") return undefined;
1117
- if (!current || isAnnotationSpec(current)) return undefined;
1115
+ if (part === "$self") return;
1116
+ if (!current || isAnnotationSpec(current)) return;
1118
1117
  current = current[part];
1119
1118
  }
1120
1119
  if (isAnnotationSpec(current)) return current;
1121
1120
  if (current && !isAnnotationSpec(current) && current.$self) return current.$self;
1122
- return undefined;
1123
1121
  }
1124
1122
 
1125
1123
  //#endregion
1126
1124
  //#region packages/core/src/config/define-config.ts
1127
- function defineConfig(config) {
1125
+ /**
1126
+ * Defines the configuration for the Intertation parser
1127
+ */ function defineConfig(config) {
1128
1128
  return config;
1129
1129
  }
1130
1130
 
1131
1131
  //#endregion
1132
1132
  //#region packages/core/src/resolve-bare.ts
1133
- function isBareSpecifier(specifier) {
1133
+ /**
1134
+ * Returns true if the specifier is a bare specifier (not relative or absolute).
1135
+ * Bare specifiers: 'my-lib/user', '@org/pkg/models'
1136
+ * NOT bare: './user', '../shared', '/absolute/path'
1137
+ */ function isBareSpecifier(specifier) {
1134
1138
  return specifier[0] !== "." && specifier[0] !== "/";
1135
1139
  }
1136
- function isBareId(id) {
1140
+ /**
1141
+ * Returns true if the document ID is a bare specifier placeholder.
1142
+ */ function isBareId(id) {
1137
1143
  return id.startsWith("bare:");
1138
1144
  }
1139
- function parseBareSpecifier(specifier) {
1145
+ /**
1146
+ * Parse a bare specifier into package name and subpath.
1147
+ *
1148
+ * '@scope/pkg/sub/path' → { packageName: '@scope/pkg', subpath: './sub/path' }
1149
+ * 'pkg/sub' → { packageName: 'pkg', subpath: './sub' }
1150
+ * 'pkg' → { packageName: 'pkg', subpath: '.' }
1151
+ */ function parseBareSpecifier(specifier) {
1140
1152
  if (specifier.startsWith("@")) {
1141
- const firstSlash$1 = specifier.indexOf("/");
1142
- if (firstSlash$1 === -1) return {
1153
+ const firstSlash = specifier.indexOf("/");
1154
+ if (firstSlash === -1) return {
1143
1155
  packageName: specifier,
1144
1156
  subpath: "."
1145
1157
  };
1146
- const secondSlash = specifier.indexOf("/", firstSlash$1 + 1);
1158
+ const secondSlash = specifier.indexOf("/", firstSlash + 1);
1147
1159
  if (secondSlash === -1) return {
1148
1160
  packageName: specifier,
1149
1161
  subpath: "."
@@ -1163,21 +1175,23 @@ function parseBareSpecifier(specifier) {
1163
1175
  subpath: `./${specifier.slice(firstSlash + 1)}`
1164
1176
  };
1165
1177
  }
1166
- function resolvePackageExports(exports$1, subpath) {
1167
- if (!exports$1 || typeof exports$1 !== "object") return undefined;
1168
- const exportsMap = exports$1;
1178
+ /**
1179
+ * Resolve a subpath against a package.json `exports` field using the `atscript` condition.
1180
+ * Returns the resolved file path relative to the package directory, or undefined.
1181
+ */ function resolvePackageExports(exports, subpath) {
1182
+ if (!exports || typeof exports !== "object") return;
1183
+ const exportsMap = exports;
1169
1184
  const subpathWithExt = subpath === "." ? "." : `${subpath}.as`;
1170
1185
  const entry = exportsMap[subpathWithExt];
1171
1186
  if (entry) return resolveExportEntry(entry);
1172
1187
  for (const [pattern, value] of Object.entries(exportsMap)) {
1173
1188
  if (!pattern.includes("*")) continue;
1174
1189
  const match = matchSubpathPattern(pattern, subpathWithExt);
1175
- if (match !== undefined) {
1190
+ if (match !== void 0) {
1176
1191
  const resolved = resolveExportEntry(value);
1177
1192
  if (resolved) return resolved.replaceAll("*", match);
1178
1193
  }
1179
1194
  }
1180
- return undefined;
1181
1195
  }
1182
1196
  /**
1183
1197
  * Resolve a single export entry, checking for `atscript` condition.
@@ -1188,18 +1202,16 @@ function resolvePackageExports(exports$1, subpath) {
1188
1202
  if (typeof obj["atscript"] === "string") return obj["atscript"];
1189
1203
  if (typeof obj["default"] === "string") return obj["default"];
1190
1204
  }
1191
- return undefined;
1192
1205
  }
1193
1206
  /**
1194
1207
  * Match a subpath against a pattern with a single `*` wildcard.
1195
1208
  * Returns the matched wildcard portion, or undefined if no match.
1196
1209
  */ function matchSubpathPattern(pattern, subpath) {
1197
1210
  const starIdx = pattern.indexOf("*");
1198
- if (starIdx === -1) return undefined;
1211
+ if (starIdx === -1) return;
1199
1212
  const prefix = pattern.slice(0, starIdx);
1200
1213
  const suffix = pattern.slice(starIdx + 1);
1201
1214
  if (subpath.startsWith(prefix) && subpath.endsWith(suffix) && subpath.length >= prefix.length + suffix.length) return subpath.slice(prefix.length, subpath.length - suffix.length);
1202
- return undefined;
1203
1215
  }
1204
1216
  /**
1205
1217
  * Check if a file exists.
@@ -1211,11 +1223,27 @@ function resolvePackageExports(exports$1, subpath) {
1211
1223
  return false;
1212
1224
  }
1213
1225
  }
1214
- const resolveCache = new Map();
1215
- function clearResolveBareCache() {
1226
+ const resolveCache = /* @__PURE__ */ new Map();
1227
+ /**
1228
+ * Clear the bare specifier resolution cache.
1229
+ * Call this when node_modules may have changed (e.g., after install).
1230
+ */ function clearResolveBareCache() {
1216
1231
  resolveCache.clear();
1217
1232
  }
1218
- async function resolveBareSpecifier(specifier, fromDir) {
1233
+ /**
1234
+ * Resolve a bare specifier to an absolute file path.
1235
+ *
1236
+ * Algorithm:
1237
+ * 1. Parse specifier into packageName + subpath
1238
+ * 2. Walk up from `fromDir` looking for `node_modules/<packageName>/package.json`
1239
+ * 3. Check `exports` field for subpath with `atscript` condition
1240
+ * 4. Fallback: check if file exists at `node_modules/<pkg>/<subpath>.as`
1241
+ * 5. Resolve symlinks via `fs.realpath`
1242
+ *
1243
+ * @param specifier Bare specifier, e.g. 'my-lib/user' or '@org/pkg/models'
1244
+ * @param fromDir Absolute directory of the importing file
1245
+ * @returns Resolved absolute file path, or undefined if not found
1246
+ */ async function resolveBareSpecifier(specifier, fromDir) {
1219
1247
  const cacheKey = `${fromDir}\0${specifier}`;
1220
1248
  if (resolveCache.has(cacheKey)) return resolveCache.get(cacheKey);
1221
1249
  const result = await _resolveBareSpecifier(specifier, fromDir);
@@ -1225,7 +1253,7 @@ async function resolveBareSpecifier(specifier, fromDir) {
1225
1253
  async function _resolveBareSpecifier(specifier, fromDir) {
1226
1254
  const { packageName, subpath } = parseBareSpecifier(specifier);
1227
1255
  let dir = fromDir;
1228
- const root$1 = node_path.default.parse(dir).root;
1256
+ const root = node_path.default.parse(dir).root;
1229
1257
  while (true) {
1230
1258
  const pkgDir = node_path.default.join(dir, "node_modules", packageName);
1231
1259
  const pkgJsonPath = node_path.default.join(pkgDir, "package.json");
@@ -1244,10 +1272,9 @@ async function _resolveBareSpecifier(specifier, fromDir) {
1244
1272
  if (await fileExists(directPath)) return resolveRealPath(directPath);
1245
1273
  }
1246
1274
  const parentDir = node_path.default.dirname(dir);
1247
- if (parentDir === dir || dir === root$1) break;
1275
+ if (parentDir === dir || dir === root) break;
1248
1276
  dir = parentDir;
1249
1277
  }
1250
- return undefined;
1251
1278
  }
1252
1279
  /**
1253
1280
  * Resolve symlinks to get the canonical path (important for pnpm).
@@ -1279,8 +1306,7 @@ function getRelPath(fromUri, toUri) {
1279
1306
  const toPath = new url.URL(toUri).pathname;
1280
1307
  const relPath = path.default.relative(path.default.dirname(fromPath), toPath);
1281
1308
  const { dir, name } = path.default.parse(relPath);
1282
- const prefix = dir.startsWith("..") ? "" : "./";
1283
- return `${prefix}${dir ? `${dir}/` : ""}${name}`;
1309
+ return `${dir.startsWith("..") ? "" : "./"}${dir ? `${dir}/` : ""}${name}`;
1284
1310
  }
1285
1311
 
1286
1312
  //#endregion
@@ -1308,9 +1334,8 @@ async function bundleTsConfig(configFile, forceFormat) {
1308
1334
  transform: {
1309
1335
  filter: { id: /\.[cm]?[jt]s$/u },
1310
1336
  handler(code, id) {
1311
- const injectValues = `const ${dirnameVarName} = ${JSON.stringify(node_path.default.dirname(id))};` + `const ${filenameVarName} = ${JSON.stringify(id)};` + `const ${importMetaUrlVarName} = ${JSON.stringify((0, node_url.pathToFileURL)(id).href)};`;
1312
1337
  return {
1313
- code: injectValues + code,
1338
+ code: `const ${dirnameVarName} = ${JSON.stringify(node_path.default.dirname(id))};const ${filenameVarName} = ${JSON.stringify(id)};const ${importMetaUrlVarName} = ${JSON.stringify((0, node_url.pathToFileURL)(id).href)};` + code,
1314
1339
  map: null
1315
1340
  };
1316
1341
  }
@@ -1318,13 +1343,12 @@ async function bundleTsConfig(configFile, forceFormat) {
1318
1343
  }]
1319
1344
  });
1320
1345
  const outputDir = node_path.default.dirname(configFile);
1321
- const result = await bundle.write({
1346
+ const fileName = (await bundle.write({
1322
1347
  dir: outputDir,
1323
1348
  format: forceFormat || "esm",
1324
1349
  sourcemap: "inline",
1325
1350
  entryFileNames: forceFormat === "cjs" ? "atscript.config.[hash].cjs" : "atscript.config.[hash].mjs"
1326
- });
1327
- const fileName = result.output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
1351
+ })).output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
1328
1352
  return node_path.default.join(outputDir, fileName);
1329
1353
  }
1330
1354
  const SUPPORTED_JS_CONFIG_FORMATS = [
@@ -1339,11 +1363,13 @@ const SUPPORTED_TS_CONFIG_FORMATS = [
1339
1363
  ];
1340
1364
  const SUPPORTED_CONFIG_FORMATS = [...SUPPORTED_JS_CONFIG_FORMATS, ...SUPPORTED_TS_CONFIG_FORMATS];
1341
1365
  const DEFAULT_CONFIG_BASE = "atscript.config";
1342
- async function resolveConfigFile(docUri, _root) {
1366
+ /**
1367
+ * Resolves nearest config file
1368
+ */ async function resolveConfigFile(docUri, _root) {
1343
1369
  const startDir = docUri.endsWith(".as") ? node_path.default.dirname(docUri) : docUri;
1344
- const root$1 = _root || startDir;
1370
+ const root = _root || startDir;
1345
1371
  let currentDir = startDir;
1346
- const rootId = `file://${root$1}`;
1372
+ const rootId = `file://${root}`;
1347
1373
  while (true) {
1348
1374
  const candidate = await findConfigFileName(currentDir);
1349
1375
  if (candidate) return node_path.default.join(currentDir, candidate).replace(/^file:/, "");
@@ -1351,7 +1377,6 @@ async function resolveConfigFile(docUri, _root) {
1351
1377
  if (currentDir === rootId || parentDir === currentDir) break;
1352
1378
  currentDir = parentDir;
1353
1379
  }
1354
- return undefined;
1355
1380
  }
1356
1381
  async function findConfigFileName(d) {
1357
1382
  const filesInWorkingDirectory = new Set(await (0, node_fs_promises.readdir)(fileUriToPath(d)));
@@ -1383,10 +1408,8 @@ async function loadConfig(configPath, forceFormat) {
1383
1408
  /* @vite-ignore */
1384
1409
  (0, node_url.pathToFileURL)(configPath).href
1385
1410
  )).default;
1386
- else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) {
1387
- const rawConfigPath = node_path.default.resolve(configPath);
1388
- return await loadTsConfig(rawConfigPath, forceFormat);
1389
- } else throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${ext}\``);
1411
+ else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) return await loadTsConfig(node_path.default.resolve(configPath), forceFormat);
1412
+ else throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${ext}\``);
1390
1413
  } catch (error) {
1391
1414
  console.error(error);
1392
1415
  throw new Error("Error happened while loading config.");
@@ -1395,21 +1418,22 @@ else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) {
1395
1418
 
1396
1419
  //#endregion
1397
1420
  //#region packages/core/src/defaults/db-query-lsp.ts
1398
- function getQueryScope(queryArgToken, doc) {
1421
+ /**
1422
+ * Determine the allowed type scope for a query arg token
1423
+ * by reading sibling annotations on the owner node.
1424
+ */ function getQueryScope(queryArgToken, doc) {
1399
1425
  const annotationRef = queryArgToken.annotationRef;
1400
- if (!annotationRef) return undefined;
1426
+ if (!annotationRef) return;
1401
1427
  const owner = queryArgToken.parentNode;
1402
- if (!owner) return undefined;
1428
+ if (!owner) return;
1403
1429
  const annotationName = annotationRef.text.slice(1);
1404
1430
  if (annotationName === "db.view.filter") return getViewFilterScope(owner);
1405
1431
  if (annotationName === "db.view.joins") return getViewJoinsScope(owner, queryArgToken);
1406
1432
  if (annotationName === "db.rel.filter") return getRelFilterScope(owner);
1407
- return undefined;
1408
1433
  }
1409
1434
  function getViewFilterScope(owner) {
1410
- const forAnnotations = owner.annotations?.filter((a) => a.name === "db.view.for");
1411
- const entryTypeName = forAnnotations?.[0]?.args[0]?.text;
1412
- if (!entryTypeName) return undefined;
1435
+ const entryTypeName = (owner.annotations?.filter((a) => a.name === "db.view.for"))?.[0]?.args[0]?.text;
1436
+ if (!entryTypeName) return;
1413
1437
  const allowedTypes = [entryTypeName];
1414
1438
  const joinsAnnotations = owner.annotations?.filter((a) => a.name === "db.view.joins");
1415
1439
  if (joinsAnnotations) {
@@ -1421,12 +1445,10 @@ function getViewFilterScope(owner) {
1421
1445
  };
1422
1446
  }
1423
1447
  function getViewJoinsScope(owner, queryArgToken) {
1424
- const forAnnotations = owner.annotations?.filter((a) => a.name === "db.view.for");
1425
- const entryTypeName = forAnnotations?.[0]?.args[0]?.text;
1426
- if (!entryTypeName) return undefined;
1427
- const joinsAnnotation = owner.annotations?.find((a) => a.name === "db.view.joins" && a.args.includes(queryArgToken));
1428
- const joinTargetName = joinsAnnotation?.args[0]?.text;
1429
- if (!joinTargetName) return undefined;
1448
+ const entryTypeName = (owner.annotations?.filter((a) => a.name === "db.view.for"))?.[0]?.args[0]?.text;
1449
+ if (!entryTypeName) return;
1450
+ const joinTargetName = (owner.annotations?.find((a) => a.name === "db.view.joins" && a.args.includes(queryArgToken)))?.args[0]?.text;
1451
+ if (!joinTargetName) return;
1430
1452
  return {
1431
1453
  allowedTypes: [joinTargetName, entryTypeName],
1432
1454
  unqualifiedTarget: entryTypeName
@@ -1435,7 +1457,7 @@ function getViewJoinsScope(owner, queryArgToken) {
1435
1457
  function getRelFilterScope(owner) {
1436
1458
  let def = owner.getDefinition();
1437
1459
  if (isArray(def)) def = def?.getDefinition();
1438
- if (!isRef(def)) return undefined;
1460
+ if (!isRef(def)) return;
1439
1461
  const targetTypeName = def.id;
1440
1462
  const allowedTypes = [targetTypeName];
1441
1463
  const viaAnnotation = owner.annotations?.find((a) => a.name === "db.rel.via");
@@ -1445,16 +1467,17 @@ function getRelFilterScope(owner) {
1445
1467
  unqualifiedTarget: targetTypeName
1446
1468
  };
1447
1469
  }
1448
- function resolveQueryFieldRef(fieldRefNode, doc, scope) {
1470
+ /**
1471
+ * Resolve a query field ref node to a property definition.
1472
+ */ function resolveQueryFieldRef(fieldRefNode, doc, scope) {
1449
1473
  const typeName = fieldRefNode.typeRef?.text ?? scope.unqualifiedTarget;
1450
- if (!typeName) return undefined;
1451
- const fieldPath = fieldRefNode.fieldRef.text;
1452
- const chain = fieldPath.split(".");
1474
+ if (!typeName) return;
1475
+ const chain = fieldRefNode.fieldRef.text.split(".");
1453
1476
  const parentChain = chain.slice(0, -1);
1454
1477
  const parentUnwound = doc.unwindType(typeName, parentChain);
1455
- if (!parentUnwound?.def) return undefined;
1478
+ if (!parentUnwound?.def) return;
1456
1479
  const unwound = doc.unwindType(typeName, chain);
1457
- if (!unwound?.node) return undefined;
1480
+ if (!unwound?.node) return;
1458
1481
  const prop = unwound.node;
1459
1482
  return {
1460
1483
  targetUri: parentUnwound.doc.id,
@@ -1462,21 +1485,25 @@ function resolveQueryFieldRef(fieldRefNode, doc, scope) {
1462
1485
  prop
1463
1486
  };
1464
1487
  }
1465
- function getFieldsForType(doc, typeName) {
1488
+ /**
1489
+ * Get fields available for a type (resolving extends/intersections).
1490
+ */ function getFieldsForType(doc, typeName) {
1466
1491
  const unwound = doc.unwindType(typeName);
1467
1492
  if (!unwound?.def) return [];
1468
1493
  let def = doc.mergeIntersection(unwound.def);
1469
1494
  if (isInterface(def)) {
1470
1495
  const resolved = doc.resolveInterfaceExtends(def);
1471
1496
  if (resolved) def = resolved;
1472
- else def = def.getDefinition() || def;
1497
+ else def = def.getDefinition() || def;
1473
1498
  }
1474
1499
  if (isStructure(def) || isInterface(def)) return Array.from(def.props.values());
1475
1500
  return [];
1476
1501
  }
1477
- function getQueryCompletionScope(queryArgToken, doc) {
1502
+ /**
1503
+ * Get completion scope data for a query context.
1504
+ */ function getQueryCompletionScope(queryArgToken, doc) {
1478
1505
  const scope = getQueryScope(queryArgToken, doc);
1479
- if (!scope) return undefined;
1506
+ if (!scope) return;
1480
1507
  return {
1481
1508
  typeNames: scope.allowedTypes,
1482
1509
  unqualifiedTarget: scope.unqualifiedTarget,
@@ -1507,7 +1534,12 @@ const VALUE_KEYWORDS$1 = new Set([
1507
1534
  "null",
1508
1535
  "undefined"
1509
1536
  ]);
1510
- function analyzeQueryCursorContext(textBeforeCursor) {
1537
+ /**
1538
+ * Analyze text inside backticks up to cursor position
1539
+ * to determine what kind of completions to offer.
1540
+ * Uses lightweight text scanning, not full AST parsing,
1541
+ * so it works on incomplete/mid-typing input.
1542
+ */ function analyzeQueryCursorContext(textBeforeCursor) {
1511
1543
  const trimmed = textBeforeCursor.trimEnd();
1512
1544
  const hasTrailingSpace = textBeforeCursor.length > trimmed.length;
1513
1545
  if (trimmed.length === 0) return { type: "field-start" };
@@ -1520,17 +1552,17 @@ function analyzeQueryCursorContext(textBeforeCursor) {
1520
1552
  };
1521
1553
  return { type: "field-start" };
1522
1554
  }
1523
- const tokens$1 = tokenizeQueryText(trimmed);
1524
- if (tokens$1.length === 0) return { type: "field-start" };
1525
- const last = tokens$1[tokens$1.length - 1];
1555
+ const tokens = tokenizeQueryText(trimmed);
1556
+ if (tokens.length === 0) return { type: "field-start" };
1557
+ const last = tokens[tokens.length - 1];
1526
1558
  if (LOGICAL_KEYWORDS.has(last) || last === "(") return { type: "field-start" };
1527
1559
  if (SYMBOLIC_OPS$1.has(last)) return { type: "after-operator" };
1528
1560
  if (last === "in" || last === "matches") return { type: "after-operator" };
1529
1561
  if (last === "exists") return { type: "after-comparison" };
1530
1562
  if (VALUE_KEYWORDS$1.has(last)) return { type: "after-comparison" };
1531
1563
  if (/^['"]/.test(last) || /^\d/.test(last)) return { type: "after-comparison" };
1532
- if (tokens$1.length >= 2) {
1533
- const prev = tokens$1[tokens$1.length - 2];
1564
+ if (tokens.length >= 2) {
1565
+ const prev = tokens[tokens.length - 2];
1534
1566
  if (SYMBOLIC_OPS$1.has(prev) || KEYWORD_OPS.has(prev)) return { type: "after-comparison" };
1535
1567
  }
1536
1568
  if (/^\w+$/u.test(last)) {
@@ -1542,53 +1574,53 @@ function analyzeQueryCursorContext(textBeforeCursor) {
1542
1574
  /**
1543
1575
  * Simple tokenizer for query text — splits into identifiers, operators, and punctuation.
1544
1576
  * Does NOT need to handle all edge cases; just enough for cursor context analysis.
1545
- */ function tokenizeQueryText(text$2) {
1546
- const tokens$1 = [];
1577
+ */ function tokenizeQueryText(text) {
1578
+ const tokens = [];
1547
1579
  let i = 0;
1548
- while (i < text$2.length) {
1549
- if (/\s/.test(text$2[i])) {
1580
+ while (i < text.length) {
1581
+ if (/\s/.test(text[i])) {
1550
1582
  i++;
1551
1583
  continue;
1552
1584
  }
1553
- if (text$2[i] === "'" || text$2[i] === "\"") {
1554
- const quote = text$2[i];
1585
+ if (text[i] === "'" || text[i] === "\"") {
1586
+ const quote = text[i];
1555
1587
  let j = i + 1;
1556
- while (j < text$2.length && text$2[j] !== quote) {
1557
- if (text$2[j] === "\\") j++;
1588
+ while (j < text.length && text[j] !== quote) {
1589
+ if (text[j] === "\\") j++;
1558
1590
  j++;
1559
1591
  }
1560
- tokens$1.push(text$2.slice(i, j + 1));
1592
+ tokens.push(text.slice(i, j + 1));
1561
1593
  i = j + 1;
1562
1594
  continue;
1563
1595
  }
1564
- if (i + 1 < text$2.length) {
1565
- const two = text$2.slice(i, i + 2);
1596
+ if (i + 1 < text.length) {
1597
+ const two = text.slice(i, i + 2);
1566
1598
  if (two === "!=" || two === ">=" || two === "<=") {
1567
- tokens$1.push(two);
1599
+ tokens.push(two);
1568
1600
  i += 2;
1569
1601
  continue;
1570
1602
  }
1571
1603
  }
1572
- if ("=><(),".includes(text$2[i])) {
1573
- tokens$1.push(text$2[i]);
1604
+ if ("=><(),".includes(text[i])) {
1605
+ tokens.push(text[i]);
1574
1606
  i++;
1575
1607
  continue;
1576
1608
  }
1577
- if (text$2[i] === ".") {
1578
- tokens$1.push(".");
1609
+ if (text[i] === ".") {
1610
+ tokens.push(".");
1579
1611
  i++;
1580
1612
  continue;
1581
1613
  }
1582
- if (/[\w]/u.test(text$2[i])) {
1614
+ if (/[\w]/u.test(text[i])) {
1583
1615
  let j = i;
1584
- while (j < text$2.length && /[\w]/u.test(text$2[j])) j++;
1585
- tokens$1.push(text$2.slice(i, j));
1616
+ while (j < text.length && /[\w]/u.test(text[j])) j++;
1617
+ tokens.push(text.slice(i, j));
1586
1618
  i = j;
1587
1619
  continue;
1588
1620
  }
1589
1621
  i++;
1590
1622
  }
1591
- return tokens$1;
1623
+ return tokens;
1592
1624
  }
1593
1625
 
1594
1626
  //#endregion
@@ -1600,7 +1632,7 @@ function _define_property$7(obj, key, value) {
1600
1632
  configurable: true,
1601
1633
  writable: true
1602
1634
  });
1603
- else obj[key] = value;
1635
+ else obj[key] = value;
1604
1636
  return obj;
1605
1637
  }
1606
1638
  var IdRegistry = class {
@@ -1612,12 +1644,12 @@ var IdRegistry = class {
1612
1644
  registerDefinition(token) {
1613
1645
  if (!token) return;
1614
1646
  if (this.reserved.has(token.text)) this.forbidden.add(token);
1615
- else if (this.definitions.has(token.text)) this.duplicates.add(token);
1616
- else this.definitions.set(token.text, token);
1647
+ else if (this.definitions.has(token.text)) this.duplicates.add(token);
1648
+ else this.definitions.set(token.text, token);
1617
1649
  }
1618
1650
  isDefined(t) {
1619
- const text$2 = typeof t === "string" ? t : t.text;
1620
- return this.definitions.has(text$2) || this.globalTypes.has(text$2);
1651
+ const text = typeof t === "string" ? t : t.text;
1652
+ return this.definitions.has(text) || this.globalTypes.has(text);
1621
1653
  }
1622
1654
  getErrors() {
1623
1655
  return [...Array.from(this.duplicates, (t) => ({
@@ -1633,9 +1665,9 @@ else this.definitions.set(token.text, token);
1633
1665
  constructor(globalTypes = []) {
1634
1666
  _define_property$7(this, "reserved", void 0);
1635
1667
  _define_property$7(this, "globalTypes", void 0);
1636
- _define_property$7(this, "definitions", new Map());
1637
- _define_property$7(this, "duplicates", new Set());
1638
- _define_property$7(this, "forbidden", new Set());
1668
+ _define_property$7(this, "definitions", /* @__PURE__ */ new Map());
1669
+ _define_property$7(this, "duplicates", /* @__PURE__ */ new Set());
1670
+ _define_property$7(this, "forbidden", /* @__PURE__ */ new Set());
1639
1671
  this.reserved = new Set([
1640
1672
  "interface",
1641
1673
  "type",
@@ -1658,7 +1690,7 @@ function _define_property$6(obj, key, value) {
1658
1690
  configurable: true,
1659
1691
  writable: true
1660
1692
  });
1661
- else obj[key] = value;
1693
+ else obj[key] = value;
1662
1694
  return obj;
1663
1695
  }
1664
1696
  var NodeIterator = class NodeIterator {
@@ -1699,14 +1731,14 @@ var NodeIterator = class NodeIterator {
1699
1731
  fork(nodes) {
1700
1732
  return new NodeIterator(nodes || this.nodes, this.messages, this.badNodes, this.issues, nodes ? this.$ : this.parent, nodes ? 0 : this.i).update();
1701
1733
  }
1702
- skip(pun$1) {
1703
- while (this.$?.type === "comment" || this.$?.type === "punctuation" && pun$1?.length && pun$1.includes(this.$.text)) this.move();
1734
+ skip(pun) {
1735
+ while (this.$?.type === "comment" || this.$?.type === "punctuation" && pun?.length && pun.includes(this.$.text)) this.move();
1704
1736
  return this;
1705
1737
  }
1706
- skipUntil(pun$1) {
1738
+ skipUntil(pun) {
1707
1739
  while (this.$ && !this.satisfies({
1708
1740
  node: "punctuation",
1709
- text: pun$1
1741
+ text: pun
1710
1742
  })) this.move();
1711
1743
  }
1712
1744
  unexpected(force = false, msg = "Unexpected token") {
@@ -1722,15 +1754,14 @@ var NodeIterator = class NodeIterator {
1722
1754
  satisfies(...rules) {
1723
1755
  for (const rule of rules) {
1724
1756
  const passed = Array.isArray(rule.node) ? rule.node.includes(this.$?.type) : this.$?.type === rule.node;
1725
- if (passed && rule.text === undefined) return true;
1757
+ if (passed && rule.text === void 0) return true;
1726
1758
  if (passed && Array.isArray(rule.text) ? rule.text.includes(this.$?.text) : this.$?.text === rule.text) return true;
1727
1759
  }
1728
1760
  return false;
1729
1761
  }
1730
1762
  confirmIssues() {
1731
1763
  if (this.issues.unexpectedEOB) {
1732
- const node = this.lastNode || this.parent;
1733
- const pos = node?.getRange().end || {
1764
+ const pos = (this.lastNode || this.parent)?.getRange().end || {
1734
1765
  character: 1,
1735
1766
  line: 1
1736
1767
  };
@@ -1764,7 +1795,7 @@ var NodeIterator = class NodeIterator {
1764
1795
  }
1765
1796
  })).concat(this.messages);
1766
1797
  }
1767
- constructor(nodes, messages = [], badNodes = new Map(), issues = {}, parent, i = -1) {
1798
+ constructor(nodes, messages = [], badNodes = /* @__PURE__ */ new Map(), issues = {}, parent, i = -1) {
1768
1799
  _define_property$6(this, "nodes", void 0);
1769
1800
  _define_property$6(this, "messages", void 0);
1770
1801
  _define_property$6(this, "badNodes", void 0);
@@ -1783,7 +1814,9 @@ var NodeIterator = class NodeIterator {
1783
1814
 
1784
1815
  //#endregion
1785
1816
  //#region packages/core/src/tokenizer/tokens/a-identifier.token.ts
1786
- const AIdentifierToken = new __prostojs_parser.Node({
1817
+ /**
1818
+ * Annotation (@) Identifier node
1819
+ */ const AIdentifierToken = new _prostojs_parser.Node({
1787
1820
  name: "annotation",
1788
1821
  start: { token: RegExp("@[\\p{ID_Continue}$.]*", "u") },
1789
1822
  end: {
@@ -1805,7 +1838,9 @@ const pairs = {
1805
1838
  "(": ")",
1806
1839
  "[": "]"
1807
1840
  };
1808
- const BlockToken = new __prostojs_parser.Node({
1841
+ /**
1842
+ * Block node
1843
+ */ const BlockToken = new _prostojs_parser.Node({
1809
1844
  name: "block",
1810
1845
  start: {
1811
1846
  token: RegExp("(?<text>[([{])", "u"),
@@ -1825,7 +1860,7 @@ const BlockToken = new __prostojs_parser.Node({
1825
1860
 
1826
1861
  //#endregion
1827
1862
  //#region packages/core/src/tokenizer/tokens/comment.token.ts
1828
- const inline = new __prostojs_parser.Node({
1863
+ const inline = new _prostojs_parser.Node({
1829
1864
  name: "inline-comment",
1830
1865
  start: {
1831
1866
  token: "//",
@@ -1842,7 +1877,7 @@ const inline = new __prostojs_parser.Node({
1842
1877
  },
1843
1878
  mapContent: "text"
1844
1879
  });
1845
- const block$1 = new __prostojs_parser.Node({
1880
+ const block$1 = new _prostojs_parser.Node({
1846
1881
  name: "block-comment",
1847
1882
  start: {
1848
1883
  token: "/*",
@@ -1859,7 +1894,9 @@ const block$1 = new __prostojs_parser.Node({
1859
1894
  },
1860
1895
  mapContent: "text"
1861
1896
  });
1862
- const commentNodes = {
1897
+ /**
1898
+ * Block and inline comments
1899
+ */ const commentNodes = {
1863
1900
  inline,
1864
1901
  block: block$1,
1865
1902
  all: [inline, block$1]
@@ -1867,7 +1904,9 @@ const commentNodes = {
1867
1904
 
1868
1905
  //#endregion
1869
1906
  //#region packages/core/src/tokenizer/tokens/identifier.token.ts
1870
- const IdentifierToken = new __prostojs_parser.Node({
1907
+ /**
1908
+ * Identifier node
1909
+ */ const IdentifierToken = new _prostojs_parser.Node({
1871
1910
  name: "identifier",
1872
1911
  start: { token: RegExp("[\\p{ID_Start}$_][\\p{ID_Continue}$]*", "u") },
1873
1912
  end: {
@@ -1884,7 +1923,9 @@ const IdentifierToken = new __prostojs_parser.Node({
1884
1923
 
1885
1924
  //#endregion
1886
1925
  //#region packages/core/src/tokenizer/tokens/number.token.ts
1887
- const NumberToken = new __prostojs_parser.Node({
1926
+ /**
1927
+ * Number node
1928
+ */ const NumberToken = new _prostojs_parser.Node({
1888
1929
  name: "number",
1889
1930
  start: { token: /[-+]?(?:\d*\.\d+|\d+)(?:[eE][-+]?\d+)?/u },
1890
1931
  end: {
@@ -1901,7 +1942,9 @@ const NumberToken = new __prostojs_parser.Node({
1901
1942
 
1902
1943
  //#endregion
1903
1944
  //#region packages/core/src/tokenizer/tokens/punctuation.token.ts
1904
- const PunctuationToken = new __prostojs_parser.Node({
1945
+ /**
1946
+ * Punctuation node
1947
+ */ const PunctuationToken = new _prostojs_parser.Node({
1905
1948
  name: "punctuation",
1906
1949
  start: {
1907
1950
  token: RegExp("(?<text>[\\n!&+,./:;=?|])", "u"),
@@ -1920,7 +1963,13 @@ const PunctuationToken = new __prostojs_parser.Node({
1920
1963
 
1921
1964
  //#endregion
1922
1965
  //#region packages/core/src/tokenizer/tokens/query-operator.token.ts
1923
- const QueryOperatorToken = new __prostojs_parser.Node({
1966
+ /**
1967
+ * Query operator token — matches symbolic comparison operators
1968
+ * inside backtick-delimited query expressions.
1969
+ *
1970
+ * Multi-character operators (!=, >=, <=) are matched as single tokens.
1971
+ * Only recognized inside QueryToken — not in root or BlockToken.
1972
+ */ const QueryOperatorToken = new _prostojs_parser.Node({
1924
1973
  name: "punctuation",
1925
1974
  start: {
1926
1975
  token: RegExp("(?<text>!=|>=|<=|[=><])", "u"),
@@ -1939,7 +1988,10 @@ const QueryOperatorToken = new __prostojs_parser.Node({
1939
1988
 
1940
1989
  //#endregion
1941
1990
  //#region packages/core/src/tokenizer/tokens/query.token.ts
1942
- const QueryToken = new __prostojs_parser.Node({
1991
+ /**
1992
+ * Query node — backtick-delimited filter expressions
1993
+ * Content inside backticks is tokenized into children.
1994
+ */ const QueryToken = new _prostojs_parser.Node({
1943
1995
  name: "query",
1944
1996
  start: {
1945
1997
  token: /`/u,
@@ -1960,7 +2012,11 @@ const QueryToken = new __prostojs_parser.Node({
1960
2012
  //#endregion
1961
2013
  //#region packages/core/src/tokenizer/tokens/regexp.token.ts
1962
2014
  const REGEXP_LITERAL_RE = /\/(?![/*])(?:\\.|\[.*?]|[^/\\\n\r[])*\/[dgimsuy]*/;
1963
- const RegExpToken = new __prostojs_parser.Node({
2015
+ /**
2016
+ * RegExp literal – `/pattern/flags`
2017
+ * • Starts with `/` but *not* `//` or `/*`
2018
+ * • Ends with `/` followed by zero-or-more valid flags
2019
+ */ const RegExpToken = new _prostojs_parser.Node({
1964
2020
  name: "regexp",
1965
2021
  start: {
1966
2022
  token: REGEXP_LITERAL_RE,
@@ -1981,7 +2037,9 @@ const RegExpToken = new __prostojs_parser.Node({
1981
2037
 
1982
2038
  //#endregion
1983
2039
  //#region packages/core/src/tokenizer/tokens/text.node.ts
1984
- const TextToken = new __prostojs_parser.Node({
2040
+ /**
2041
+ * Text node single or doublequoted
2042
+ */ const TextToken = new _prostojs_parser.Node({
1985
2043
  name: "text",
1986
2044
  start: {
1987
2045
  token: RegExp("(?<quote>[\"'])", "u"),
@@ -2018,9 +2076,9 @@ const tokens = {
2018
2076
  text: TextToken,
2019
2077
  regexp: RegExpToken,
2020
2078
  query: QueryToken,
2021
- root: undefined
2079
+ root: void 0
2022
2080
  };
2023
- const root = new __prostojs_parser.Node({
2081
+ const root = new _prostojs_parser.Node({
2024
2082
  name: "root",
2025
2083
  skip: /\s/u,
2026
2084
  eofClose: true,
@@ -2038,7 +2096,14 @@ const root = new __prostojs_parser.Node({
2038
2096
  tokens.root = root;
2039
2097
  BlockToken.recognize(RegExpToken, ...commentNodes.all, BlockToken, QueryToken, AIdentifierToken, IdentifierToken, TextToken, NumberToken, PunctuationToken);
2040
2098
  QueryToken.recognize(RegExpToken, QueryOperatorToken, BlockToken, IdentifierToken, TextToken, NumberToken, PunctuationToken);
2041
- function extractTokens(node) {
2099
+ /**
2100
+ * Recursively extract TLexicalToken[] from a ParsedNode tree.
2101
+ * Replaces the v0.5 mapContent('children', callback) + global loop.
2102
+ *
2103
+ * v0.6 Position has { offset, line, column }.
2104
+ * line is 1-based, column is 1-based.
2105
+ * VSCode expects 0-based line, 0-based character.
2106
+ */ function extractTokens(node) {
2042
2107
  return node.content.map((item) => {
2043
2108
  if (typeof item === "string") return {
2044
2109
  type: "unknown",
@@ -2064,29 +2129,29 @@ function extractTokens(node) {
2064
2129
  //#region packages/core/src/tokenizer/index.ts
2065
2130
  function tokenize(source, debug = false) {
2066
2131
  const result = root.parse(source);
2067
- if (debug) console.log((0, __prostojs_parser.printTree)(result));
2132
+ if (debug) console.log((0, _prostojs_parser.printTree)(result));
2068
2133
  return extractTokens(result);
2069
2134
  }
2070
2135
 
2071
2136
  //#endregion
2072
2137
  //#region packages/core/src/parser/pipes/tokens.pipe.ts
2073
- const identifier = (...text$2) => $token("identifier", text$2.length > 0 ? text$2 : undefined);
2074
- const text = (...text$2) => $token("text", text$2.length > 0 ? text$2 : undefined);
2075
- const block = (...text$2) => $token("block", text$2.length > 0 ? text$2.map((v) => v[0]) : undefined);
2076
- const pun = (...text$2) => $token("punctuation", text$2.length > 0 ? text$2 : undefined);
2077
- function $token(name, text$2) {
2138
+ const identifier = (...text) => $token("identifier", text.length > 0 ? text : void 0);
2139
+ const text = (...text) => $token("text", text.length > 0 ? text : void 0);
2140
+ const block = (...text) => $token("block", text.length > 0 ? text.map((v) => v[0]) : void 0);
2141
+ const pun = (...text) => $token("punctuation", text.length > 0 ? text : void 0);
2142
+ function $token(name, text) {
2078
2143
  const opts = {
2079
2144
  optional: false,
2080
- saveAs: undefined,
2081
- skip: undefined,
2145
+ saveAs: void 0,
2146
+ skip: void 0,
2082
2147
  expect: [{
2083
2148
  node: name,
2084
- text: text$2
2149
+ text
2085
2150
  }],
2086
- contains: undefined,
2151
+ contains: void 0,
2087
2152
  isGlobal: false,
2088
2153
  empty: false,
2089
- wrapper: undefined,
2154
+ wrapper: void 0,
2090
2155
  wrapMultiple: false,
2091
2156
  debug: false,
2092
2157
  eob: false,
@@ -2096,7 +2161,7 @@ function $token(name, text$2) {
2096
2161
  return {
2097
2162
  expect: [{
2098
2163
  node: name,
2099
- text: text$2
2164
+ text
2100
2165
  }],
2101
2166
  handler(ni, target) {
2102
2167
  if (opts.debug) debugger;
@@ -2137,7 +2202,7 @@ function $token(name, text$2) {
2137
2202
  ni.move();
2138
2203
  if (opts.skip) ni.skip(opts.skip);
2139
2204
  if (opts.wrapMultiple) continue;
2140
- else return true;
2205
+ else return true;
2141
2206
  } else {
2142
2207
  if (!opts.optional) ni.unexpected();
2143
2208
  return opts.optional;
@@ -2222,7 +2287,7 @@ function $pipe(entity, pipe = []) {
2222
2287
  pipe,
2223
2288
  toString: () => entity,
2224
2289
  skipTokens: [],
2225
- stopCondition: undefined,
2290
+ stopCondition: void 0,
2226
2291
  skip(...s) {
2227
2292
  this.skipTokens.push(...s);
2228
2293
  return this;
@@ -2237,12 +2302,12 @@ function $pipe(entity, pipe = []) {
2237
2302
  }
2238
2303
  };
2239
2304
  }
2240
- function runPipes(pipes$1, ni, singlePass = false) {
2305
+ function runPipes(pipes, ni, singlePass = false) {
2241
2306
  const nodes = [];
2242
2307
  while (ni.$) {
2243
2308
  let matched = true;
2244
2309
  let depth = ni.index;
2245
- for (const { targetFactory, pipe, skipTokens: skip, stopCondition } of pipes$1) {
2310
+ for (const { targetFactory, pipe, skipTokens: skip, stopCondition } of pipes) {
2246
2311
  const target = { node: targetFactory() };
2247
2312
  const fork = ni.fork();
2248
2313
  fork.skip(skip);
@@ -2277,15 +2342,15 @@ function runPipes(pipes$1, ni, singlePass = false) {
2277
2342
  }
2278
2343
  return nodes;
2279
2344
  }
2280
- function runPipesOnce(pipes$1, ni) {
2281
- return runPipes(pipes$1, ni, true)[0];
2345
+ function runPipesOnce(pipes, ni) {
2346
+ return runPipes(pipes, ni, true)[0];
2282
2347
  }
2283
2348
 
2284
2349
  //#endregion
2285
2350
  //#region packages/core/src/parser/grouping.ts
2286
2351
  function groupByPriority(nodes, priority) {
2287
2352
  if (nodes.length === 1) return nodes[0];
2288
- if (nodes.length === 0) return undefined;
2353
+ if (nodes.length === 0) return;
2289
2354
  if (nodes.length % 2 === 0) throw new Error(`Invalid number of nodes ${nodes.length}. Odd number expected`);
2290
2355
  let currentPass = nodes;
2291
2356
  let temporaryResult = [];
@@ -2294,7 +2359,7 @@ function groupByPriority(nodes, priority) {
2294
2359
  for (const [i, node] of currentPass.entries()) {
2295
2360
  const isOperator = i % 2 === 1;
2296
2361
  if (!isOperator && node instanceof Token) throw new Error(`Unexpected token ${node.toString()} at ${i}`);
2297
- else if (isOperator && !(node instanceof Token)) throw new Error(`Unexpected token ${isGroup(node) ? node.op : node.token.toString()} at ${i}`);
2362
+ else if (isOperator && !(node instanceof Token)) throw new Error(`Unexpected token ${isGroup(node) ? node.op : node.token.toString()} at ${i}`);
2298
2363
  if (isOperator) {
2299
2364
  if (node.text !== p) temporaryResult.push(node);
2300
2365
  continue;
@@ -2336,12 +2401,15 @@ const VALUE_KEYWORDS = new Set([
2336
2401
  "null",
2337
2402
  "undefined"
2338
2403
  ]);
2339
- function parseQueryExpression(children, messages, sourceToken) {
2340
- if (children.length === 0) return undefined;
2404
+ /**
2405
+ * Parse a backtick-delimited query expression from its child tokens.
2406
+ * Returns a SemanticQueryNode or undefined if the content is empty.
2407
+ */ function parseQueryExpression(children, messages, sourceToken) {
2408
+ if (children.length === 0) return;
2341
2409
  const ni = new NodeIterator(children, messages);
2342
2410
  ni.move();
2343
2411
  const expr = parseOrExpr(ni, messages);
2344
- if (!expr) return undefined;
2412
+ if (!expr) return;
2345
2413
  if (ni.$) messages.push({
2346
2414
  severity: 1,
2347
2415
  message: `Unexpected token in query expression: "${ni.$.text}"`,
@@ -2363,7 +2431,7 @@ function parseQueryExpression(children, messages, sourceToken) {
2363
2431
  }
2364
2432
  function parseOrExpr(ni, messages) {
2365
2433
  const left = parseAndExpr(ni, messages);
2366
- if (!left) return undefined;
2434
+ if (!left) return;
2367
2435
  const operands = [left];
2368
2436
  while (ni.$?.type === "identifier" && ni.$.text === "or") {
2369
2437
  ni.move();
@@ -2382,7 +2450,7 @@ function parseOrExpr(ni, messages) {
2382
2450
  }
2383
2451
  function parseAndExpr(ni, messages) {
2384
2452
  const left = parseUnaryExpr(ni, messages);
2385
- if (!left) return undefined;
2453
+ if (!left) return;
2386
2454
  const operands = [left];
2387
2455
  while (ni.$?.type === "identifier" && ni.$.text === "and") {
2388
2456
  ni.move();
@@ -2405,7 +2473,7 @@ function parseUnaryExpr(ni, messages) {
2405
2473
  const operand = parseUnaryExpr(ni, messages);
2406
2474
  if (!operand) {
2407
2475
  pushError(ni, messages, "Expected expression after \"not\"");
2408
- return undefined;
2476
+ return;
2409
2477
  }
2410
2478
  const node = new SemanticQueryLogicalNode();
2411
2479
  node.operator = "not";
@@ -2417,7 +2485,7 @@ function parseUnaryExpr(ni, messages) {
2417
2485
  ni.move();
2418
2486
  if (blockChildren.length === 0) {
2419
2487
  pushError(ni, messages, "Empty parenthesized expression");
2420
- return undefined;
2488
+ return;
2421
2489
  }
2422
2490
  const subNi = new NodeIterator(blockChildren, messages);
2423
2491
  subNi.move();
@@ -2429,14 +2497,14 @@ function parseUnaryExpr(ni, messages) {
2429
2497
  }
2430
2498
  function parseComparison(ni, messages) {
2431
2499
  const left = parseFieldRef(ni, messages);
2432
- if (!left) return undefined;
2500
+ if (!left) return;
2433
2501
  if (ni.$?.type === "punctuation" && SYMBOLIC_OPS.has(ni.$.text)) {
2434
2502
  const opText = ni.$.text;
2435
2503
  ni.move();
2436
2504
  const right = parseValueOrFieldRef(ni, messages);
2437
2505
  if (!right) {
2438
2506
  pushError(ni, messages, `Expected value or field reference after "${opText}"`);
2439
- return undefined;
2507
+ return;
2440
2508
  }
2441
2509
  const node = new SemanticQueryComparisonNode();
2442
2510
  node.left = left;
@@ -2449,7 +2517,7 @@ function parseComparison(ni, messages) {
2449
2517
  if (opText === "in") {
2450
2518
  ni.move();
2451
2519
  const right = parseValueList(ni, messages);
2452
- if (!right) return undefined;
2520
+ if (!right) return;
2453
2521
  const node = new SemanticQueryComparisonNode();
2454
2522
  node.left = left;
2455
2523
  node.operator = "in";
@@ -2461,7 +2529,7 @@ function parseComparison(ni, messages) {
2461
2529
  const right = parseValueOrFieldRef(ni, messages);
2462
2530
  if (!right) {
2463
2531
  pushError(ni, messages, "Expected value after \"matches\"");
2464
- return undefined;
2532
+ return;
2465
2533
  }
2466
2534
  const node = new SemanticQueryComparisonNode();
2467
2535
  node.left = left;
@@ -2478,17 +2546,16 @@ function parseComparison(ni, messages) {
2478
2546
  }
2479
2547
  if (opText === "not") return parseNotComparison(ni, messages, left);
2480
2548
  pushError(ni, messages, `Unknown operator "${opText}"`);
2481
- return undefined;
2549
+ return;
2482
2550
  }
2483
2551
  pushError(ni, messages, "Expected operator after field reference");
2484
- return undefined;
2485
2552
  }
2486
2553
  function parseNotComparison(ni, messages, left) {
2487
2554
  ni.move();
2488
2555
  if (ni.$?.type === "identifier" && ni.$.text === "in") {
2489
2556
  ni.move();
2490
2557
  const right = parseValueList(ni, messages);
2491
- if (!right) return undefined;
2558
+ if (!right) return;
2492
2559
  const node = new SemanticQueryComparisonNode();
2493
2560
  node.left = left;
2494
2561
  node.operator = "not in";
@@ -2503,12 +2570,11 @@ function parseNotComparison(ni, messages, left) {
2503
2570
  return node;
2504
2571
  }
2505
2572
  pushError(ni, messages, "Expected \"in\" or \"exists\" after \"not\"");
2506
- return undefined;
2507
2573
  }
2508
2574
  function parseFieldRef(ni, messages) {
2509
2575
  if (ni.$?.type !== "identifier") {
2510
2576
  pushError(ni, messages, "Expected field reference");
2511
- return undefined;
2577
+ return;
2512
2578
  }
2513
2579
  const firstToken = new Token(ni.$);
2514
2580
  ni.move();
@@ -2528,35 +2594,34 @@ function parseFieldRef(ni, messages) {
2528
2594
  break;
2529
2595
  }
2530
2596
  }
2531
- const node$2 = new SemanticQueryFieldRefNode();
2532
- node$2.typeRef = firstToken;
2533
- if (fieldText !== secondToken.text) node$2.fieldRef = secondToken.clone({ text: fieldText });
2534
- else node$2.fieldRef = secondToken;
2535
- return node$2;
2597
+ const node = new SemanticQueryFieldRefNode();
2598
+ node.typeRef = firstToken;
2599
+ if (fieldText !== secondToken.text) node.fieldRef = secondToken.clone({ text: fieldText });
2600
+ else node.fieldRef = secondToken;
2601
+ return node;
2536
2602
  }
2537
2603
  pushError(ni, messages, "Expected identifier after \".\"");
2538
- const node$1 = new SemanticQueryFieldRefNode();
2539
- node$1.fieldRef = firstToken;
2540
- return node$1;
2604
+ const node = new SemanticQueryFieldRefNode();
2605
+ node.fieldRef = firstToken;
2606
+ return node;
2541
2607
  }
2542
2608
  const node = new SemanticQueryFieldRefNode();
2543
2609
  node.fieldRef = firstToken;
2544
2610
  return node;
2545
2611
  }
2546
2612
  function parseValueOrFieldRef(ni, messages) {
2547
- if (!ni.$) return undefined;
2613
+ if (!ni.$) return;
2548
2614
  if (ni.$.type === "text" || ni.$.type === "number" || ni.$.type === "regexp") return parseValue(ni, messages);
2549
2615
  if (ni.$.type === "identifier") {
2550
2616
  if (VALUE_KEYWORDS.has(ni.$.text)) return parseValue(ni, messages);
2551
2617
  return parseFieldRef(ni, messages);
2552
2618
  }
2553
2619
  pushError(ni, messages, "Expected value or field reference");
2554
- return undefined;
2555
2620
  }
2556
2621
  function parseValue(ni, messages) {
2557
2622
  if (!ni.$) {
2558
2623
  pushError(ni, messages, "Expected value");
2559
- return undefined;
2624
+ return;
2560
2625
  }
2561
2626
  const token = ni.$;
2562
2627
  if (token.type === "text" || token.type === "number" || token.type === "regexp" || token.type === "identifier" && VALUE_KEYWORDS.has(token.text)) {
@@ -2566,7 +2631,6 @@ function parseValue(ni, messages) {
2566
2631
  return node;
2567
2632
  }
2568
2633
  pushError(ni, messages, `Unexpected token "${token.text}" where value expected`);
2569
- return undefined;
2570
2634
  }
2571
2635
  function parseValueList(ni, messages) {
2572
2636
  if (ni.$?.type === "block" && ni.$.text === "(") {
@@ -2575,7 +2639,7 @@ function parseValueList(ni, messages) {
2575
2639
  const values = [];
2576
2640
  if (blockChildren.length === 0) {
2577
2641
  pushError(ni, messages, "Empty value list in \"in\" expression");
2578
- return undefined;
2642
+ return;
2579
2643
  }
2580
2644
  const subNi = new NodeIterator(blockChildren, messages);
2581
2645
  subNi.move();
@@ -2592,7 +2656,6 @@ function parseValueList(ni, messages) {
2592
2656
  return node;
2593
2657
  }
2594
2658
  pushError(ni, messages, "Expected parenthesized value list after \"in\"");
2595
- return undefined;
2596
2659
  }
2597
2660
  function pushError(ni, messages, message) {
2598
2661
  const range = ni.$?.getRange?.() ?? {
@@ -2658,7 +2721,7 @@ function refWithChain() {
2658
2721
  } else if (fork.$.children?.length === 1 && fork.$.children[0].type === "text") {
2659
2722
  if (isRef(target.node)) target.node.addChain(new Token(fork.$.children[0]));
2660
2723
  } else return true;
2661
- else {
2724
+ else {
2662
2725
  fork.skip(["\n"]);
2663
2726
  if (fork.next().satisfies(s.id)) {
2664
2727
  if (isRef(target.node)) target.node.addDot(new Token(fork.$));
@@ -2765,7 +2828,7 @@ function annotations() {
2765
2828
  } else break;
2766
2829
  }
2767
2830
  if (ni.satisfies(opts.end)) ni.skip([";", "\n"]);
2768
- else if (ni.$) {
2831
+ else if (ni.$) {
2769
2832
  ni.unexpected(false, `Unexpected token in annotation ${ni.toString()}`);
2770
2833
  ni.skipUntil([";", "\n"]);
2771
2834
  ni.skip([";", "\n"]);
@@ -2774,12 +2837,12 @@ else if (ni.$) {
2774
2837
  return true;
2775
2838
  } };
2776
2839
  }
2777
- function definition(pipes$1) {
2840
+ function definition(pipes) {
2778
2841
  const opts = {
2779
2842
  sep: [],
2780
2843
  priority: false,
2781
2844
  multiple: false,
2782
- from: undefined,
2845
+ from: void 0,
2783
2846
  debug: false,
2784
2847
  skip: []
2785
2848
  };
@@ -2797,7 +2860,7 @@ function definition(pipes$1) {
2797
2860
  targetNode.define(new $n.SemanticGroup());
2798
2861
  return true;
2799
2862
  }
2800
- const resolvedPipes = pipes$1.map((p) => typeof p === "function" ? p() : p);
2863
+ const resolvedPipes = pipes.map((p) => typeof p === "function" ? p() : p);
2801
2864
  const node = runPipesOnce(resolvedPipes, fork);
2802
2865
  if (node) {
2803
2866
  fork.accepted();
@@ -2818,7 +2881,7 @@ function definition(pipes$1) {
2818
2881
  text: opts.sep
2819
2882
  })) {
2820
2883
  if (opts.priority) if (fork.next(opts.skip).$) nodes.push(new Token(fork.$));
2821
- else {
2884
+ else {
2822
2885
  fork.unexpected(false, "Unexpected end of group");
2823
2886
  break;
2824
2887
  }
@@ -2841,7 +2904,7 @@ else {
2841
2904
  }
2842
2905
  }
2843
2906
  if (nodes.length === 1) targetNode.define(nodes[0]);
2844
- else if (opts.priority && opts.sep.length > 0) {
2907
+ else if (opts.priority && opts.sep.length > 0) {
2845
2908
  if (nodes.length % 2 === 0) {
2846
2909
  fork.next().unexpected(false, "Error in group definition");
2847
2910
  return false;
@@ -2888,8 +2951,8 @@ function unwrap(attr) {
2888
2951
  target.node.define(new $n.SemanticGroup(nodes));
2889
2952
  return true;
2890
2953
  },
2891
- with(pipes$1) {
2892
- opts.pipes = pipes$1;
2954
+ with(pipes) {
2955
+ opts.pipes = pipes;
2893
2956
  return this;
2894
2957
  }
2895
2958
  };
@@ -2898,13 +2961,12 @@ function propName() {
2898
2961
  return { handler(ni, target) {
2899
2962
  switch (ni.$?.type) {
2900
2963
  case "identifier":
2901
- case "text": {
2964
+ case "text":
2902
2965
  target.node.saveToken(new Token(ni.$), "identifier");
2903
2966
  ni.accepted();
2904
2967
  ni.move();
2905
2968
  ni.skip(["\n"]);
2906
2969
  return true;
2907
- }
2908
2970
  case "block": {
2909
2971
  const childrenLength = ni.$.children?.length || 0;
2910
2972
  const firstText = ni.$.children?.[0]?.text;
@@ -2927,13 +2989,12 @@ function propName() {
2927
2989
  }
2928
2990
  if (ni.$.text === "[" && !childrenLength) ni.unexpected(false, "Wildcard \"*\" or a Regular Expression expected");
2929
2991
  if (ni.$.text === "[" && childrenLength > 1) ni.unexpected(false, firstText?.startsWith("/") ? "Invalid Regular Expression" : "To many arguments in prop pattern []");
2930
- else ni.unexpected(false, "Unexpected identifier at property name");
2992
+ else ni.unexpected(false, "Unexpected identifier at property name");
2931
2993
  return false;
2932
2994
  }
2933
- default: {
2995
+ default:
2934
2996
  ni.unexpected(false, "Unexpected identifier at property name");
2935
2997
  return false;
2936
- }
2937
2998
  }
2938
2999
  } };
2939
3000
  }
@@ -2980,9 +3041,8 @@ function extendsClause() {
2980
3041
  //#region packages/core/src/parser/pipes/pipes.ts
2981
3042
  const ref = $pipe("ref", [refWithChain()]);
2982
3043
  const constText = defineValuePipe("const", "text", false);
2983
- const constNumber = defineValuePipe("const", "number", false);
2984
3044
  const allowedValuesPipeArray = [
2985
- constNumber,
3045
+ defineValuePipe("const", "number", false),
2986
3046
  ref,
2987
3047
  constText
2988
3048
  ];
@@ -3045,14 +3105,13 @@ const importPipe = $pipe("import", [
3045
3105
  text().saveAs("path").skip(";", "\n"),
3046
3106
  definition([$pipe("ref", [identifier().saveAs("identifier").skip("\n")])]).from("inner").separatedBy(",").skip("\n").respectPriority()
3047
3107
  ]).skip("\n", ";");
3048
- const skipComments = { handler(ni) {
3049
- ni.skip();
3050
- return true;
3051
- } };
3052
3108
  const annotateEntry = $pipe("ref", [
3053
3109
  annotations(),
3054
3110
  refWithChain(),
3055
- skipComments,
3111
+ { handler(ni) {
3112
+ ni.skip();
3113
+ return true;
3114
+ } },
3056
3115
  pun(";", ",", "\n").orEob().lookBehind()
3057
3116
  ]).skip("\n", ";", ",");
3058
3117
  const annotatePipe = $pipe("annotate", [
@@ -3076,12 +3135,12 @@ const pipes = {
3076
3135
 
3077
3136
  //#endregion
3078
3137
  //#region packages/core/src/parser/types.ts
3079
- var TSeverity = /*#__PURE__*/ function(TSeverity$1) {
3080
- TSeverity$1[TSeverity$1["Error"] = 1] = "Error";
3081
- TSeverity$1[TSeverity$1["Warning"] = 2] = "Warning";
3082
- TSeverity$1[TSeverity$1["Info"] = 3] = "Info";
3083
- TSeverity$1[TSeverity$1["Hint"] = 4] = "Hint";
3084
- return TSeverity$1;
3138
+ var TSeverity = /* @__PURE__ */ function(TSeverity) {
3139
+ TSeverity[TSeverity["Error"] = 1] = "Error";
3140
+ TSeverity[TSeverity["Warning"] = 2] = "Warning";
3141
+ TSeverity[TSeverity["Info"] = 3] = "Info";
3142
+ TSeverity[TSeverity["Hint"] = 4] = "Hint";
3143
+ return TSeverity;
3085
3144
  }({});
3086
3145
 
3087
3146
  //#endregion
@@ -3093,7 +3152,7 @@ function _define_property$5(obj, key, value) {
3093
3152
  configurable: true,
3094
3153
  writable: true
3095
3154
  });
3096
- else obj[key] = value;
3155
+ else obj[key] = value;
3097
3156
  return obj;
3098
3157
  }
3099
3158
  /**
@@ -3135,19 +3194,22 @@ else obj[key] = value;
3135
3194
  const endCmp = comparePos(a.range.end, b.range.end);
3136
3195
  return startCmp >= 0 && endCmp <= 0;
3137
3196
  }
3138
- var BlocksIndex = class {
3197
+ /**
3198
+ * Implementation of `IBlocksIndex` that manages a collection of tokens and provides efficient methods to add tokens
3199
+ * and query the most nested token at a specific position.
3200
+ */ var BlocksIndex = class {
3139
3201
  /**
3140
3202
  * Adds a new token to the index. The token collection is maintained in sorted order by start position.
3141
3203
  * @param block - The token to add.
3142
- */ add(block$2) {
3204
+ */ add(block) {
3143
3205
  let left = 0;
3144
3206
  let right = this.blocks.length;
3145
3207
  while (left < right) {
3146
3208
  const mid = left + right >> 1;
3147
- if (comparePos(this.blocks[mid].range.start, block$2.range.start) < 0) left = mid + 1;
3148
- else right = mid;
3209
+ if (comparePos(this.blocks[mid].range.start, block.range.start) < 0) left = mid + 1;
3210
+ else right = mid;
3149
3211
  }
3150
- this.blocks.splice(left, 0, block$2);
3212
+ this.blocks.splice(left, 0, block);
3151
3213
  }
3152
3214
  /**
3153
3215
  * Finds the most nested token at a specific position.
@@ -3156,14 +3218,14 @@ else right = mid;
3156
3218
  * @returns The most nested token at the given position, or `undefined` if no token is found.
3157
3219
  */ at(line, character) {
3158
3220
  const candidates = [];
3159
- for (const block$2 of this.blocks) {
3160
- if (comparePos(block$2.range.start, {
3221
+ for (const block of this.blocks) {
3222
+ if (comparePos(block.range.start, {
3161
3223
  line,
3162
3224
  character
3163
3225
  }) > 0) break;
3164
- if (contains(block$2, line, character)) candidates.push(block$2);
3226
+ if (contains(block, line, character)) candidates.push(block);
3165
3227
  }
3166
- if (candidates.length === 0) return undefined;
3228
+ if (candidates.length === 0) return;
3167
3229
  let result = candidates[0];
3168
3230
  for (let i = 1; i < candidates.length; i++) if (moreNested(candidates[i], result)) result = candidates[i];
3169
3231
  return result;
@@ -3185,17 +3247,20 @@ function _define_property$4(obj, key, value) {
3185
3247
  configurable: true,
3186
3248
  writable: true
3187
3249
  });
3188
- else obj[key] = value;
3250
+ else obj[key] = value;
3189
3251
  return obj;
3190
3252
  }
3191
- var TokensIndex = class {
3253
+ /**
3254
+ * A class that implements a flat index for tokens, allowing quick access to tokens
3255
+ * at a specific line and character. Tokens in this index are not nested.
3256
+ */ var TokensIndex = class {
3192
3257
  /**
3193
3258
  * Adds a token to the index. The token is stored based on its starting line.
3194
3259
  * @param token - The token to add to the index.
3195
3260
  */ add(token) {
3196
3261
  if (!token?.range) return;
3197
3262
  const line = token.range.start.line;
3198
- this.tokensMap[line] = this.tokensMap[line] ?? new Set();
3263
+ this.tokensMap[line] = this.tokensMap[line] ?? /* @__PURE__ */ new Set();
3199
3264
  this.tokensMap[line].add(token);
3200
3265
  }
3201
3266
  /**
@@ -3204,10 +3269,10 @@ var TokensIndex = class {
3204
3269
  * @param character - The character position within the line to search for.
3205
3270
  * @returns The token at the specified line and character, or `undefined` if none exists.
3206
3271
  */ at(line, character) {
3207
- const tokens$1 = this.tokensMap[line];
3208
- if (!tokens$1) return undefined;
3272
+ const tokens = this.tokensMap[line];
3273
+ if (!tokens) return;
3209
3274
  let best;
3210
- for (const t of tokens$1) if (t.range.start.character <= character && t.range.end.character >= character) {
3275
+ for (const t of tokens) if (t.range.start.character <= character && t.range.end.character >= character) {
3211
3276
  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;
3212
3277
  }
3213
3278
  return best;
@@ -3231,14 +3296,13 @@ var TokensIndex = class {
3231
3296
  if (candidate) return candidate;
3232
3297
  }
3233
3298
  for (let l = line - 1; l >= 0; l--) {
3234
- const tokens$1 = this.tokensMap[l];
3235
- if (tokens$1 && tokens$1.size > 0) {
3299
+ const tokens = this.tokensMap[l];
3300
+ if (tokens && tokens.size > 0) {
3236
3301
  let candidate;
3237
- for (const t of tokens$1) if (!candidate || t.range.end.character > candidate.range.end.character) candidate = t;
3302
+ for (const t of tokens) if (!candidate || t.range.end.character > candidate.range.end.character) candidate = t;
3238
3303
  if (candidate) return candidate;
3239
3304
  }
3240
3305
  }
3241
- return undefined;
3242
3306
  }
3243
3307
  constructor() {
3244
3308
  /**
@@ -3257,7 +3321,7 @@ function _define_property$3(obj, key, value) {
3257
3321
  configurable: true,
3258
3322
  writable: true
3259
3323
  });
3260
- else obj[key] = value;
3324
+ else obj[key] = value;
3261
3325
  return obj;
3262
3326
  }
3263
3327
  var AtscriptDoc = class {
@@ -3272,7 +3336,7 @@ var AtscriptDoc = class {
3272
3336
  }
3273
3337
  resolveAnnotation(name) {
3274
3338
  let spec = this._annotationSpecCache.get(name);
3275
- if (spec === undefined && !this._annotationSpecCache.has(name)) {
3339
+ if (spec === void 0 && !this._annotationSpecCache.has(name)) {
3276
3340
  spec = resolveAnnotation(name, this.config.annotations);
3277
3341
  this._annotationSpecCache.set(name, spec);
3278
3342
  }
@@ -3311,11 +3375,10 @@ var AtscriptDoc = class {
3311
3375
  get text() {
3312
3376
  return this._text;
3313
3377
  }
3314
- update(text$2, debug = false) {
3315
- this._text = text$2;
3378
+ update(text, debug = false) {
3379
+ this._text = text;
3316
3380
  this.cleanup();
3317
- const rawTokens = tokenize(text$2, debug);
3318
- const ni = new NodeIterator(rawTokens, []).move();
3381
+ const ni = new NodeIterator(tokenize(text, debug), []).move();
3319
3382
  this.nodes = runPipes([
3320
3383
  pipes.importPipe,
3321
3384
  pipes.type,
@@ -3335,8 +3398,8 @@ var AtscriptDoc = class {
3335
3398
  this.queryFieldRefs = [];
3336
3399
  this.imports.clear();
3337
3400
  this.resolvedImports.clear();
3338
- this._allMessages = undefined;
3339
- this._annotateNodesByTarget = undefined;
3401
+ this._allMessages = void 0;
3402
+ this._annotateNodesByTarget = void 0;
3340
3403
  this.tokensIndex = new TokensIndex();
3341
3404
  this.blocksIndex = new BlocksIndex();
3342
3405
  this.resolvedAnnotations = [];
@@ -3383,14 +3446,12 @@ var AtscriptDoc = class {
3383
3446
  } else {
3384
3447
  let severity = 1;
3385
3448
  switch (this.config.unknownAnnotation) {
3386
- case "warn": {
3449
+ case "warn":
3387
3450
  severity = 2;
3388
3451
  break;
3389
- }
3390
- case "allow": {
3452
+ case "allow":
3391
3453
  severity = 0;
3392
3454
  break;
3393
- }
3394
3455
  default:
3395
3456
  }
3396
3457
  if (severity > 0) this.registerMessage(mainToken, `Unknown annotation "${mainToken.text}"`, severity, "dim");
@@ -3417,9 +3478,9 @@ var AtscriptDoc = class {
3417
3478
  *
3418
3479
  * If the type cannot be resolved or does not exist, returns `undefined`.
3419
3480
  */ unwindType(name, chain = [], watchCb, _tracked) {
3420
- const tracked = _tracked || new Set();
3481
+ const tracked = _tracked || /* @__PURE__ */ new Set();
3421
3482
  const decl = this.getDeclarationOwnerNode(name);
3422
- if (!decl) return undefined;
3483
+ if (!decl) return;
3423
3484
  const callCb = watchCb ? () => {
3424
3485
  if (def && !tracked.has(def) && [
3425
3486
  "type",
@@ -3450,19 +3511,19 @@ var AtscriptDoc = class {
3450
3511
  }
3451
3512
  };
3452
3513
  resolveType();
3453
- if (!def) return undefined;
3514
+ if (!def) return;
3454
3515
  if (isAnnotate(def)) return doc.unwindType(def.targetName, chain, watchCb, tracked);
3455
3516
  for (const item of chain) {
3456
3517
  const itemText = typeof item === "string" ? item : item.text;
3457
- if (!def) return undefined;
3518
+ if (!def) return;
3458
3519
  if (isProp(def)) if (def.nestedProps?.get(itemText)) def = def.nestedProps.get(itemText);
3459
- else {
3520
+ else {
3460
3521
  def = def.nestedType;
3461
3522
  resolveRef();
3462
3523
  resolveType();
3463
3524
  if (isStructure(def) || isInterface(def)) def = def.props.get(itemText);
3464
3525
  }
3465
- else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.props.get(itemText);
3526
+ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.props.get(itemText);
3466
3527
  }
3467
3528
  if (_tracked) callCb();
3468
3529
  while (isProp(def)) {
@@ -3475,7 +3536,7 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
3475
3536
  def,
3476
3537
  doc,
3477
3538
  node
3478
- } : undefined;
3539
+ } : void 0;
3479
3540
  }
3480
3541
  getUsageListAt(line, character) {
3481
3542
  const token = this.tokensIndex.at(line, character);
@@ -3485,7 +3546,7 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
3485
3546
  let right = givenNode.annotations;
3486
3547
  let def = givenNode.getDefinition();
3487
3548
  if (def) {
3488
- const refDef = isRef(def) ? def : undefined;
3549
+ const refDef = isRef(def) ? def : void 0;
3489
3550
  if (refDef) {
3490
3551
  const chainNodes = [];
3491
3552
  const unwound = this.unwindType(refDef.token("identifier").text, refDef.chain, (intermediate) => {
@@ -3507,20 +3568,20 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
3507
3568
  * when folding annotations across a ref boundary. Annotations without a
3508
3569
  * resolvable spec pass through (default is to inherit). Returns the input
3509
3570
  * array unchanged when nothing is dropped.
3510
- */ filterPassedWhenReferred(annotations$1) {
3511
- if (!annotations$1?.length) return annotations$1;
3571
+ */ filterPassedWhenReferred(annotations) {
3572
+ if (!annotations?.length) return annotations;
3512
3573
  let filtered;
3513
- 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));
3514
- else filtered?.push(annotations$1[i]);
3515
- return filtered ?? annotations$1;
3574
+ for (let i = 0; i < annotations.length; i++) if (this.resolveAnnotation(annotations[i].name)?.config.passedWhenReferred === false) filtered ?? (filtered = annotations.slice(0, i));
3575
+ else filtered?.push(annotations[i]);
3576
+ return filtered ?? annotations;
3516
3577
  }
3517
3578
  /**
3518
3579
  * If the position falls inside an `annotate` block, returns that block's node
3519
3580
  * (whose `targetName` is the annotated interface). Entry refs within the block
3520
3581
  * resolve through the target interface rather than as top-level definitions.
3521
3582
  */ annotateBlockAt(line, character) {
3522
- const block$2 = this.blocksIndex.at(line, character);
3523
- return block$2?.blockType === "annotate" && isAnnotate(block$2.parentNode) ? block$2.parentNode : undefined;
3583
+ const block = this.blocksIndex.at(line, character);
3584
+ return block?.blockType === "annotate" && isAnnotate(block.parentNode) ? block.parentNode : void 0;
3524
3585
  }
3525
3586
  /**
3526
3587
  * Collects ad-hoc annotations from all `annotate` blocks targeting a given type/interface.
@@ -3528,11 +3589,11 @@ else filtered?.push(annotations$1[i]);
3528
3589
  * For entries without a chain (root-level), the key is the entry identifier.
3529
3590
  */ getAnnotateNodesFor(targetName) {
3530
3591
  if (!this._annotateNodesByTarget) {
3531
- const index = new Map();
3592
+ const index = /* @__PURE__ */ new Map();
3532
3593
  for (const node of this.nodes) if (isAnnotate(node)) {
3533
3594
  const existing = index.get(node.targetName);
3534
3595
  if (existing) existing.push(node);
3535
- else index.set(node.targetName, [node]);
3596
+ else index.set(node.targetName, [node]);
3536
3597
  }
3537
3598
  this._annotateNodesByTarget = index;
3538
3599
  }
@@ -3551,9 +3612,9 @@ else index.set(node.targetName, [node]);
3551
3612
  * the child's file apply to grandparent-inherited fields, even when the chain crosses
3552
3613
  * package boundaries (child → mid → grandparent, all in different .as files).
3553
3614
  */ resolveInterfaceExtends(node, _visited, _originDoc) {
3554
- if (!node.hasExtends) return undefined;
3555
- const visited = _visited || new Set();
3556
- if (node.id && visited.has(node.id)) return undefined;
3615
+ if (!node.hasExtends) return;
3616
+ const visited = _visited || /* @__PURE__ */ new Set();
3617
+ if (node.id && visited.has(node.id)) return;
3557
3618
  if (node.id) visited.add(node.id);
3558
3619
  const originDoc = _originDoc ?? this;
3559
3620
  let mergedStruct;
@@ -3562,10 +3623,8 @@ else index.set(node.targetName, [node]);
3562
3623
  if (!unwound?.def) continue;
3563
3624
  let parentDef = unwound.def;
3564
3625
  const parentDeclName = unwound.node?.id ?? parentDef.id;
3565
- if (isInterface(parentDef) && parentDef.hasExtends) {
3566
- const resolved = unwound.doc.resolveInterfaceExtends(parentDef, visited, originDoc);
3567
- parentDef = resolved || parentDef.getDefinition() || parentDef;
3568
- } else if (isInterface(parentDef)) parentDef = parentDef.getDefinition() || parentDef;
3626
+ if (isInterface(parentDef) && parentDef.hasExtends) parentDef = unwound.doc.resolveInterfaceExtends(parentDef, visited, originDoc) || parentDef.getDefinition() || parentDef;
3627
+ else if (isInterface(parentDef)) parentDef = parentDef.getDefinition() || parentDef;
3569
3628
  parentDef = this.mergeIntersection(parentDef);
3570
3629
  const annotateNodes = [];
3571
3630
  const collect = (doc, name) => {
@@ -3577,16 +3636,10 @@ else index.set(node.targetName, [node]);
3577
3636
  if (originDoc !== this && originDoc !== unwound.doc) collect(originDoc, parentDeclName);
3578
3637
  if (annotateNodes.length > 0) parentDef = this.applyAnnotateBlocksToStructure(parentDef, annotateNodes);
3579
3638
  if (!mergedStruct) mergedStruct = parentDef;
3580
- else {
3581
- const merged = this.mergeDefs(mergedStruct, parentDef);
3582
- mergedStruct = merged[0];
3583
- }
3639
+ else mergedStruct = this.mergeDefs(mergedStruct, parentDef)[0];
3584
3640
  }
3585
3641
  const ownDef = node.getDefinition();
3586
- if (ownDef && mergedStruct) {
3587
- const merged = this.mergeDefs(mergedStruct, ownDef);
3588
- return merged[0];
3589
- }
3642
+ if (ownDef && mergedStruct) return this.mergeDefs(mergedStruct, ownDef)[0];
3590
3643
  return mergedStruct || ownDef;
3591
3644
  }
3592
3645
  /**
@@ -3617,19 +3670,19 @@ else {
3617
3670
  * prop. Returns a new structure with cloned props/structures along touched paths, or
3618
3671
  * `undefined` when nothing matched (so callers can reuse the original by reference).
3619
3672
  */ foldAnnotationsIntoStructure(struct, entries) {
3620
- const byHead = new Map();
3673
+ const byHead = /* @__PURE__ */ new Map();
3621
3674
  for (const entry of entries) {
3622
3675
  const head = entry.parts[0];
3623
- let group$1 = byHead.get(head);
3624
- if (!group$1) {
3625
- group$1 = {
3676
+ let group = byHead.get(head);
3677
+ if (!group) {
3678
+ group = {
3626
3679
  own: [],
3627
3680
  nested: []
3628
3681
  };
3629
- byHead.set(head, group$1);
3682
+ byHead.set(head, group);
3630
3683
  }
3631
- if (entry.parts.length === 1) group$1.own.push(...entry.anns);
3632
- else group$1.nested.push({
3684
+ if (entry.parts.length === 1) group.own.push(...entry.anns);
3685
+ else group.nested.push({
3633
3686
  parts: entry.parts.slice(1),
3634
3687
  anns: entry.anns
3635
3688
  });
@@ -3637,18 +3690,18 @@ else group$1.nested.push({
3637
3690
  const newProps = [];
3638
3691
  let changed = false;
3639
3692
  for (const [name, prop] of struct.props) {
3640
- const group$1 = byHead.get(name);
3641
- if (!group$1) {
3693
+ const group = byHead.get(name);
3694
+ if (!group) {
3642
3695
  newProps.push(prop);
3643
3696
  continue;
3644
3697
  }
3645
3698
  const propDef = prop.getDefinition();
3646
3699
  let newDef = propDef;
3647
- if (group$1.nested.length > 0 && propDef && isStructure(propDef)) {
3648
- const foldedNested = this.foldAnnotationsIntoStructure(propDef, group$1.nested);
3700
+ if (group.nested.length > 0 && propDef && isStructure(propDef)) {
3701
+ const foldedNested = this.foldAnnotationsIntoStructure(propDef, group.nested);
3649
3702
  if (foldedNested) newDef = foldedNested;
3650
3703
  }
3651
- if (group$1.own.length === 0 && newDef === propDef) {
3704
+ if (group.own.length === 0 && newDef === propDef) {
3652
3705
  newProps.push(prop);
3653
3706
  continue;
3654
3707
  }
@@ -3656,13 +3709,13 @@ else group$1.nested.push({
3656
3709
  const idToken = prop.token("identifier");
3657
3710
  if (idToken) cloned.saveToken(idToken, "identifier");
3658
3711
  if (newDef) cloned.define(newDef);
3659
- cloned.annotations = group$1.own.length > 0 ? this.mergeNodesAnnotations(prop.annotations, group$1.own) : prop.annotations;
3712
+ cloned.annotations = group.own.length > 0 ? this.mergeNodesAnnotations(prop.annotations, group.own) : prop.annotations;
3660
3713
  const optionalToken = prop.token("optional");
3661
3714
  if (optionalToken) cloned.saveToken(optionalToken, "optional");
3662
3715
  newProps.push(cloned);
3663
3716
  changed = true;
3664
3717
  }
3665
- if (!changed) return undefined;
3718
+ if (!changed) return;
3666
3719
  const newStruct = new SemanticStructureNode();
3667
3720
  newStruct.setProps(newProps);
3668
3721
  newStruct.annotations = struct.annotations;
@@ -3675,9 +3728,8 @@ else group$1.nested.push({
3675
3728
  range: r.range,
3676
3729
  token: r
3677
3730
  }));
3678
- if (token.exported) for (const d of this.dependants) {
3679
- const imp = d.imports.get(this.id);
3680
- if (imp?.imports.find((t) => t.text === token.text)) refs.push(...d.referred.filter((t) => t.text === token.text).map((r) => ({
3731
+ if (token.exported) {
3732
+ 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) => ({
3681
3733
  uri: d.id,
3682
3734
  range: r.range,
3683
3735
  token: r
@@ -3686,20 +3738,20 @@ else group$1.nested.push({
3686
3738
  return refs;
3687
3739
  }
3688
3740
  if (isProp(token.parentNode)) {
3689
- const propName$1 = token.parentNode.id;
3690
- if (!propName$1) return undefined;
3741
+ const propName = token.parentNode.id;
3742
+ if (!propName) return;
3691
3743
  let parentName;
3692
- for (const node of this.nodes) if ((isInterface(node) || isStructure(node)) && node.props.get(propName$1) === token.parentNode) {
3744
+ for (const node of this.nodes) if ((isInterface(node) || isStructure(node)) && node.props.get(propName) === token.parentNode) {
3693
3745
  parentName = node.id;
3694
3746
  break;
3695
3747
  }
3696
- if (!parentName) return undefined;
3748
+ if (!parentName) return;
3697
3749
  const refs = [];
3698
3750
  const searchDoc = (doc, uri) => {
3699
3751
  for (const t of doc.referred) {
3700
3752
  if (t.text !== parentName || !isRef(t.parentNode) || !t.parentNode.hasChain) continue;
3701
3753
  const chainToken = t.parentNode.chain[0];
3702
- if (chainToken?.text === propName$1) refs.push({
3754
+ if (chainToken?.text === propName) refs.push({
3703
3755
  uri,
3704
3756
  range: chainToken.range,
3705
3757
  token: chainToken
@@ -3707,7 +3759,7 @@ else group$1.nested.push({
3707
3759
  }
3708
3760
  for (const node of doc.nodes) {
3709
3761
  if (!isAnnotate(node) || node.targetName !== parentName) continue;
3710
- for (const entry of node.entries) if (entry.id === propName$1) {
3762
+ for (const entry of node.entries) if (entry.id === propName) {
3711
3763
  const entryToken = entry.token("identifier");
3712
3764
  if (entryToken) refs.push({
3713
3765
  uri,
@@ -3717,11 +3769,10 @@ else group$1.nested.push({
3717
3769
  }
3718
3770
  }
3719
3771
  for (const qfr of doc.queryFieldRefs) {
3720
- if (!qfr.queryArgToken || qfr.fieldRef.text !== propName$1) continue;
3772
+ if (!qfr.queryArgToken || qfr.fieldRef.text !== propName) continue;
3721
3773
  const scope = getQueryScope(qfr.queryArgToken, doc);
3722
3774
  if (!scope) continue;
3723
- const resolvedTypeName = qfr.typeRef?.text ?? scope.unqualifiedTarget;
3724
- if (resolvedTypeName === parentName) refs.push({
3775
+ if ((qfr.typeRef?.text ?? scope.unqualifiedTarget) === parentName) refs.push({
3725
3776
  uri,
3726
3777
  range: qfr.fieldRef.range,
3727
3778
  token: qfr.fieldRef
@@ -3729,13 +3780,9 @@ else group$1.nested.push({
3729
3780
  }
3730
3781
  };
3731
3782
  searchDoc(this, this.id);
3732
- const parentDefToken = this.registry.definitions.get(parentName);
3733
- if (parentDefToken?.exported) {
3783
+ if (this.registry.definitions.get(parentName)?.exported) {
3734
3784
  const targetName = parentName;
3735
- for (const d of this.dependants) {
3736
- const imp = d.imports.get(this.id);
3737
- if (imp?.imports.find((t) => t.text === targetName)) searchDoc(d, d.id);
3738
- }
3785
+ for (const d of this.dependants) if (d.imports.get(this.id)?.imports.find((t) => t.text === targetName)) searchDoc(d, d.id);
3739
3786
  }
3740
3787
  return refs;
3741
3788
  }
@@ -3752,13 +3799,12 @@ else group$1.nested.push({
3752
3799
  }
3753
3800
  }
3754
3801
  }
3755
- return undefined;
3802
+ return;
3756
3803
  }
3757
3804
  {
3758
3805
  const defForToken = this.getDefinitionFor(token);
3759
3806
  if (defForToken?.token?.isDefinition && defForToken.doc) return defForToken.doc.usageListFor(defForToken.token);
3760
3807
  }
3761
- return undefined;
3762
3808
  }
3763
3809
  /**
3764
3810
  * Retrieves the definition (i.e., the “go to definition” target) for a given token.
@@ -3799,7 +3845,7 @@ else group$1.nested.push({
3799
3845
  uri: targetDoc.id,
3800
3846
  doc: targetDoc,
3801
3847
  token: target
3802
- } : undefined;
3848
+ } : void 0;
3803
3849
  }
3804
3850
  }
3805
3851
  if (token.isReference) {
@@ -3808,7 +3854,7 @@ else group$1.nested.push({
3808
3854
  uri: this.id,
3809
3855
  doc: this,
3810
3856
  token: def
3811
- } : undefined;
3857
+ } : void 0;
3812
3858
  }
3813
3859
  }
3814
3860
  getToDefinitionAt(line, character) {
@@ -3826,7 +3872,7 @@ else group$1.nested.push({
3826
3872
  targetSelectionRange: unwound.node.token("identifier")?.range ?? zeroRange,
3827
3873
  originSelectionRange: token.range
3828
3874
  }];
3829
- return undefined;
3875
+ return;
3830
3876
  }
3831
3877
  if (isQueryFieldRef(token.parentNode)) {
3832
3878
  const fieldRefNode = token.parentNode;
@@ -3841,7 +3887,7 @@ else group$1.nested.push({
3841
3887
  targetRange: result.token?.range ?? zeroRange,
3842
3888
  targetSelectionRange: result.token?.range ?? zeroRange,
3843
3889
  originSelectionRange: token.range
3844
- }] : undefined;
3890
+ }] : void 0;
3845
3891
  }
3846
3892
  if (token === fieldRefNode.fieldRef) {
3847
3893
  const resolved = resolveQueryFieldRef(fieldRefNode, this, scope);
@@ -3857,7 +3903,7 @@ else group$1.nested.push({
3857
3903
  }
3858
3904
  }
3859
3905
  }
3860
- return undefined;
3906
+ return;
3861
3907
  }
3862
3908
  if (isProp(token.parentNode)) return [{
3863
3909
  targetUri: this.id,
@@ -3881,19 +3927,19 @@ else group$1.nested.push({
3881
3927
  targetRange: result.token?.range ?? zeroRange,
3882
3928
  targetSelectionRange: result.token?.range ?? zeroRange,
3883
3929
  originSelectionRange: token.range
3884
- }] : undefined;
3930
+ }] : void 0;
3885
3931
  }
3886
3932
  }
3887
3933
  }
3888
- registerImport({ from, imports, block: block$2 }) {
3934
+ registerImport({ from, imports, block }) {
3889
3935
  const importId = resolveAtscriptFromPath(from.text, this.id);
3890
3936
  this.imports.set(importId, {
3891
3937
  from,
3892
3938
  imports
3893
3939
  });
3894
- this.blocksIndex.add(block$2);
3895
- block$2.blockType = "import";
3896
- block$2.fromPath = from.text;
3940
+ this.blocksIndex.add(block);
3941
+ block.blockType = "import";
3942
+ block.fromPath = from.text;
3897
3943
  this.tokensIndex.add(from);
3898
3944
  from.fromPath = from.text;
3899
3945
  imports.forEach((t) => {
@@ -3933,27 +3979,26 @@ else group$1.nested.push({
3933
3979
  * - `token`: The specific token for the declaration (if applicable).
3934
3980
  *
3935
3981
  * If no declaration is found, returns `undefined`.
3936
- */ getDeclarationOwnerNode(identifier$1) {
3937
- if (this.config.primitives?.has(identifier$1)) return {
3982
+ */ getDeclarationOwnerNode(identifier) {
3983
+ if (this.config.primitives?.has(identifier)) return {
3938
3984
  doc: this,
3939
- node: this.config.primitives.get(identifier$1)
3985
+ node: this.config.primitives.get(identifier)
3940
3986
  };
3941
- const def = this.registry.definitions.get(identifier$1);
3987
+ const def = this.registry.definitions.get(identifier);
3942
3988
  if (def?.imported && def.fromPath) {
3943
3989
  const absolutePath = this.resolveImportId(resolveAtscriptFromPath(def.fromPath, this.id));
3944
- const doc = this.dependenciesMap.get(absolutePath);
3945
- return doc?.getDeclarationOwnerNode(identifier$1);
3990
+ return this.dependenciesMap.get(absolutePath)?.getDeclarationOwnerNode(identifier);
3946
3991
  } else if (!def?.imported) return def ? {
3947
3992
  doc: this,
3948
3993
  node: def.parentNode,
3949
3994
  token: def
3950
- } : undefined;
3995
+ } : void 0;
3951
3996
  }
3952
3997
  registerExport(node) {
3953
3998
  if (node.id) this.exports.set(node.id, node);
3954
3999
  }
3955
4000
  registerMessage(token, message, severity = 1, tag) {
3956
- if (this._allMessages) this._allMessages = undefined;
4001
+ if (this._allMessages) this._allMessages = void 0;
3957
4002
  this.messages.push({
3958
4003
  severity,
3959
4004
  message,
@@ -3965,13 +4010,13 @@ else group$1.nested.push({
3965
4010
  if (messages) this.messages.push(...messages);
3966
4011
  }
3967
4012
  clearMessages() {
3968
- this._allMessages = undefined;
4013
+ this._allMessages = void 0;
3969
4014
  }
3970
4015
  getUnusedTokens() {
3971
4016
  const refSet = new Set(this.referred.filter((r) => !r.imported).map((r) => r.text));
3972
- const tokens$1 = [];
3973
- for (const [key, token] of this.registry.definitions) if (!refSet.has(key) && !this.exports.has(key)) tokens$1.push(token);
3974
- return tokens$1;
4017
+ const tokens = [];
4018
+ for (const [key, token] of this.registry.definitions) if (!refSet.has(key) && !this.exports.has(key)) tokens.push(token);
4019
+ return tokens;
3975
4020
  }
3976
4021
  renderDiagMessage(m, addSourceLinses = false, colors = false) {
3977
4022
  const c = {
@@ -3985,30 +4030,26 @@ else group$1.nested.push({
3985
4030
  let sc = "";
3986
4031
  let banner = "[atscript]";
3987
4032
  switch (m.severity) {
3988
- case TSeverity.Error: {
4033
+ case TSeverity.Error:
3989
4034
  sc = c.red;
3990
4035
  banner += "[Error]";
3991
4036
  break;
3992
- }
3993
- case TSeverity.Warning: {
4037
+ case TSeverity.Warning:
3994
4038
  sc = c.yellow;
3995
4039
  banner += "[Warning]";
3996
4040
  break;
3997
- }
3998
- case TSeverity.Info: {
4041
+ case TSeverity.Info:
3999
4042
  sc = "";
4000
4043
  banner += "[Info]";
4001
4044
  break;
4002
- }
4003
- case TSeverity.Hint: {
4045
+ case TSeverity.Hint:
4004
4046
  sc = c.dim;
4005
4047
  banner += "[Hint]";
4006
4048
  break;
4007
- }
4008
4049
  default: sc = "";
4009
4050
  }
4010
4051
  const n = m.range.start.line + 1;
4011
- let out = `\n${sc}${banner} ${m.message}${c.reset}` + `\nin ${c.blue}${this.id}:${n}:${m.range.start.character + 1}${c.reset}`;
4052
+ let out = `\n${sc}${banner} ${m.message}${c.reset}\nin ${c.blue}${this.id}:${n}:${m.range.start.character + 1}${c.reset}`;
4012
4053
  if (addSourceLinses) {
4013
4054
  const lines = this.text.split("\n");
4014
4055
  const renderLines = [
@@ -4024,7 +4065,7 @@ else group$1.nested.push({
4024
4065
  l: lines[n - 1],
4025
4066
  i: n - 1
4026
4067
  }
4027
- ].filter((r) => r.l !== undefined);
4068
+ ].filter((r) => r.l !== void 0);
4028
4069
  const nl = String(n).length + 1;
4029
4070
  for (const { l, i } of renderLines) {
4030
4071
  const prefix = `${c.dim + c.cyan}${`0${i}`.slice(-nl)} | ${c.reset}`;
@@ -4050,7 +4091,7 @@ else group$1.nested.push({
4050
4091
  });
4051
4092
  const ownDef = iface.getDefinition();
4052
4093
  if (ownDef && isStructure(ownDef)) {
4053
- const parentProps = new Map();
4094
+ const parentProps = /* @__PURE__ */ new Map();
4054
4095
  for (const t of iface.extendsTokens) {
4055
4096
  if (t.text === iface.id) continue;
4056
4097
  const unwound = this.unwindType(t.text);
@@ -4088,8 +4129,7 @@ else group$1.nested.push({
4088
4129
  if (!this.registry.isDefined(targetName)) continue;
4089
4130
  const chain = isRef(t.parentNode) && t.parentNode.hasChain ? [t.text, ...t.parentNode.chain.map((c) => c.text)] : [t.text];
4090
4131
  const unwound = this.unwindType(targetName, chain);
4091
- const chainResolved = unwound?.def && !isGroup(unwound.def);
4092
- const resolvedType = chainResolved ? unwound.def : this.resolveChainWithMerge(targetName, chain);
4132
+ const resolvedType = unwound?.def && !isGroup(unwound.def) ? unwound.def : this.resolveChainWithMerge(targetName, chain);
4093
4133
  if (!resolvedType) {
4094
4134
  const lastToken = chain.length > 1 && isRef(t.parentNode) ? t.parentNode.chain[t.parentNode.chain.length - 1] || t : t;
4095
4135
  this._allMessages.push({
@@ -4103,8 +4143,7 @@ else group$1.nested.push({
4103
4143
  const token = t.parentNode.chain[i];
4104
4144
  const memberChain = [t.text, ...t.parentNode.chain.slice(0, i + 1).map((c) => c.text)];
4105
4145
  const decl = this.unwindType(targetName, memberChain);
4106
- const memberResolved = decl?.def && !isGroup(decl.def);
4107
- if (!memberResolved && !this.resolveChainWithMerge(targetName, memberChain)) this._allMessages.push({
4146
+ if (!(decl?.def && !isGroup(decl.def)) && !this.resolveChainWithMerge(targetName, memberChain)) this._allMessages.push({
4108
4147
  severity: 1,
4109
4148
  message: `Unknown property "${memberChain.join(".")}" in "${targetName}"`,
4110
4149
  range: token.range
@@ -4112,8 +4151,7 @@ else group$1.nested.push({
4112
4151
  }
4113
4152
  }
4114
4153
  if (resolvedType && isRef(t.parentNode) && t.parentNode.annotations) for (const a of t.parentNode.annotations) {
4115
- const spec = this.resolveAnnotation(a.token.text.slice(1));
4116
- const msgs = spec?.validateTargetType(resolvedType, a.token.range);
4154
+ const msgs = this.resolveAnnotation(a.token.text.slice(1))?.validateTargetType(resolvedType, a.token.range);
4117
4155
  if (msgs) this._allMessages.push(...msgs);
4118
4156
  }
4119
4157
  continue;
@@ -4145,8 +4183,7 @@ else group$1.nested.push({
4145
4183
  const length = t.parentNode.chain.length - 1;
4146
4184
  for (let i = length; i >= 0; i--) {
4147
4185
  const token = t.parentNode.chain[i];
4148
- const decl = this.unwindType(t.parentNode.id, t.parentNode.chain.slice(0, i + 1));
4149
- if (!decl?.def) this._allMessages.push({
4186
+ if (!this.unwindType(t.parentNode.id, t.parentNode.chain.slice(0, i + 1))?.def) this._allMessages.push({
4150
4187
  severity: 1,
4151
4188
  message: `Unknown member "${token.text}"`,
4152
4189
  range: token.range
@@ -4172,7 +4209,7 @@ else group$1.nested.push({
4172
4209
  * only need a yes/no resolution check use the truthiness of the result.
4173
4210
  */ resolveChainWithMerge(targetName, chain) {
4174
4211
  let def = this.unwindType(targetName)?.def;
4175
- if (!def) return undefined;
4212
+ if (!def) return;
4176
4213
  for (const prop of chain) {
4177
4214
  def = this.mergeIntersection(def);
4178
4215
  if (isProp(def)) {
@@ -4181,30 +4218,29 @@ else group$1.nested.push({
4181
4218
  }
4182
4219
  if (isStructure(def) || isInterface(def)) {
4183
4220
  const next = def.props.get(prop);
4184
- if (!next) return undefined;
4221
+ if (!next) return;
4185
4222
  def = next.getDefinition() || next;
4186
4223
  } else if (isGroup(def)) {
4187
4224
  const found = this.findPropInGroup(def, prop);
4188
- if (!found) return undefined;
4225
+ if (!found) return;
4189
4226
  def = found;
4190
- } else return undefined;
4227
+ } else return;
4191
4228
  }
4192
4229
  if (isRef(def)) def = this.unwindType(def.id, def.chain)?.def || def;
4193
4230
  return def;
4194
4231
  }
4195
- findPropInGroup(group$1, propName$1) {
4196
- for (const item of group$1.unwrap()) {
4232
+ findPropInGroup(group, propName) {
4233
+ for (const item of group.unwrap()) {
4197
4234
  const merged = this.mergeIntersection(item);
4198
4235
  if (isStructure(merged) || isInterface(merged)) {
4199
- const prop = merged.props.get(propName$1);
4236
+ const prop = merged.props.get(propName);
4200
4237
  if (prop) return prop.getDefinition() || prop;
4201
4238
  }
4202
4239
  if (isGroup(merged)) {
4203
- const found = this.findPropInGroup(merged, propName$1);
4240
+ const found = this.findPropInGroup(merged, propName);
4204
4241
  if (found) return found;
4205
4242
  }
4206
4243
  }
4207
- return undefined;
4208
4244
  }
4209
4245
  mergeIntersection(node) {
4210
4246
  if (!isGroup(node)) return node;
@@ -4223,10 +4259,8 @@ else group$1.nested.push({
4223
4259
  } else left = merged[0];
4224
4260
  }
4225
4261
  newGroup.push(left);
4226
- if (newGroup.length > 1) {
4227
- const newNode = new SemanticGroup(newGroup, "&");
4228
- return newNode;
4229
- } else return newGroup[0];
4262
+ if (newGroup.length > 1) return new SemanticGroup(newGroup, "&");
4263
+ else return newGroup[0];
4230
4264
  }
4231
4265
  mergeDefs(_left, _right) {
4232
4266
  let left = _left;
@@ -4260,7 +4294,7 @@ else group$1.nested.push({
4260
4294
  const oldProps = [leftProp, rightProp].filter(Boolean);
4261
4295
  let optionalToken = oldProps[0]?.token("optional");
4262
4296
  for (const oldProp of oldProps) if (!oldProp.token("optional")) {
4263
- optionalToken = undefined;
4297
+ optionalToken = void 0;
4264
4298
  break;
4265
4299
  }
4266
4300
  if (optionalToken) prop.saveToken(optionalToken, "optional");
@@ -4285,18 +4319,17 @@ else group$1.nested.push({
4285
4319
  * @param right - An optional array of annotation tokens to merge (higher priority).
4286
4320
  * @returns A merged array of annotation tokens, preserving order while preventing duplicates.
4287
4321
  */ mergeNodesAnnotations(left, right) {
4288
- const annotations$1 = [];
4289
- const savedAnnotations = new Set();
4322
+ const annotations = [];
4323
+ const savedAnnotations = /* @__PURE__ */ new Set();
4290
4324
  for (const a of right || []) {
4291
- annotations$1.push(a);
4325
+ annotations.push(a);
4292
4326
  savedAnnotations.add(a.name);
4293
4327
  }
4294
4328
  for (const a of left || []) {
4295
4329
  const spec = this.resolveAnnotation(a.name);
4296
- const append = spec && spec.config.multiple && spec.config.mergeStrategy === "append";
4297
- if (append || !savedAnnotations.has(a.name)) annotations$1.push(a);
4330
+ if (spec && spec.config.multiple && spec.config.mergeStrategy === "append" || !savedAnnotations.has(a.name)) annotations.push(a);
4298
4331
  }
4299
- return annotations$1;
4332
+ return annotations;
4300
4333
  }
4301
4334
  constructor(id, config, manager) {
4302
4335
  _define_property$3(this, "id", void 0);
@@ -4354,22 +4387,22 @@ else group$1.nested.push({
4354
4387
  this.messages = [];
4355
4388
  this.tokensIndex = new TokensIndex();
4356
4389
  this.blocksIndex = new BlocksIndex();
4357
- this.imports = new Map();
4358
- this.resolvedImports = new Map();
4359
- this.importedDefs = new Map();
4360
- this.exports = new Map();
4361
- this.dependencies = new Set();
4362
- this.dependants = new Set();
4390
+ this.imports = /* @__PURE__ */ new Map();
4391
+ this.resolvedImports = /* @__PURE__ */ new Map();
4392
+ this.importedDefs = /* @__PURE__ */ new Map();
4393
+ this.exports = /* @__PURE__ */ new Map();
4394
+ this.dependencies = /* @__PURE__ */ new Set();
4395
+ this.dependants = /* @__PURE__ */ new Set();
4363
4396
  this.referred = [];
4364
4397
  this.queryFieldRefs = [];
4365
- this.dependenciesMap = new Map();
4366
- this._annotationSpecCache = new Map();
4398
+ this.dependenciesMap = /* @__PURE__ */ new Map();
4399
+ this._annotationSpecCache = /* @__PURE__ */ new Map();
4367
4400
  this.nodes = [];
4368
4401
  this._text = "";
4369
4402
  this.resolvedAnnotations = [];
4370
4403
  this.annotations = [];
4371
4404
  this._nextTypeId = 0;
4372
- this._allMessages = undefined;
4405
+ this._allMessages = void 0;
4373
4406
  this.registry = new IdRegistry(Array.from(config.primitives?.keys() || []));
4374
4407
  }
4375
4408
  };
@@ -4384,13 +4417,13 @@ const zeroRange = {
4384
4417
  }
4385
4418
  };
4386
4419
  function createSyntheticRef(name) {
4387
- const ref$1 = new SemanticRefNode();
4388
- ref$1.saveToken(new Token({
4420
+ const ref = new SemanticRefNode();
4421
+ ref.saveToken(new Token({
4389
4422
  text: name,
4390
4423
  type: "identifier",
4391
4424
  getRange: () => zeroRange
4392
4425
  }), "identifier");
4393
- return ref$1;
4426
+ return ref;
4394
4427
  }
4395
4428
 
4396
4429
  //#endregion
@@ -4584,13 +4617,13 @@ const expectAnnotations = {
4584
4617
  validate(token, args, doc) {
4585
4618
  const field = token.parentNode;
4586
4619
  const errors = [];
4587
- const definition$1 = field.getDefinition();
4588
- if (!definition$1) return errors;
4620
+ const definition = field.getDefinition();
4621
+ if (!definition) return errors;
4589
4622
  let wrongType = false;
4590
- if (isRef(definition$1)) {
4591
- const def = doc.unwindType(definition$1.id, definition$1.chain)?.def;
4623
+ if (isRef(definition)) {
4624
+ const def = doc.unwindType(definition.id, definition.chain)?.def;
4592
4625
  if (!isArray(def)) wrongType = true;
4593
- } else if (!isArray(definition$1)) wrongType = true;
4626
+ } else if (!isArray(definition)) wrongType = true;
4594
4627
  if (wrongType) errors.push({
4595
4628
  message: `@expect.array.uniqueItems requires an array field`,
4596
4629
  severity: 1,
@@ -4612,17 +4645,16 @@ const expectAnnotations = {
4612
4645
  validate(token, args, doc) {
4613
4646
  const field = token.parentNode;
4614
4647
  const errors = [];
4615
- const isOptional = !!field.token("optional");
4616
- if (isOptional) errors.push({
4648
+ if (!!field.token("optional")) errors.push({
4617
4649
  message: `@expect.array.key can't be optional`,
4618
4650
  severity: 1,
4619
4651
  range: field.token("identifier").range
4620
4652
  });
4621
- const definition$1 = field.getDefinition();
4622
- if (!definition$1) return errors;
4653
+ const definition = field.getDefinition();
4654
+ if (!definition) return errors;
4623
4655
  let wrongType = false;
4624
- if (isRef(definition$1)) {
4625
- const def = doc.unwindType(definition$1.id, definition$1.chain)?.def;
4656
+ if (isRef(definition)) {
4657
+ const def = doc.unwindType(definition.id, definition.chain)?.def;
4626
4658
  if (isPrimitive(def) && !["string", "number"].includes(def.config.type)) wrongType = true;
4627
4659
  } else wrongType = true;
4628
4660
  if (wrongType) errors.push({
@@ -4716,17 +4748,15 @@ const metaAnnotations = {
4716
4748
  //#region packages/core/src/defaults/primitives.ts
4717
4749
  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)$";
4718
4750
  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}|:))$";
4719
- const positive = {
4720
- documentation: "Number that greater than or equal to zero.",
4721
- annotations: { "expect.min": 0 }
4722
- };
4723
- const negative = {
4724
- documentation: "Number that less than or equal to zero.",
4725
- annotations: { "expect.max": 0 }
4726
- };
4727
4751
  const positiveOrNegative = {
4728
- positive,
4729
- negative
4752
+ positive: {
4753
+ documentation: "Number that greater than or equal to zero.",
4754
+ annotations: { "expect.min": 0 }
4755
+ },
4756
+ negative: {
4757
+ documentation: "Number that less than or equal to zero.",
4758
+ annotations: { "expect.max": 0 }
4759
+ }
4730
4760
  };
4731
4761
  const primitives = {
4732
4762
  never: { documentation: "Represents impossible type." },
@@ -4959,7 +4989,7 @@ const primitives = {
4959
4989
  //#endregion
4960
4990
  //#region packages/core/src/default-atscript-config.ts
4961
4991
  function getDefaultAtscriptConfig() {
4962
- const defaulTAtscriptConfig = {
4992
+ return {
4963
4993
  primitives,
4964
4994
  annotations: {
4965
4995
  meta: { ...metaAnnotations },
@@ -4967,7 +4997,6 @@ function getDefaultAtscriptConfig() {
4967
4997
  emit: { ...emitAnnotations }
4968
4998
  }
4969
4999
  };
4970
- return defaulTAtscriptConfig;
4971
5000
  }
4972
5001
 
4973
5002
  //#endregion
@@ -4979,7 +5008,7 @@ function _define_property$2(obj, key, value) {
4979
5008
  configurable: true,
4980
5009
  writable: true
4981
5010
  });
4982
- else obj[key] = value;
5011
+ else obj[key] = value;
4983
5012
  return obj;
4984
5013
  }
4985
5014
  var PluginManager = class {
@@ -4991,7 +5020,7 @@ var PluginManager = class {
4991
5020
  const raw = await this.config();
4992
5021
  this._docConfig = {};
4993
5022
  if (raw?.primitives) {
4994
- this._docConfig.primitives = new Map();
5023
+ this._docConfig.primitives = /* @__PURE__ */ new Map();
4995
5024
  for (const [key, value] of Object.entries(raw.primitives)) this._docConfig.primitives.set(key, new SemanticPrimitiveNode(key, value, "", raw.annotations));
4996
5025
  }
4997
5026
  if (raw?.annotations) this._docConfig.annotations = { ...raw.annotations };
@@ -5002,7 +5031,7 @@ var PluginManager = class {
5002
5031
  async config(config = this.cfg) {
5003
5032
  if (!this._config) {
5004
5033
  config = (0, defu.defu)(config, getDefaultAtscriptConfig());
5005
- const seen = new Set();
5034
+ const seen = /* @__PURE__ */ new Set();
5006
5035
  for (const plugin of this.plugins) {
5007
5036
  if (seen.has(plugin.name)) continue;
5008
5037
  seen.add(plugin.name);
@@ -5044,16 +5073,15 @@ var PluginManager = class {
5044
5073
  for (const plugin of this.plugins) if (plugin.buildEnd) await plugin.buildEnd(output, format, repo);
5045
5074
  }
5046
5075
  async loopInAnnotationsSpec(cb) {
5047
- const config = await this.config();
5048
- const annotations$1 = config.annotations || {};
5049
- return this._loopInAnnotationsSpec(annotations$1, cb);
5076
+ const annotations = (await this.config()).annotations || {};
5077
+ return this._loopInAnnotationsSpec(annotations, cb);
5050
5078
  }
5051
- _loopInAnnotationsSpec(annotations$1, cb, prefix) {
5052
- if (annotations$1.$self && prefix) cb(prefix, annotations$1.$self);
5053
- for (const [key, value] of Object.entries(annotations$1)) {
5079
+ _loopInAnnotationsSpec(annotations, cb, prefix) {
5080
+ if (annotations.$self && prefix) cb(prefix, annotations.$self);
5081
+ for (const [key, value] of Object.entries(annotations)) {
5054
5082
  if (key === "$self") continue;
5055
5083
  if (isAnnotationSpec(value)) cb(prefix ? `${prefix}.${key}` : key, value);
5056
- else this._loopInAnnotationsSpec(value, cb, prefix ? `${prefix}.${key}` : key);
5084
+ else this._loopInAnnotationsSpec(value, cb, prefix ? `${prefix}.${key}` : key);
5057
5085
  }
5058
5086
  }
5059
5087
  constructor(cfg) {
@@ -5075,7 +5103,7 @@ function _define_property$1(obj, key, value) {
5075
5103
  configurable: true,
5076
5104
  writable: true
5077
5105
  });
5078
- else obj[key] = value;
5106
+ else obj[key] = value;
5079
5107
  return obj;
5080
5108
  }
5081
5109
  var AtscriptRepo = class {
@@ -5084,12 +5112,12 @@ var AtscriptRepo = class {
5084
5112
  }
5085
5113
  async getPrimitivesTags() {
5086
5114
  const manager = await this.getSharedPluginManager();
5087
- if (!manager) return undefined;
5115
+ if (!manager) return;
5088
5116
  const docConfig = await manager.getDocConfig();
5089
- const primitives$1 = Array.from(docConfig.primitives?.entries() || []);
5117
+ const primitives = Array.from(docConfig.primitives?.entries() || []);
5090
5118
  const tags = [];
5091
- const processed = new Set();
5092
- for (const [, primitive] of primitives$1) tags.push(...primitive.getAllTags(processed));
5119
+ const processed = /* @__PURE__ */ new Set();
5120
+ for (const [, primitive] of primitives) tags.push(...primitive.getAllTags(processed));
5093
5121
  return new Set(tags);
5094
5122
  }
5095
5123
  async getUsedAnnotations() {
@@ -5099,7 +5127,7 @@ var AtscriptRepo = class {
5099
5127
  };
5100
5128
  const mapArgType = (t) => ANNOTATION_TYPE_MAP[t] || t;
5101
5129
  const manager = await this.getSharedPluginManager();
5102
- const annotations$1 = {};
5130
+ const annotations = {};
5103
5131
  if (manager) await manager.loopInAnnotationsSpec((name, spec) => {
5104
5132
  const types = [];
5105
5133
  const multiple = !!spec.config.multiple;
@@ -5117,62 +5145,57 @@ var AtscriptRepo = class {
5117
5145
  type: mapArgType(spec.config.argument.type),
5118
5146
  optional: spec.config.argument.optional
5119
5147
  });
5120
- else types.push({ type: "boolean" });
5121
- annotations$1[name] = {
5148
+ else types.push({ type: "boolean" });
5149
+ annotations[name] = {
5122
5150
  multiple,
5123
5151
  fromSpec: true,
5124
- typeSet: new Set(),
5152
+ typeSet: /* @__PURE__ */ new Set(),
5125
5153
  types
5126
5154
  };
5127
5155
  });
5128
5156
  for (const doc of Array.from(this.atscripts.values())) {
5129
5157
  const awaited = await doc;
5130
5158
  for (const { name, token, args } of awaited.annotations) {
5131
- if (annotations$1[name]?.fromSpec) continue;
5132
- if (!annotations$1[name]) {
5133
- const types = [];
5134
- const multiple = false;
5135
- annotations$1[name] = {
5136
- multiple,
5137
- fromSpec: false,
5138
- typeSet: new Set(),
5139
- types
5140
- };
5141
- }
5142
- const isArray$1 = token.parentNode.countAnnotations(name) > 1;
5143
- if (isArray$1) annotations$1[name].multiple = true;
5159
+ if (annotations[name]?.fromSpec) continue;
5160
+ if (!annotations[name]) annotations[name] = {
5161
+ multiple: false,
5162
+ fromSpec: false,
5163
+ typeSet: /* @__PURE__ */ new Set(),
5164
+ types: []
5165
+ };
5166
+ if (token.parentNode.countAnnotations(name) > 1) annotations[name].multiple = true;
5144
5167
  for (const arg of args) if (arg.type === "text") {
5145
- if (!annotations$1[name].typeSet.has("string")) {
5146
- annotations$1[name].typeSet.add("string");
5147
- annotations$1[name].types.push({ type: "string" });
5168
+ if (!annotations[name].typeSet.has("string")) {
5169
+ annotations[name].typeSet.add("string");
5170
+ annotations[name].types.push({ type: "string" });
5148
5171
  }
5149
5172
  } else if (arg.type === "number") {
5150
- if (!annotations$1[name].typeSet.has("number")) {
5151
- annotations$1[name].typeSet.add("number");
5152
- annotations$1[name].types.push({ type: "number" });
5173
+ if (!annotations[name].typeSet.has("number")) {
5174
+ annotations[name].typeSet.add("number");
5175
+ annotations[name].types.push({ type: "number" });
5153
5176
  }
5154
5177
  } else if (arg.type === "identifier" && ["true", "false"].includes(arg.text)) {
5155
- if (!annotations$1[name].typeSet.has("boolean")) {
5156
- annotations$1[name].typeSet.add("boolean");
5157
- annotations$1[name].types.push({ type: "boolean" });
5178
+ if (!annotations[name].typeSet.has("boolean")) {
5179
+ annotations[name].typeSet.add("boolean");
5180
+ annotations[name].types.push({ type: "boolean" });
5158
5181
  }
5159
- } else if (!annotations$1[name].typeSet.has("unknown")) {
5160
- annotations$1[name].typeSet.add("unknown");
5161
- annotations$1[name].types.push({ type: "unknown" });
5182
+ } else if (!annotations[name].typeSet.has("unknown")) {
5183
+ annotations[name].typeSet.add("unknown");
5184
+ annotations[name].types.push({ type: "unknown" });
5162
5185
  }
5163
- if (args.length === 0 && !annotations$1[name].typeSet.has("boolean")) {
5164
- annotations$1[name].typeSet.add("boolean");
5165
- annotations$1[name].types.push({ type: "boolean" });
5186
+ if (args.length === 0 && !annotations[name].typeSet.has("boolean")) {
5187
+ annotations[name].typeSet.add("boolean");
5188
+ annotations[name].types.push({ type: "boolean" });
5166
5189
  }
5167
5190
  }
5168
5191
  }
5169
- return annotations$1;
5192
+ return annotations;
5170
5193
  }
5171
5194
  async loadPluginManagerFor(id) {
5172
5195
  if (this.sharedConfig) {
5173
5196
  if (!this.sharedPluginManager) this.sharedPluginManager = {
5174
5197
  manager: new PluginManager(this.sharedConfig),
5175
- dependants: new Set()
5198
+ dependants: /* @__PURE__ */ new Set()
5176
5199
  };
5177
5200
  return this.sharedPluginManager;
5178
5201
  }
@@ -5189,14 +5212,14 @@ else types.push({ type: "boolean" });
5189
5212
  return {
5190
5213
  file: configFile,
5191
5214
  manager,
5192
- dependants: new Set()
5215
+ dependants: /* @__PURE__ */ new Set()
5193
5216
  };
5194
5217
  } else {
5195
5218
  const manager = new PluginManager({ rootDir: process.cwd() });
5196
5219
  await manager.getDocConfig();
5197
5220
  return {
5198
5221
  manager,
5199
- dependants: new Set()
5222
+ dependants: /* @__PURE__ */ new Set()
5200
5223
  };
5201
5224
  }
5202
5225
  }
@@ -5211,18 +5234,18 @@ else types.push({ type: "boolean" });
5211
5234
  }
5212
5235
  return config;
5213
5236
  }
5214
- async openDocument(id, text$2) {
5237
+ async openDocument(id, text) {
5215
5238
  let atscript = this.atscripts.get(id);
5216
5239
  if (atscript) {
5217
- if (text$2) {
5240
+ if (text) {
5218
5241
  atscript = atscript.then((d) => {
5219
- d.update(text$2);
5242
+ d.update(text);
5220
5243
  return d;
5221
5244
  });
5222
5245
  this.atscripts.set(id, atscript);
5223
5246
  }
5224
5247
  } else {
5225
- atscript = this._openDocument(id, text$2);
5248
+ atscript = this._openDocument(id, text);
5226
5249
  atscript.catch(() => {
5227
5250
  this.atscripts.delete(id);
5228
5251
  });
@@ -5230,11 +5253,11 @@ else types.push({ type: "boolean" });
5230
5253
  }
5231
5254
  return atscript;
5232
5255
  }
5233
- async _openDocument(id, text$2) {
5256
+ async _openDocument(id, text) {
5234
5257
  const { manager } = await this.resolveConfig(id);
5235
5258
  const newId = await manager.resolve(id);
5236
5259
  if (!newId) throw new Error(`Document not resolved: ${id}`);
5237
- const content = text$2 || await manager.load(newId);
5260
+ const content = text || await manager.load(newId);
5238
5261
  if (typeof content !== "string") throw new TypeError(`Document not found: ${newId}`);
5239
5262
  const atscript = new AtscriptDoc(id, await manager.getDocConfig(), manager);
5240
5263
  atscript.update(content);
@@ -5245,11 +5268,10 @@ else types.push({ type: "boolean" });
5245
5268
  await this.checkImports(atscript);
5246
5269
  }
5247
5270
  async checkImports(atscript, checked) {
5248
- const _checked = checked || new Set();
5271
+ const _checked = checked || /* @__PURE__ */ new Set();
5249
5272
  if (_checked.has(atscript.id)) return;
5250
5273
  _checked.add(atscript.id);
5251
- const promise = Promise.all(Array.from(atscript.imports.values(), async ({ from, imports }) => this.checkImport(atscript, from, imports, _checked)));
5252
- const results = await promise;
5274
+ const results = await Promise.all(Array.from(atscript.imports.values(), async ({ from, imports }) => this.checkImport(atscript, from, imports, _checked)));
5253
5275
  atscript.updateDependencies(results.filter(Boolean));
5254
5276
  }
5255
5277
  async checkImport(atscript, from, imports, checked) {
@@ -5297,7 +5319,7 @@ else types.push({ type: "boolean" });
5297
5319
  }
5298
5320
  return external;
5299
5321
  }
5300
- constructor(root$1 = process.cwd(), sharedConfig) {
5322
+ constructor(root = process.cwd(), sharedConfig) {
5301
5323
  _define_property$1(this, "root", void 0);
5302
5324
  _define_property$1(this, "sharedConfig", void 0);
5303
5325
  _define_property$1(this, "configFormat", void 0);
@@ -5314,18 +5336,35 @@ else types.push({ type: "boolean" });
5314
5336
  /**
5315
5337
  * cache for raw content of config files
5316
5338
  */ _define_property$1(this, "configFiles", void 0);
5317
- this.root = root$1;
5339
+ this.root = root;
5318
5340
  this.sharedConfig = sharedConfig;
5319
- this.configs = new Map();
5320
- this.atscripts = new Map();
5321
- this.resolvedToBare = new Map();
5322
- this.configFiles = new Map();
5341
+ this.configs = /* @__PURE__ */ new Map();
5342
+ this.atscripts = /* @__PURE__ */ new Map();
5343
+ this.resolvedToBare = /* @__PURE__ */ new Map();
5344
+ this.configFiles = /* @__PURE__ */ new Map();
5323
5345
  }
5324
5346
  };
5325
5347
 
5326
5348
  //#endregion
5327
5349
  //#region packages/core/src/plugin/types.ts
5328
- const DEFAULT_FORMAT = "__default__";
5350
+ /**
5351
+ * Well-known render format for a plugin's primary output.
5352
+ *
5353
+ * When a `.as` file is saved in an editor (VSCode, etc.), the editor
5354
+ * passes this format to `render()` and `buildEnd()`. Plugins should
5355
+ * check for this value alongside their own format strings to produce
5356
+ * output that is essential for the development experience — typically
5357
+ * type declarations for the host language.
5358
+ *
5359
+ * @example
5360
+ * ```ts
5361
+ * render(doc, format) {
5362
+ * if (format === 'dts' || format === DEFAULT_FORMAT) {
5363
+ * return [{ fileName: `${doc.name}.d.ts`, content: renderTypes(doc) }]
5364
+ * }
5365
+ * }
5366
+ * ```
5367
+ */ const DEFAULT_FORMAT = "__default__";
5329
5368
  const createAtscriptPlugin = (plugin) => plugin;
5330
5369
 
5331
5370
  //#endregion
@@ -5337,7 +5376,7 @@ function _define_property(obj, key, value) {
5337
5376
  configurable: true,
5338
5377
  writable: true
5339
5378
  });
5340
- else obj[key] = value;
5379
+ else obj[key] = value;
5341
5380
  return obj;
5342
5381
  }
5343
5382
  async function build(config) {
@@ -5346,13 +5385,11 @@ async function build(config) {
5346
5385
  const repo = new AtscriptRepo(rootDir, config);
5347
5386
  const entries = [];
5348
5387
  if (config.entries && config.entries.length > 0) for (const entry of config.entries) entries.push(path.default.join(rootDir, entry));
5349
- else {
5350
- const includes = config.include && config.include.length > 0 ? config.include : ["**/*.as"];
5351
- const excludes = config.exclude && config.exclude.length > 0 ? config.exclude : ["node_modules"];
5352
- const found = await (0, glob.glob)(includes, {
5388
+ else {
5389
+ const found = await (0, glob.glob)(config.include && config.include.length > 0 ? config.include : ["**/*.as"], {
5353
5390
  cwd: rootDir,
5354
5391
  absolute: true,
5355
- ignore: excludes
5392
+ ignore: config.exclude && config.exclude.length > 0 ? config.exclude : ["node_modules"]
5356
5393
  });
5357
5394
  entries.push(...found);
5358
5395
  }
@@ -5367,7 +5404,7 @@ var BuildRepo = class {
5367
5404
  return this.docs.find((d) => d.id === id);
5368
5405
  }
5369
5406
  async diagnostics() {
5370
- const docMessages = new Map();
5407
+ const docMessages = /* @__PURE__ */ new Map();
5371
5408
  for (const document of this.docs) docMessages.set(document.id, document.getDiagMessages());
5372
5409
  return docMessages;
5373
5410
  }
@@ -5411,9 +5448,29 @@ var BuildRepo = class {
5411
5448
 
5412
5449
  //#endregion
5413
5450
  //#region packages/core/src/flatten.ts
5414
- function flattenInterfaceNode(doc, node, options) {
5415
- const flatMap = new Map();
5416
- const stack = new Set();
5451
+ /**
5452
+ * Flattens an interface node into a map of dot-notation paths to their type descriptors.
5453
+ *
5454
+ * This utility exists to improve type-safety for filter expressions and `$select`/`$sort`
5455
+ * operations in the DB layer. The generated `__flat` static property on `@db.table`
5456
+ * interfaces uses this map to provide autocomplete and compile-time checks for
5457
+ * dot-notation query paths.
5458
+ *
5459
+ * Walks the interface structure (including inherited props from `extends`) and collects
5460
+ * all reachable field paths. Nested objects are recursed into, arrays are recursed through
5461
+ * their element types, and unions/intersections are recursed through each branch (with
5462
+ * colliding paths merged into union groups).
5463
+ *
5464
+ * Fields annotated with `@db.json` are treated as leaves — their sub-paths are NOT included,
5465
+ * because `@db.json` fields are stored as a single JSON column in the database and their
5466
+ * sub-paths are not individually queryable.
5467
+ *
5468
+ * @param doc - The document owning the interface node.
5469
+ * @param node - The interface node to flatten.
5470
+ * @returns A map of dot-separated paths to their field descriptors.
5471
+ */ function flattenInterfaceNode(doc, node, options) {
5472
+ const flatMap = /* @__PURE__ */ new Map();
5473
+ const stack = /* @__PURE__ */ new Set();
5417
5474
  let struct;
5418
5475
  if (node.hasExtends) struct = doc.resolveInterfaceExtends(node);
5419
5476
  if (!struct) struct = node.getDefinition();
@@ -5448,10 +5505,10 @@ function isPhantomNode(doc, def) {
5448
5505
  }
5449
5506
  function resolveNode(doc, def) {
5450
5507
  if (isRef(def)) {
5451
- const ref$1 = def;
5452
- const unwound = doc.unwindType(ref$1.id, ref$1.chain);
5508
+ const ref = def;
5509
+ const unwound = doc.unwindType(ref.id, ref.chain);
5453
5510
  if (unwound?.def) return resolveNode(unwound.doc, unwound.def);
5454
- return undefined;
5511
+ return;
5455
5512
  }
5456
5513
  if (isInterface(def)) {
5457
5514
  const iface = def;
@@ -5462,7 +5519,7 @@ function resolveNode(doc, def) {
5462
5519
  def: struct,
5463
5520
  doc
5464
5521
  };
5465
- return undefined;
5522
+ return;
5466
5523
  }
5467
5524
  return {
5468
5525
  def,
@@ -5472,18 +5529,18 @@ function resolveNode(doc, def) {
5472
5529
  function isComplexNode(def) {
5473
5530
  return isStructure(def) || isArray(def) || isGroup(def) && def.entity !== "tuple";
5474
5531
  }
5475
- function addToFlatMap(flatMap, path$6, descriptor) {
5476
- const existing = flatMap.get(path$6);
5532
+ function addToFlatMap(flatMap, path, descriptor) {
5533
+ const existing = flatMap.get(path);
5477
5534
  if (existing) {
5478
- const group$1 = new SemanticGroup([existing.def, descriptor.def], "|");
5479
- flatMap.set(path$6, {
5480
- def: group$1,
5535
+ const group = new SemanticGroup([existing.def, descriptor.def], "|");
5536
+ flatMap.set(path, {
5537
+ def: group,
5481
5538
  doc: existing.doc,
5482
5539
  optional: existing.optional || descriptor.optional,
5483
5540
  propNode: existing.propNode,
5484
- intermediate: existing.intermediate && descriptor.intermediate ? true : undefined
5541
+ intermediate: existing.intermediate && descriptor.intermediate ? true : void 0
5485
5542
  });
5486
- } else flatMap.set(path$6, descriptor);
5543
+ } else flatMap.set(path, descriptor);
5487
5544
  }
5488
5545
  function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack, options) {
5489
5546
  for (const [name, prop] of struct.props) {
@@ -5491,11 +5548,11 @@ function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack, opti
5491
5548
  const propDef = prop.getDefinition();
5492
5549
  if (isPhantomNode(doc, propDef)) continue;
5493
5550
  if (options?.skipNavProps && hasNavPropAnnotation(prop)) continue;
5494
- const path$6 = prefix ? `${prefix}.${name}` : name;
5551
+ const path = prefix ? `${prefix}.${name}` : name;
5495
5552
  const optional = parentOptional || !!prop.token("optional");
5496
5553
  const dbJson = hasDbJsonAnnotation(prop);
5497
5554
  if (!propDef) {
5498
- addToFlatMap(flatMap, path$6, {
5555
+ addToFlatMap(flatMap, path, {
5499
5556
  def: prop,
5500
5557
  doc,
5501
5558
  optional,
@@ -5505,7 +5562,7 @@ function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack, opti
5505
5562
  }
5506
5563
  const resolved = resolveNode(doc, propDef);
5507
5564
  if (!resolved) {
5508
- addToFlatMap(flatMap, path$6, {
5565
+ addToFlatMap(flatMap, path, {
5509
5566
  def: propDef,
5510
5567
  doc,
5511
5568
  optional,
@@ -5514,7 +5571,7 @@ function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack, opti
5514
5571
  continue;
5515
5572
  }
5516
5573
  if (dbJson) {
5517
- addToFlatMap(flatMap, path$6, {
5574
+ addToFlatMap(flatMap, path, {
5518
5575
  def: resolved.def,
5519
5576
  doc: resolved.doc,
5520
5577
  optional,
@@ -5523,12 +5580,12 @@ function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack, opti
5523
5580
  });
5524
5581
  continue;
5525
5582
  }
5526
- walkNode(resolved.doc, resolved.def, path$6, optional, prop, flatMap, stack, options);
5583
+ walkNode(resolved.doc, resolved.def, path, optional, prop, flatMap, stack, options);
5527
5584
  }
5528
5585
  }
5529
- function walkNode(doc, def, path$6, optional, propNode, flatMap, stack, options) {
5586
+ function walkNode(doc, def, path, optional, propNode, flatMap, stack, options) {
5530
5587
  if (stack.has(def)) {
5531
- addToFlatMap(flatMap, path$6, {
5588
+ addToFlatMap(flatMap, path, {
5532
5589
  def,
5533
5590
  doc,
5534
5591
  optional,
@@ -5539,69 +5596,68 @@ function walkNode(doc, def, path$6, optional, propNode, flatMap, stack, options)
5539
5596
  stack.add(def);
5540
5597
  try {
5541
5598
  if (isStructure(def)) {
5542
- addToFlatMap(flatMap, path$6, {
5599
+ addToFlatMap(flatMap, path, {
5543
5600
  def,
5544
5601
  doc,
5545
5602
  optional,
5546
5603
  propNode,
5547
5604
  intermediate: true
5548
5605
  });
5549
- walkStructure(doc, def, path$6, optional, flatMap, stack, options);
5606
+ walkStructure(doc, def, path, optional, flatMap, stack, options);
5550
5607
  } else if (isArray(def)) {
5551
5608
  const elementDef = def.getDefinition();
5552
- const resolvedElement = elementDef ? resolveNode(doc, elementDef) : undefined;
5553
- const isComplexElement = resolvedElement && (isStructure(resolvedElement.def) || isGroup(resolvedElement.def) && resolvedElement.def.entity !== "tuple" || isArray(resolvedElement.def));
5554
- if (isComplexElement) {
5555
- addToFlatMap(flatMap, path$6, {
5609
+ const resolvedElement = elementDef ? resolveNode(doc, elementDef) : void 0;
5610
+ if (resolvedElement && (isStructure(resolvedElement.def) || isGroup(resolvedElement.def) && resolvedElement.def.entity !== "tuple" || isArray(resolvedElement.def))) {
5611
+ addToFlatMap(flatMap, path, {
5556
5612
  def,
5557
5613
  doc,
5558
5614
  optional,
5559
5615
  propNode,
5560
5616
  intermediate: true
5561
5617
  });
5562
- walkArrayElement(doc, def, path$6, optional, flatMap, stack, options);
5563
- } else addToFlatMap(flatMap, path$6, {
5618
+ walkArrayElement(doc, def, path, optional, flatMap, stack, options);
5619
+ } else addToFlatMap(flatMap, path, {
5564
5620
  def,
5565
5621
  doc,
5566
5622
  optional,
5567
5623
  propNode
5568
5624
  });
5569
5625
  } else if (isGroup(def) && def.entity !== "structure") {
5570
- const group$1 = def;
5571
- if (group$1.op === "&") {
5626
+ const group = def;
5627
+ if (group.op === "&") {
5572
5628
  const merged = doc.mergeIntersection(def);
5573
5629
  if (merged !== def && isStructure(merged)) {
5574
- addToFlatMap(flatMap, path$6, {
5630
+ addToFlatMap(flatMap, path, {
5575
5631
  def: merged,
5576
5632
  doc,
5577
5633
  optional,
5578
5634
  propNode,
5579
5635
  intermediate: true
5580
5636
  });
5581
- walkStructure(doc, merged, path$6, optional, flatMap, stack, options);
5582
- } else addToFlatMap(flatMap, path$6, {
5637
+ walkStructure(doc, merged, path, optional, flatMap, stack, options);
5638
+ } else addToFlatMap(flatMap, path, {
5583
5639
  def,
5584
5640
  doc,
5585
5641
  optional,
5586
5642
  propNode
5587
5643
  });
5588
- } else if (group$1.op === "|") {
5589
- const branches = group$1.unwrap();
5644
+ } else if (group.op === "|") {
5645
+ const branches = group.unwrap();
5590
5646
  let hasComplexBranch = false;
5591
5647
  let hasLeafBranch = false;
5592
5648
  for (const branch of branches) {
5593
5649
  const resolved = resolveNode(doc, branch);
5594
5650
  if (resolved && isComplexNode(resolved.def)) hasComplexBranch = true;
5595
- else hasLeafBranch = true;
5651
+ else hasLeafBranch = true;
5596
5652
  }
5597
5653
  if (hasComplexBranch) {
5598
- if (hasLeafBranch) addToFlatMap(flatMap, path$6, {
5654
+ if (hasLeafBranch) addToFlatMap(flatMap, path, {
5599
5655
  def,
5600
5656
  doc,
5601
5657
  optional,
5602
5658
  propNode
5603
5659
  });
5604
- else addToFlatMap(flatMap, path$6, {
5660
+ else addToFlatMap(flatMap, path, {
5605
5661
  def,
5606
5662
  doc,
5607
5663
  optional,
@@ -5610,21 +5666,21 @@ else addToFlatMap(flatMap, path$6, {
5610
5666
  });
5611
5667
  for (const branch of branches) {
5612
5668
  const resolved = resolveNode(doc, branch);
5613
- if (resolved) walkBranch(resolved.doc, resolved.def, path$6, optional, flatMap, stack, options);
5669
+ if (resolved) walkBranch(resolved.doc, resolved.def, path, optional, flatMap, stack, options);
5614
5670
  }
5615
- } else addToFlatMap(flatMap, path$6, {
5671
+ } else addToFlatMap(flatMap, path, {
5616
5672
  def,
5617
5673
  doc,
5618
5674
  optional,
5619
5675
  propNode
5620
5676
  });
5621
- } else addToFlatMap(flatMap, path$6, {
5677
+ } else addToFlatMap(flatMap, path, {
5622
5678
  def,
5623
5679
  doc,
5624
5680
  optional,
5625
5681
  propNode
5626
5682
  });
5627
- } else addToFlatMap(flatMap, path$6, {
5683
+ } else addToFlatMap(flatMap, path, {
5628
5684
  def,
5629
5685
  doc,
5630
5686
  optional,
@@ -5646,13 +5702,13 @@ function walkArrayElement(doc, arrayNode, prefix, parentOptional, flatMap, stack
5646
5702
  * Does NOT add an entry for the branch itself — the parent already did that.
5647
5703
  */ function walkBranch(doc, def, prefix, parentOptional, flatMap, stack, options) {
5648
5704
  if (isStructure(def)) walkStructure(doc, def, prefix, parentOptional, flatMap, stack, options);
5649
- else if (isArray(def)) walkArrayElement(doc, def, prefix, parentOptional, flatMap, stack, options);
5650
- else if (isGroup(def) && def.entity !== "structure") {
5651
- const group$1 = def;
5652
- if (group$1.op === "&") {
5705
+ else if (isArray(def)) walkArrayElement(doc, def, prefix, parentOptional, flatMap, stack, options);
5706
+ else if (isGroup(def) && def.entity !== "structure") {
5707
+ const group = def;
5708
+ if (group.op === "&") {
5653
5709
  const merged = doc.mergeIntersection(def);
5654
5710
  if (isStructure(merged)) walkStructure(doc, merged, prefix, parentOptional, flatMap, stack, options);
5655
- } else if (group$1.op === "|") for (const branch of group$1.unwrap()) {
5711
+ } else if (group.op === "|") for (const branch of group.unwrap()) {
5656
5712
  const resolved = resolveNode(doc, branch);
5657
5713
  if (resolved) walkBranch(resolved.doc, resolved.def, prefix, parentOptional, flatMap, stack, options);
5658
5714
  }
@@ -5660,69 +5716,69 @@ else if (isGroup(def) && def.entity !== "structure") {
5660
5716
  }
5661
5717
 
5662
5718
  //#endregion
5663
- exports.$n = $n
5664
- exports.AnnotationSpec = AnnotationSpec
5665
- exports.AtscriptDoc = AtscriptDoc
5666
- exports.AtscriptRepo = AtscriptRepo
5667
- exports.BuildRepo = BuildRepo
5668
- exports.DEFAULT_FORMAT = DEFAULT_FORMAT
5669
- exports.PluginManager = PluginManager
5670
- exports.SemanticAnnotateNode = SemanticAnnotateNode
5671
- exports.SemanticArrayNode = SemanticArrayNode
5672
- exports.SemanticConstNode = SemanticConstNode
5673
- exports.SemanticGroup = SemanticGroup
5674
- exports.SemanticImportNode = SemanticImportNode
5675
- exports.SemanticInterfaceNode = SemanticInterfaceNode
5676
- exports.SemanticNode = SemanticNode
5677
- exports.SemanticPrimitiveNode = SemanticPrimitiveNode
5678
- exports.SemanticPropNode = SemanticPropNode
5679
- exports.SemanticQueryComparisonNode = SemanticQueryComparisonNode
5680
- exports.SemanticQueryFieldRefNode = SemanticQueryFieldRefNode
5681
- exports.SemanticQueryLogicalNode = SemanticQueryLogicalNode
5682
- exports.SemanticQueryNode = SemanticQueryNode
5683
- exports.SemanticQueryValueListNode = SemanticQueryValueListNode
5684
- exports.SemanticQueryValueNode = SemanticQueryValueNode
5685
- exports.SemanticRefNode = SemanticRefNode
5686
- exports.SemanticStructureNode = SemanticStructureNode
5687
- exports.SemanticTupleNode = SemanticTupleNode
5688
- exports.SemanticTypeNode = SemanticTypeNode
5689
- exports.Token = Token
5690
- exports.analyzeQueryCursorContext = analyzeQueryCursorContext
5691
- exports.build = build
5692
- exports.clearResolveBareCache = clearResolveBareCache
5693
- exports.createAtscriptPlugin = createAtscriptPlugin
5694
- exports.defineConfig = defineConfig
5695
- exports.fileUriToPath = fileUriToPath
5696
- exports.flattenInterfaceNode = flattenInterfaceNode
5697
- exports.getFieldsForType = getFieldsForType
5698
- exports.getQueryCompletionScope = getQueryCompletionScope
5699
- exports.getQueryScope = getQueryScope
5700
- exports.getRelPath = getRelPath
5701
- exports.hasNavPropAnnotation = hasNavPropAnnotation
5702
- exports.isAnnotate = isAnnotate
5703
- exports.isAnnotationSpec = isAnnotationSpec
5704
- exports.isArray = isArray
5705
- exports.isBareId = isBareId
5706
- exports.isBareSpecifier = isBareSpecifier
5707
- exports.isConst = isConst
5708
- exports.isGroup = isGroup
5709
- exports.isImport = isImport
5710
- exports.isInterface = isInterface
5711
- exports.isPhantomNode = isPhantomNode
5712
- exports.isPrimitive = isPrimitive
5713
- exports.isProp = isProp
5714
- exports.isQueryComparison = isQueryComparison
5715
- exports.isQueryFieldRef = isQueryFieldRef
5716
- exports.isQueryLogical = isQueryLogical
5717
- exports.isRef = isRef
5718
- exports.isStructure = isStructure
5719
- exports.isTuple = isTuple
5720
- exports.isType = isType
5721
- exports.loadConfig = loadConfig
5722
- exports.loadTsConfig = loadTsConfig
5723
- exports.parseBareSpecifier = parseBareSpecifier
5724
- exports.resolveAnnotation = resolveAnnotation
5725
- exports.resolveAtscriptFromPath = resolveAtscriptFromPath
5726
- exports.resolveBareSpecifier = resolveBareSpecifier
5727
- exports.resolveConfigFile = resolveConfigFile
5728
- exports.resolveQueryFieldRef = resolveQueryFieldRef
5719
+ exports.$n = $n;
5720
+ exports.AnnotationSpec = AnnotationSpec;
5721
+ exports.AtscriptDoc = AtscriptDoc;
5722
+ exports.AtscriptRepo = AtscriptRepo;
5723
+ exports.BuildRepo = BuildRepo;
5724
+ exports.DEFAULT_FORMAT = DEFAULT_FORMAT;
5725
+ exports.PluginManager = PluginManager;
5726
+ exports.SemanticAnnotateNode = SemanticAnnotateNode;
5727
+ exports.SemanticArrayNode = SemanticArrayNode;
5728
+ exports.SemanticConstNode = SemanticConstNode;
5729
+ exports.SemanticGroup = SemanticGroup;
5730
+ exports.SemanticImportNode = SemanticImportNode;
5731
+ exports.SemanticInterfaceNode = SemanticInterfaceNode;
5732
+ exports.SemanticNode = SemanticNode;
5733
+ exports.SemanticPrimitiveNode = SemanticPrimitiveNode;
5734
+ exports.SemanticPropNode = SemanticPropNode;
5735
+ exports.SemanticQueryComparisonNode = SemanticQueryComparisonNode;
5736
+ exports.SemanticQueryFieldRefNode = SemanticQueryFieldRefNode;
5737
+ exports.SemanticQueryLogicalNode = SemanticQueryLogicalNode;
5738
+ exports.SemanticQueryNode = SemanticQueryNode;
5739
+ exports.SemanticQueryValueListNode = SemanticQueryValueListNode;
5740
+ exports.SemanticQueryValueNode = SemanticQueryValueNode;
5741
+ exports.SemanticRefNode = SemanticRefNode;
5742
+ exports.SemanticStructureNode = SemanticStructureNode;
5743
+ exports.SemanticTupleNode = SemanticTupleNode;
5744
+ exports.SemanticTypeNode = SemanticTypeNode;
5745
+ exports.Token = Token;
5746
+ exports.analyzeQueryCursorContext = analyzeQueryCursorContext;
5747
+ exports.build = build;
5748
+ exports.clearResolveBareCache = clearResolveBareCache;
5749
+ exports.createAtscriptPlugin = createAtscriptPlugin;
5750
+ exports.defineConfig = defineConfig;
5751
+ exports.fileUriToPath = fileUriToPath;
5752
+ exports.flattenInterfaceNode = flattenInterfaceNode;
5753
+ exports.getFieldsForType = getFieldsForType;
5754
+ exports.getQueryCompletionScope = getQueryCompletionScope;
5755
+ exports.getQueryScope = getQueryScope;
5756
+ exports.getRelPath = getRelPath;
5757
+ exports.hasNavPropAnnotation = hasNavPropAnnotation;
5758
+ exports.isAnnotate = isAnnotate;
5759
+ exports.isAnnotationSpec = isAnnotationSpec;
5760
+ exports.isArray = isArray;
5761
+ exports.isBareId = isBareId;
5762
+ exports.isBareSpecifier = isBareSpecifier;
5763
+ exports.isConst = isConst;
5764
+ exports.isGroup = isGroup;
5765
+ exports.isImport = isImport;
5766
+ exports.isInterface = isInterface;
5767
+ exports.isPhantomNode = isPhantomNode;
5768
+ exports.isPrimitive = isPrimitive;
5769
+ exports.isProp = isProp;
5770
+ exports.isQueryComparison = isQueryComparison;
5771
+ exports.isQueryFieldRef = isQueryFieldRef;
5772
+ exports.isQueryLogical = isQueryLogical;
5773
+ exports.isRef = isRef;
5774
+ exports.isStructure = isStructure;
5775
+ exports.isTuple = isTuple;
5776
+ exports.isType = isType;
5777
+ exports.loadConfig = loadConfig;
5778
+ exports.loadTsConfig = loadTsConfig;
5779
+ exports.parseBareSpecifier = parseBareSpecifier;
5780
+ exports.resolveAnnotation = resolveAnnotation;
5781
+ exports.resolveAtscriptFromPath = resolveAtscriptFromPath;
5782
+ exports.resolveBareSpecifier = resolveBareSpecifier;
5783
+ exports.resolveConfigFile = resolveConfigFile;
5784
+ exports.resolveQueryFieldRef = resolveQueryFieldRef;