typesea 0.1.0 → 0.3.0
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/CHANGELOG.md +85 -6
- package/README.md +143 -28
- package/dist/adapters/index.d.ts +50 -8
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +169 -48
- package/dist/aot/index.d.ts +19 -3
- package/dist/aot/index.d.ts.map +1 -1
- package/dist/aot/index.js +115 -17
- package/dist/async/index.d.ts +28 -56
- package/dist/async/index.d.ts.map +1 -1
- package/dist/async/index.js +94 -37
- package/dist/builders/composite.d.ts +43 -9
- package/dist/builders/composite.d.ts.map +1 -1
- package/dist/builders/composite.js +100 -17
- package/dist/builders/index.d.ts +8 -5
- package/dist/builders/index.d.ts.map +1 -1
- package/dist/builders/index.js +7 -4
- package/dist/builders/modifier.d.ts +36 -5
- package/dist/builders/modifier.d.ts.map +1 -1
- package/dist/builders/modifier.js +52 -5
- package/dist/builders/object/guard.d.ts +72 -24
- package/dist/builders/object/guard.d.ts.map +1 -1
- package/dist/builders/object/guard.js +139 -29
- package/dist/builders/object/index.d.ts +4 -2
- package/dist/builders/object/index.d.ts.map +1 -1
- package/dist/builders/object/index.js +3 -1
- package/dist/builders/object/schema.d.ts +88 -11
- package/dist/builders/object/schema.d.ts.map +1 -1
- package/dist/builders/object/schema.js +290 -23
- package/dist/builders/object/types.d.ts +20 -31
- package/dist/builders/object/types.d.ts.map +1 -1
- package/dist/builders/object/types.js +2 -0
- package/dist/builders/runtime.d.ts +40 -0
- package/dist/builders/runtime.d.ts.map +1 -0
- package/dist/builders/runtime.js +150 -0
- package/dist/builders/scalar.d.ts +49 -9
- package/dist/builders/scalar.d.ts.map +1 -1
- package/dist/builders/scalar.js +87 -9
- package/dist/builders/table.d.ts +35 -5
- package/dist/builders/table.d.ts.map +1 -1
- package/dist/builders/table.js +35 -5
- package/dist/builders/types.d.ts +20 -4
- package/dist/builders/types.d.ts.map +1 -1
- package/dist/builders/types.js +2 -0
- package/dist/compile/check-composite.d.ts +25 -2
- package/dist/compile/check-composite.d.ts.map +1 -1
- package/dist/compile/check-composite.js +699 -27
- package/dist/compile/check-scalar.d.ts +88 -0
- package/dist/compile/check-scalar.d.ts.map +1 -1
- package/dist/compile/check-scalar.js +570 -3
- package/dist/compile/check.d.ts +12 -0
- package/dist/compile/check.d.ts.map +1 -1
- package/dist/compile/check.js +62 -3
- package/dist/compile/context.d.ts +47 -9
- package/dist/compile/context.d.ts.map +1 -1
- package/dist/compile/context.js +53 -8
- package/dist/compile/first.d.ts +26 -0
- package/dist/compile/first.d.ts.map +1 -0
- package/dist/compile/first.js +850 -0
- package/dist/compile/graph-predicate.d.ts +4 -2
- package/dist/compile/graph-predicate.d.ts.map +1 -1
- package/dist/compile/graph-predicate.js +2272 -165
- package/dist/compile/guard.d.ts +16 -24
- package/dist/compile/guard.d.ts.map +1 -1
- package/dist/compile/guard.js +202 -72
- package/dist/compile/index.d.ts +3 -1
- package/dist/compile/index.d.ts.map +1 -1
- package/dist/compile/index.js +2 -0
- package/dist/compile/issue.d.ts +110 -0
- package/dist/compile/issue.d.ts.map +1 -1
- package/dist/compile/issue.js +184 -1
- package/dist/compile/names.d.ts +12 -2
- package/dist/compile/names.d.ts.map +1 -1
- package/dist/compile/names.js +19 -3
- package/dist/compile/predicate.d.ts +24 -0
- package/dist/compile/predicate.d.ts.map +1 -1
- package/dist/compile/predicate.js +287 -10
- package/dist/compile/runtime.d.ts +100 -13
- package/dist/compile/runtime.d.ts.map +1 -1
- package/dist/compile/runtime.js +56 -6
- package/dist/compile/source.d.ts +10 -2
- package/dist/compile/source.d.ts.map +1 -1
- package/dist/compile/source.js +385 -26
- package/dist/compile/types.d.ts +22 -0
- package/dist/compile/types.d.ts.map +1 -1
- package/dist/compile/types.js +2 -0
- package/dist/decoder/index.d.ts +92 -46
- package/dist/decoder/index.d.ts.map +1 -1
- package/dist/decoder/index.js +266 -39
- package/dist/evaluate/check-composite.d.ts +111 -2
- package/dist/evaluate/check-composite.d.ts.map +1 -1
- package/dist/evaluate/check-composite.js +343 -8
- package/dist/evaluate/check-scalar.d.ts +25 -0
- package/dist/evaluate/check-scalar.d.ts.map +1 -1
- package/dist/evaluate/check-scalar.js +124 -3
- package/dist/evaluate/check.d.ts +7 -0
- package/dist/evaluate/check.d.ts.map +1 -1
- package/dist/evaluate/check.js +62 -4
- package/dist/evaluate/index.d.ts +2 -0
- package/dist/evaluate/index.d.ts.map +1 -1
- package/dist/evaluate/index.js +2 -0
- package/dist/evaluate/issue.d.ts +11 -1
- package/dist/evaluate/issue.d.ts.map +1 -1
- package/dist/evaluate/issue.js +15 -1
- package/dist/evaluate/predicate.d.ts +16 -5
- package/dist/evaluate/predicate.d.ts.map +1 -1
- package/dist/evaluate/predicate.js +20 -5
- package/dist/evaluate/shared.d.ts +78 -13
- package/dist/evaluate/shared.d.ts.map +1 -1
- package/dist/evaluate/shared.js +101 -8
- package/dist/evaluate/state.d.ts +35 -13
- package/dist/evaluate/state.d.ts.map +1 -1
- package/dist/evaluate/state.js +35 -2
- package/dist/guard/array.d.ts +48 -0
- package/dist/guard/array.d.ts.map +1 -0
- package/dist/guard/array.js +84 -0
- package/dist/guard/base.d.ts +111 -31
- package/dist/guard/base.d.ts.map +1 -1
- package/dist/guard/base.js +165 -32
- package/dist/guard/date.d.ts +34 -0
- package/dist/guard/date.d.ts.map +1 -0
- package/dist/guard/date.js +60 -0
- package/dist/guard/error.d.ts +10 -5
- package/dist/guard/error.d.ts.map +1 -1
- package/dist/guard/error.js +10 -5
- package/dist/guard/index.d.ts +4 -0
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +4 -0
- package/dist/guard/number.d.ts +86 -11
- package/dist/guard/number.d.ts.map +1 -1
- package/dist/guard/number.js +159 -11
- package/dist/guard/props.d.ts +27 -3
- package/dist/guard/props.d.ts.map +1 -1
- package/dist/guard/props.js +27 -3
- package/dist/guard/read.d.ts +115 -10
- package/dist/guard/read.d.ts.map +1 -1
- package/dist/guard/read.js +185 -10
- package/dist/guard/registry.d.ts +12 -2
- package/dist/guard/registry.d.ts.map +1 -1
- package/dist/guard/registry.js +15 -3
- package/dist/guard/string.d.ts +115 -13
- package/dist/guard/string.d.ts.map +1 -1
- package/dist/guard/string.js +250 -13
- package/dist/guard/types.d.ts +110 -40
- package/dist/guard/types.d.ts.map +1 -1
- package/dist/guard/types.js +2 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/internal/index.d.ts +42 -6
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +51 -8
- package/dist/ir/builder.d.ts +17 -127
- package/dist/ir/builder.d.ts.map +1 -1
- package/dist/ir/builder.js +80 -137
- package/dist/ir/freeze.d.ts +4 -0
- package/dist/ir/freeze.d.ts.map +1 -1
- package/dist/ir/freeze.js +66 -0
- package/dist/ir/index.d.ts +3 -1
- package/dist/ir/index.d.ts.map +1 -1
- package/dist/ir/index.js +2 -0
- package/dist/ir/regexp.d.ts +2 -0
- package/dist/ir/regexp.d.ts.map +1 -1
- package/dist/ir/regexp.js +2 -0
- package/dist/ir/types.d.ts +94 -56
- package/dist/ir/types.d.ts.map +1 -1
- package/dist/ir/types.js +2 -0
- package/dist/ir/validate.d.ts +8 -1
- package/dist/ir/validate.d.ts.map +1 -1
- package/dist/ir/validate.js +511 -61
- package/dist/issue/index.d.ts +42 -10
- package/dist/issue/index.d.ts.map +1 -1
- package/dist/issue/index.js +65 -11
- package/dist/json-schema/emit-combinator.d.ts +44 -4
- package/dist/json-schema/emit-combinator.d.ts.map +1 -1
- package/dist/json-schema/emit-combinator.js +44 -4
- package/dist/json-schema/emit-composite.d.ts +16 -2
- package/dist/json-schema/emit-composite.d.ts.map +1 -1
- package/dist/json-schema/emit-composite.js +81 -13
- package/dist/json-schema/emit-scalar.d.ts +26 -3
- package/dist/json-schema/emit-scalar.d.ts.map +1 -1
- package/dist/json-schema/emit-scalar.js +124 -10
- package/dist/json-schema/emit-types.d.ts +11 -1
- package/dist/json-schema/emit-types.d.ts.map +1 -1
- package/dist/json-schema/emit-types.js +2 -0
- package/dist/json-schema/emit.d.ts +12 -1
- package/dist/json-schema/emit.d.ts.map +1 -1
- package/dist/json-schema/emit.js +23 -3
- package/dist/json-schema/freeze.d.ts +13 -2
- package/dist/json-schema/freeze.d.ts.map +1 -1
- package/dist/json-schema/freeze.js +41 -8
- package/dist/json-schema/index.d.ts +16 -2
- package/dist/json-schema/index.d.ts.map +1 -1
- package/dist/json-schema/index.js +23 -3
- package/dist/json-schema/issue.d.ts +4 -1
- package/dist/json-schema/issue.d.ts.map +1 -1
- package/dist/json-schema/issue.js +4 -1
- package/dist/json-schema/read.d.ts +24 -3
- package/dist/json-schema/read.d.ts.map +1 -1
- package/dist/json-schema/read.js +59 -12
- package/dist/json-schema/types.d.ts +45 -16
- package/dist/json-schema/types.d.ts.map +1 -1
- package/dist/json-schema/types.js +2 -0
- package/dist/kind/index.d.ts +40 -28
- package/dist/kind/index.d.ts.map +1 -1
- package/dist/kind/index.js +41 -13
- package/dist/lower/index.d.ts +6 -1
- package/dist/lower/index.d.ts.map +1 -1
- package/dist/lower/index.js +462 -46
- package/dist/message/index.d.ts +64 -10
- package/dist/message/index.d.ts.map +1 -1
- package/dist/message/index.js +155 -17
- package/dist/optimize/algebraic.d.ts +54 -0
- package/dist/optimize/algebraic.d.ts.map +1 -0
- package/dist/optimize/algebraic.js +314 -0
- package/dist/optimize/compact.d.ts +8 -1
- package/dist/optimize/compact.d.ts.map +1 -1
- package/dist/optimize/compact.js +13 -2
- package/dist/optimize/domain.d.ts +16 -0
- package/dist/optimize/domain.d.ts.map +1 -0
- package/dist/optimize/domain.js +619 -0
- package/dist/optimize/fold-boolean.d.ts +17 -2
- package/dist/optimize/fold-boolean.d.ts.map +1 -1
- package/dist/optimize/fold-boolean.js +59 -14
- package/dist/optimize/fold-common.d.ts +43 -8
- package/dist/optimize/fold-common.d.ts.map +1 -1
- package/dist/optimize/fold-common.js +37 -6
- package/dist/optimize/fold-constraints.d.ts +33 -0
- package/dist/optimize/fold-constraints.d.ts.map +1 -0
- package/dist/optimize/fold-constraints.js +484 -0
- package/dist/optimize/fold-scalar.d.ts +98 -13
- package/dist/optimize/fold-scalar.d.ts.map +1 -1
- package/dist/optimize/fold-scalar.js +98 -13
- package/dist/optimize/fold.d.ts +8 -1
- package/dist/optimize/fold.d.ts.map +1 -1
- package/dist/optimize/fold.js +22 -2
- package/dist/optimize/index.d.ts +9 -1
- package/dist/optimize/index.d.ts.map +1 -1
- package/dist/optimize/index.js +18 -3
- package/dist/optimize/map-node.d.ts +3 -1
- package/dist/optimize/map-node.d.ts.map +1 -1
- package/dist/optimize/map-node.js +48 -3
- package/dist/optimize/peephole.d.ts +16 -0
- package/dist/optimize/peephole.d.ts.map +1 -0
- package/dist/optimize/peephole.js +254 -0
- package/dist/optimize/remap.d.ts +2 -0
- package/dist/optimize/remap.d.ts.map +1 -1
- package/dist/optimize/remap.js +2 -0
- package/dist/optimize/rewrite.d.ts +13 -8
- package/dist/optimize/rewrite.d.ts.map +1 -1
- package/dist/optimize/rewrite.js +13 -8
- package/dist/plan/cache.d.ts +9 -3
- package/dist/plan/cache.d.ts.map +1 -1
- package/dist/plan/cache.js +34 -6
- package/dist/plan/index.d.ts +2 -0
- package/dist/plan/index.d.ts.map +1 -1
- package/dist/plan/index.js +2 -0
- package/dist/plan/predicate.d.ts +2 -0
- package/dist/plan/predicate.d.ts.map +1 -1
- package/dist/plan/predicate.js +298 -29
- package/dist/plan/schema-predicate.d.ts +6 -0
- package/dist/plan/schema-predicate.d.ts.map +1 -1
- package/dist/plan/schema-predicate.js +382 -19
- package/dist/plan/types.d.ts +2 -0
- package/dist/plan/types.d.ts.map +1 -1
- package/dist/plan/types.js +2 -0
- package/dist/result/index.d.ts +19 -5
- package/dist/result/index.d.ts.map +1 -1
- package/dist/result/index.js +10 -2
- package/dist/schema/common.d.ts +69 -6
- package/dist/schema/common.d.ts.map +1 -1
- package/dist/schema/common.js +104 -10
- package/dist/schema/freeze.d.ts +4 -0
- package/dist/schema/freeze.d.ts.map +1 -1
- package/dist/schema/freeze.js +40 -0
- package/dist/schema/index.d.ts +5 -2
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +4 -1
- package/dist/schema/lazy.d.ts +4 -0
- package/dist/schema/lazy.d.ts.map +1 -1
- package/dist/schema/lazy.js +4 -0
- package/dist/schema/literal.d.ts +7 -1
- package/dist/schema/literal.d.ts.map +1 -1
- package/dist/schema/literal.js +7 -1
- package/dist/schema/types.d.ts +109 -100
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/schema/types.js +13 -2
- package/dist/schema/undefined.d.ts +17 -0
- package/dist/schema/undefined.d.ts.map +1 -0
- package/dist/schema/undefined.js +77 -0
- package/dist/schema/validate.d.ts +8 -1
- package/dist/schema/validate.d.ts.map +1 -1
- package/dist/schema/validate.js +255 -57
- package/docs/api.md +128 -8
- package/docs/assets/benchmark-headline.svg +163 -0
- package/docs/engine-notes.md +62 -15
- package/docs/index.html +1340 -702
- package/docs/ko/api.md +375 -0
- package/docs/ko/engine-notes.md +156 -0
- package/docs/ko/readme.md +378 -0
- package/package.json +66 -65
package/dist/compile/issue.js
CHANGED
|
@@ -1,28 +1,211 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file compile/issue.ts
|
|
3
3
|
* @brief Diagnostic issue source snippets.
|
|
4
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
5
|
+
* stable across runtime and AOT emission.
|
|
4
6
|
*/
|
|
5
7
|
import { UUID_PATTERN } from "../schema/index.js";
|
|
6
8
|
import { pushRegex, stringRef } from "./context.js";
|
|
7
9
|
import { stringLiteral } from "./names.js";
|
|
8
10
|
/**
|
|
9
11
|
* @brief emit pattern issue.
|
|
12
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
13
|
+
* stable across runtime and AOT emission.
|
|
14
|
+
* @param value Generated expression for the string value.
|
|
15
|
+
* @param path Generated expression for the current diagnostic path.
|
|
16
|
+
* @param issues Generated expression for the diagnostic buffer.
|
|
17
|
+
* @param regex Pattern used by the schema check.
|
|
18
|
+
* @param name Human-readable pattern name stored in the issue.
|
|
19
|
+
* @param context Shared code-generation context.
|
|
20
|
+
* @returns JavaScript source that appends a pattern issue when the test fails.
|
|
10
21
|
*/
|
|
11
22
|
export function emitPatternIssue(value, path, issues, regex, name, context) {
|
|
12
23
|
const source = regex === UUID_PATTERN ? UUID_PATTERN : regex;
|
|
13
24
|
const index = pushRegex(context, source);
|
|
14
25
|
const access = `r[${String(index)}]`;
|
|
15
|
-
|
|
26
|
+
const test = regexNeedsLastIndexReset(source)
|
|
27
|
+
? `((${access}.lastIndex=0),!${access}.test(${value}))`
|
|
28
|
+
: `!${access}.test(${value})`;
|
|
29
|
+
/*
|
|
30
|
+
* Pattern names live in the string side table. That keeps generated source
|
|
31
|
+
* stable even when users provide long or escaped pattern descriptions.
|
|
32
|
+
*/
|
|
33
|
+
return `if(${test}){${emitIssueExpr(issues, path, "expected_pattern", stringRef(context, name), stringLiteral("string"))}}`;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @brief emit pattern issue at one appended path segment.
|
|
37
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
38
|
+
* stable across runtime and AOT emission.
|
|
39
|
+
* @param value Generated expression for the string value.
|
|
40
|
+
* @param path Generated expression for the current diagnostic path.
|
|
41
|
+
* @param segmentExpression Generated expression for the appended segment.
|
|
42
|
+
* @param issues Generated expression for the diagnostic buffer.
|
|
43
|
+
* @param regex Pattern used by the schema check.
|
|
44
|
+
* @param name Human-readable pattern name stored in the issue.
|
|
45
|
+
* @param context Shared code-generation context.
|
|
46
|
+
* @returns JavaScript source that appends a one-segment pattern issue.
|
|
47
|
+
*/
|
|
48
|
+
export function emitPatternIssueAtSegment(value, path, segmentExpression, issues, regex, name, context) {
|
|
49
|
+
const source = regex === UUID_PATTERN ? UUID_PATTERN : regex;
|
|
50
|
+
const index = pushRegex(context, source);
|
|
51
|
+
const access = `r[${String(index)}]`;
|
|
52
|
+
const test = regexNeedsLastIndexReset(source)
|
|
53
|
+
? `((${access}.lastIndex=0),!${access}.test(${value}))`
|
|
54
|
+
: `!${access}.test(${value})`;
|
|
55
|
+
return `if(${test}){${emitIssueExprAtSegment(issues, path, segmentExpression, "expected_pattern", stringRef(context, name), stringLiteral("string"))}}`;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* @brief emit pattern issue at two appended path segments.
|
|
59
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
60
|
+
* stable across runtime and AOT emission.
|
|
61
|
+
* @param value Generated expression for the string value.
|
|
62
|
+
* @param path Generated expression for the current diagnostic path.
|
|
63
|
+
* @param firstSegmentExpression Generated expression for the first appended segment.
|
|
64
|
+
* @param secondSegmentExpression Generated expression for the second appended segment.
|
|
65
|
+
* @param issues Generated expression for the diagnostic buffer.
|
|
66
|
+
* @param regex Pattern used by the schema check.
|
|
67
|
+
* @param name Human-readable pattern name stored in the issue.
|
|
68
|
+
* @param context Shared code-generation context.
|
|
69
|
+
* @returns JavaScript source that appends a two-segment pattern issue.
|
|
70
|
+
*/
|
|
71
|
+
export function emitPatternIssueAtTwoSegments(value, path, firstSegmentExpression, secondSegmentExpression, issues, regex, name, context) {
|
|
72
|
+
const source = regex === UUID_PATTERN ? UUID_PATTERN : regex;
|
|
73
|
+
const index = pushRegex(context, source);
|
|
74
|
+
const access = `r[${String(index)}]`;
|
|
75
|
+
const test = regexNeedsLastIndexReset(source)
|
|
76
|
+
? `((${access}.lastIndex=0),!${access}.test(${value}))`
|
|
77
|
+
: `!${access}.test(${value})`;
|
|
78
|
+
return `if(${test}){${emitIssueExprAtTwoSegments(issues, path, firstSegmentExpression, secondSegmentExpression, "expected_pattern", stringRef(context, name), stringLiteral("string"))}}`;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* @brief Decide whether a RegExp must be reset before generated testing.
|
|
82
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
83
|
+
* stable across runtime and AOT emission.
|
|
84
|
+
* @param regex RegExp stored in the generated side table.
|
|
85
|
+
* @returns True for stateful global or sticky expressions.
|
|
86
|
+
*/
|
|
87
|
+
function regexNeedsLastIndexReset(regex) {
|
|
88
|
+
return regex.global || regex.sticky;
|
|
16
89
|
}
|
|
17
90
|
/**
|
|
18
91
|
* @brief emit issue.
|
|
92
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
93
|
+
* stable across runtime and AOT emission.
|
|
94
|
+
* @param issues Generated expression for the diagnostic buffer.
|
|
95
|
+
* @param path Generated expression for the current diagnostic path.
|
|
96
|
+
* @param code Issue code string.
|
|
97
|
+
* @param expected Expected type or condition text.
|
|
98
|
+
* @param actualExpression Generated expression for actual type text.
|
|
99
|
+
* @returns JavaScript source that appends an issue at the current path.
|
|
19
100
|
*/
|
|
20
101
|
export function emitIssue(issues, path, code, expected, actualExpression) {
|
|
21
102
|
return emitIssueExpr(issues, path, code, stringLiteral(expected), actualExpression);
|
|
22
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* @brief emit issue at one appended path segment.
|
|
106
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
107
|
+
* stable across runtime and AOT emission.
|
|
108
|
+
* @param issues Generated expression for the diagnostic buffer.
|
|
109
|
+
* @param path Generated expression for the current diagnostic path.
|
|
110
|
+
* @param segmentExpression Generated expression for the appended segment.
|
|
111
|
+
* @param code Issue code string.
|
|
112
|
+
* @param expected Expected type or condition text.
|
|
113
|
+
* @param actualExpression Generated expression for actual type text.
|
|
114
|
+
* @returns JavaScript source that appends an issue under one extra segment.
|
|
115
|
+
*/
|
|
116
|
+
export function emitIssueAtSegment(issues, path, segmentExpression, code, expected, actualExpression) {
|
|
117
|
+
return emitIssueExprAtSegment(issues, path, segmentExpression, code, stringLiteral(expected), actualExpression);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* @brief emit issue at two appended path segments.
|
|
121
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
122
|
+
* stable across runtime and AOT emission.
|
|
123
|
+
* @param issues Generated expression for the diagnostic buffer.
|
|
124
|
+
* @param path Generated expression for the current diagnostic path.
|
|
125
|
+
* @param firstSegmentExpression Generated expression for the first appended segment.
|
|
126
|
+
* @param secondSegmentExpression Generated expression for the second appended segment.
|
|
127
|
+
* @param code Issue code string.
|
|
128
|
+
* @param expected Expected type or condition text.
|
|
129
|
+
* @param actualExpression Generated expression for actual type text.
|
|
130
|
+
* @returns JavaScript source that appends an issue under two extra segments.
|
|
131
|
+
*/
|
|
132
|
+
export function emitIssueAtTwoSegments(issues, path, firstSegmentExpression, secondSegmentExpression, code, expected, actualExpression) {
|
|
133
|
+
return emitIssueExprAtTwoSegments(issues, path, firstSegmentExpression, secondSegmentExpression, code, stringLiteral(expected), actualExpression);
|
|
134
|
+
}
|
|
23
135
|
/**
|
|
24
136
|
* @brief emit issue expr.
|
|
137
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
138
|
+
* stable across runtime and AOT emission.
|
|
139
|
+
* @param issues Generated expression for the diagnostic buffer.
|
|
140
|
+
* @param path Generated expression for the current diagnostic path.
|
|
141
|
+
* @param code Issue code string.
|
|
142
|
+
* @param expectedExpression Generated expression for expected text.
|
|
143
|
+
* @param actualExpression Generated expression for actual type text.
|
|
144
|
+
* @returns JavaScript source that appends an issue using expression operands.
|
|
25
145
|
*/
|
|
26
146
|
export function emitIssueExpr(issues, path, code, expectedExpression, actualExpression) {
|
|
27
147
|
return `q(${issues},${path},${stringLiteral(code)},${expectedExpression},${actualExpression});`;
|
|
28
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* @brief emit issue expr at one appended path segment.
|
|
151
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
152
|
+
* stable across runtime and AOT emission.
|
|
153
|
+
* @param issues Generated expression for the diagnostic buffer.
|
|
154
|
+
* @param path Generated expression for the current diagnostic path.
|
|
155
|
+
* @param segmentExpression Generated expression for the appended segment.
|
|
156
|
+
* @param code Issue code string.
|
|
157
|
+
* @param expectedExpression Generated expression for expected text.
|
|
158
|
+
* @param actualExpression Generated expression for actual type text.
|
|
159
|
+
* @returns JavaScript source using the most compact one-segment issue helper.
|
|
160
|
+
*/
|
|
161
|
+
export function emitIssueExprAtSegment(issues, path, segmentExpression, code, expectedExpression, actualExpression) {
|
|
162
|
+
const stringIndex = readStringRefIndex(segmentExpression);
|
|
163
|
+
if (stringIndex !== undefined) {
|
|
164
|
+
/*
|
|
165
|
+
* q1s reuses the pre-frozen path segment cache for static string keys.
|
|
166
|
+
* Dynamic segments still go through q1 because their value is known only
|
|
167
|
+
* inside the generated validator.
|
|
168
|
+
*/
|
|
169
|
+
return `q1s(${issues},${path},${stringIndex},${stringLiteral(code)},${expectedExpression},${actualExpression});`;
|
|
170
|
+
}
|
|
171
|
+
return `q1(${issues},${path},${segmentExpression},${stringLiteral(code)},${expectedExpression},${actualExpression});`;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* @brief emit issue expr at two appended path segments.
|
|
175
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
176
|
+
* stable across runtime and AOT emission.
|
|
177
|
+
* @param issues Generated expression for the diagnostic buffer.
|
|
178
|
+
* @param path Generated expression for the current diagnostic path.
|
|
179
|
+
* @param firstSegmentExpression Generated expression for the first appended segment.
|
|
180
|
+
* @param secondSegmentExpression Generated expression for the second appended segment.
|
|
181
|
+
* @param code Issue code string.
|
|
182
|
+
* @param expectedExpression Generated expression for expected text.
|
|
183
|
+
* @param actualExpression Generated expression for actual type text.
|
|
184
|
+
* @returns JavaScript source using the two-segment issue helper.
|
|
185
|
+
*/
|
|
186
|
+
export function emitIssueExprAtTwoSegments(issues, path, firstSegmentExpression, secondSegmentExpression, code, expectedExpression, actualExpression) {
|
|
187
|
+
return `q2(${issues},${path},${firstSegmentExpression},${secondSegmentExpression},${stringLiteral(code)},${expectedExpression},${actualExpression});`;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* @brief Extract the numeric side-table index from a generated string reference.
|
|
191
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
192
|
+
* stable across runtime and AOT emission.
|
|
193
|
+
* @param expression Candidate generated expression such as `u[3]`.
|
|
194
|
+
* @returns Index text when the expression is a plain string-table read.
|
|
195
|
+
*/
|
|
196
|
+
function readStringRefIndex(expression) {
|
|
197
|
+
if (!expression.startsWith("u[") || !expression.endsWith("]")) {
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
const value = expression.slice(2, -1);
|
|
201
|
+
if (value.length === 0) {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
205
|
+
const code = value.charCodeAt(index);
|
|
206
|
+
if (code < 48 || code > 57) {
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return value;
|
|
211
|
+
}
|
package/dist/compile/names.d.ts
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file compile-names.ts
|
|
3
3
|
* @brief Generated function-name and string literal helpers.
|
|
4
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
5
|
+
* stable across runtime and AOT emission.
|
|
4
6
|
*
|
|
5
7
|
* @invariant User-provided names never enter generated source until they are
|
|
6
8
|
* reduced to a strict-mode-safe identifier with a fixed length bound.
|
|
7
9
|
*/
|
|
8
10
|
/**
|
|
9
|
-
* @brief
|
|
11
|
+
* @brief Convert a user supplied compile name into a strict-mode function id.
|
|
12
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
13
|
+
* stable across runtime and AOT emission.
|
|
14
|
+
* @param value Requested public function name.
|
|
15
|
+
* @returns Identifier-safe, reserved-word-safe, bounded function name.
|
|
10
16
|
*/
|
|
11
17
|
export declare function safeFunctionName(value: string): string;
|
|
12
18
|
/**
|
|
13
|
-
* @brief string
|
|
19
|
+
* @brief Quote a string for generated JavaScript source.
|
|
20
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
21
|
+
* stable across runtime and AOT emission.
|
|
22
|
+
* @param value Runtime string to embed.
|
|
23
|
+
* @returns JSON-escaped string literal source.
|
|
14
24
|
*/
|
|
15
25
|
export declare function stringLiteral(value: string): string;
|
|
16
26
|
//# sourceMappingURL=names.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"names.d.ts","sourceRoot":"","sources":["../../src/compile/names.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"names.d.ts","sourceRoot":"","sources":["../../src/compile/names.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAgBtD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnD"}
|
package/dist/compile/names.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file compile-names.ts
|
|
3
3
|
* @brief Generated function-name and string literal helpers.
|
|
4
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
5
|
+
* stable across runtime and AOT emission.
|
|
4
6
|
*
|
|
5
7
|
* @invariant User-provided names never enter generated source until they are
|
|
6
8
|
* reduced to a strict-mode-safe identifier with a fixed length bound.
|
|
7
9
|
*/
|
|
8
10
|
const MAX_GENERATED_FUNCTION_NAME_LENGTH = 96;
|
|
9
11
|
/**
|
|
10
|
-
* @brief
|
|
12
|
+
* @brief Convert a user supplied compile name into a strict-mode function id.
|
|
13
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
14
|
+
* stable across runtime and AOT emission.
|
|
15
|
+
* @param value Requested public function name.
|
|
16
|
+
* @returns Identifier-safe, reserved-word-safe, bounded function name.
|
|
11
17
|
*/
|
|
12
18
|
export function safeFunctionName(value) {
|
|
13
19
|
const replaced = value.replace(/[^$_a-zA-Z0-9]/gu, "_");
|
|
@@ -17,19 +23,29 @@ export function safeFunctionName(value) {
|
|
|
17
23
|
if (/^[$_a-zA-Z]/u.test(bounded) && !reservedFunctionNames.has(bounded)) {
|
|
18
24
|
return bounded;
|
|
19
25
|
}
|
|
26
|
+
/*
|
|
27
|
+
* Prefixing recovers names that start with a digit or collide with reserved
|
|
28
|
+
* words while keeping the final identifier under the same length cap.
|
|
29
|
+
*/
|
|
20
30
|
const prefixed = `_${bounded}`;
|
|
21
31
|
return prefixed.length > MAX_GENERATED_FUNCTION_NAME_LENGTH
|
|
22
32
|
? prefixed.slice(0, MAX_GENERATED_FUNCTION_NAME_LENGTH)
|
|
23
33
|
: prefixed;
|
|
24
34
|
}
|
|
25
35
|
/**
|
|
26
|
-
* @brief string
|
|
36
|
+
* @brief Quote a string for generated JavaScript source.
|
|
37
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
38
|
+
* stable across runtime and AOT emission.
|
|
39
|
+
* @param value Runtime string to embed.
|
|
40
|
+
* @returns JSON-escaped string literal source.
|
|
27
41
|
*/
|
|
28
42
|
export function stringLiteral(value) {
|
|
29
43
|
return JSON.stringify(value);
|
|
30
44
|
}
|
|
31
45
|
/**
|
|
32
|
-
* @brief
|
|
46
|
+
* @brief Strict-mode names that cannot be emitted as generated function ids.
|
|
47
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
48
|
+
* stable across runtime and AOT emission.
|
|
33
49
|
*/
|
|
34
50
|
const reservedFunctionNames = new Set([
|
|
35
51
|
"arguments",
|
|
@@ -1,23 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file compile/predicate.ts
|
|
3
3
|
* @brief Boolean validator source emitter.
|
|
4
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
5
|
+
* stable across runtime and AOT emission.
|
|
4
6
|
*/
|
|
5
7
|
import { type Schema } from "../schema/index.js";
|
|
6
8
|
import type { EmitContext } from "./types.js";
|
|
7
9
|
/**
|
|
8
10
|
* @brief emit function.
|
|
11
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
12
|
+
* stable across runtime and AOT emission.
|
|
13
|
+
* @param schema Schema represented by the predicate.
|
|
14
|
+
* @param context Shared code-generation context.
|
|
15
|
+
* @returns Generated predicate function name.
|
|
16
|
+
* @invariant The same schema object maps to one predicate function per bundle.
|
|
9
17
|
*/
|
|
10
18
|
export declare function emitFunction(schema: Schema, context: EmitContext): string;
|
|
11
19
|
/**
|
|
12
20
|
* @brief emit functions.
|
|
21
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
22
|
+
* stable across runtime and AOT emission.
|
|
23
|
+
* @param context Shared code-generation context with accumulated predicate sources.
|
|
24
|
+
* @returns Concatenated JavaScript function declarations.
|
|
13
25
|
*/
|
|
14
26
|
export declare function emitFunctions(context: EmitContext): string;
|
|
15
27
|
/**
|
|
16
28
|
* @brief emit expression.
|
|
29
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
30
|
+
* stable across runtime and AOT emission.
|
|
31
|
+
* @param schema Schema represented by the expression.
|
|
32
|
+
* @param value Generated expression for the candidate value.
|
|
33
|
+
* @param context Shared code-generation context.
|
|
34
|
+
* @returns JavaScript expression that evaluates to a boolean.
|
|
17
35
|
*/
|
|
18
36
|
export declare function emitExpression(schema: Schema, value: string, context: EmitContext): string;
|
|
19
37
|
/**
|
|
20
38
|
* @brief emit union.
|
|
39
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
40
|
+
* stable across runtime and AOT emission.
|
|
41
|
+
* @param options Union option schemas.
|
|
42
|
+
* @param value Generated expression for the candidate value.
|
|
43
|
+
* @param context Shared code-generation context.
|
|
44
|
+
* @returns JavaScript expression for the union predicate.
|
|
21
45
|
*/
|
|
22
46
|
export declare function emitUnion(options: readonly Schema[], value: string, context: EmitContext): string;
|
|
23
47
|
//# sourceMappingURL=predicate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predicate.d.ts","sourceRoot":"","sources":["../../src/compile/predicate.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"predicate.d.ts","sourceRoot":"","sources":["../../src/compile/predicate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH,OAAO,EAYH,KAAK,MAAM,EACd,MAAM,oBAAoB,CAAC;AAO5B,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,YAAY,CAAC;AAE9D;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,MAAM,CAkBzE;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,CAU1D;AAoCD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC1B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,WAAW,GACrB,MAAM,CAiER;AAucD;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CACrB,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,WAAW,GACrB,MAAM,CAYR"}
|