@atscript/typescript 0.1.109 → 0.1.110
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 +1587 -189
- package/dist/index.cjs +5 -2
- package/dist/index.d.ts +53 -1
- package/dist/index.mjs +3 -3
- package/dist/{json-schema-CioBVi6F.mjs → json-schema-B3iAqkGQ.cjs} +919 -37
- package/dist/{json-schema-9OBvrg9D.cjs → json-schema-BG1SEcjI.mjs} +618 -120
- package/dist/{plugin-D3_BnRrI.mjs → plugin-DpzE8aJr.mjs} +955 -116
- package/dist/{plugin-6r27w6rG.cjs → plugin-mzTvme4k.cjs} +966 -115
- package/dist/test-utils.cjs +4 -4
- package/dist/test-utils.d.ts +53 -0
- package/dist/test-utils.mjs +4 -4
- package/dist/utils.cjs +14 -26
- package/dist/utils.d.ts +81 -2
- package/dist/utils.mjs +13 -27
- package/package.json +3 -3
|
@@ -25,13 +25,13 @@ 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-
|
|
28
|
+
const require_json_schema = require('./json-schema-B3iAqkGQ.cjs');
|
|
29
29
|
let path = require("path");
|
|
30
30
|
path = __toESM(path);
|
|
31
31
|
let _atscript_core = require("@atscript/core");
|
|
32
32
|
|
|
33
33
|
//#region packages/typescript/src/codegen/code-printer.ts
|
|
34
|
-
function _define_property$
|
|
34
|
+
function _define_property$5(obj, key, value) {
|
|
35
35
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
36
36
|
value,
|
|
37
37
|
enumerable: true,
|
|
@@ -124,17 +124,17 @@ var CodePrinter = class {
|
|
|
124
124
|
return " ".repeat(this.indentLevel * this.indentSize);
|
|
125
125
|
}
|
|
126
126
|
constructor() {
|
|
127
|
-
_define_property$
|
|
128
|
-
_define_property$
|
|
129
|
-
_define_property$
|
|
130
|
-
_define_property$
|
|
131
|
-
_define_property$
|
|
127
|
+
_define_property$5(this, "lines", []);
|
|
128
|
+
_define_property$5(this, "currentLine", "");
|
|
129
|
+
_define_property$5(this, "indentLevel", 0);
|
|
130
|
+
_define_property$5(this, "indentSize", 2);
|
|
131
|
+
_define_property$5(this, "blockStack", []);
|
|
132
132
|
}
|
|
133
133
|
};
|
|
134
134
|
|
|
135
135
|
//#endregion
|
|
136
136
|
//#region packages/typescript/src/codegen/base-renderer.ts
|
|
137
|
-
function _define_property$
|
|
137
|
+
function _define_property$4(obj, key, value) {
|
|
138
138
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
139
139
|
value,
|
|
140
140
|
enumerable: true,
|
|
@@ -197,7 +197,7 @@ var BaseRenderer = class extends CodePrinter {
|
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
constructor(doc) {
|
|
200
|
-
super(), _define_property$
|
|
200
|
+
super(), _define_property$4(this, "doc", void 0), _define_property$4(this, "_unused", void 0), this.doc = doc;
|
|
201
201
|
}
|
|
202
202
|
};
|
|
203
203
|
|
|
@@ -220,7 +220,7 @@ function escapeQuotes(str) {
|
|
|
220
220
|
|
|
221
221
|
//#endregion
|
|
222
222
|
//#region packages/typescript/src/codegen/type-renderer.ts
|
|
223
|
-
function _define_property$
|
|
223
|
+
function _define_property$3(obj, key, value) {
|
|
224
224
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
225
225
|
value,
|
|
226
226
|
enumerable: true,
|
|
@@ -644,7 +644,7 @@ var TypeRenderer = class TypeRenderer extends BaseRenderer {
|
|
|
644
644
|
this.writeln(` */`);
|
|
645
645
|
}
|
|
646
646
|
constructor(doc, opts) {
|
|
647
|
-
super(doc), _define_property$
|
|
647
|
+
super(doc), _define_property$3(this, "opts", void 0), this.opts = opts;
|
|
648
648
|
}
|
|
649
649
|
};
|
|
650
650
|
function renderPrimitiveTypeDef(def) {
|
|
@@ -661,6 +661,662 @@ function renderPrimitiveTypeDef(def) {
|
|
|
661
661
|
}
|
|
662
662
|
}
|
|
663
663
|
|
|
664
|
+
//#endregion
|
|
665
|
+
//#region packages/typescript/src/runtime/compiled-check/build-layout.ts
|
|
666
|
+
/**
|
|
667
|
+
* Build-time layout derivation (renderer and tests; not part of the runtime bundle).
|
|
668
|
+
*/
|
|
669
|
+
/**
|
|
670
|
+
* Derives the layout of `root` (see layout.ts). Shared / recursive type defs are recorded
|
|
671
|
+
* once and referenced by index.
|
|
672
|
+
*/ function buildLayout(root, reader, classify) {
|
|
673
|
+
const defs = [];
|
|
674
|
+
const index = /* @__PURE__ */ new Map();
|
|
675
|
+
let slots = 0;
|
|
676
|
+
function describeDef(type) {
|
|
677
|
+
switch (type.kind) {
|
|
678
|
+
case "": return type.value === void 0 ? [require_json_schema.D_FINAL, type.designType] : [
|
|
679
|
+
require_json_schema.D_FINAL,
|
|
680
|
+
type.designType,
|
|
681
|
+
type.value
|
|
682
|
+
];
|
|
683
|
+
case "object": {
|
|
684
|
+
if (type.propsPatterns.length > 0) return [require_json_schema.D_OBJECT_PATTERNS];
|
|
685
|
+
const props = [...type.props];
|
|
686
|
+
return [
|
|
687
|
+
require_json_schema.D_OBJECT,
|
|
688
|
+
props.map(([key]) => key),
|
|
689
|
+
props.map(([, prop]) => site(prop))
|
|
690
|
+
];
|
|
691
|
+
}
|
|
692
|
+
case "array": return [require_json_schema.D_ARRAY, site(type.of)];
|
|
693
|
+
case "union":
|
|
694
|
+
case "intersection":
|
|
695
|
+
case "tuple": return [require_json_schema.ITEMS_KIND_CODES[type.kind], type.items.map(site)];
|
|
696
|
+
default: return [require_json_schema.D_UNKNOWN, String(type.kind)];
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
function site(node) {
|
|
700
|
+
const type = node.type;
|
|
701
|
+
const marker = classify?.(type);
|
|
702
|
+
const optional = !marker || marker === "ext" ? node.optional ? 1 : 0 : 0;
|
|
703
|
+
let d;
|
|
704
|
+
let keys = {
|
|
705
|
+
mask: 0,
|
|
706
|
+
shape: ""
|
|
707
|
+
};
|
|
708
|
+
if (marker === "interp") d = require_json_schema.INTERP;
|
|
709
|
+
else if (marker === "ext") {
|
|
710
|
+
d = require_json_schema.EXT;
|
|
711
|
+
keys = require_json_schema.readKeys(node.metadata, require_json_schema.siteBits(void 0, optional === 1), reader);
|
|
712
|
+
} else {
|
|
713
|
+
d = index.get(type) ?? -1;
|
|
714
|
+
if (d < 0) {
|
|
715
|
+
d = defs.length;
|
|
716
|
+
defs.push([]);
|
|
717
|
+
index.set(type, d);
|
|
718
|
+
defs[d] = describeDef(type);
|
|
719
|
+
}
|
|
720
|
+
keys = require_json_schema.readKeys(node.metadata, require_json_schema.siteBits(type, optional === 1), reader);
|
|
721
|
+
}
|
|
722
|
+
const result = [
|
|
723
|
+
optional,
|
|
724
|
+
keys.mask,
|
|
725
|
+
d,
|
|
726
|
+
keys.shape,
|
|
727
|
+
slots
|
|
728
|
+
];
|
|
729
|
+
slots += require_json_schema.siteSlotCount(result);
|
|
730
|
+
return result;
|
|
731
|
+
}
|
|
732
|
+
return [
|
|
733
|
+
defs,
|
|
734
|
+
site(root),
|
|
735
|
+
slots
|
|
736
|
+
];
|
|
737
|
+
}
|
|
738
|
+
/** JS source of a layout literal (plain arrays, strings and numbers incl. NaN / ±Infinity / -0). */ function layoutSource(value) {
|
|
739
|
+
if (Array.isArray(value)) return `[${value.map(layoutSource).join(",")}]`;
|
|
740
|
+
return literalSource(value);
|
|
741
|
+
}
|
|
742
|
+
/** JS source of a primitive literal. */ function literalSource(value) {
|
|
743
|
+
if (typeof value === "number") return Object.is(value, -0) ? "-0" : String(value);
|
|
744
|
+
if (typeof value === "string") return JSON.stringify(value).replaceAll("\u2028", "\\u2028").replaceAll("\u2029", "\\u2029");
|
|
745
|
+
if (value === void 0) return "undefined";
|
|
746
|
+
return JSON.stringify(value);
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
//#endregion
|
|
750
|
+
//#region packages/typescript/src/runtime/compiled-check/emit.ts
|
|
751
|
+
/**
|
|
752
|
+
* Emits the JS source of a compiled validator check factory from its layout.
|
|
753
|
+
*
|
|
754
|
+
* Build-time only (the renderer, and test code): the runtime never generates code. The
|
|
755
|
+
* emitted factory `(K, H) => check` mirrors the interpreted pre-check
|
|
756
|
+
* (validator-fast-check.ts) node for node — the same checks with the same PASS (1) /
|
|
757
|
+
* FAIL (0) / BAIL (2) contract — specialised to the layout: one function per object type
|
|
758
|
+
* def and per def that closes a reference cycle, everything else inlined.
|
|
759
|
+
*
|
|
760
|
+
* Generated code conventions:
|
|
761
|
+
* - Every function is `(v, f, o)`: the value, the flags (TOP, IN_UNION and option bits —
|
|
762
|
+
* see `optionFlags`) and the validator options (passed on to interpreted sub-checks).
|
|
763
|
+
* - A FAIL statement always leaves the current check: `return 0` outside unions; inside a
|
|
764
|
+
* union (where failures must visit everything the walk would) it records the failure and
|
|
765
|
+
* jumps past the failed node. `q` (`IN_UNION` unset) picks between the two when only the
|
|
766
|
+
* runtime flags tell. BAIL is always `return 2`.
|
|
767
|
+
* - Annotation values are closure constants `k<slot>` read from `K` once per bind.
|
|
768
|
+
*/ function _define_property$2(obj, key, value) {
|
|
769
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
770
|
+
value,
|
|
771
|
+
enumerable: true,
|
|
772
|
+
configurable: true,
|
|
773
|
+
writable: true
|
|
774
|
+
});
|
|
775
|
+
else obj[key] = value;
|
|
776
|
+
return obj;
|
|
777
|
+
}
|
|
778
|
+
const ROOT_CTX = {
|
|
779
|
+
fail: "return 0",
|
|
780
|
+
inUnionFail: "return 0",
|
|
781
|
+
union: false,
|
|
782
|
+
clearTop: false
|
|
783
|
+
};
|
|
784
|
+
/** Factory-level helpers (see `TCompiledHelpers`), in declaration order. */ const HELPERS = [
|
|
785
|
+
["pk", /\bpk\./],
|
|
786
|
+
["ho", /\bho\.call\(/],
|
|
787
|
+
["dec", /\bdec\.test\(/],
|
|
788
|
+
["rn", /\brn\(/]
|
|
789
|
+
];
|
|
790
|
+
/** Source of the check factory `(K, H) => check` of `layout`. */ function emitCheckFactory(layout) {
|
|
791
|
+
return new CheckEmitter(layout).emit();
|
|
792
|
+
}
|
|
793
|
+
let CheckEmitter = class CheckEmitter {
|
|
794
|
+
emit() {
|
|
795
|
+
const body = [];
|
|
796
|
+
for (let d = 0; d < this.defs.length; d++) if (this.fn[d]) body.push(...this.defFunction(d));
|
|
797
|
+
const root = this.layout[1];
|
|
798
|
+
const rootDef = root[2] >= 0 ? this.defs[root[2]][0] : -1;
|
|
799
|
+
if (root[0] === 0 && this.fn[root[2]] && (rootDef === require_json_schema.D_OBJECT || rootDef === require_json_schema.D_OBJECT_PATTERNS || rootDef === require_json_schema.D_TUPLE || rootDef === require_json_schema.D_INTERSECTION)) body.push(`return d${root[2]}`);
|
|
800
|
+
else {
|
|
801
|
+
body.push(...this.fnLines("r", () => [...this.site(root, "v", ROOT_CTX), "return 1"]));
|
|
802
|
+
body.push("return r");
|
|
803
|
+
}
|
|
804
|
+
const code = body.join("\n");
|
|
805
|
+
const head = [];
|
|
806
|
+
const helpers = HELPERS.filter(([, use]) => use.test(code)).map(([h]) => `${h} = H.${h}`);
|
|
807
|
+
if (helpers.length > 0) head.push(`const ${helpers.join(", ")}`);
|
|
808
|
+
const slots = [...new Set(Array.from(code.matchAll(/\bk(\d+)\b/g), (m) => Number(m[1])))].filter((k) => k < this.layout[2]).sort((a, b) => a - b);
|
|
809
|
+
for (let i = 0; i < slots.length; i += 16) head.push(`const ${slots.slice(i, i + 16).map((k) => `k${k} = K[${k}]`).join(", ")}`);
|
|
810
|
+
return [
|
|
811
|
+
"(K, H) => {",
|
|
812
|
+
...indent([...head, ...body]),
|
|
813
|
+
"}"
|
|
814
|
+
].join("\n");
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Object defs get a function each; so does every def a reference cycle passes through
|
|
818
|
+
* (each back-edge target of a DFS), which keeps inlining finite.
|
|
819
|
+
*/ functionDefs() {
|
|
820
|
+
const defs = this.defs;
|
|
821
|
+
const fn = defs.map((def) => def[0] === require_json_schema.D_OBJECT || def[0] === require_json_schema.D_OBJECT_PATTERNS);
|
|
822
|
+
const state = Array.from({ length: defs.length }).fill(0);
|
|
823
|
+
const dfs = (d) => {
|
|
824
|
+
state[d] = 1;
|
|
825
|
+
for (const site of require_json_schema.childSites(defs[d])) {
|
|
826
|
+
const c = site[2];
|
|
827
|
+
if (c < 0) continue;
|
|
828
|
+
if (state[c] === 1) fn[c] = true;
|
|
829
|
+
else if (state[c] === 0) dfs(c);
|
|
830
|
+
}
|
|
831
|
+
state[d] = 2;
|
|
832
|
+
};
|
|
833
|
+
for (let d = 0; d < defs.length; d++) if (state[d] === 0) dfs(d);
|
|
834
|
+
return fn;
|
|
835
|
+
}
|
|
836
|
+
next(prefix) {
|
|
837
|
+
return `${prefix}${this.uid++}`;
|
|
838
|
+
}
|
|
839
|
+
/** A check function `name(v, f, o)` declaring the `q` / `t` locals its body uses. */ fnLines(name, body) {
|
|
840
|
+
const lines = body();
|
|
841
|
+
const code = lines.join("\n");
|
|
842
|
+
const locals = [];
|
|
843
|
+
if (code.includes("if (q) return 0")) locals.push(`const q = (f & ${require_json_schema.F_IN_UNION}) === 0`);
|
|
844
|
+
if (/\bt = /.test(code)) locals.push("let t");
|
|
845
|
+
return [
|
|
846
|
+
`function ${name}(v, f, o) {`,
|
|
847
|
+
...indent([...locals, ...lines]),
|
|
848
|
+
"}"
|
|
849
|
+
];
|
|
850
|
+
}
|
|
851
|
+
defFunction(d) {
|
|
852
|
+
const def = this.defs[d];
|
|
853
|
+
return this.fnLines(`d${d}`, () => {
|
|
854
|
+
switch (def[0]) {
|
|
855
|
+
case require_json_schema.D_OBJECT: return this.objectBody(def);
|
|
856
|
+
case require_json_schema.D_OBJECT_PATTERNS: return [`if (${notObject("v")}) return 0`, "return 2"];
|
|
857
|
+
case require_json_schema.D_ARRAY: return [...this.items(def[1], "v", ROOT_CTX), "return 1"];
|
|
858
|
+
case require_json_schema.D_UNION: return [...this.unionBranches(def[1], "v", false, (item) => [`return ${choose(this.literalExpr(item), "3", "1")}`]), "return 0"];
|
|
859
|
+
case require_json_schema.D_TUPLE: return [...this.tuple(def[1], "v", ROOT_CTX), "return 1"];
|
|
860
|
+
case require_json_schema.D_INTERSECTION: return [...def[1].flatMap((item) => this.site(item, "v", ROOT_CTX)), "return 1"];
|
|
861
|
+
default: return ["return 2"];
|
|
862
|
+
}
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
/** Mirrors `fastCheckObject` (+ `pendStrips` / `hasUnknownKey`). */ objectBody(def) {
|
|
866
|
+
const sites = def[2];
|
|
867
|
+
const props = def[1].map((key, i) => ({
|
|
868
|
+
key,
|
|
869
|
+
site: sites[i]
|
|
870
|
+
})).filter((p) => !this.isPhantom(p.site));
|
|
871
|
+
const lines = [`if (${notObject("v")}) return 0`, "if (pk.length !== 0) return 2"];
|
|
872
|
+
if (props.some((p) => p.site[0] === 0 || p.site[2] === require_json_schema.INTERP)) {
|
|
873
|
+
const top = require_json_schema.F_PARTIAL_TOP | require_json_schema.F_TOP;
|
|
874
|
+
lines.push(`const sk = (f & ${require_json_schema.F_PARTIAL_DEEP}) !== 0 || (f & ${top}) === ${top}`);
|
|
875
|
+
}
|
|
876
|
+
if (props.length > 0) lines.push("let r = 1");
|
|
877
|
+
for (const { key, site } of props) {
|
|
878
|
+
const p = this.next("P");
|
|
879
|
+
const x = this.next("x");
|
|
880
|
+
const access = validIdentifier.test(key) ? `v.${key}` : `v[${literalSource(key)}]`;
|
|
881
|
+
lines.push(`${p}: {`, ` const ${x} = ${access}`);
|
|
882
|
+
if (site[0] === 0 || site[2] === require_json_schema.INTERP) lines.push(` if (${x} === undefined && sk) break ${p}`);
|
|
883
|
+
const ctx = recordingCtx(`r = 0; break ${p}`, false, true);
|
|
884
|
+
lines.push(...indent(this.site(site, x, ctx)), "}");
|
|
885
|
+
}
|
|
886
|
+
if (props.length > 0) lines.push("if (r === 0) return 0");
|
|
887
|
+
const known = props.map((p) => p.key);
|
|
888
|
+
const onUnknown = `{ if ((f & ${require_json_schema.F_ERROR}) !== 0) return 0; if ((f & ${require_json_schema.F_TOP}) === 0) return 2; pk.push(k) }`;
|
|
889
|
+
const scan = known.length === 0 ? [`for (const k in v) if (ho.call(v, k)) ${onUnknown}`] : [
|
|
890
|
+
"for (const k in v) {",
|
|
891
|
+
" switch (k) {",
|
|
892
|
+
...known.map((key) => ` case ${literalSource(key)}:`),
|
|
893
|
+
" break",
|
|
894
|
+
" default:",
|
|
895
|
+
` if (ho.call(v, k)) ${onUnknown}`,
|
|
896
|
+
" }",
|
|
897
|
+
"}"
|
|
898
|
+
];
|
|
899
|
+
lines.push(`if ((f & ${require_json_schema.F_ERROR | require_json_schema.F_STRIP}) !== 0) {`, ...indent(scan), "}", "return 1");
|
|
900
|
+
return lines;
|
|
901
|
+
}
|
|
902
|
+
isPhantom(site) {
|
|
903
|
+
const d = site[2];
|
|
904
|
+
return d >= 0 && this.defs[d][0] === require_json_schema.D_FINAL && this.defs[d][1] === "phantom";
|
|
905
|
+
}
|
|
906
|
+
isLiteralDef(d) {
|
|
907
|
+
return d >= 0 && this.defs[d][0] === require_json_schema.D_FINAL && this.defs[d].length > 2;
|
|
908
|
+
}
|
|
909
|
+
/** A required `never` union branch: it can never match (skipped). */ isNever(site) {
|
|
910
|
+
const d = site[2];
|
|
911
|
+
return site[0] === 0 && d >= 0 && this.defs[d][0] === require_json_schema.D_FINAL && this.defs[d][1] === "never" && !this.isLiteralDef(d);
|
|
912
|
+
}
|
|
913
|
+
/** Expression telling whether the site's type is a literal (`'true'` / `'false'` when known). */ literalExpr(site) {
|
|
914
|
+
const [, , d, , slot] = site;
|
|
915
|
+
if (d >= 0) return this.isLiteralDef(d) ? "true" : "false";
|
|
916
|
+
return `k${d === require_json_schema.INTERP ? slot + 1 : slot + (require_json_schema.hasRejectSlot(site) ? 1 : 0) + 1}`;
|
|
917
|
+
}
|
|
918
|
+
/** Mirrors `fastCheck` for one node holding `x`. */ site(site, x, ctx) {
|
|
919
|
+
const [optional, mask, d, shape, slot] = site;
|
|
920
|
+
if (d === require_json_schema.INTERP) return this.call(`k${slot}`, x, ctx);
|
|
921
|
+
let at = slot;
|
|
922
|
+
const rej = require_json_schema.hasRejectSlot(site) ? at++ : -1;
|
|
923
|
+
const body = d === require_json_schema.EXT ? this.call(`k${at}`, x, ctx) : this.def(d, mask, shape, at, x, ctx);
|
|
924
|
+
if (!optional) return body;
|
|
925
|
+
if (rej < 0) return body.length > 0 ? [
|
|
926
|
+
`if (${x} !== undefined && ${x} !== null) {`,
|
|
927
|
+
...indent(body),
|
|
928
|
+
"}"
|
|
929
|
+
] : [];
|
|
930
|
+
const lines = [`if (${x} === undefined || ${x} === null) {`, ` if (${x} === null && rn(k${rej})) ${ctx.fail}`];
|
|
931
|
+
if (body.length > 0) lines.push("} else {", ...indent(body));
|
|
932
|
+
lines.push("}");
|
|
933
|
+
return lines;
|
|
934
|
+
}
|
|
935
|
+
/** Calls a check function returning 0 / 1 / 2. */ call(fn, x, ctx) {
|
|
936
|
+
this.calls++;
|
|
937
|
+
return [`t = ${fn}(${x}, ${flags(ctx)}, o)`, `if (t !== 1) { if (t === 2) return 2; ${unblock(ctx.fail)} }`];
|
|
938
|
+
}
|
|
939
|
+
def(d, mask, shape, at, x, ctx) {
|
|
940
|
+
const def = this.defs[d];
|
|
941
|
+
const kind = def[0];
|
|
942
|
+
if (this.fn[d] && kind !== require_json_schema.D_ARRAY && kind !== require_json_schema.D_UNION) return this.call(`d${d}`, x, ctx);
|
|
943
|
+
switch (kind) {
|
|
944
|
+
case require_json_schema.D_FINAL: return this.final(def, mask, shape, at, x, ctx.fail);
|
|
945
|
+
case require_json_schema.D_ARRAY: return [
|
|
946
|
+
`if (!Array.isArray(${x})) ${ctx.fail}`,
|
|
947
|
+
...this.arrayConstraints(mask, require_json_schema.keySlots(mask, shape, at), x, ctx.fail),
|
|
948
|
+
...this.fn[d] ? this.call(`d${d}`, x, ctx) : this.items(def[1], x, ctx)
|
|
949
|
+
];
|
|
950
|
+
case require_json_schema.D_UNION: {
|
|
951
|
+
const constraints = this.unionConstraints(mask, shape, at, x, ctx.fail);
|
|
952
|
+
if (!this.fn[d]) return this.union(def[1], {
|
|
953
|
+
mask,
|
|
954
|
+
shape,
|
|
955
|
+
at
|
|
956
|
+
}, constraints, x, ctx);
|
|
957
|
+
this.calls++;
|
|
958
|
+
const lines = [
|
|
959
|
+
`t = d${d}(${x}, ${flags(ctx)}, o)`,
|
|
960
|
+
"if (t === 2) return 2",
|
|
961
|
+
`if (t === 0) ${ctx.fail}`
|
|
962
|
+
];
|
|
963
|
+
if (constraints.length > 0) lines.push("if (t === 1) {", ...indent(constraints), "}");
|
|
964
|
+
return lines;
|
|
965
|
+
}
|
|
966
|
+
case require_json_schema.D_INTERSECTION: return def[1].flatMap((item) => this.site(item, x, ctx));
|
|
967
|
+
case require_json_schema.D_TUPLE: return this.tuple(def[1], x, ctx);
|
|
968
|
+
default: return ["return 2"];
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
/** Mirrors `fastCheckFinal` + the string / number / boolean constraints. */ final(def, mask, shape, at, x, fail) {
|
|
972
|
+
const designType = def[1];
|
|
973
|
+
if (designType === "phantom") return [];
|
|
974
|
+
if (def.length > 2) return [`if (${x} !== ${literalSource(def[2])}) ${fail}`];
|
|
975
|
+
const ks = require_json_schema.keySlots(mask, shape, at);
|
|
976
|
+
switch (designType) {
|
|
977
|
+
case "string": return this.stringChecks(mask, shape, ks, x, fail, [`typeof ${x} !== "string"`]);
|
|
978
|
+
case "number": return this.numberChecks(mask, ks, x, fail, [`typeof ${x} !== "number"`, `!Number.isFinite(${x})`]);
|
|
979
|
+
case "boolean": {
|
|
980
|
+
const conds = [`typeof ${x} !== "boolean"`];
|
|
981
|
+
if (mask & require_json_schema.B_REQUIRED) conds.push(`${x} !== true`);
|
|
982
|
+
return [`if (${conds.join(" || ")}) ${fail}`];
|
|
983
|
+
}
|
|
984
|
+
case "any": return [];
|
|
985
|
+
case "never": return [fail];
|
|
986
|
+
case "undefined": return [`if (${x} !== undefined) ${fail}`];
|
|
987
|
+
case "null": return [`if (${x} !== null) ${fail}`];
|
|
988
|
+
case "decimal": return [`if (typeof ${x} !== "string" || !dec.test(${x})) ${fail}`];
|
|
989
|
+
default: return ["return 2"];
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
stringChecks(mask, shape, ks, x, fail, conds) {
|
|
993
|
+
if (mask & require_json_schema.B_REQUIRED) conds.push(`${x}.trim().length === 0`);
|
|
994
|
+
if (ks.minLength >= 0) conds.push(`${x}.length < k${ks.minLength}`);
|
|
995
|
+
if (ks.maxLength >= 0) conds.push(`${x}.length > k${ks.maxLength}`);
|
|
996
|
+
const lines = conds.length > 0 ? [`if (${conds.join(" || ")}) ${fail}`] : [];
|
|
997
|
+
let p = 0;
|
|
998
|
+
for (const c of shape) if (c === "n") lines.push(`if (!k${ks.patterns[p++]}.test(${x})) ${fail}`);
|
|
999
|
+
else if (c === "s") {
|
|
1000
|
+
lines.push("return 2");
|
|
1001
|
+
break;
|
|
1002
|
+
}
|
|
1003
|
+
return lines;
|
|
1004
|
+
}
|
|
1005
|
+
numberChecks(mask, ks, x, fail, conds) {
|
|
1006
|
+
if (mask & require_json_schema.B_INT) conds.push(`${x} % 1 !== 0`);
|
|
1007
|
+
if (ks.min >= 0) conds.push(`${x} < k${ks.min}`);
|
|
1008
|
+
if (ks.max >= 0) conds.push(`${x} > k${ks.max}`);
|
|
1009
|
+
if (ks.exMin >= 0) conds.push(`${x} <= k${ks.exMin}`);
|
|
1010
|
+
if (ks.exMax >= 0) conds.push(`${x} >= k${ks.exMax}`);
|
|
1011
|
+
return conds.length > 0 ? [`if (${conds.join(" || ")}) ${fail}`] : [];
|
|
1012
|
+
}
|
|
1013
|
+
/** Array length constraints; `uniqueItems` (duplicate detection) is left to the walk. */ arrayConstraints(mask, ks, x, fail) {
|
|
1014
|
+
const conds = [];
|
|
1015
|
+
if (ks.minLength >= 0) conds.push(`${x}.length < k${ks.minLength}`);
|
|
1016
|
+
if (ks.maxLength >= 0) conds.push(`${x}.length > k${ks.maxLength}`);
|
|
1017
|
+
const lines = conds.length > 0 ? [`if (${conds.join(" || ")}) ${fail}`] : [];
|
|
1018
|
+
if (mask & require_json_schema.B_UNIQUE) lines.push("return 2");
|
|
1019
|
+
return lines;
|
|
1020
|
+
}
|
|
1021
|
+
/** Mirrors `fastCheckUnionConstraints` (the caller skips literal branches). */ unionConstraints(mask, shape, at, x, fail) {
|
|
1022
|
+
const ks = require_json_schema.keySlots(mask, shape, at);
|
|
1023
|
+
const branches = [];
|
|
1024
|
+
if (mask & require_json_schema.STRING_BITS) branches.push([`typeof ${x} === "string"`, this.stringChecks(mask, shape, ks, x, fail, [])]);
|
|
1025
|
+
if (mask & require_json_schema.NUMBER_BITS) branches.push([`typeof ${x} === "number"`, this.numberChecks(mask, ks, x, fail, [])]);
|
|
1026
|
+
if (mask & require_json_schema.B_REQUIRED) branches.push([`typeof ${x} === "boolean"`, [`if (${x} !== true) ${fail}`]]);
|
|
1027
|
+
if (mask & require_json_schema.ARRAY_BITS) branches.push([`Array.isArray(${x})`, this.arrayConstraints(mask, ks, x, fail)]);
|
|
1028
|
+
const lines = [];
|
|
1029
|
+
branches.forEach(([cond, body], i) => {
|
|
1030
|
+
lines.push(`${i === 0 ? "if" : "} else if"} (${cond}) {`, ...indent(body));
|
|
1031
|
+
});
|
|
1032
|
+
if (lines.length > 0) lines.push("}");
|
|
1033
|
+
return lines;
|
|
1034
|
+
}
|
|
1035
|
+
/**
|
|
1036
|
+
* The union-level constraints after a non-literal branch passed. A required (non-optional)
|
|
1037
|
+
* branch of a known primitive / array type fixes `typeof`: only that part applies.
|
|
1038
|
+
*/ branchConstraints(item, { mask, shape, at }, constraints, x, fail) {
|
|
1039
|
+
const [optional, , d] = item;
|
|
1040
|
+
const def = this.defs[d];
|
|
1041
|
+
if (optional) return constraints;
|
|
1042
|
+
const ks = require_json_schema.keySlots(mask, shape, at);
|
|
1043
|
+
if (def[0] === require_json_schema.D_ARRAY) return this.arrayConstraints(mask, ks, x, fail);
|
|
1044
|
+
if (def[0] !== require_json_schema.D_FINAL) return constraints;
|
|
1045
|
+
switch (def[1]) {
|
|
1046
|
+
case "string": return this.stringChecks(mask, shape, ks, x, fail, []);
|
|
1047
|
+
case "number": return this.numberChecks(mask, ks, x, fail, []);
|
|
1048
|
+
case "boolean": return mask & require_json_schema.B_REQUIRED ? [`if (${x} !== true) ${fail}`] : [];
|
|
1049
|
+
case "null":
|
|
1050
|
+
case "undefined": return [];
|
|
1051
|
+
default: return constraints;
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
/**
|
|
1055
|
+
* Mirrors the `fastCheck` union case: branches in declared order, each a labelled block a
|
|
1056
|
+
* FAIL breaks out of; `onMatch` ends a passing branch.
|
|
1057
|
+
*/ unionBranches(items, x, clearTop, onMatch) {
|
|
1058
|
+
const lines = [];
|
|
1059
|
+
for (const item of items) {
|
|
1060
|
+
if (this.isNever(item)) continue;
|
|
1061
|
+
const b = this.next("B");
|
|
1062
|
+
const calls = this.calls;
|
|
1063
|
+
const fail = `break ${b}`;
|
|
1064
|
+
const body = this.site(item, x, {
|
|
1065
|
+
fail,
|
|
1066
|
+
inUnionFail: fail,
|
|
1067
|
+
union: true,
|
|
1068
|
+
clearTop
|
|
1069
|
+
});
|
|
1070
|
+
lines.push(`${b}: {`, ...indent([...body, ...onMatch(item)]), "}");
|
|
1071
|
+
if (this.calls !== calls) lines.push("if (pk.length !== 0) return 2");
|
|
1072
|
+
}
|
|
1073
|
+
return lines;
|
|
1074
|
+
}
|
|
1075
|
+
/** An inline union: the first matching branch passes after the union-level constraints. */ union(items, keys, constraints, x, ctx) {
|
|
1076
|
+
const u = this.next("U");
|
|
1077
|
+
const branches = this.unionBranches(items, x, ctx.clearTop, (item) => {
|
|
1078
|
+
const lines = [];
|
|
1079
|
+
const literal = constraints.length > 0 ? this.literalExpr(item) : "true";
|
|
1080
|
+
if (literal === "false") lines.push(...this.branchConstraints(item, keys, constraints, x, ctx.fail));
|
|
1081
|
+
else if (literal !== "true") lines.push(`if (!${literal}) {`, ...indent(constraints), "}");
|
|
1082
|
+
lines.push(`break ${u}`);
|
|
1083
|
+
return lines;
|
|
1084
|
+
});
|
|
1085
|
+
return [
|
|
1086
|
+
`${u}: {`,
|
|
1087
|
+
...indent([...branches, ctx.fail]),
|
|
1088
|
+
"}"
|
|
1089
|
+
];
|
|
1090
|
+
}
|
|
1091
|
+
/** Mirrors `checkItems`: every item is visited inside a union (BAIL beats FAIL). */ items(of, x, ctx) {
|
|
1092
|
+
const y = this.next("y");
|
|
1093
|
+
const a = this.next("a");
|
|
1094
|
+
const body = this.site(of, y, recordingCtx(`${a} = 0; continue`, ctx.union, true));
|
|
1095
|
+
if (body.length === 0) return [`for (const ${y} of ${x}) {}`];
|
|
1096
|
+
return [
|
|
1097
|
+
`let ${a} = 1`,
|
|
1098
|
+
`for (const ${y} of ${x}) {`,
|
|
1099
|
+
...indent(body),
|
|
1100
|
+
"}",
|
|
1101
|
+
`if (${a} === 0) ${ctx.inUnionFail}`
|
|
1102
|
+
];
|
|
1103
|
+
}
|
|
1104
|
+
/** Mirrors the `fastCheck` tuple case: stops at the first non-passing item. */ tuple(items, x, ctx) {
|
|
1105
|
+
const lines = [`if (!Array.isArray(${x}) || ${x}.length !== ${items.length}) ${ctx.fail}`];
|
|
1106
|
+
items.forEach((item, i) => {
|
|
1107
|
+
const e = this.next("e");
|
|
1108
|
+
lines.push(`const ${e} = ${x}[${i}]`, ...this.site(item, e, {
|
|
1109
|
+
...ctx,
|
|
1110
|
+
clearTop: true
|
|
1111
|
+
}));
|
|
1112
|
+
});
|
|
1113
|
+
return lines;
|
|
1114
|
+
}
|
|
1115
|
+
constructor(layout) {
|
|
1116
|
+
_define_property$2(this, "layout", void 0);
|
|
1117
|
+
_define_property$2(this, "defs", void 0);
|
|
1118
|
+
/** Def index → emitted as its own function. */ _define_property$2(this, "fn", void 0);
|
|
1119
|
+
_define_property$2(this, "uid", void 0);
|
|
1120
|
+
/** Calls emitted so far (a union branch without calls cannot record strips). */ _define_property$2(this, "calls", void 0);
|
|
1121
|
+
this.layout = layout;
|
|
1122
|
+
this.uid = 0;
|
|
1123
|
+
this.calls = 0;
|
|
1124
|
+
this.defs = layout[0];
|
|
1125
|
+
this.fn = this.functionDefs();
|
|
1126
|
+
}
|
|
1127
|
+
};
|
|
1128
|
+
/**
|
|
1129
|
+
* Context of a node whose failure is recorded (`record`: e.g. `r = 0; break P1`) when
|
|
1130
|
+
* inside a union and leaves the check otherwise.
|
|
1131
|
+
*/ function recordingCtx(record, union, clearTop) {
|
|
1132
|
+
const inUnionFail = `{ ${record} }`;
|
|
1133
|
+
return {
|
|
1134
|
+
fail: union ? inUnionFail : `{ if (q) return 0; ${record} }`,
|
|
1135
|
+
inUnionFail,
|
|
1136
|
+
union,
|
|
1137
|
+
clearTop
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
/** Flags passed to a callee. */ function flags(ctx) {
|
|
1141
|
+
if (ctx.clearTop) return ctx.union ? `(f & ${~require_json_schema.F_TOP}) | ${require_json_schema.F_IN_UNION}` : `f & ${~require_json_schema.F_TOP}`;
|
|
1142
|
+
return ctx.union ? `f | ${require_json_schema.F_IN_UNION}` : "f";
|
|
1143
|
+
}
|
|
1144
|
+
/** The statements of a `{ … }` block statement (other statements as they are). */ function unblock(statement) {
|
|
1145
|
+
return statement.startsWith("{ ") && statement.endsWith(" }") ? statement.slice(2, -2) : statement;
|
|
1146
|
+
}
|
|
1147
|
+
/** `cond ? a : b` folded when `cond` is a constant. */ function choose(cond, a, b) {
|
|
1148
|
+
return cond === "true" ? a : cond === "false" ? b : `${cond} ? ${a} : ${b}`;
|
|
1149
|
+
}
|
|
1150
|
+
function notObject(x) {
|
|
1151
|
+
return `typeof ${x} !== "object" || ${x} === null || Array.isArray(${x})`;
|
|
1152
|
+
}
|
|
1153
|
+
function indent(lines, n = 2) {
|
|
1154
|
+
const pad = " ".repeat(n);
|
|
1155
|
+
return lines.map((l) => pad + l);
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
//#endregion
|
|
1159
|
+
//#region packages/typescript/src/codegen/validation-model.ts
|
|
1160
|
+
function _define_property$1(obj, key, value) {
|
|
1161
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
1162
|
+
value,
|
|
1163
|
+
enumerable: true,
|
|
1164
|
+
configurable: true,
|
|
1165
|
+
writable: true
|
|
1166
|
+
});
|
|
1167
|
+
else obj[key] = value;
|
|
1168
|
+
return obj;
|
|
1169
|
+
}
|
|
1170
|
+
/** Kinds of the opaque types standing for another module's types (see {@link classifyType}). */ const EXT_KIND = "#ext";
|
|
1171
|
+
const INTERP_KIND = "#interp";
|
|
1172
|
+
/**
|
|
1173
|
+
* How the layout treats a model type: `'ext'` — another module's type referenced as a
|
|
1174
|
+
* whole (also an alias / prop clone of one: `cloneTypeDef` keeps the kind); `'interp'` — a
|
|
1175
|
+
* chained reference into another module's type, only known at runtime.
|
|
1176
|
+
*/ function classifyType(type) {
|
|
1177
|
+
const kind = type?.kind;
|
|
1178
|
+
return kind === EXT_KIND ? "ext" : kind === INTERP_KIND ? "interp" : void 0;
|
|
1179
|
+
}
|
|
1180
|
+
/**
|
|
1181
|
+
* Build-time model of the runtime type trees a generated `.as.js` module builds, used to
|
|
1182
|
+
* compile validator checks (`compileValidators`).
|
|
1183
|
+
*
|
|
1184
|
+
* The renderer drives it in lockstep with the builder chains it emits, through the real
|
|
1185
|
+
* runtime builder (`defineAnnotatedType`, `annotate`, `cloneRefProp`), so the model has
|
|
1186
|
+
* the same structure, the same type-def sharing (by identity) and the same validator
|
|
1187
|
+
* annotations as the module after its initialisation. Only the annotations the validator
|
|
1188
|
+
* pre-check reads are recorded. Types of other modules are opaque markers: a reference to
|
|
1189
|
+
* one (also an alias or a cloned prop of one) compiles to a cross-module site, bound at
|
|
1190
|
+
* runtime to the referenced class's own compiled check (see compiled-check/registry.ts).
|
|
1191
|
+
*
|
|
1192
|
+
* Anything the model cannot follow marks it broken; nothing is compiled then. A model that
|
|
1193
|
+
* nevertheless diverges from the runtime only costs speed: the runtime bind detects it and
|
|
1194
|
+
* the interpreted pre-check runs.
|
|
1195
|
+
*/ var ValidationModel = class {
|
|
1196
|
+
/** Runs a model step; a throw marks the model broken. */ run(step) {
|
|
1197
|
+
if (this.broken) return;
|
|
1198
|
+
try {
|
|
1199
|
+
return step();
|
|
1200
|
+
} catch {
|
|
1201
|
+
this.broken = true;
|
|
1202
|
+
return;
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
/** Declares a generated class (`static type = {}; static metadata = new Map()`). */ declare(name) {
|
|
1206
|
+
this.classes.set(name, {
|
|
1207
|
+
__is_atscript_annotated_type: true,
|
|
1208
|
+
type: {},
|
|
1209
|
+
metadata: /* @__PURE__ */ new Map(),
|
|
1210
|
+
name
|
|
1211
|
+
});
|
|
1212
|
+
}
|
|
1213
|
+
/** The model of a class declared in this module (anything else: the emitted code throws). */ classBase(name) {
|
|
1214
|
+
const cls = this.classes.get(name);
|
|
1215
|
+
if (!cls) throw new Error(`${name} is not a class of this module`);
|
|
1216
|
+
return cls;
|
|
1217
|
+
}
|
|
1218
|
+
/** `$(kind, name?)`. */ handle(kind, name) {
|
|
1219
|
+
return this.run(() => require_json_schema.defineAnnotatedType(kind, name === void 0 ? void 0 : this.classBase(name)));
|
|
1220
|
+
}
|
|
1221
|
+
/** `.refTo(Local)` / `.refTo(() => Imported)` (with an optional chain). */ refTo(handle, name, imported, chain) {
|
|
1222
|
+
this.run(() => {
|
|
1223
|
+
if (!handle) throw new Error("no chain");
|
|
1224
|
+
if (imported) {
|
|
1225
|
+
const marker = this.marker(name, chain ? INTERP_KIND : EXT_KIND);
|
|
1226
|
+
handle.refTo(() => marker, chain);
|
|
1227
|
+
} else handle.refTo(this.classBase(name), chain);
|
|
1228
|
+
});
|
|
1229
|
+
}
|
|
1230
|
+
/** The opaque stand-in of another module's type `name`. */ marker(name, kind) {
|
|
1231
|
+
const key = `${name}${kind}`;
|
|
1232
|
+
let marker = this.markers.get(key);
|
|
1233
|
+
if (!marker) {
|
|
1234
|
+
marker = {
|
|
1235
|
+
__is_atscript_annotated_type: true,
|
|
1236
|
+
type: { kind },
|
|
1237
|
+
metadata: /* @__PURE__ */ new Map()
|
|
1238
|
+
};
|
|
1239
|
+
this.markers.set(key, marker);
|
|
1240
|
+
}
|
|
1241
|
+
return marker;
|
|
1242
|
+
}
|
|
1243
|
+
/** `.annotate(key, value, multiple)` on the current chain (validator keys only). */ annotate(key, value, multiple) {
|
|
1244
|
+
if (!require_json_schema.isValidatorKey(key)) return;
|
|
1245
|
+
this.run(() => {
|
|
1246
|
+
if (!this.current) throw new Error("no chain");
|
|
1247
|
+
this.current.annotate(key, value, multiple);
|
|
1248
|
+
});
|
|
1249
|
+
}
|
|
1250
|
+
/** The node a mutating-annotate accessor (`Name.type.props.get("a")?…`) points at. */ resolve(name, steps) {
|
|
1251
|
+
let cur = this.classes.get(name);
|
|
1252
|
+
for (const step of steps) {
|
|
1253
|
+
if (cur === void 0 || cur === null) return;
|
|
1254
|
+
if (step === "type") {
|
|
1255
|
+
cur = cur.type;
|
|
1256
|
+
if (classifyType(cur) !== void 0) return;
|
|
1257
|
+
} else if (step[0] === "props") cur = cur.props?.get(step[1]);
|
|
1258
|
+
else cur = cur.items?.[step[1]];
|
|
1259
|
+
}
|
|
1260
|
+
return cur;
|
|
1261
|
+
}
|
|
1262
|
+
/** `$c(<accessor>, "prop")`. */ cloneProp(name, steps, prop) {
|
|
1263
|
+
this.run(() => {
|
|
1264
|
+
const parent = this.resolve(name, steps);
|
|
1265
|
+
if (parent) require_json_schema.cloneRefProp(parent, prop);
|
|
1266
|
+
});
|
|
1267
|
+
}
|
|
1268
|
+
/** `<accessor>.metadata.delete(key)`. */ deleteAnnotation(name, steps, key) {
|
|
1269
|
+
this.run(() => {
|
|
1270
|
+
this.resolve(name, steps)?.metadata?.delete(key);
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
/** `$a(<accessor>.metadata, key, value, multiple)`. */ mutateAnnotation(name, steps, key, value, multiple) {
|
|
1274
|
+
if (!require_json_schema.isValidatorKey(key)) return;
|
|
1275
|
+
this.run(() => {
|
|
1276
|
+
require_json_schema.annotate(this.resolve(name, steps)?.metadata, key, value, multiple);
|
|
1277
|
+
});
|
|
1278
|
+
}
|
|
1279
|
+
/**
|
|
1280
|
+
* `$cv(Name, version, layout, factory)` for class `name`, or `undefined` when it cannot be
|
|
1281
|
+
* compiled (its root type is only known at runtime, or the model is broken).
|
|
1282
|
+
*/ registration(name) {
|
|
1283
|
+
if (this.broken) return;
|
|
1284
|
+
const cls = this.classes.get(name);
|
|
1285
|
+
if (!cls) return;
|
|
1286
|
+
let layout;
|
|
1287
|
+
try {
|
|
1288
|
+
layout = buildLayout(cls, { regex: require_json_schema.getRegex }, classifyType);
|
|
1289
|
+
} catch {
|
|
1290
|
+
return;
|
|
1291
|
+
}
|
|
1292
|
+
const root = layout[1][2];
|
|
1293
|
+
if (root === require_json_schema.INTERP || root >= 0 && layout[0][root][0] === require_json_schema.D_UNKNOWN) return;
|
|
1294
|
+
return `$cv(${name}, ${require_json_schema.LAYOUT_VERSION}, ${layoutSource(layout)}, ${emitCheckFactory(layout)})`;
|
|
1295
|
+
}
|
|
1296
|
+
constructor() {
|
|
1297
|
+
/** The model could not follow the emitted code: compile nothing. */ _define_property$1(this, "broken", false);
|
|
1298
|
+
/** Handle of the chain being emitted (the target of `.annotate(…)` lines). */ _define_property$1(this, "current", void 0);
|
|
1299
|
+
_define_property$1(this, "classes", /* @__PURE__ */ new Map());
|
|
1300
|
+
_define_property$1(this, "markers", /* @__PURE__ */ new Map());
|
|
1301
|
+
}
|
|
1302
|
+
};
|
|
1303
|
+
/**
|
|
1304
|
+
* Runtime value of an annotation argument the emitted code writes as a raw expression
|
|
1305
|
+
* (`true`, `5`, `-1.5`, …). Anything else is opaque (truthy and not a number): the bind
|
|
1306
|
+
* compares only presence / truthiness and reads the real values at runtime.
|
|
1307
|
+
*/ function rawLiteralValue(text) {
|
|
1308
|
+
switch (text) {
|
|
1309
|
+
case "true": return true;
|
|
1310
|
+
case "false": return false;
|
|
1311
|
+
case "null": return null;
|
|
1312
|
+
case "undefined": return;
|
|
1313
|
+
default: {
|
|
1314
|
+
const n = Number(text);
|
|
1315
|
+
return text.trim() !== "" && !Number.isNaN(n) ? n : { opaque: text };
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
|
|
664
1320
|
//#endregion
|
|
665
1321
|
//#region packages/typescript/src/codegen/js-renderer.ts
|
|
666
1322
|
function _define_property(obj, key, value) {
|
|
@@ -693,6 +1349,17 @@ const QUERY_OP_MAP = {
|
|
|
693
1349
|
"expect.exclusiveMax": "exclusiveMaxValue"
|
|
694
1350
|
};
|
|
695
1351
|
const SYNTH_IMPORTS_MARKER = "/*@@atscript-synth-imports@@*/";
|
|
1352
|
+
/** The runtime value of an annotation argument (see `JsRenderer.computeAnnotationValue`). */ function runtimeArg(type, token) {
|
|
1353
|
+
return type === "string" || type === void 0 && token.type === "text" ? token.text : rawLiteralValue(token.text);
|
|
1354
|
+
}
|
|
1355
|
+
/**
|
|
1356
|
+
* The runtime accessor of a mutating-annotate path: `Name` followed by the steps
|
|
1357
|
+
* (`.type`, `.props.get("a")?`, `.items[0]`).
|
|
1358
|
+
*/ function accessorPath(targetName, steps) {
|
|
1359
|
+
let path = targetName;
|
|
1360
|
+
for (const step of steps) path += step === "type" ? ".type" : step[0] === "props" ? `.props.get("${escapeQuotes(step[1])}")?` : `.items[${step[1]}]`;
|
|
1361
|
+
return path;
|
|
1362
|
+
}
|
|
696
1363
|
var JsRenderer = class extends BaseRenderer {
|
|
697
1364
|
/**
|
|
698
1365
|
* Relative imports get the configured `moduleExtension`; bare specifiers
|
|
@@ -871,6 +1538,7 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
871
1538
|
if (jsonSchemaMode === "lazy") imports.push("buildJsonSchema as $$");
|
|
872
1539
|
if (this.opts?.exampleData) imports.push("createDataFromAnnotatedType as $e");
|
|
873
1540
|
if (jsonSchemaMode === false) imports.push("throwFeatureDisabled as $d");
|
|
1541
|
+
if (this.model) imports.push("registerCompiledCheck as $cv");
|
|
874
1542
|
this.writeln(`import { ${imports.join(", ")} } from "@atscript/typescript/utils"`);
|
|
875
1543
|
this.computeSynthesizedImports();
|
|
876
1544
|
this.writeln(SYNTH_IMPORTS_MARKER);
|
|
@@ -918,7 +1586,7 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
918
1586
|
if ((0, _atscript_core.isInterface)(def)) if (def.hasExtends) def = unwound.doc.resolveInterfaceExtends(def) || def.getDefinition() || def;
|
|
919
1587
|
else def = def.getDefinition() || def;
|
|
920
1588
|
this._adHocAnnotations = this.buildAdHocMap([annotateNode]);
|
|
921
|
-
this.annotateType(def, node.id);
|
|
1589
|
+
this.modelClass(node.id, () => this.annotateType(def, node.id));
|
|
922
1590
|
this._adHocAnnotations = null;
|
|
923
1591
|
this.indent();
|
|
924
1592
|
this.defineMetadataForAnnotateAlias(annotateNode);
|
|
@@ -932,13 +1600,38 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
932
1600
|
const resolved = this.doc.resolveInterfaceExtends(node);
|
|
933
1601
|
if (resolved) def = resolved;
|
|
934
1602
|
}
|
|
935
|
-
this.annotateType(def, node.id);
|
|
1603
|
+
this.modelClass(node.id, () => this.annotateType(def, node.id));
|
|
936
1604
|
this.indent().defineMetadata(node).unindent();
|
|
937
1605
|
this.writeln();
|
|
938
1606
|
}
|
|
1607
|
+
this.renderCompiledChecks();
|
|
939
1608
|
this.writeln("// prettier-ignore-end");
|
|
940
1609
|
super.post();
|
|
941
1610
|
}
|
|
1611
|
+
/**
|
|
1612
|
+
* Emits class `name`'s chain; the validation model follows it (its handle stays the current
|
|
1613
|
+
* chain, the target of the class-level annotations emitted next).
|
|
1614
|
+
*/ modelClass(name, emit) {
|
|
1615
|
+
if (this.model) this.model.current = void 0;
|
|
1616
|
+
emit();
|
|
1617
|
+
if (this.model?.current) this.modelClasses.push(name);
|
|
1618
|
+
}
|
|
1619
|
+
/**
|
|
1620
|
+
* `compileValidators`: one `$cv(Class, …)` registration per class, after every chain and
|
|
1621
|
+
* mutating annotate of the module ran (the compiled check binds on first use).
|
|
1622
|
+
*/ renderCompiledChecks() {
|
|
1623
|
+
if (!this.model) return;
|
|
1624
|
+
const registrations = [];
|
|
1625
|
+
for (const name of this.modelClasses) {
|
|
1626
|
+
const registration = this.model.registration(name);
|
|
1627
|
+
if (registration) registrations.push(registration);
|
|
1628
|
+
}
|
|
1629
|
+
if (registrations.length > 0) {
|
|
1630
|
+
this.writeln("// Compiled validator checks");
|
|
1631
|
+
for (const registration of registrations) for (const line of registration.split("\n")) this.writeln(line);
|
|
1632
|
+
this.writeln();
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
942
1635
|
renderClassStatics(node) {
|
|
943
1636
|
this.writeln("static __is_atscript_annotated_type = true");
|
|
944
1637
|
this.writeln("static type = {}");
|
|
@@ -969,6 +1662,7 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
969
1662
|
this.write(exported ? "export " : "");
|
|
970
1663
|
this.write(`class ${node.id} `);
|
|
971
1664
|
this.blockln("{}");
|
|
1665
|
+
this.model?.declare(node.id);
|
|
972
1666
|
this.renderClassStatics(node);
|
|
973
1667
|
this.popln();
|
|
974
1668
|
this.postAnnotate.push(node);
|
|
@@ -1018,23 +1712,63 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
1018
1712
|
if (measures.length > 0) this.writeln(`static measures = [${measures.map((m) => `'${escapeQuotes(m)}'`).join(", ")}]`);
|
|
1019
1713
|
}
|
|
1020
1714
|
toAnnotatedType(node) {
|
|
1021
|
-
return this.toAnnotatedHandle(node).$type;
|
|
1715
|
+
return node?.entity === "interface" || node?.entity === "type" ? this.declType(node) : this.toAnnotatedHandle(node).$type;
|
|
1022
1716
|
}
|
|
1023
|
-
|
|
1024
|
-
|
|
1717
|
+
/**
|
|
1718
|
+
* The build-time runtime type of an interface / type declaration (see `_declTypes`);
|
|
1719
|
+
* `doc` is the document that declares it (where an alias's target name resolves).
|
|
1720
|
+
*/ declType(node, doc = this.doc) {
|
|
1721
|
+
const known = this._declTypes.get(node);
|
|
1722
|
+
if (known) return known;
|
|
1723
|
+
let def = node.getDefinition();
|
|
1724
|
+
if ((0, _atscript_core.isInterface)(node) && node.hasExtends) {
|
|
1725
|
+
const resolved = this.doc.resolveInterfaceExtends(node);
|
|
1726
|
+
if (resolved) def = resolved;
|
|
1727
|
+
}
|
|
1728
|
+
const typeId = this.typeIds.get(node) ?? (node.__typeId !== null && node.__typeId !== void 0 ? node.id : void 0);
|
|
1729
|
+
let handle;
|
|
1730
|
+
if (def && (0, _atscript_core.isRef)(def)) {
|
|
1731
|
+
const ref = def;
|
|
1732
|
+
const decl = doc.unwindType(ref.id, ref.chain)?.def;
|
|
1733
|
+
const target = this.refTarget(ref, decl, doc);
|
|
1734
|
+
handle = target ? require_json_schema.defineAnnotatedType().refTo(target) : this.toAnnotatedHandle(decl, true);
|
|
1735
|
+
} else {
|
|
1736
|
+
const base = {
|
|
1737
|
+
__is_atscript_annotated_type: true,
|
|
1738
|
+
type: {},
|
|
1739
|
+
metadata: /* @__PURE__ */ new Map(),
|
|
1740
|
+
id: typeId
|
|
1741
|
+
};
|
|
1742
|
+
this._declTypes.set(node, base);
|
|
1743
|
+
if (def) this._declTypes.set(def, base);
|
|
1744
|
+
handle = this.toAnnotatedHandle(def, true, base);
|
|
1745
|
+
}
|
|
1746
|
+
this._declTypes.set(node, handle.$type);
|
|
1747
|
+
if (typeId) handle.id(typeId);
|
|
1748
|
+
this.applyExpectAnnotations(handle, this.doc.evalAnnotationsForNode(node));
|
|
1749
|
+
return handle.$type;
|
|
1750
|
+
}
|
|
1751
|
+
/**
|
|
1752
|
+
* The declaration type a reference points at (see `declType`), or `undefined` when it is
|
|
1753
|
+
* not a declaration (a chained reference into a prop, an unresolved name). A plain
|
|
1754
|
+
* reference to a type alias points at the alias itself (its own type and id, like the
|
|
1755
|
+
* runtime `$().refTo(Alias)`), not at what the alias unwinds to.
|
|
1756
|
+
*/ refTarget(ref, decl, doc = this.doc) {
|
|
1757
|
+
if (!decl) return;
|
|
1758
|
+
const owner = ref.hasChain ? void 0 : this.resolveOwner(doc, ref.id);
|
|
1759
|
+
if (owner?.node?.entity === "type" || owner?.node?.entity === "interface") return this.declType(owner.node, owner.doc);
|
|
1760
|
+
const known = this._declTypes.get(decl);
|
|
1761
|
+
if (known) return known;
|
|
1762
|
+
return (0, _atscript_core.isInterface)(decl) ? this.declType(decl) : void 0;
|
|
1763
|
+
}
|
|
1764
|
+
/**
|
|
1765
|
+
* The build-time runtime type of an expression node; with `base`, built into that object
|
|
1766
|
+
* (a declaration's type, see `declType`).
|
|
1767
|
+
*/ toAnnotatedHandle(node, skipAnnotations = false, base) {
|
|
1768
|
+
if (!node) return require_json_schema.defineAnnotatedType(void 0, base);
|
|
1025
1769
|
switch (node.entity) {
|
|
1026
1770
|
case "interface":
|
|
1027
|
-
case "type":
|
|
1028
|
-
let def = node.getDefinition();
|
|
1029
|
-
if ((0, _atscript_core.isInterface)(node) && node.hasExtends) {
|
|
1030
|
-
const resolved = this.doc.resolveInterfaceExtends(node);
|
|
1031
|
-
if (resolved) def = resolved;
|
|
1032
|
-
}
|
|
1033
|
-
const handle = this.toAnnotatedHandle(def, true);
|
|
1034
|
-
const typeId = this.typeIds.get(node) ?? (node.__typeId !== null && node.__typeId !== void 0 ? node.id : void 0);
|
|
1035
|
-
if (typeId) handle.id(typeId);
|
|
1036
|
-
return skipAnnotations ? handle : this.applyExpectAnnotations(handle, this.doc.evalAnnotationsForNode(node));
|
|
1037
|
-
}
|
|
1771
|
+
case "type": return require_json_schema.defineAnnotatedType().refTo(this.declType(node));
|
|
1038
1772
|
case "prop": {
|
|
1039
1773
|
const prop = node;
|
|
1040
1774
|
const def = prop.getDefinition();
|
|
@@ -1048,7 +1782,8 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
1048
1782
|
case "ref": {
|
|
1049
1783
|
const ref = node;
|
|
1050
1784
|
const decl = this.doc.unwindType(ref.id, ref.chain)?.def;
|
|
1051
|
-
const
|
|
1785
|
+
const target = this.refTarget(ref, decl);
|
|
1786
|
+
const handle = target ? require_json_schema.defineAnnotatedType().refTo(target) : this.toAnnotatedHandle(decl, true);
|
|
1052
1787
|
if (skipAnnotations) return handle;
|
|
1053
1788
|
const own = this.doc.evalAnnotationsForNode(node);
|
|
1054
1789
|
const referred = this.refTargetAnnotations(ref, decl);
|
|
@@ -1056,14 +1791,14 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
1056
1791
|
}
|
|
1057
1792
|
case "primitive": {
|
|
1058
1793
|
const prim = node;
|
|
1059
|
-
const handle = require_json_schema.defineAnnotatedType();
|
|
1794
|
+
const handle = require_json_schema.defineAnnotatedType(void 0, base);
|
|
1060
1795
|
handle.designType(prim.id === "never" ? "never" : prim.config.type);
|
|
1061
1796
|
if (!skipAnnotations) this.applyExpectAnnotations(handle, this.doc.evalAnnotationsForNode(node));
|
|
1062
1797
|
return handle;
|
|
1063
1798
|
}
|
|
1064
1799
|
case "const": {
|
|
1065
1800
|
const c = node;
|
|
1066
|
-
const handle = require_json_schema.defineAnnotatedType();
|
|
1801
|
+
const handle = require_json_schema.defineAnnotatedType(void 0, base);
|
|
1067
1802
|
const t = c.token("identifier")?.type;
|
|
1068
1803
|
handle.designType(t === "number" ? "number" : "string");
|
|
1069
1804
|
handle.value(t === "number" ? Number(c.id) : c.id);
|
|
@@ -1071,7 +1806,7 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
1071
1806
|
}
|
|
1072
1807
|
case "structure": {
|
|
1073
1808
|
const struct = node;
|
|
1074
|
-
const handle = require_json_schema.defineAnnotatedType("object");
|
|
1809
|
+
const handle = require_json_schema.defineAnnotatedType("object", base);
|
|
1075
1810
|
for (const prop of Array.from(struct.props.values())) {
|
|
1076
1811
|
const propHandle = this.toAnnotatedHandle(prop);
|
|
1077
1812
|
const pattern = prop.token("identifier")?.pattern;
|
|
@@ -1082,24 +1817,24 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
1082
1817
|
}
|
|
1083
1818
|
case "group": {
|
|
1084
1819
|
const group = node;
|
|
1085
|
-
const handle = require_json_schema.defineAnnotatedType(group.op === "|" ? "union" : "intersection");
|
|
1820
|
+
const handle = require_json_schema.defineAnnotatedType(group.op === "|" ? "union" : "intersection", base);
|
|
1086
1821
|
for (const item of group.unwrap()) handle.item(this.toAnnotatedHandle(item).$type);
|
|
1087
1822
|
return skipAnnotations ? handle : this.applyExpectAnnotations(handle, this.doc.evalAnnotationsForNode(node));
|
|
1088
1823
|
}
|
|
1089
1824
|
case "tuple": {
|
|
1090
1825
|
const group = node;
|
|
1091
|
-
const handle = require_json_schema.defineAnnotatedType("tuple");
|
|
1826
|
+
const handle = require_json_schema.defineAnnotatedType("tuple", base);
|
|
1092
1827
|
for (const item of group.unwrap()) handle.item(this.toAnnotatedHandle(item).$type);
|
|
1093
1828
|
return skipAnnotations ? handle : this.applyExpectAnnotations(handle, this.doc.evalAnnotationsForNode(node));
|
|
1094
1829
|
}
|
|
1095
1830
|
case "array": {
|
|
1096
1831
|
const arr = node;
|
|
1097
|
-
const handle = require_json_schema.defineAnnotatedType("array");
|
|
1832
|
+
const handle = require_json_schema.defineAnnotatedType("array", base);
|
|
1098
1833
|
handle.of(this.toAnnotatedHandle(arr.getDefinition()).$type);
|
|
1099
1834
|
return skipAnnotations ? handle : this.applyExpectAnnotations(handle, this.doc.evalAnnotationsForNode(node));
|
|
1100
1835
|
}
|
|
1101
1836
|
default: {
|
|
1102
|
-
const handle = require_json_schema.defineAnnotatedType();
|
|
1837
|
+
const handle = require_json_schema.defineAnnotatedType(void 0, base);
|
|
1103
1838
|
return skipAnnotations ? handle : this.applyExpectAnnotations(handle, this.doc.evalAnnotationsForNode(node));
|
|
1104
1839
|
}
|
|
1105
1840
|
}
|
|
@@ -1171,8 +1906,10 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
1171
1906
|
node: synth.ownerNode
|
|
1172
1907
|
} : this.resolveOwner(this.doc, ref.id);
|
|
1173
1908
|
const refName = synth?.alias ?? ref.id;
|
|
1174
|
-
const
|
|
1909
|
+
const isImported = !!synth || (ownerDecl ? ownerDecl.doc !== this.doc : false);
|
|
1910
|
+
const refExpr = isImported ? `() => ${refName}` : refName;
|
|
1175
1911
|
this.writeln(`$(${name ? `"", ${name}` : ""})`).indent().writeln(`.refTo(${refExpr}${chain})`);
|
|
1912
|
+
this.model?.refTo(this.modelHandle("", name), refName, isImported, ref.hasChain ? ref.chain.map((c) => c.text) : void 0);
|
|
1176
1913
|
if (!ref.hasChain) {
|
|
1177
1914
|
if (ownerDecl?.node) ownerDecl.doc.evalReferredAnnotations(ownerDecl.node)?.forEach((an) => {
|
|
1178
1915
|
this.resolveAnnotationValue(ownerDecl.node, an);
|
|
@@ -1185,29 +1922,63 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
1185
1922
|
this.definePrimitive(node, name);
|
|
1186
1923
|
return this;
|
|
1187
1924
|
case "const":
|
|
1925
|
+
this.modelHandle("", name);
|
|
1188
1926
|
this.writeln(`$(${name ? `"", ${name}` : ""})`).indent().defineConst(node).unindent();
|
|
1189
1927
|
return this;
|
|
1190
1928
|
case "structure":
|
|
1929
|
+
this.modelHandle("object", name);
|
|
1191
1930
|
this.writeln(`$("object"${name ? `, ${name}` : ""})`).indent().defineObject(node).unindent();
|
|
1192
1931
|
return this;
|
|
1193
1932
|
case "group":
|
|
1194
1933
|
kind = node.op === "|" ? "union" : "intersection";
|
|
1934
|
+
this.modelHandle(kind, name);
|
|
1195
1935
|
this.writeln(`$("${kind}"${name ? `, ${name}` : ""})`).indent().defineGroup(node).unindent();
|
|
1196
1936
|
return this;
|
|
1197
1937
|
case "tuple":
|
|
1938
|
+
this.modelHandle("tuple", name);
|
|
1198
1939
|
this.writeln(`$("tuple"${name ? `, ${name}` : ""})`).indent().defineGroup(node).unindent();
|
|
1199
1940
|
return this;
|
|
1200
1941
|
case "array":
|
|
1942
|
+
this.modelHandle("array", name);
|
|
1201
1943
|
this.writeln(`$("array"${name ? `, ${name}` : ""})`).indent().defineArray(node).unindent();
|
|
1202
1944
|
return this;
|
|
1203
1945
|
default: return this;
|
|
1204
1946
|
}
|
|
1205
1947
|
}
|
|
1948
|
+
/** `$(kind, name?)` in the validation model; it becomes the current chain. */ modelHandle(kind, name) {
|
|
1949
|
+
if (!this.model) return;
|
|
1950
|
+
const h = this.model.handle(kind, name);
|
|
1951
|
+
this.model.current = h;
|
|
1952
|
+
return h;
|
|
1953
|
+
}
|
|
1954
|
+
/**
|
|
1955
|
+
* The model handle of a nested chain (`emit` writes it and its annotations): `current`
|
|
1956
|
+
* is cleared first so a chain that emits nothing breaks the model instead of leaving a
|
|
1957
|
+
* stale handle, and restored to the parent chain afterwards.
|
|
1958
|
+
*/ modelChild(emit) {
|
|
1959
|
+
if (!this.model) {
|
|
1960
|
+
emit();
|
|
1961
|
+
return;
|
|
1962
|
+
}
|
|
1963
|
+
const parent = this.model.current;
|
|
1964
|
+
this.model.current = void 0;
|
|
1965
|
+
emit();
|
|
1966
|
+
const child = this.model.current;
|
|
1967
|
+
this.model.current = parent;
|
|
1968
|
+
if (!child) this.model.broken = true;
|
|
1969
|
+
return child;
|
|
1970
|
+
}
|
|
1206
1971
|
defineConst(node) {
|
|
1207
1972
|
const t = node.token("identifier")?.type;
|
|
1208
1973
|
const designType = t === "text" ? "string" : t === "number" ? "number" : "unknown";
|
|
1209
1974
|
this.writeln(`.designType("${escapeQuotes(designType)}")`);
|
|
1210
1975
|
this.writeln(`.value(${t === "text" ? `"${escapeQuotes(node.id)}"` : node.id})`);
|
|
1976
|
+
if (this.model) {
|
|
1977
|
+
const h = this.model.current;
|
|
1978
|
+
this.model.run(() => {
|
|
1979
|
+
h.designType(designType).value(t === "text" ? node.id : rawLiteralValue(node.id));
|
|
1980
|
+
});
|
|
1981
|
+
}
|
|
1211
1982
|
return this;
|
|
1212
1983
|
}
|
|
1213
1984
|
definePrimitive(node, name) {
|
|
@@ -1215,66 +1986,82 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
1215
1986
|
this.writeln(` .tags(${Array.from(node.tags).map((f) => `"${escapeQuotes(f)}"`).join(", ")})`);
|
|
1216
1987
|
return this;
|
|
1217
1988
|
}
|
|
1218
|
-
renderPrimitiveDef(def, name) {
|
|
1989
|
+
/** Emits a primitive's builder chain (and follows it in the validation model). */ renderPrimitiveDef(def, name) {
|
|
1219
1990
|
const d = (t) => [`"${t || ""}"`, name].filter(Boolean).join(", ").replace(/^""$/, "");
|
|
1220
|
-
|
|
1221
|
-
|
|
1991
|
+
const final = (designType) => {
|
|
1992
|
+
this.writeln(`$(${d()}).designType("${designType}")`);
|
|
1993
|
+
const h = this.modelHandle("", name);
|
|
1994
|
+
this.model?.run(() => h.designType(designType));
|
|
1995
|
+
};
|
|
1996
|
+
if (!def) return final("any");
|
|
1997
|
+
if (typeof def === "string") return final(def === "void" ? "undefined" : def);
|
|
1222
1998
|
switch (def.kind) {
|
|
1223
|
-
case "final": return
|
|
1999
|
+
case "final": return final(def.value === "void" ? "undefined" : def.value);
|
|
1224
2000
|
case "union":
|
|
1225
2001
|
case "intersection":
|
|
1226
2002
|
case "tuple":
|
|
1227
2003
|
this.writeln(`$(${d(def.kind)})`);
|
|
2004
|
+
this.modelHandle(def.kind, name);
|
|
1228
2005
|
this.indent();
|
|
1229
2006
|
for (const itemDef of def.items) {
|
|
1230
2007
|
this.write(`.item(`);
|
|
1231
2008
|
this.indent();
|
|
1232
|
-
this.renderPrimitiveDef(itemDef);
|
|
2009
|
+
const child = this.modelChild(() => this.renderPrimitiveDef(itemDef));
|
|
1233
2010
|
this.writeln(".$type");
|
|
1234
2011
|
this.unindent();
|
|
1235
2012
|
this.write(`)`);
|
|
2013
|
+
this.model?.run(() => this.model.current.item(child.$type));
|
|
1236
2014
|
}
|
|
1237
2015
|
this.unindent();
|
|
1238
2016
|
return;
|
|
1239
|
-
case "array":
|
|
2017
|
+
case "array": {
|
|
1240
2018
|
this.writeln(`$(${d("array")})`);
|
|
2019
|
+
this.modelHandle("array", name);
|
|
1241
2020
|
this.indent();
|
|
1242
2021
|
this.write(".of(");
|
|
1243
2022
|
this.indent();
|
|
1244
|
-
this.renderPrimitiveDef(def.of);
|
|
2023
|
+
const child = this.modelChild(() => this.renderPrimitiveDef(def.of));
|
|
1245
2024
|
this.writeln(`.$type`);
|
|
1246
2025
|
this.unindent();
|
|
1247
2026
|
this.writeln(`)`);
|
|
1248
2027
|
this.unindent();
|
|
2028
|
+
this.model?.run(() => this.model.current.of(child.$type));
|
|
1249
2029
|
return;
|
|
1250
|
-
|
|
2030
|
+
}
|
|
2031
|
+
case "object": {
|
|
1251
2032
|
this.writeln(`$(${d("object")})`);
|
|
2033
|
+
this.modelHandle("object", name);
|
|
1252
2034
|
this.indent();
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
}
|
|
1264
|
-
for (const [key, propDef] of Object.entries(def.propsPatterns)) {
|
|
2035
|
+
const props = [...Object.entries(def.props).map(([k, p]) => [
|
|
2036
|
+
k,
|
|
2037
|
+
p,
|
|
2038
|
+
false
|
|
2039
|
+
]), ...Object.entries(def.propsPatterns).map(([k, p]) => [
|
|
2040
|
+
k,
|
|
2041
|
+
p,
|
|
2042
|
+
true
|
|
2043
|
+
])];
|
|
2044
|
+
for (const [key, propDef, isPattern] of props) {
|
|
1265
2045
|
const optional = typeof propDef === "object" && propDef.optional;
|
|
1266
|
-
this.writeln(`.propPattern(`);
|
|
2046
|
+
this.writeln(isPattern ? `.propPattern(` : `.prop(`);
|
|
1267
2047
|
this.indent();
|
|
1268
|
-
this.writeln(`${key},`);
|
|
1269
|
-
this.
|
|
1270
|
-
|
|
2048
|
+
this.writeln(isPattern ? `${key},` : `"${escapeQuotes(key)}",`);
|
|
2049
|
+
const child = this.modelChild(() => {
|
|
2050
|
+
this.renderPrimitiveDef(propDef);
|
|
2051
|
+
if (optional) {
|
|
2052
|
+
this.writeln(".optional()");
|
|
2053
|
+
this.model?.run(() => this.model.current.optional());
|
|
2054
|
+
}
|
|
2055
|
+
});
|
|
1271
2056
|
this.writeln(".$type");
|
|
1272
2057
|
this.unindent();
|
|
1273
2058
|
this.write(`)`);
|
|
2059
|
+
this.model?.run(() => isPattern ? this.model.current.propPattern(/./, child.$type) : this.model.current.prop(key, child.$type));
|
|
1274
2060
|
}
|
|
1275
2061
|
this.unindent();
|
|
1276
2062
|
return;
|
|
1277
|
-
|
|
2063
|
+
}
|
|
2064
|
+
default: return final("any");
|
|
1278
2065
|
}
|
|
1279
2066
|
}
|
|
1280
2067
|
defineObject(node) {
|
|
@@ -1292,25 +2079,39 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
1292
2079
|
this.indent();
|
|
1293
2080
|
this.writeln(`"${escapeQuotes(prop.id)}",`);
|
|
1294
2081
|
}
|
|
1295
|
-
this.
|
|
1296
|
-
|
|
2082
|
+
const child = this.modelChild(() => {
|
|
2083
|
+
this.annotateType(prop.getDefinition());
|
|
2084
|
+
this.indent().defineMetadata(prop).unindent();
|
|
2085
|
+
});
|
|
1297
2086
|
if (optional) this.writeln(" .optional()");
|
|
1298
2087
|
this.writeln(" .$type");
|
|
1299
2088
|
this.unindent();
|
|
1300
2089
|
this.write(`)`);
|
|
1301
2090
|
this._propPath.pop();
|
|
2091
|
+
this.model?.run(() => {
|
|
2092
|
+
if (optional) child.optional();
|
|
2093
|
+
if (pattern) this.model.current.propPattern(pattern, child.$type);
|
|
2094
|
+
else this.model.current.prop(prop.id, child.$type);
|
|
2095
|
+
});
|
|
1302
2096
|
}
|
|
1303
2097
|
this.writeln();
|
|
1304
2098
|
return this;
|
|
1305
2099
|
}
|
|
1306
2100
|
defineGroup(node) {
|
|
1307
|
-
const
|
|
1308
|
-
|
|
2101
|
+
for (const item of node.unwrap()) {
|
|
2102
|
+
this.write(".item(").indent();
|
|
2103
|
+
const child = this.modelChild(() => this.annotateType(item).defineInlinePrimitiveMetadata(item));
|
|
2104
|
+
this.write(" .$type").writeln(`)`).unindent();
|
|
2105
|
+
this.model?.run(() => this.model.current.item(child.$type));
|
|
2106
|
+
}
|
|
1309
2107
|
return this;
|
|
1310
2108
|
}
|
|
1311
2109
|
defineArray(node) {
|
|
1312
2110
|
const of = node.getDefinition();
|
|
1313
|
-
this.write(".of(").indent()
|
|
2111
|
+
this.write(".of(").indent();
|
|
2112
|
+
const child = this.modelChild(() => this.annotateType(of).defineInlinePrimitiveMetadata(of));
|
|
2113
|
+
this.write(" .$type").writeln(`)`).unindent();
|
|
2114
|
+
this.model?.run(() => this.model.current.of(child.$type));
|
|
1314
2115
|
return this;
|
|
1315
2116
|
}
|
|
1316
2117
|
/**
|
|
@@ -1381,9 +2182,10 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
1381
2182
|
return this;
|
|
1382
2183
|
}
|
|
1383
2184
|
resolveAnnotationValue(node, an) {
|
|
1384
|
-
const { value, multiple } = this.computeAnnotationValue(node, an);
|
|
2185
|
+
const { value, multiple, runtime } = this.computeAnnotationValue(node, an);
|
|
1385
2186
|
if (multiple) this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value}, true)`);
|
|
1386
2187
|
else this.writeln(`.annotate("${escapeQuotes(an.name)}", ${value})`);
|
|
2188
|
+
this.model?.annotate(an.name, runtime, multiple);
|
|
1387
2189
|
}
|
|
1388
2190
|
emitRefValue(text, origin) {
|
|
1389
2191
|
const dotIdx = text.indexOf(".");
|
|
@@ -1462,33 +2264,50 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
1462
2264
|
default: return token.text;
|
|
1463
2265
|
}
|
|
1464
2266
|
}
|
|
1465
|
-
|
|
2267
|
+
/**
|
|
2268
|
+
* The JS source of an annotation's value, and (for the validation model, which only reads
|
|
2269
|
+
* validator annotations: numbers, strings, flags) the runtime value it evaluates to;
|
|
2270
|
+
* other argument kinds are opaque there.
|
|
2271
|
+
*/ computeAnnotationValue(node, an) {
|
|
1466
2272
|
const origin = this.doc.annotationOrigin(an);
|
|
1467
2273
|
const spec = this.doc.resolveAnnotation(an.name);
|
|
1468
2274
|
let targetValue = "true";
|
|
2275
|
+
let runtime = true;
|
|
1469
2276
|
let multiple = false;
|
|
1470
2277
|
if (spec) {
|
|
1471
2278
|
multiple = spec.config.multiple;
|
|
1472
2279
|
const length = spec.arguments.length;
|
|
1473
|
-
if (length !== 0)
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
2280
|
+
if (length !== 0) {
|
|
2281
|
+
if (Array.isArray(spec.config.argument)) {
|
|
2282
|
+
targetValue = "{ ";
|
|
2283
|
+
const fields = {};
|
|
2284
|
+
let i = 0;
|
|
2285
|
+
for (const aSpec of spec.arguments) {
|
|
2286
|
+
if (an.args[i]) {
|
|
2287
|
+
targetValue += `${wrapProp(aSpec.name)}: ${this.emitArgValue(aSpec, an.args[i], origin)}${i === length - 1 ? "" : ", "} `;
|
|
2288
|
+
fields[aSpec.name] = runtimeArg(aSpec.type, an.args[i]);
|
|
2289
|
+
}
|
|
2290
|
+
i++;
|
|
2291
|
+
}
|
|
2292
|
+
targetValue += "}";
|
|
2293
|
+
runtime = fields;
|
|
2294
|
+
} else if (an.args[0]) {
|
|
2295
|
+
const aSpec = spec.arguments[0];
|
|
2296
|
+
targetValue = this.emitArgValue(aSpec, an.args[0], origin);
|
|
2297
|
+
runtime = runtimeArg(aSpec.type, an.args[0]);
|
|
1479
2298
|
}
|
|
1480
|
-
targetValue += "}";
|
|
1481
|
-
} else {
|
|
1482
|
-
const aSpec = spec.arguments[0];
|
|
1483
|
-
targetValue = an.args[0] ? this.emitArgValue(aSpec, an.args[0], origin) : "true";
|
|
1484
2299
|
}
|
|
1485
2300
|
} else {
|
|
1486
2301
|
multiple = node.countAnnotations(an.name) > 1 || an.args.length > 1;
|
|
1487
|
-
if (an.args.length > 0)
|
|
2302
|
+
if (an.args.length > 0) {
|
|
2303
|
+
targetValue = an.args[0].type === "text" ? `"${escapeQuotes(an.args[0].text)}"` : an.args[0].text;
|
|
2304
|
+
runtime = runtimeArg(void 0, an.args[0]);
|
|
2305
|
+
}
|
|
1488
2306
|
}
|
|
1489
2307
|
return {
|
|
1490
2308
|
value: targetValue,
|
|
1491
|
-
multiple: !!multiple
|
|
2309
|
+
multiple: !!multiple,
|
|
2310
|
+
runtime
|
|
1492
2311
|
};
|
|
1493
2312
|
}
|
|
1494
2313
|
renderMutatingAnnotateNode(node) {
|
|
@@ -1501,7 +2320,7 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
1501
2320
|
const anns = entry.annotations;
|
|
1502
2321
|
if (!anns || anns.length === 0) continue;
|
|
1503
2322
|
const parts = entry.hasChain ? [entry.id, ...entry.chain.map((c) => c.text)] : [entry.id];
|
|
1504
|
-
const { accessors, clones } = this.buildMutatingAccessors(
|
|
2323
|
+
const { accessors, clones } = this.buildMutatingAccessors(targetDef, parts);
|
|
1505
2324
|
allClones.push(...clones);
|
|
1506
2325
|
entryAccessors.push({
|
|
1507
2326
|
entry,
|
|
@@ -1510,29 +2329,36 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
1510
2329
|
}
|
|
1511
2330
|
const cloneKeys = /* @__PURE__ */ new Set();
|
|
1512
2331
|
for (const clone of allClones) {
|
|
1513
|
-
const
|
|
2332
|
+
const parentPath = accessorPath(targetName, clone.parentSteps);
|
|
2333
|
+
const key = `${parentPath}|${clone.propName}`;
|
|
1514
2334
|
if (!cloneKeys.has(key)) {
|
|
1515
2335
|
cloneKeys.add(key);
|
|
1516
|
-
this.writeln(`$c(${
|
|
2336
|
+
this.writeln(`$c(${parentPath}, "${escapeQuotes(clone.propName)}")`);
|
|
2337
|
+
this.model?.cloneProp(targetName, clone.parentSteps, clone.propName);
|
|
1517
2338
|
}
|
|
1518
2339
|
}
|
|
1519
|
-
for (const { entry, accessors } of entryAccessors) for (const accessor of accessors) this.emitMutatingAnnotations(entry, entry.annotations, accessor);
|
|
2340
|
+
for (const { entry, accessors } of entryAccessors) for (const accessor of accessors) this.emitMutatingAnnotations(entry, entry.annotations, accessor, targetName);
|
|
1520
2341
|
const topAnnotations = node.annotations;
|
|
1521
|
-
if (topAnnotations && topAnnotations.length > 0) this.emitMutatingAnnotations(node, topAnnotations, targetName);
|
|
2342
|
+
if (topAnnotations && topAnnotations.length > 0) this.emitMutatingAnnotations(node, topAnnotations, [], targetName);
|
|
1522
2343
|
this.writeln();
|
|
1523
2344
|
}
|
|
1524
|
-
emitMutatingAnnotations(node, annotations,
|
|
2345
|
+
emitMutatingAnnotations(node, annotations, steps, targetName) {
|
|
2346
|
+
const accessor = accessorPath(targetName, steps);
|
|
1525
2347
|
const cleared = /* @__PURE__ */ new Set();
|
|
1526
2348
|
for (const an of annotations) {
|
|
1527
|
-
const { value, multiple } = this.computeAnnotationValue(node, an);
|
|
2349
|
+
const { value, multiple, runtime } = this.computeAnnotationValue(node, an);
|
|
1528
2350
|
if (multiple) {
|
|
1529
2351
|
if (!cleared.has(an.name)) {
|
|
1530
2352
|
const spec = this.doc.resolveAnnotation(an.name);
|
|
1531
|
-
if (!spec || spec.config.mergeStrategy !== "append")
|
|
2353
|
+
if (!spec || spec.config.mergeStrategy !== "append") {
|
|
2354
|
+
this.writeln(`${accessor}.metadata.delete("${escapeQuotes(an.name)}")`);
|
|
2355
|
+
this.model?.deleteAnnotation(targetName, steps, an.name);
|
|
2356
|
+
}
|
|
1532
2357
|
cleared.add(an.name);
|
|
1533
2358
|
}
|
|
1534
2359
|
this.writeln(`$a(${accessor}.metadata, "${escapeQuotes(an.name)}", ${value}, true)`);
|
|
1535
2360
|
} else this.writeln(`$a(${accessor}.metadata, "${escapeQuotes(an.name)}", ${value})`);
|
|
2361
|
+
this.model?.mutateAnnotation(targetName, steps, an.name, runtime, multiple);
|
|
1536
2362
|
}
|
|
1537
2363
|
}
|
|
1538
2364
|
resolveTargetDef(targetName) {
|
|
@@ -1543,51 +2369,48 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
1543
2369
|
return def;
|
|
1544
2370
|
}
|
|
1545
2371
|
/**
|
|
1546
|
-
* Builds the
|
|
2372
|
+
* Builds the accessor paths (as steps, see `accessorPath`) for mutating annotate entries.
|
|
1547
2373
|
* Computes exact paths at compile time by walking the AST,
|
|
1548
2374
|
* so the generated JS accesses props directly without runtime search.
|
|
1549
2375
|
* Returns multiple paths when a property appears in multiple union branches.
|
|
1550
|
-
*/ buildMutatingAccessors(
|
|
2376
|
+
*/ buildMutatingAccessors(targetDef, parts) {
|
|
1551
2377
|
let accessors = [{
|
|
1552
|
-
|
|
2378
|
+
steps: ["type"],
|
|
1553
2379
|
def: targetDef
|
|
1554
2380
|
}];
|
|
1555
2381
|
const clones = [];
|
|
1556
2382
|
for (let i = 0; i < parts.length; i++) {
|
|
2383
|
+
const last = i === parts.length - 1;
|
|
1557
2384
|
const nextAccessors = [];
|
|
1558
|
-
for (const {
|
|
2385
|
+
for (const { steps, def } of accessors) {
|
|
1559
2386
|
const results = this.buildPropPaths(def, parts[i]);
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
2387
|
+
const found = results.length > 0 ? results : [{
|
|
2388
|
+
steps: [["props", parts[i]]],
|
|
2389
|
+
propDef: void 0
|
|
2390
|
+
}];
|
|
2391
|
+
for (const result of found) {
|
|
2392
|
+
if (!last && result.propDef && (0, _atscript_core.isRef)(result.propDef)) clones.push({
|
|
2393
|
+
parentSteps: steps,
|
|
1563
2394
|
propName: parts[i]
|
|
1564
2395
|
});
|
|
2396
|
+
const next = [...steps, ...result.steps];
|
|
2397
|
+
if (!last) next.push("type");
|
|
1565
2398
|
nextAccessors.push({
|
|
1566
|
-
|
|
2399
|
+
steps: next,
|
|
1567
2400
|
def: result.propDef
|
|
1568
2401
|
});
|
|
1569
|
-
} else nextAccessors.push({
|
|
1570
|
-
prefix: `${prefix}${result.path}?`,
|
|
1571
|
-
def: result.propDef
|
|
1572
|
-
});
|
|
1573
|
-
else {
|
|
1574
|
-
const suffix = `.props.get("${escapeQuotes(parts[i])}")${i < parts.length - 1 ? "?.type" : "?"}`;
|
|
1575
|
-
nextAccessors.push({
|
|
1576
|
-
prefix: `${prefix}${suffix}`,
|
|
1577
|
-
def: void 0
|
|
1578
|
-
});
|
|
1579
2402
|
}
|
|
1580
2403
|
}
|
|
1581
2404
|
accessors = nextAccessors;
|
|
1582
2405
|
}
|
|
1583
2406
|
return {
|
|
1584
|
-
accessors: accessors.map((a) => a.
|
|
2407
|
+
accessors: accessors.map((a) => a.steps),
|
|
1585
2408
|
clones
|
|
1586
2409
|
};
|
|
1587
2410
|
}
|
|
1588
2411
|
/**
|
|
1589
2412
|
* Finds a property in a type tree at compile time, returning all
|
|
1590
|
-
* matching
|
|
2413
|
+
* matching accessor steps and prop definitions for further chaining.
|
|
1591
2414
|
* Returns multiple results when the same property appears in different union branches.
|
|
1592
2415
|
*/ buildPropPaths(def, propName) {
|
|
1593
2416
|
if (!def) return [];
|
|
@@ -1601,7 +2424,7 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
1601
2424
|
if ((0, _atscript_core.isStructure)(def)) {
|
|
1602
2425
|
const prop = def.props.get(propName);
|
|
1603
2426
|
if (prop) return [{
|
|
1604
|
-
|
|
2427
|
+
steps: [["props", propName]],
|
|
1605
2428
|
propDef: prop.getDefinition()
|
|
1606
2429
|
}];
|
|
1607
2430
|
return [];
|
|
@@ -1610,7 +2433,11 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
1610
2433
|
const items = def.unwrap();
|
|
1611
2434
|
const results = [];
|
|
1612
2435
|
for (let i = 0; i < items.length; i++) for (const result of this.buildPropPaths(items[i], propName)) results.push({
|
|
1613
|
-
|
|
2436
|
+
steps: [
|
|
2437
|
+
["items", i],
|
|
2438
|
+
"type",
|
|
2439
|
+
...result.steps
|
|
2440
|
+
],
|
|
1614
2441
|
propDef: result.propDef
|
|
1615
2442
|
});
|
|
1616
2443
|
return results;
|
|
@@ -1618,13 +2445,19 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
1618
2445
|
return [];
|
|
1619
2446
|
}
|
|
1620
2447
|
constructor(doc, opts) {
|
|
1621
|
-
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();
|
|
2448
|
+
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), _define_property(this, "model", void 0), _define_property(this, "modelClasses", void 0), _define_property(this, "_declTypes", 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(), this.modelClasses = [], this._declTypes = /* @__PURE__ */ new Map();
|
|
2449
|
+
if (opts?.compileValidators) this.model = new ValidationModel();
|
|
1622
2450
|
}
|
|
1623
2451
|
};
|
|
1624
2452
|
|
|
1625
2453
|
//#endregion
|
|
1626
2454
|
//#region packages/typescript/src/plugin.ts
|
|
1627
2455
|
/**
|
|
2456
|
+
* Render formats of the JS output that override {@link TTsPluginOptions.compileValidators}
|
|
2457
|
+
* (used by `unplugin-atscript`'s `compileValidators` option).
|
|
2458
|
+
*/ const JS_COMPILED_FORMAT = "js:compiled";
|
|
2459
|
+
const JS_INTERPRETED_FORMAT = "js:interpreted";
|
|
2460
|
+
/**
|
|
1628
2461
|
* Resolves the effective JSON schema mode from plugin options.
|
|
1629
2462
|
*/ function resolveJsonSchemaMode(opts) {
|
|
1630
2463
|
if (opts?.jsonSchema !== void 0) return opts.jsonSchema;
|
|
@@ -1638,10 +2471,16 @@ const tsPlugin = (opts) => {
|
|
|
1638
2471
|
fileName: `${doc.name}.d.ts`,
|
|
1639
2472
|
content: new TypeRenderer(doc, opts).render()
|
|
1640
2473
|
}];
|
|
1641
|
-
if (format === "js")
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
2474
|
+
if (format === "js" || format === JS_COMPILED_FORMAT || format === JS_INTERPRETED_FORMAT) {
|
|
2475
|
+
const jsOpts = format === "js" ? opts : {
|
|
2476
|
+
...opts,
|
|
2477
|
+
compileValidators: format === JS_COMPILED_FORMAT
|
|
2478
|
+
};
|
|
2479
|
+
return [{
|
|
2480
|
+
fileName: `${doc.name}.js`,
|
|
2481
|
+
content: new JsRenderer(doc, jsOpts).render()
|
|
2482
|
+
}];
|
|
2483
|
+
}
|
|
1645
2484
|
},
|
|
1646
2485
|
async buildEnd(output, format, repo) {
|
|
1647
2486
|
if (format === "dts" || format === _atscript_core.DEFAULT_FORMAT) {
|
|
@@ -1669,6 +2508,18 @@ const tsPlugin = (opts) => {
|
|
|
1669
2508
|
};
|
|
1670
2509
|
|
|
1671
2510
|
//#endregion
|
|
2511
|
+
Object.defineProperty(exports, 'JS_COMPILED_FORMAT', {
|
|
2512
|
+
enumerable: true,
|
|
2513
|
+
get: function () {
|
|
2514
|
+
return JS_COMPILED_FORMAT;
|
|
2515
|
+
}
|
|
2516
|
+
});
|
|
2517
|
+
Object.defineProperty(exports, 'JS_INTERPRETED_FORMAT', {
|
|
2518
|
+
enumerable: true,
|
|
2519
|
+
get: function () {
|
|
2520
|
+
return JS_INTERPRETED_FORMAT;
|
|
2521
|
+
}
|
|
2522
|
+
});
|
|
1672
2523
|
Object.defineProperty(exports, '__toESM', {
|
|
1673
2524
|
enumerable: true,
|
|
1674
2525
|
get: function () {
|