@atscript/typescript 0.2.3 → 0.2.4
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 +211 -29
- package/dist/index.cjs +3 -3
- package/dist/index.mjs +2 -2
- package/dist/{plugin-oUSsb3Ri.cjs → plugin-Cqao46Gt.cjs} +62 -23
- package/dist/{plugin-DhesoKce.mjs → plugin-Ct9Ko5JG.mjs} +59 -20
- package/dist/realm-runtime.js +867 -256
- package/dist/test-utils.cjs +3 -3
- package/dist/test-utils.d.ts +179 -4
- package/dist/test-utils.mjs +2 -2
- package/dist/{unique-name-xWd9uO-k.cjs → user-text-BddKk8EU.cjs} +823 -191
- package/dist/{unique-name-hg1CyPIs.mjs → user-text-qL59indq.mjs} +758 -192
- package/dist/utils.cjs +158 -154
- package/dist/utils.d.ts +312 -28
- package/dist/utils.mjs +58 -63
- package/package.json +5 -5
|
@@ -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
|
|
28
|
+
const require_user_text = require('./user-text-BddKk8EU.cjs');
|
|
29
29
|
let path = require("path");
|
|
30
30
|
path = __toESM(path);
|
|
31
31
|
let _atscript_core = require("@atscript/core");
|
|
@@ -182,7 +182,7 @@ var BaseRenderer = class extends CodePrinter {
|
|
|
182
182
|
renderType(node) {}
|
|
183
183
|
renderAnnotate(node) {}
|
|
184
184
|
transformFromPath(path) {
|
|
185
|
-
return `${path}.as`;
|
|
185
|
+
return `${(0, _atscript_core.withoutAsExtension)(path)}.as`;
|
|
186
186
|
}
|
|
187
187
|
renderImport(node) {
|
|
188
188
|
const def = node.getDefinition();
|
|
@@ -380,7 +380,8 @@ const CHECKS_IMPORT_MARKER = "/*@@atscript-compiled-checks-import@@*/";
|
|
|
380
380
|
bundledSchemaOf: "$jbm",
|
|
381
381
|
$ps: "$ps",
|
|
382
382
|
$ak: "$ak",
|
|
383
|
-
$nr: "$nk"
|
|
383
|
+
$nr: "$nk",
|
|
384
|
+
$ut: "$ut"
|
|
384
385
|
};
|
|
385
386
|
const LITERAL_IDENTIFIERS = new Set([
|
|
386
387
|
"true",
|
|
@@ -434,7 +435,8 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
434
435
|
/**
|
|
435
436
|
* Relative imports get the configured `moduleExtension`; bare specifiers
|
|
436
437
|
* always keep `.as` — they resolve through the package's `exports` map.
|
|
437
|
-
*/ transformFromPath(
|
|
438
|
+
*/ transformFromPath(written) {
|
|
439
|
+
const path = (0, _atscript_core.withoutAsExtension)(written);
|
|
438
440
|
return (0, _atscript_core.isBareSpecifier)(path) ? `${path}.as` : `${path}${this.opts?.moduleExtension ?? ".as"}`;
|
|
439
441
|
}
|
|
440
442
|
/**
|
|
@@ -518,7 +520,7 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
518
520
|
};
|
|
519
521
|
}
|
|
520
522
|
/** `name`, suffixed (`_1`, `_2`, …) when `taken`; the result is taken from now on. */ allocAlias(name, taken) {
|
|
521
|
-
const alias =
|
|
523
|
+
const alias = require_user_text.uniqueName(name, (n) => taken.has(n), "_");
|
|
522
524
|
taken.add(alias);
|
|
523
525
|
return alias;
|
|
524
526
|
}
|
|
@@ -836,12 +838,16 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
836
838
|
if (dotIdx === -1) return `() => ${this.annotationTypeName(text, origin)}`;
|
|
837
839
|
return `{ type: () => ${this.annotationTypeName(text.slice(0, dotIdx), origin)}, field: "${escapeQuotes(text.slice(dotIdx + 1))}" }`;
|
|
838
840
|
}
|
|
839
|
-
emitArgValue(aSpec, argToken, origin) {
|
|
841
|
+
emitArgValue(aSpec, argToken, origin, mainToken) {
|
|
840
842
|
if (aSpec.type === "ref") return this.emitRefValue(argToken.text, origin);
|
|
841
843
|
if (aSpec.type === "query" && argToken.queryNode) return this.emitQueryTree(argToken.queryNode, origin);
|
|
842
844
|
if (aSpec.type === "expr" && argToken.exprNode) return this.emitExprNode(argToken.exprNode.expression, origin);
|
|
843
845
|
if (aSpec.type === "order" && argToken.orderNode) return `[${argToken.orderNode.items.map((item) => `{ ref: ${this.emitQueryFieldRef(item.ref, origin)}${item.desc ? ", desc: true" : ""} }`).join(", ")}]`;
|
|
844
|
-
return aSpec.type === "string" ? `"${escapeQuotes(argToken.text)}"` : argToken.text;
|
|
846
|
+
return aSpec.type === "string" || aSpec.type === "value" && (argToken.type === "text" || argToken.type === "number" && this.decimalField(mainToken, origin)) ? `"${escapeQuotes(argToken.text)}"` : argToken.text;
|
|
847
|
+
}
|
|
848
|
+
/** Whether annotation `mainToken` is written on a `decimal` field (not one that holds numbers). */ decimalField(mainToken, origin) {
|
|
849
|
+
const kinds = (0, _atscript_core.annotatedValueKinds)(mainToken, origin ?? this.doc);
|
|
850
|
+
return !!kinds?.has("decimal") && !kinds.has("number") && !kinds.has("unknown");
|
|
845
851
|
}
|
|
846
852
|
emitExprNode(node, origin) {
|
|
847
853
|
switch (node.entity) {
|
|
@@ -921,13 +927,13 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
921
927
|
targetValue = "{ ";
|
|
922
928
|
let i = 0;
|
|
923
929
|
for (const aSpec of spec.arguments) {
|
|
924
|
-
if (an.args[i]) targetValue += `${wrapProp(aSpec.name)}: ${this.emitArgValue(aSpec, an.args[i], origin)}${i === length - 1 ? "" : ", "} `;
|
|
930
|
+
if (an.args[i]) targetValue += `${wrapProp(aSpec.name)}: ${this.emitArgValue(aSpec, an.args[i], origin, an.token)}${i === length - 1 ? "" : ", "} `;
|
|
925
931
|
i++;
|
|
926
932
|
}
|
|
927
933
|
targetValue += "}";
|
|
928
934
|
} else if (an.args[0]) {
|
|
929
935
|
const aSpec = spec.arguments[0];
|
|
930
|
-
targetValue = this.emitArgValue(aSpec, an.args[0], origin);
|
|
936
|
+
targetValue = this.emitArgValue(aSpec, an.args[0], origin, an.token);
|
|
931
937
|
}
|
|
932
938
|
}
|
|
933
939
|
} else {
|
|
@@ -1282,7 +1288,7 @@ const flagKeysMemo = /* @__PURE__ */ new WeakMap();
|
|
|
1282
1288
|
* `let`, exported with an exported declaration (another module's merge may have its fields as
|
|
1283
1289
|
* contributors: a merge operand is flattened into its operands).
|
|
1284
1290
|
*/ function inPlaceName(d, steps) {
|
|
1285
|
-
return
|
|
1291
|
+
return require_user_text.uniqueName(`$i_${d.name}_${steps.map((s) => s.replace(/[^\w$]/g, (c) => c === "&" ? "" : "_")).join("_")}`, (n) => d.doc.registry.definitions.has(n) || d.doc.importedDefs.has(n), "_");
|
|
1286
1292
|
}
|
|
1287
1293
|
const hiddenExports = /* @__PURE__ */ new WeakMap();
|
|
1288
1294
|
/**
|
|
@@ -1319,7 +1325,7 @@ const hiddenExports = /* @__PURE__ */ new WeakMap();
|
|
|
1319
1325
|
def: def.base
|
|
1320
1326
|
});
|
|
1321
1327
|
if (def.kind === "merge" || def.kind === "umerge") {
|
|
1322
|
-
const name =
|
|
1328
|
+
const name = require_user_text.uniqueName(`$h_${[decl.name, ...steps.map((s) => s.replace(/[^\w$]/g, "_"))].join("_")}`, (n) => names.has(n) || doc.registry.definitions.has(n) || doc.importedDefs.has(n), "_");
|
|
1323
1329
|
names.add(name);
|
|
1324
1330
|
out.set(def.key, name);
|
|
1325
1331
|
}
|
|
@@ -1430,7 +1436,13 @@ var JsNextRenderer = class extends JsRenderer {
|
|
|
1430
1436
|
}
|
|
1431
1437
|
/** `$a(P.metadata, …)` writes of a class's own annotations (after its `$alias`). */ annotateCalls(name, node) {
|
|
1432
1438
|
let out = "";
|
|
1439
|
+
const resets = (node.annotations ?? []).filter((an) => an.name === _atscript_core.ANNOTATE_RESET);
|
|
1440
|
+
if (resets.length > 0) {
|
|
1441
|
+
const data = this.blockAnnotationsData(node, resets);
|
|
1442
|
+
out += `\n${this.util("$blk")}(null, -1, ${name}, [[[${data.join(", ")}], []]])`;
|
|
1443
|
+
}
|
|
1433
1444
|
for (const an of node.annotations ?? []) {
|
|
1445
|
+
if (an.name === _atscript_core.ANNOTATE_RESET) continue;
|
|
1434
1446
|
const { value, multiple } = this.computeAnnotationValue(node, an);
|
|
1435
1447
|
out += `\n${this.util("annotate")}(${name}.metadata, ${str(an.name)}, ${value}${multiple ? ", true" : ""})`;
|
|
1436
1448
|
}
|
|
@@ -2371,19 +2383,21 @@ var JsNextRenderer = class extends JsRenderer {
|
|
|
2371
2383
|
* The statement needs what the paths go through built (`$f` guards, needs).
|
|
2372
2384
|
*/ entriesData(b, reads) {
|
|
2373
2385
|
const entries = [];
|
|
2374
|
-
|
|
2375
|
-
const { value, multiple } = this.computeAnnotationValue(node, an);
|
|
2376
|
-
return `[${str(an.name)}, ${value}${multiple ? ", 1" : ""}]`;
|
|
2377
|
-
});
|
|
2378
|
-
if (b.rank && b.node.annotations?.length) entries.push(`[[${annotationsOf(b.node).join(", ")}], []]`);
|
|
2386
|
+
if (b.rank && b.node.annotations?.length) entries.push(`[[${this.blockAnnotationsData(b.node).join(", ")}], []]`);
|
|
2379
2387
|
for (const en of b.entries) {
|
|
2380
2388
|
if (en.error || en.paths.length === 0) continue;
|
|
2381
2389
|
const copy = reads !== b.target;
|
|
2382
2390
|
const paths = en.paths.map((p, i) => `[${stepsText(this.stepsData(reads, p, en.kinds[i], false, copy))}]`);
|
|
2383
|
-
entries.push(`[[${
|
|
2391
|
+
entries.push(`[[${this.blockAnnotationsData(en.ref).join(", ")}], ${paths.join(", ")}]`);
|
|
2384
2392
|
}
|
|
2385
2393
|
return entries.length > 0 ? `[\n ${entries.join(",\n ")},\n]` : "";
|
|
2386
2394
|
}
|
|
2395
|
+
/** Annotations `anns` of `node` as `$blk` entry data: `[name, value]`, `, 1` for a `multiple`. */ blockAnnotationsData(node, anns = node.annotations ?? []) {
|
|
2396
|
+
return anns.map((an) => {
|
|
2397
|
+
const { value, multiple } = this.computeAnnotationValue(node, an);
|
|
2398
|
+
return `[${str(an.name)}, ${value}${multiple ? ", 1" : ""}]`;
|
|
2399
|
+
});
|
|
2400
|
+
}
|
|
2387
2401
|
/**
|
|
2388
2402
|
* The runtime `[step, kind]`s of model path `p` of `reads` (an `as` copy's: its target's
|
|
2389
2403
|
* structure), and its needs: the classes it walks are built first (a shell def clones a built
|
|
@@ -2610,7 +2624,7 @@ var JsNextRenderer = class extends JsRenderer {
|
|
|
2610
2624
|
};
|
|
2611
2625
|
this.shellIndex.set(n, x);
|
|
2612
2626
|
const names = p.map(([s]) => s);
|
|
2613
|
-
for (const j of
|
|
2627
|
+
for (const j of require_user_text.stageEnds(p)) {
|
|
2614
2628
|
const kind = p[j][1];
|
|
2615
2629
|
const at = pathKey(names.slice(0, j + 1));
|
|
2616
2630
|
if (kind !== 0 && (j === p.length - 1 || !x.at.has(at))) {
|
|
@@ -2871,14 +2885,33 @@ var JsNextRenderer = class extends JsRenderer {
|
|
|
2871
2885
|
const rank = blocks[0].rank;
|
|
2872
2886
|
return `const ${R} = [${rank.depth}, ${str(rank.id)}]`;
|
|
2873
2887
|
}
|
|
2874
|
-
/**
|
|
2888
|
+
/**
|
|
2889
|
+
* The registries (`$ak`, `$nr`: how layers read those keys; `$ut`: the keys holding user-facing
|
|
2890
|
+
* text), before any statement.
|
|
2891
|
+
*/ registries() {
|
|
2875
2892
|
const { append, notReferred } = flagKeys(this.doc.config.annotations);
|
|
2876
2893
|
const out = [];
|
|
2877
2894
|
if (append.length > 0) out.push(`${this.util("$ak")}(${append.map(str).join(", ")})`);
|
|
2878
2895
|
if (notReferred.length > 0) out.push(`${this.util("$nr")}(${notReferred.map(str).join(", ")})`);
|
|
2896
|
+
const userText = this.moduleUserText();
|
|
2897
|
+
if (userText.length > 0) out.push(`${this.util("$ut")}(${userText.map(str).join(", ")})`);
|
|
2879
2898
|
return out;
|
|
2880
2899
|
}
|
|
2881
2900
|
/**
|
|
2901
|
+
* The plugin annotations holding user-facing text this module writes (`$ut` entries: `key`, or
|
|
2902
|
+
* `key:field`); core's are known to the runtime from the start (`CORE_USER_TEXT`).
|
|
2903
|
+
*/ moduleUserText() {
|
|
2904
|
+
const out = /* @__PURE__ */ new Set();
|
|
2905
|
+
for (const name of new Set(this.doc.annotations.map((a) => a.name))) {
|
|
2906
|
+
if (require_user_text.CORE_USER_TEXT.has(name)) continue;
|
|
2907
|
+
const spec = this.doc.resolveAnnotation(name);
|
|
2908
|
+
const fields = spec && (0, _atscript_core.userTextFields)(spec);
|
|
2909
|
+
if (fields === true) out.add(name);
|
|
2910
|
+
else if (fields) for (const f of fields) out.add(`${name}:${f}`);
|
|
2911
|
+
}
|
|
2912
|
+
return [...out].sort();
|
|
2913
|
+
}
|
|
2914
|
+
/**
|
|
2882
2915
|
* The runtime steps of a model path: a `X | null` union the model passes through is a union
|
|
2883
2916
|
* node at runtime (its non-null item: `|i`, own when the union's holder is, else shelled).
|
|
2884
2917
|
*/ runtimeSteps(d, steps, kinds, { copy = false, items: withItems = false, pure = false } = {}) {
|
|
@@ -3658,11 +3691,14 @@ var TypeRenderer = class TypeRenderer extends BaseRenderer {
|
|
|
3658
3691
|
const written = only?.prop.getDefinition();
|
|
3659
3692
|
return written && !((0, _atscript_core.isGroup)(only.def) && only.def !== written) ? written : only?.def;
|
|
3660
3693
|
}
|
|
3694
|
+
/** The TypeScript type of a final primitive type (`any`, the `unknown` primitive: `unknown`). */ function finalTsType(t) {
|
|
3695
|
+
return t === "void" ? "undefined" : t === "any" ? "unknown" : t;
|
|
3696
|
+
}
|
|
3661
3697
|
function renderPrimitiveTypeDef(def) {
|
|
3662
3698
|
if (!def) return "unknown";
|
|
3663
|
-
if (typeof def === "string") return def
|
|
3699
|
+
if (typeof def === "string") return finalTsType(def);
|
|
3664
3700
|
switch (def.kind) {
|
|
3665
|
-
case "final": return def.value
|
|
3701
|
+
case "final": return finalTsType(def.value);
|
|
3666
3702
|
case "union": return def.items.map(renderPrimitiveTypeDef).join(" | ");
|
|
3667
3703
|
case "intersection": return def.items.map((item) => typeof item === "object" && item.kind === "union" ? `(${renderPrimitiveTypeDef(item)})` : renderPrimitiveTypeDef(item)).join(" & ");
|
|
3668
3704
|
case "tuple": return `[${def.items.map(renderPrimitiveTypeDef).join(", ")}]`;
|
|
@@ -3724,8 +3760,11 @@ const tsPlugin = (opts) => {
|
|
|
3724
3760
|
for (const [key, val] of Object.entries(annotations)) {
|
|
3725
3761
|
const multiple = val.multiple;
|
|
3726
3762
|
const typeLine = Array.from(val.types).map((t) => {
|
|
3727
|
-
if (t.type === "object" && "props" in t)
|
|
3728
|
-
|
|
3763
|
+
if (t.type === "object" && "props" in t) {
|
|
3764
|
+
const props = Object.entries(t.props);
|
|
3765
|
+
const object = `{ ${props.map(([k, v]) => `${wrapProp(k)}${v.optional ? "?" : ""}: ${v.type}`).join(", ")} }`;
|
|
3766
|
+
return props.length === 1 && props[0][1].optional ? `${object} | true` : object;
|
|
3767
|
+
} else return "optional" in t && t.optional ? `${t.type} | true` : t.type;
|
|
3729
3768
|
}).join(" | ");
|
|
3730
3769
|
rendered.push(`${wrapProp(key)}: ${multiple ? "(" : ""}${typeLine}${multiple ? ")[]" : ""}`);
|
|
3731
3770
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as CORE_USER_TEXT, o as uniqueName, v as stageEnds } from "./user-text-qL59indq.mjs";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import { DEFAULT_FORMAT, MERGE_TOO_COMPLEX, NAV_PROP_ANNOTATIONS, SemanticGroup, andExprs, componentOf, components, defPosition, documentsEpoch, entryParts, flatDefinitions, forEachAnnotationSpec, getRelPath, hasMutatingAnnotates, hasNavPropAnnotation, isAnnotate, isArray, isAsView, isBareId, isBareSpecifier, isConst, isDbEntityNode, isGroup, isInterface, isNull, isPhantomNode, isPrimitive, isQueryLogical, isRef, isStructure, isTuple, moduleId, pastViews, resolveAtscriptFromPath, unshell } from "@atscript/core";
|
|
3
|
+
import { ANNOTATE_RESET, DEFAULT_FORMAT, MERGE_TOO_COMPLEX, NAV_PROP_ANNOTATIONS, SemanticGroup, andExprs, annotatedValueKinds, componentOf, components, defPosition, documentsEpoch, entryParts, flatDefinitions, forEachAnnotationSpec, getRelPath, hasMutatingAnnotates, hasNavPropAnnotation, isAnnotate, isArray, isAsView, isBareId, isBareSpecifier, isConst, isDbEntityNode, isGroup, isInterface, isNull, isPhantomNode, isPrimitive, isQueryLogical, isRef, isStructure, isTuple, moduleId, pastViews, resolveAtscriptFromPath, unshell, userTextFields, withoutAsExtension } from "@atscript/core";
|
|
4
4
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
5
|
import { readFileSync } from "fs";
|
|
6
6
|
import { fileURLToPath } from "url";
|
|
@@ -154,7 +154,7 @@ var BaseRenderer = class extends CodePrinter {
|
|
|
154
154
|
renderType(node) {}
|
|
155
155
|
renderAnnotate(node) {}
|
|
156
156
|
transformFromPath(path) {
|
|
157
|
-
return `${path}.as`;
|
|
157
|
+
return `${withoutAsExtension(path)}.as`;
|
|
158
158
|
}
|
|
159
159
|
renderImport(node) {
|
|
160
160
|
const def = node.getDefinition();
|
|
@@ -352,7 +352,8 @@ const CHECKS_IMPORT_MARKER = "/*@@atscript-compiled-checks-import@@*/";
|
|
|
352
352
|
bundledSchemaOf: "$jbm",
|
|
353
353
|
$ps: "$ps",
|
|
354
354
|
$ak: "$ak",
|
|
355
|
-
$nr: "$nk"
|
|
355
|
+
$nr: "$nk",
|
|
356
|
+
$ut: "$ut"
|
|
356
357
|
};
|
|
357
358
|
const LITERAL_IDENTIFIERS = new Set([
|
|
358
359
|
"true",
|
|
@@ -406,7 +407,8 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
406
407
|
/**
|
|
407
408
|
* Relative imports get the configured `moduleExtension`; bare specifiers
|
|
408
409
|
* always keep `.as` — they resolve through the package's `exports` map.
|
|
409
|
-
*/ transformFromPath(
|
|
410
|
+
*/ transformFromPath(written) {
|
|
411
|
+
const path = withoutAsExtension(written);
|
|
410
412
|
return isBareSpecifier(path) ? `${path}.as` : `${path}${this.opts?.moduleExtension ?? ".as"}`;
|
|
411
413
|
}
|
|
412
414
|
/**
|
|
@@ -808,12 +810,16 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
808
810
|
if (dotIdx === -1) return `() => ${this.annotationTypeName(text, origin)}`;
|
|
809
811
|
return `{ type: () => ${this.annotationTypeName(text.slice(0, dotIdx), origin)}, field: "${escapeQuotes(text.slice(dotIdx + 1))}" }`;
|
|
810
812
|
}
|
|
811
|
-
emitArgValue(aSpec, argToken, origin) {
|
|
813
|
+
emitArgValue(aSpec, argToken, origin, mainToken) {
|
|
812
814
|
if (aSpec.type === "ref") return this.emitRefValue(argToken.text, origin);
|
|
813
815
|
if (aSpec.type === "query" && argToken.queryNode) return this.emitQueryTree(argToken.queryNode, origin);
|
|
814
816
|
if (aSpec.type === "expr" && argToken.exprNode) return this.emitExprNode(argToken.exprNode.expression, origin);
|
|
815
817
|
if (aSpec.type === "order" && argToken.orderNode) return `[${argToken.orderNode.items.map((item) => `{ ref: ${this.emitQueryFieldRef(item.ref, origin)}${item.desc ? ", desc: true" : ""} }`).join(", ")}]`;
|
|
816
|
-
return aSpec.type === "string" ? `"${escapeQuotes(argToken.text)}"` : argToken.text;
|
|
818
|
+
return aSpec.type === "string" || aSpec.type === "value" && (argToken.type === "text" || argToken.type === "number" && this.decimalField(mainToken, origin)) ? `"${escapeQuotes(argToken.text)}"` : argToken.text;
|
|
819
|
+
}
|
|
820
|
+
/** Whether annotation `mainToken` is written on a `decimal` field (not one that holds numbers). */ decimalField(mainToken, origin) {
|
|
821
|
+
const kinds = annotatedValueKinds(mainToken, origin ?? this.doc);
|
|
822
|
+
return !!kinds?.has("decimal") && !kinds.has("number") && !kinds.has("unknown");
|
|
817
823
|
}
|
|
818
824
|
emitExprNode(node, origin) {
|
|
819
825
|
switch (node.entity) {
|
|
@@ -893,13 +899,13 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
893
899
|
targetValue = "{ ";
|
|
894
900
|
let i = 0;
|
|
895
901
|
for (const aSpec of spec.arguments) {
|
|
896
|
-
if (an.args[i]) targetValue += `${wrapProp(aSpec.name)}: ${this.emitArgValue(aSpec, an.args[i], origin)}${i === length - 1 ? "" : ", "} `;
|
|
902
|
+
if (an.args[i]) targetValue += `${wrapProp(aSpec.name)}: ${this.emitArgValue(aSpec, an.args[i], origin, an.token)}${i === length - 1 ? "" : ", "} `;
|
|
897
903
|
i++;
|
|
898
904
|
}
|
|
899
905
|
targetValue += "}";
|
|
900
906
|
} else if (an.args[0]) {
|
|
901
907
|
const aSpec = spec.arguments[0];
|
|
902
|
-
targetValue = this.emitArgValue(aSpec, an.args[0], origin);
|
|
908
|
+
targetValue = this.emitArgValue(aSpec, an.args[0], origin, an.token);
|
|
903
909
|
}
|
|
904
910
|
}
|
|
905
911
|
} else {
|
|
@@ -1402,7 +1408,13 @@ var JsNextRenderer = class extends JsRenderer {
|
|
|
1402
1408
|
}
|
|
1403
1409
|
/** `$a(P.metadata, …)` writes of a class's own annotations (after its `$alias`). */ annotateCalls(name, node) {
|
|
1404
1410
|
let out = "";
|
|
1411
|
+
const resets = (node.annotations ?? []).filter((an) => an.name === ANNOTATE_RESET);
|
|
1412
|
+
if (resets.length > 0) {
|
|
1413
|
+
const data = this.blockAnnotationsData(node, resets);
|
|
1414
|
+
out += `\n${this.util("$blk")}(null, -1, ${name}, [[[${data.join(", ")}], []]])`;
|
|
1415
|
+
}
|
|
1405
1416
|
for (const an of node.annotations ?? []) {
|
|
1417
|
+
if (an.name === ANNOTATE_RESET) continue;
|
|
1406
1418
|
const { value, multiple } = this.computeAnnotationValue(node, an);
|
|
1407
1419
|
out += `\n${this.util("annotate")}(${name}.metadata, ${str(an.name)}, ${value}${multiple ? ", true" : ""})`;
|
|
1408
1420
|
}
|
|
@@ -2343,19 +2355,21 @@ var JsNextRenderer = class extends JsRenderer {
|
|
|
2343
2355
|
* The statement needs what the paths go through built (`$f` guards, needs).
|
|
2344
2356
|
*/ entriesData(b, reads) {
|
|
2345
2357
|
const entries = [];
|
|
2346
|
-
|
|
2347
|
-
const { value, multiple } = this.computeAnnotationValue(node, an);
|
|
2348
|
-
return `[${str(an.name)}, ${value}${multiple ? ", 1" : ""}]`;
|
|
2349
|
-
});
|
|
2350
|
-
if (b.rank && b.node.annotations?.length) entries.push(`[[${annotationsOf(b.node).join(", ")}], []]`);
|
|
2358
|
+
if (b.rank && b.node.annotations?.length) entries.push(`[[${this.blockAnnotationsData(b.node).join(", ")}], []]`);
|
|
2351
2359
|
for (const en of b.entries) {
|
|
2352
2360
|
if (en.error || en.paths.length === 0) continue;
|
|
2353
2361
|
const copy = reads !== b.target;
|
|
2354
2362
|
const paths = en.paths.map((p, i) => `[${stepsText(this.stepsData(reads, p, en.kinds[i], false, copy))}]`);
|
|
2355
|
-
entries.push(`[[${
|
|
2363
|
+
entries.push(`[[${this.blockAnnotationsData(en.ref).join(", ")}], ${paths.join(", ")}]`);
|
|
2356
2364
|
}
|
|
2357
2365
|
return entries.length > 0 ? `[\n ${entries.join(",\n ")},\n]` : "";
|
|
2358
2366
|
}
|
|
2367
|
+
/** Annotations `anns` of `node` as `$blk` entry data: `[name, value]`, `, 1` for a `multiple`. */ blockAnnotationsData(node, anns = node.annotations ?? []) {
|
|
2368
|
+
return anns.map((an) => {
|
|
2369
|
+
const { value, multiple } = this.computeAnnotationValue(node, an);
|
|
2370
|
+
return `[${str(an.name)}, ${value}${multiple ? ", 1" : ""}]`;
|
|
2371
|
+
});
|
|
2372
|
+
}
|
|
2359
2373
|
/**
|
|
2360
2374
|
* The runtime `[step, kind]`s of model path `p` of `reads` (an `as` copy's: its target's
|
|
2361
2375
|
* structure), and its needs: the classes it walks are built first (a shell def clones a built
|
|
@@ -2843,14 +2857,33 @@ var JsNextRenderer = class extends JsRenderer {
|
|
|
2843
2857
|
const rank = blocks[0].rank;
|
|
2844
2858
|
return `const ${R} = [${rank.depth}, ${str(rank.id)}]`;
|
|
2845
2859
|
}
|
|
2846
|
-
/**
|
|
2860
|
+
/**
|
|
2861
|
+
* The registries (`$ak`, `$nr`: how layers read those keys; `$ut`: the keys holding user-facing
|
|
2862
|
+
* text), before any statement.
|
|
2863
|
+
*/ registries() {
|
|
2847
2864
|
const { append, notReferred } = flagKeys(this.doc.config.annotations);
|
|
2848
2865
|
const out = [];
|
|
2849
2866
|
if (append.length > 0) out.push(`${this.util("$ak")}(${append.map(str).join(", ")})`);
|
|
2850
2867
|
if (notReferred.length > 0) out.push(`${this.util("$nr")}(${notReferred.map(str).join(", ")})`);
|
|
2868
|
+
const userText = this.moduleUserText();
|
|
2869
|
+
if (userText.length > 0) out.push(`${this.util("$ut")}(${userText.map(str).join(", ")})`);
|
|
2851
2870
|
return out;
|
|
2852
2871
|
}
|
|
2853
2872
|
/**
|
|
2873
|
+
* The plugin annotations holding user-facing text this module writes (`$ut` entries: `key`, or
|
|
2874
|
+
* `key:field`); core's are known to the runtime from the start (`CORE_USER_TEXT`).
|
|
2875
|
+
*/ moduleUserText() {
|
|
2876
|
+
const out = /* @__PURE__ */ new Set();
|
|
2877
|
+
for (const name of new Set(this.doc.annotations.map((a) => a.name))) {
|
|
2878
|
+
if (CORE_USER_TEXT.has(name)) continue;
|
|
2879
|
+
const spec = this.doc.resolveAnnotation(name);
|
|
2880
|
+
const fields = spec && userTextFields(spec);
|
|
2881
|
+
if (fields === true) out.add(name);
|
|
2882
|
+
else if (fields) for (const f of fields) out.add(`${name}:${f}`);
|
|
2883
|
+
}
|
|
2884
|
+
return [...out].sort();
|
|
2885
|
+
}
|
|
2886
|
+
/**
|
|
2854
2887
|
* The runtime steps of a model path: a `X | null` union the model passes through is a union
|
|
2855
2888
|
* node at runtime (its non-null item: `|i`, own when the union's holder is, else shelled).
|
|
2856
2889
|
*/ runtimeSteps(d, steps, kinds, { copy = false, items: withItems = false, pure = false } = {}) {
|
|
@@ -3630,11 +3663,14 @@ var TypeRenderer = class TypeRenderer extends BaseRenderer {
|
|
|
3630
3663
|
const written = only?.prop.getDefinition();
|
|
3631
3664
|
return written && !(isGroup(only.def) && only.def !== written) ? written : only?.def;
|
|
3632
3665
|
}
|
|
3666
|
+
/** The TypeScript type of a final primitive type (`any`, the `unknown` primitive: `unknown`). */ function finalTsType(t) {
|
|
3667
|
+
return t === "void" ? "undefined" : t === "any" ? "unknown" : t;
|
|
3668
|
+
}
|
|
3633
3669
|
function renderPrimitiveTypeDef(def) {
|
|
3634
3670
|
if (!def) return "unknown";
|
|
3635
|
-
if (typeof def === "string") return def
|
|
3671
|
+
if (typeof def === "string") return finalTsType(def);
|
|
3636
3672
|
switch (def.kind) {
|
|
3637
|
-
case "final": return def.value
|
|
3673
|
+
case "final": return finalTsType(def.value);
|
|
3638
3674
|
case "union": return def.items.map(renderPrimitiveTypeDef).join(" | ");
|
|
3639
3675
|
case "intersection": return def.items.map((item) => typeof item === "object" && item.kind === "union" ? `(${renderPrimitiveTypeDef(item)})` : renderPrimitiveTypeDef(item)).join(" & ");
|
|
3640
3676
|
case "tuple": return `[${def.items.map(renderPrimitiveTypeDef).join(", ")}]`;
|
|
@@ -3696,8 +3732,11 @@ const tsPlugin = (opts) => {
|
|
|
3696
3732
|
for (const [key, val] of Object.entries(annotations)) {
|
|
3697
3733
|
const multiple = val.multiple;
|
|
3698
3734
|
const typeLine = Array.from(val.types).map((t) => {
|
|
3699
|
-
if (t.type === "object" && "props" in t)
|
|
3700
|
-
|
|
3735
|
+
if (t.type === "object" && "props" in t) {
|
|
3736
|
+
const props = Object.entries(t.props);
|
|
3737
|
+
const object = `{ ${props.map(([k, v]) => `${wrapProp(k)}${v.optional ? "?" : ""}: ${v.type}`).join(", ")} }`;
|
|
3738
|
+
return props.length === 1 && props[0][1].optional ? `${object} | true` : object;
|
|
3739
|
+
} else return "optional" in t && t.optional ? `${t.type} | true` : t.type;
|
|
3701
3740
|
}).join(" | ");
|
|
3702
3741
|
rendered.push(`${wrapProp(key)}: ${multiple ? "(" : ""}${typeLine}${multiple ? ")[]" : ""}`);
|
|
3703
3742
|
}
|