@atscript/typescript 0.1.98 → 0.1.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs CHANGED
@@ -993,6 +993,10 @@ const regexCache = /* @__PURE__ */ new Map();
993
993
  this.error(`Expected ${def.type.designType}, got ${typeOfValue}`);
994
994
  return false;
995
995
  }
996
+ if (!Number.isFinite(value)) {
997
+ this.error(`Expected finite number, got ${value}`);
998
+ return false;
999
+ }
996
1000
  return this.validateNumber(def, value);
997
1001
  case "boolean":
998
1002
  if (typeOfValue !== def.type.designType) {
@@ -1603,6 +1607,7 @@ const QUERY_OP_MAP = {
1603
1607
  "exists": "$exists",
1604
1608
  "not exists": "$exists"
1605
1609
  };
1610
+ const SYNTH_IMPORTS_MARKER = "/*@@atscript-synth-imports@@*/";
1606
1611
  var JsRenderer = class extends BaseRenderer {
1607
1612
  /**
1608
1613
  * Relative imports get the configured `moduleExtension`; bare specifiers
@@ -1660,32 +1665,56 @@ var JsRenderer = class extends BaseRenderer {
1660
1665
  this._synthComputed = true;
1661
1666
  const refToOriginDoc = this.getExtendsRefs();
1662
1667
  if (refToOriginDoc.size === 0) return;
1663
- const taken = new Set(this.doc.registry.definitions.keys());
1664
- const allocated = /* @__PURE__ */ new Map();
1665
- const synthPathCache = /* @__PURE__ */ new Map();
1666
1668
  for (const [refNode, originDoc] of refToOriginDoc) {
1667
1669
  const refId = refNode.id;
1668
1670
  if (!refId) continue;
1669
1671
  const ownerInfo = this.resolveOwner(originDoc, refId);
1670
1672
  if (!ownerInfo?.doc || ownerInfo.doc === this.doc) continue;
1671
1673
  if (ownerInfo.node && (0, _atscript_core.isPrimitive)(ownerInfo.node)) continue;
1672
- const ownerDoc = ownerInfo.doc;
1673
- let synthPath;
1674
- if (synthPathCache.has(ownerDoc)) synthPath = synthPathCache.get(ownerDoc);
1675
- else {
1676
- synthPath = this.computeSynthPath(ownerDoc);
1677
- synthPathCache.set(ownerDoc, synthPath);
1678
- }
1679
- if (!synthPath) continue;
1680
- const allocKey = `${synthPath}::${refId}`;
1681
- let info = allocated.get(allocKey);
1682
- if (!info) {
1683
- info = this.allocateSynthInfo(refId, synthPath, ownerInfo, taken);
1684
- allocated.set(allocKey, info);
1685
- }
1674
+ const info = this.synthBinding(refId, ownerInfo);
1675
+ if (!info) continue;
1686
1676
  this._refSynthInfo.set(refNode, info);
1687
1677
  }
1688
1678
  }
1679
+ getSynthTaken() {
1680
+ if (!this._synthTaken) {
1681
+ this._synthTaken = new Set(this.doc.registry.definitions.keys());
1682
+ for (const name of this.doc.importedDefs.keys()) this._synthTaken.add(name);
1683
+ }
1684
+ return this._synthTaken;
1685
+ }
1686
+ getSynthPath(ownerDoc) {
1687
+ if (!this._synthPathCache.has(ownerDoc)) this._synthPathCache.set(ownerDoc, this.computeSynthPath(ownerDoc));
1688
+ return this._synthPathCache.get(ownerDoc);
1689
+ }
1690
+ synthBinding(name, ownerInfo) {
1691
+ const synthPath = this.getSynthPath(ownerInfo.doc);
1692
+ if (!synthPath) return;
1693
+ const allocKey = `${synthPath}::${name}`;
1694
+ let info = this._synthAllocated.get(allocKey);
1695
+ if (!info) {
1696
+ info = this.allocateSynthInfo(name, synthPath, ownerInfo, this.getSynthTaken());
1697
+ this._synthAllocated.set(allocKey, info);
1698
+ }
1699
+ return info;
1700
+ }
1701
+ /**
1702
+ * Binding for a type name used by an annotation argument (`ref` / qualified
1703
+ * query field refs). An annotation inherited from another document (chain ref
1704
+ * or `extends`) carries names that only that document imports, so when the
1705
+ * name does not resolve here to the same declaration, a synthesized import is
1706
+ * allocated (lazily, spliced into the header by `render()`).
1707
+ */ annotationTypeName(typeName, origin) {
1708
+ if (!origin || origin === this.doc) return typeName;
1709
+ const theirs = this.resolveOwner(origin, typeName);
1710
+ if (!theirs?.doc || !theirs.node || theirs.doc === this.doc || (0, _atscript_core.isPrimitive)(theirs.node)) return typeName;
1711
+ const mine = this.resolveOwner(this.doc, typeName);
1712
+ if (mine?.doc === theirs.doc && mine.node === theirs.node) return typeName;
1713
+ return this.synthBinding(typeName, {
1714
+ doc: theirs.doc,
1715
+ node: theirs.node
1716
+ })?.alias ?? typeName;
1717
+ }
1689
1718
  resolveOwner(fromDoc, refId) {
1690
1719
  const key = `${fromDoc.id}::${refId}`;
1691
1720
  let v = this._ownerCache.get(key);
@@ -1759,10 +1788,17 @@ var JsRenderer = class extends BaseRenderer {
1759
1788
  if (jsonSchemaMode === false) imports.push("throwFeatureDisabled as $d");
1760
1789
  this.writeln(`import { ${imports.join(", ")} } from "@atscript/typescript/utils"`);
1761
1790
  this.computeSynthesizedImports();
1791
+ this.writeln(SYNTH_IMPORTS_MARKER);
1792
+ }
1793
+ render() {
1794
+ const out = super.render();
1795
+ const lines = [];
1762
1796
  for (const [synthPath, names] of this._synthImports) {
1763
1797
  const list = names.map((n) => n.alias === n.name ? n.name : `${n.name} as ${n.alias}`).join(", ");
1764
- this.writeln(`import { ${list} } from "${this.transformFromPath(synthPath)}"`);
1798
+ lines.push(`import { ${list} } from "${this.transformFromPath(synthPath)}"`);
1765
1799
  }
1800
+ const marker = `${SYNTH_IMPORTS_MARKER}\n`;
1801
+ return out.replace(marker, () => lines.length > 0 ? `${lines.join("\n")}\n` : "");
1766
1802
  }
1767
1803
  buildAdHocMap(annotateNodes) {
1768
1804
  const map = /* @__PURE__ */ new Map();
@@ -2234,33 +2270,53 @@ var JsRenderer = class extends BaseRenderer {
2234
2270
  if (multiple) this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value}, true)`);
2235
2271
  else this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value})`);
2236
2272
  }
2237
- emitRefValue(text) {
2273
+ emitRefValue(text, origin) {
2238
2274
  const dotIdx = text.indexOf(".");
2239
- if (dotIdx === -1) return `() => ${text}`;
2240
- return `{ type: () => ${text.slice(0, dotIdx)}, field: "${escapeQuotes(text.slice(dotIdx + 1))}" }`;
2241
- }
2242
- emitArgValue(aSpec, argToken) {
2243
- if (aSpec.type === "ref") return this.emitRefValue(argToken.text);
2244
- if (aSpec.type === "query" && argToken.queryNode) return this.emitQueryTree(argToken.queryNode);
2275
+ if (dotIdx === -1) return `() => ${this.annotationTypeName(text, origin)}`;
2276
+ return `{ type: () => ${this.annotationTypeName(text.slice(0, dotIdx), origin)}, field: "${escapeQuotes(text.slice(dotIdx + 1))}" }`;
2277
+ }
2278
+ emitArgValue(aSpec, argToken, origin) {
2279
+ if (aSpec.type === "ref") return this.emitRefValue(argToken.text, origin);
2280
+ if (aSpec.type === "query" && argToken.queryNode) return this.emitQueryTree(argToken.queryNode, origin);
2281
+ if (aSpec.type === "expr" && argToken.exprNode) return this.emitExprNode(argToken.exprNode.expression, origin);
2282
+ if (aSpec.type === "order" && argToken.orderNode) return `[${argToken.orderNode.items.map((item) => `{ ref: ${this.emitQueryFieldRef(item.ref, origin)}${item.desc ? ", desc: true" : ""} }`).join(", ")}]`;
2245
2283
  return aSpec.type === "string" ? `"${escapeQuotes(argToken.text)}"` : argToken.text;
2246
2284
  }
2247
- emitQueryTree(queryNode) {
2248
- return this.emitQueryExpr(queryNode.expression);
2285
+ emitExprNode(node, origin) {
2286
+ switch (node.entity) {
2287
+ case "query-expr-number": return String(node.value);
2288
+ case "query-expr-binary": {
2289
+ const { op, left, right } = node;
2290
+ return `{ op: "${op}", args: [${this.emitExprNode(left, origin)}, ${this.emitExprNode(right, origin)}] }`;
2291
+ }
2292
+ case "query-expr-unary": {
2293
+ const { op, operand } = node;
2294
+ return `{ op: "${op}", args: [${this.emitExprNode(operand, origin)}] }`;
2295
+ }
2296
+ case "query-expr-call": {
2297
+ const { fn, args } = node;
2298
+ return `{ op: "${fn}", args: [${args.map((a) => this.emitExprNode(a, origin)).join(", ")}] }`;
2299
+ }
2300
+ default: return this.emitQueryFieldRef(node, origin);
2301
+ }
2302
+ }
2303
+ emitQueryTree(queryNode, origin) {
2304
+ return this.emitQueryExpr(queryNode.expression, origin);
2249
2305
  }
2250
- emitQueryExpr(node) {
2251
- if ((0, _atscript_core.isQueryLogical)(node)) return this.emitQueryLogical(node);
2252
- return this.emitQueryComparison(node);
2306
+ emitQueryExpr(node, origin) {
2307
+ if ((0, _atscript_core.isQueryLogical)(node)) return this.emitQueryLogical(node, origin);
2308
+ return this.emitQueryComparison(node, origin);
2253
2309
  }
2254
- emitQueryLogical(node) {
2255
- if (node.operator === "not") return `{ "$not": ${this.emitQueryExpr(node.operands[0])} }`;
2256
- return `{ "${node.operator === "and" ? "$and" : "$or"}": [${node.operands.map((op) => this.emitQueryExpr(op)).join(", ")}] }`;
2310
+ emitQueryLogical(node, origin) {
2311
+ if (node.operator === "not") return `{ "$not": ${this.emitQueryExpr(node.operands[0], origin)} }`;
2312
+ return `{ "${node.operator === "and" ? "$and" : "$or"}": [${node.operands.map((op) => this.emitQueryExpr(op, origin)).join(", ")}] }`;
2257
2313
  }
2258
- emitQueryComparison(node) {
2259
- const left = this.emitQueryFieldRef(node.left);
2314
+ emitQueryComparison(node, origin) {
2315
+ const left = this.emitQueryFieldRef(node.left, origin);
2260
2316
  const mappedOp = QUERY_OP_MAP[node.operator] || node.operator;
2261
2317
  const parts = [`left: ${left}`, `op: "${mappedOp}"`];
2262
2318
  if (node.right) {
2263
- if ("fieldRef" in node.right && node.right.fieldRef) parts.push(`right: ${this.emitQueryFieldRef(node.right)}`);
2319
+ if ("fieldRef" in node.right && node.right.fieldRef) parts.push(`right: ${this.emitQueryFieldRef(node.right, origin)}`);
2264
2320
  else if ("values" in node.right && node.right.values) {
2265
2321
  const values = node.right.values.map((v) => this.emitQueryLiteral(v)).join(", ");
2266
2322
  parts.push(`right: [${values}]`);
@@ -2269,9 +2325,9 @@ var JsRenderer = class extends BaseRenderer {
2269
2325
  else if (node.operator === "not exists") parts.push("right: false");
2270
2326
  return `{ ${parts.join(", ")} }`;
2271
2327
  }
2272
- emitQueryFieldRef(node) {
2328
+ emitQueryFieldRef(node, origin) {
2273
2329
  const parts = [];
2274
- if (node.typeRef) parts.push(`type: () => ${node.typeRef.text}`);
2330
+ if (node.typeRef) parts.push(`type: () => ${this.annotationTypeName(node.typeRef.text, origin)}`);
2275
2331
  parts.push(`field: "${escapeQuotes(node.fieldRef.text)}"`);
2276
2332
  return `{ ${parts.join(", ")} }`;
2277
2333
  }
@@ -2292,6 +2348,7 @@ var JsRenderer = class extends BaseRenderer {
2292
2348
  }
2293
2349
  }
2294
2350
  computeAnnotationValue(node, an) {
2351
+ const origin = this.doc.annotationOrigin(an);
2295
2352
  const spec = this.doc.resolveAnnotation(an.name);
2296
2353
  let targetValue = "true";
2297
2354
  let multiple = false;
@@ -2302,13 +2359,13 @@ var JsRenderer = class extends BaseRenderer {
2302
2359
  targetValue = "{ ";
2303
2360
  let i = 0;
2304
2361
  for (const aSpec of spec.arguments) {
2305
- if (an.args[i]) targetValue += `${wrapProp(aSpec.name)}: ${this.emitArgValue(aSpec, an.args[i])}${i === length - 1 ? "" : ", "} `;
2362
+ if (an.args[i]) targetValue += `${wrapProp(aSpec.name)}: ${this.emitArgValue(aSpec, an.args[i], origin)}${i === length - 1 ? "" : ", "} `;
2306
2363
  i++;
2307
2364
  }
2308
2365
  targetValue += "}";
2309
2366
  } else {
2310
2367
  const aSpec = spec.arguments[0];
2311
- targetValue = an.args[0] ? this.emitArgValue(aSpec, an.args[0]) : "true";
2368
+ targetValue = an.args[0] ? this.emitArgValue(aSpec, an.args[0], origin) : "true";
2312
2369
  }
2313
2370
  } else {
2314
2371
  multiple = node.countAnnotations(an.name) > 1 || an.args.length > 1;
@@ -2446,7 +2503,7 @@ var JsRenderer = class extends BaseRenderer {
2446
2503
  return [];
2447
2504
  }
2448
2505
  constructor(doc, opts) {
2449
- super(doc), _define_property$3(this, "opts", void 0), _define_property$3(this, "postAnnotate", void 0), _define_property$3(this, "_adHocAnnotations", void 0), _define_property$3(this, "_propPath", void 0), _define_property$3(this, "typeIds", void 0), _define_property$3(this, "_unusedJs", void 0), _define_property$3(this, "_extendsRefs", void 0), _define_property$3(this, "_refSynthInfo", void 0), _define_property$3(this, "_synthImports", void 0), _define_property$3(this, "_synthComputed", void 0), _define_property$3(this, "_ownerCache", void 0), this.opts = opts, this.postAnnotate = [], this._adHocAnnotations = null, this._propPath = [], this.typeIds = /* @__PURE__ */ new Map(), this._refSynthInfo = /* @__PURE__ */ new Map(), this._synthImports = /* @__PURE__ */ new Map(), this._synthComputed = false, this._ownerCache = /* @__PURE__ */ new Map();
2506
+ super(doc), _define_property$3(this, "opts", void 0), _define_property$3(this, "postAnnotate", void 0), _define_property$3(this, "_adHocAnnotations", void 0), _define_property$3(this, "_propPath", void 0), _define_property$3(this, "typeIds", void 0), _define_property$3(this, "_unusedJs", void 0), _define_property$3(this, "_extendsRefs", void 0), _define_property$3(this, "_refSynthInfo", void 0), _define_property$3(this, "_synthImports", void 0), _define_property$3(this, "_synthComputed", void 0), _define_property$3(this, "_synthTaken", void 0), _define_property$3(this, "_synthAllocated", void 0), _define_property$3(this, "_synthPathCache", void 0), _define_property$3(this, "_ownerCache", void 0), this.opts = opts, this.postAnnotate = [], this._adHocAnnotations = null, this._propPath = [], this.typeIds = /* @__PURE__ */ new Map(), this._refSynthInfo = /* @__PURE__ */ new Map(), this._synthImports = /* @__PURE__ */ new Map(), this._synthComputed = false, this._synthAllocated = /* @__PURE__ */ new Map(), this._synthPathCache = /* @__PURE__ */ new Map(), this._ownerCache = /* @__PURE__ */ new Map();
2450
2507
  }
2451
2508
  };
2452
2509
 
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
- const require_plugin = require('./plugin-dcd-XTR-.cjs');
2
+ const require_plugin = require('./plugin-Cu6Nez-H.cjs');
3
3
 
4
4
  exports.default = require_plugin.tsPlugin;
5
5
  exports.tsPlugin = require_plugin.tsPlugin;
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { t as tsPlugin } from "./plugin-BDjZ2rOT.mjs";
1
+ import { t as tsPlugin } from "./plugin-DG3jlbSN.mjs";
2
2
 
3
3
  export { tsPlugin as default, tsPlugin };
@@ -324,6 +324,10 @@ const regexCache = /* @__PURE__ */ new Map();
324
324
  this.error(`Expected ${def.type.designType}, got ${typeOfValue}`);
325
325
  return false;
326
326
  }
327
+ if (!Number.isFinite(value)) {
328
+ this.error(`Expected finite number, got ${value}`);
329
+ return false;
330
+ }
327
331
  return this.validateNumber(def, value);
328
332
  case "boolean":
329
333
  if (typeOfValue !== def.type.designType) {
@@ -325,6 +325,10 @@ const regexCache = /* @__PURE__ */ new Map();
325
325
  this.error(`Expected ${def.type.designType}, got ${typeOfValue}`);
326
326
  return false;
327
327
  }
328
+ if (!Number.isFinite(value)) {
329
+ this.error(`Expected finite number, got ${value}`);
330
+ return false;
331
+ }
328
332
  return this.validateNumber(def, value);
329
333
  case "boolean":
330
334
  if (typeOfValue !== def.type.designType) {
@@ -25,7 +25,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
25
  }) : target, mod));
26
26
 
27
27
  //#endregion
28
- const require_json_schema = require('./json-schema-CZo482nY.cjs');
28
+ const require_json_schema = require('./json-schema-CtQ_rzJn.cjs');
29
29
  let path = require("path");
30
30
  path = __toESM(path);
31
31
  let _atscript_core = require("@atscript/core");
@@ -686,6 +686,7 @@ const QUERY_OP_MAP = {
686
686
  "exists": "$exists",
687
687
  "not exists": "$exists"
688
688
  };
689
+ const SYNTH_IMPORTS_MARKER = "/*@@atscript-synth-imports@@*/";
689
690
  var JsRenderer = class extends BaseRenderer {
690
691
  /**
691
692
  * Relative imports get the configured `moduleExtension`; bare specifiers
@@ -743,32 +744,56 @@ var JsRenderer = class extends BaseRenderer {
743
744
  this._synthComputed = true;
744
745
  const refToOriginDoc = this.getExtendsRefs();
745
746
  if (refToOriginDoc.size === 0) return;
746
- const taken = new Set(this.doc.registry.definitions.keys());
747
- const allocated = /* @__PURE__ */ new Map();
748
- const synthPathCache = /* @__PURE__ */ new Map();
749
747
  for (const [refNode, originDoc] of refToOriginDoc) {
750
748
  const refId = refNode.id;
751
749
  if (!refId) continue;
752
750
  const ownerInfo = this.resolveOwner(originDoc, refId);
753
751
  if (!ownerInfo?.doc || ownerInfo.doc === this.doc) continue;
754
752
  if (ownerInfo.node && (0, _atscript_core.isPrimitive)(ownerInfo.node)) continue;
755
- const ownerDoc = ownerInfo.doc;
756
- let synthPath;
757
- if (synthPathCache.has(ownerDoc)) synthPath = synthPathCache.get(ownerDoc);
758
- else {
759
- synthPath = this.computeSynthPath(ownerDoc);
760
- synthPathCache.set(ownerDoc, synthPath);
761
- }
762
- if (!synthPath) continue;
763
- const allocKey = `${synthPath}::${refId}`;
764
- let info = allocated.get(allocKey);
765
- if (!info) {
766
- info = this.allocateSynthInfo(refId, synthPath, ownerInfo, taken);
767
- allocated.set(allocKey, info);
768
- }
753
+ const info = this.synthBinding(refId, ownerInfo);
754
+ if (!info) continue;
769
755
  this._refSynthInfo.set(refNode, info);
770
756
  }
771
757
  }
758
+ getSynthTaken() {
759
+ if (!this._synthTaken) {
760
+ this._synthTaken = new Set(this.doc.registry.definitions.keys());
761
+ for (const name of this.doc.importedDefs.keys()) this._synthTaken.add(name);
762
+ }
763
+ return this._synthTaken;
764
+ }
765
+ getSynthPath(ownerDoc) {
766
+ if (!this._synthPathCache.has(ownerDoc)) this._synthPathCache.set(ownerDoc, this.computeSynthPath(ownerDoc));
767
+ return this._synthPathCache.get(ownerDoc);
768
+ }
769
+ synthBinding(name, ownerInfo) {
770
+ const synthPath = this.getSynthPath(ownerInfo.doc);
771
+ if (!synthPath) return;
772
+ const allocKey = `${synthPath}::${name}`;
773
+ let info = this._synthAllocated.get(allocKey);
774
+ if (!info) {
775
+ info = this.allocateSynthInfo(name, synthPath, ownerInfo, this.getSynthTaken());
776
+ this._synthAllocated.set(allocKey, info);
777
+ }
778
+ return info;
779
+ }
780
+ /**
781
+ * Binding for a type name used by an annotation argument (`ref` / qualified
782
+ * query field refs). An annotation inherited from another document (chain ref
783
+ * or `extends`) carries names that only that document imports, so when the
784
+ * name does not resolve here to the same declaration, a synthesized import is
785
+ * allocated (lazily, spliced into the header by `render()`).
786
+ */ annotationTypeName(typeName, origin) {
787
+ if (!origin || origin === this.doc) return typeName;
788
+ const theirs = this.resolveOwner(origin, typeName);
789
+ if (!theirs?.doc || !theirs.node || theirs.doc === this.doc || (0, _atscript_core.isPrimitive)(theirs.node)) return typeName;
790
+ const mine = this.resolveOwner(this.doc, typeName);
791
+ if (mine?.doc === theirs.doc && mine.node === theirs.node) return typeName;
792
+ return this.synthBinding(typeName, {
793
+ doc: theirs.doc,
794
+ node: theirs.node
795
+ })?.alias ?? typeName;
796
+ }
772
797
  resolveOwner(fromDoc, refId) {
773
798
  const key = `${fromDoc.id}::${refId}`;
774
799
  let v = this._ownerCache.get(key);
@@ -842,10 +867,17 @@ var JsRenderer = class extends BaseRenderer {
842
867
  if (jsonSchemaMode === false) imports.push("throwFeatureDisabled as $d");
843
868
  this.writeln(`import { ${imports.join(", ")} } from "@atscript/typescript/utils"`);
844
869
  this.computeSynthesizedImports();
870
+ this.writeln(SYNTH_IMPORTS_MARKER);
871
+ }
872
+ render() {
873
+ const out = super.render();
874
+ const lines = [];
845
875
  for (const [synthPath, names] of this._synthImports) {
846
876
  const list = names.map((n) => n.alias === n.name ? n.name : `${n.name} as ${n.alias}`).join(", ");
847
- this.writeln(`import { ${list} } from "${this.transformFromPath(synthPath)}"`);
877
+ lines.push(`import { ${list} } from "${this.transformFromPath(synthPath)}"`);
848
878
  }
879
+ const marker = `${SYNTH_IMPORTS_MARKER}\n`;
880
+ return out.replace(marker, () => lines.length > 0 ? `${lines.join("\n")}\n` : "");
849
881
  }
850
882
  buildAdHocMap(annotateNodes) {
851
883
  const map = /* @__PURE__ */ new Map();
@@ -1317,33 +1349,53 @@ var JsRenderer = class extends BaseRenderer {
1317
1349
  if (multiple) this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value}, true)`);
1318
1350
  else this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value})`);
1319
1351
  }
1320
- emitRefValue(text) {
1352
+ emitRefValue(text, origin) {
1321
1353
  const dotIdx = text.indexOf(".");
1322
- if (dotIdx === -1) return `() => ${text}`;
1323
- return `{ type: () => ${text.slice(0, dotIdx)}, field: "${escapeQuotes(text.slice(dotIdx + 1))}" }`;
1324
- }
1325
- emitArgValue(aSpec, argToken) {
1326
- if (aSpec.type === "ref") return this.emitRefValue(argToken.text);
1327
- if (aSpec.type === "query" && argToken.queryNode) return this.emitQueryTree(argToken.queryNode);
1354
+ if (dotIdx === -1) return `() => ${this.annotationTypeName(text, origin)}`;
1355
+ return `{ type: () => ${this.annotationTypeName(text.slice(0, dotIdx), origin)}, field: "${escapeQuotes(text.slice(dotIdx + 1))}" }`;
1356
+ }
1357
+ emitArgValue(aSpec, argToken, origin) {
1358
+ if (aSpec.type === "ref") return this.emitRefValue(argToken.text, origin);
1359
+ if (aSpec.type === "query" && argToken.queryNode) return this.emitQueryTree(argToken.queryNode, origin);
1360
+ if (aSpec.type === "expr" && argToken.exprNode) return this.emitExprNode(argToken.exprNode.expression, origin);
1361
+ if (aSpec.type === "order" && argToken.orderNode) return `[${argToken.orderNode.items.map((item) => `{ ref: ${this.emitQueryFieldRef(item.ref, origin)}${item.desc ? ", desc: true" : ""} }`).join(", ")}]`;
1328
1362
  return aSpec.type === "string" ? `"${escapeQuotes(argToken.text)}"` : argToken.text;
1329
1363
  }
1330
- emitQueryTree(queryNode) {
1331
- return this.emitQueryExpr(queryNode.expression);
1364
+ emitExprNode(node, origin) {
1365
+ switch (node.entity) {
1366
+ case "query-expr-number": return String(node.value);
1367
+ case "query-expr-binary": {
1368
+ const { op, left, right } = node;
1369
+ return `{ op: "${op}", args: [${this.emitExprNode(left, origin)}, ${this.emitExprNode(right, origin)}] }`;
1370
+ }
1371
+ case "query-expr-unary": {
1372
+ const { op, operand } = node;
1373
+ return `{ op: "${op}", args: [${this.emitExprNode(operand, origin)}] }`;
1374
+ }
1375
+ case "query-expr-call": {
1376
+ const { fn, args } = node;
1377
+ return `{ op: "${fn}", args: [${args.map((a) => this.emitExprNode(a, origin)).join(", ")}] }`;
1378
+ }
1379
+ default: return this.emitQueryFieldRef(node, origin);
1380
+ }
1381
+ }
1382
+ emitQueryTree(queryNode, origin) {
1383
+ return this.emitQueryExpr(queryNode.expression, origin);
1332
1384
  }
1333
- emitQueryExpr(node) {
1334
- if ((0, _atscript_core.isQueryLogical)(node)) return this.emitQueryLogical(node);
1335
- return this.emitQueryComparison(node);
1385
+ emitQueryExpr(node, origin) {
1386
+ if ((0, _atscript_core.isQueryLogical)(node)) return this.emitQueryLogical(node, origin);
1387
+ return this.emitQueryComparison(node, origin);
1336
1388
  }
1337
- emitQueryLogical(node) {
1338
- if (node.operator === "not") return `{ "$not": ${this.emitQueryExpr(node.operands[0])} }`;
1339
- return `{ "${node.operator === "and" ? "$and" : "$or"}": [${node.operands.map((op) => this.emitQueryExpr(op)).join(", ")}] }`;
1389
+ emitQueryLogical(node, origin) {
1390
+ if (node.operator === "not") return `{ "$not": ${this.emitQueryExpr(node.operands[0], origin)} }`;
1391
+ return `{ "${node.operator === "and" ? "$and" : "$or"}": [${node.operands.map((op) => this.emitQueryExpr(op, origin)).join(", ")}] }`;
1340
1392
  }
1341
- emitQueryComparison(node) {
1342
- const left = this.emitQueryFieldRef(node.left);
1393
+ emitQueryComparison(node, origin) {
1394
+ const left = this.emitQueryFieldRef(node.left, origin);
1343
1395
  const mappedOp = QUERY_OP_MAP[node.operator] || node.operator;
1344
1396
  const parts = [`left: ${left}`, `op: "${mappedOp}"`];
1345
1397
  if (node.right) {
1346
- if ("fieldRef" in node.right && node.right.fieldRef) parts.push(`right: ${this.emitQueryFieldRef(node.right)}`);
1398
+ if ("fieldRef" in node.right && node.right.fieldRef) parts.push(`right: ${this.emitQueryFieldRef(node.right, origin)}`);
1347
1399
  else if ("values" in node.right && node.right.values) {
1348
1400
  const values = node.right.values.map((v) => this.emitQueryLiteral(v)).join(", ");
1349
1401
  parts.push(`right: [${values}]`);
@@ -1352,9 +1404,9 @@ var JsRenderer = class extends BaseRenderer {
1352
1404
  else if (node.operator === "not exists") parts.push("right: false");
1353
1405
  return `{ ${parts.join(", ")} }`;
1354
1406
  }
1355
- emitQueryFieldRef(node) {
1407
+ emitQueryFieldRef(node, origin) {
1356
1408
  const parts = [];
1357
- if (node.typeRef) parts.push(`type: () => ${node.typeRef.text}`);
1409
+ if (node.typeRef) parts.push(`type: () => ${this.annotationTypeName(node.typeRef.text, origin)}`);
1358
1410
  parts.push(`field: "${escapeQuotes(node.fieldRef.text)}"`);
1359
1411
  return `{ ${parts.join(", ")} }`;
1360
1412
  }
@@ -1375,6 +1427,7 @@ var JsRenderer = class extends BaseRenderer {
1375
1427
  }
1376
1428
  }
1377
1429
  computeAnnotationValue(node, an) {
1430
+ const origin = this.doc.annotationOrigin(an);
1378
1431
  const spec = this.doc.resolveAnnotation(an.name);
1379
1432
  let targetValue = "true";
1380
1433
  let multiple = false;
@@ -1385,13 +1438,13 @@ var JsRenderer = class extends BaseRenderer {
1385
1438
  targetValue = "{ ";
1386
1439
  let i = 0;
1387
1440
  for (const aSpec of spec.arguments) {
1388
- if (an.args[i]) targetValue += `${wrapProp(aSpec.name)}: ${this.emitArgValue(aSpec, an.args[i])}${i === length - 1 ? "" : ", "} `;
1441
+ if (an.args[i]) targetValue += `${wrapProp(aSpec.name)}: ${this.emitArgValue(aSpec, an.args[i], origin)}${i === length - 1 ? "" : ", "} `;
1389
1442
  i++;
1390
1443
  }
1391
1444
  targetValue += "}";
1392
1445
  } else {
1393
1446
  const aSpec = spec.arguments[0];
1394
- targetValue = an.args[0] ? this.emitArgValue(aSpec, an.args[0]) : "true";
1447
+ targetValue = an.args[0] ? this.emitArgValue(aSpec, an.args[0], origin) : "true";
1395
1448
  }
1396
1449
  } else {
1397
1450
  multiple = node.countAnnotations(an.name) > 1 || an.args.length > 1;
@@ -1529,7 +1582,7 @@ var JsRenderer = class extends BaseRenderer {
1529
1582
  return [];
1530
1583
  }
1531
1584
  constructor(doc, opts) {
1532
- super(doc), _define_property(this, "opts", void 0), _define_property(this, "postAnnotate", void 0), _define_property(this, "_adHocAnnotations", void 0), _define_property(this, "_propPath", void 0), _define_property(this, "typeIds", void 0), _define_property(this, "_unusedJs", void 0), _define_property(this, "_extendsRefs", void 0), _define_property(this, "_refSynthInfo", void 0), _define_property(this, "_synthImports", void 0), _define_property(this, "_synthComputed", void 0), _define_property(this, "_ownerCache", void 0), this.opts = opts, this.postAnnotate = [], this._adHocAnnotations = null, this._propPath = [], this.typeIds = /* @__PURE__ */ new Map(), this._refSynthInfo = /* @__PURE__ */ new Map(), this._synthImports = /* @__PURE__ */ new Map(), this._synthComputed = false, this._ownerCache = /* @__PURE__ */ new Map();
1585
+ super(doc), _define_property(this, "opts", void 0), _define_property(this, "postAnnotate", void 0), _define_property(this, "_adHocAnnotations", void 0), _define_property(this, "_propPath", void 0), _define_property(this, "typeIds", void 0), _define_property(this, "_unusedJs", void 0), _define_property(this, "_extendsRefs", void 0), _define_property(this, "_refSynthInfo", void 0), _define_property(this, "_synthImports", void 0), _define_property(this, "_synthComputed", void 0), _define_property(this, "_synthTaken", void 0), _define_property(this, "_synthAllocated", void 0), _define_property(this, "_synthPathCache", void 0), _define_property(this, "_ownerCache", void 0), this.opts = opts, this.postAnnotate = [], this._adHocAnnotations = null, this._propPath = [], this.typeIds = /* @__PURE__ */ new Map(), this._refSynthInfo = /* @__PURE__ */ new Map(), this._synthImports = /* @__PURE__ */ new Map(), this._synthComputed = false, this._synthAllocated = /* @__PURE__ */ new Map(), this._synthPathCache = /* @__PURE__ */ new Map(), this._ownerCache = /* @__PURE__ */ new Map();
1533
1586
  }
1534
1587
  };
1535
1588