@litert/typeguard 1.0.1 → 1.3.0-dev.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/CHANGES.md +16 -0
- package/lib/BuiltInTypeCompiler.d.ts +4 -4
- package/lib/BuiltInTypeCompiler.d.ts.map +1 -1
- package/lib/BuiltInTypeCompiler.js +167 -166
- package/lib/BuiltInTypeCompiler.js.map +1 -1
- package/lib/BuiltInTypes.d.ts +1 -1
- package/lib/BuiltInTypes.js +37 -36
- package/lib/BuiltInTypes.js.map +1 -1
- package/lib/Common.d.ts +27 -10
- package/lib/Common.d.ts.map +1 -1
- package/lib/Common.js +1 -1
- package/lib/Compiler.d.ts +2 -2
- package/lib/Compiler.d.ts.map +1 -1
- package/lib/Compiler.js +159 -102
- package/lib/Compiler.js.map +1 -1
- package/lib/Context.d.ts +6 -5
- package/lib/Context.d.ts.map +1 -1
- package/lib/Context.js +11 -7
- package/lib/Context.js.map +1 -1
- package/lib/FilterCompiler.d.ts +5 -5
- package/lib/FilterCompiler.d.ts.map +1 -1
- package/lib/FilterCompiler.js +25 -24
- package/lib/FilterCompiler.js.map +1 -1
- package/lib/InlineCompiler.d.ts +12 -5
- package/lib/InlineCompiler.d.ts.map +1 -1
- package/lib/InlineCompiler.js +18 -6
- package/lib/InlineCompiler.js.map +1 -1
- package/lib/Internal.d.ts +6 -4
- package/lib/Internal.d.ts.map +1 -1
- package/lib/Internal.js +12 -10
- package/lib/Internal.js.map +1 -1
- package/lib/Modifiers.d.ts +1 -1
- package/lib/Modifiers.js +2 -1
- package/lib/Modifiers.js.map +1 -1
- package/lib/index.d.ts +5 -5
- package/lib/index.js +19 -7
- package/lib/index.js.map +1 -1
- package/lib/langs/JavaScript.d.ts +2 -2
- package/lib/langs/JavaScript.d.ts.map +1 -1
- package/lib/langs/JavaScript.js +55 -29
- package/lib/langs/JavaScript.js.map +1 -1
- package/package.json +17 -13
- package/src/examples/quick-start.ts +172 -0
- package/src/lib/BuiltInTypeCompiler.ts +171 -171
- package/src/lib/BuiltInTypes.ts +36 -36
- package/src/lib/Common.ts +49 -10
- package/src/lib/Compiler.ts +354 -247
- package/src/lib/Context.ts +11 -13
- package/src/lib/FilterCompiler.ts +84 -84
- package/src/lib/InlineCompiler.ts +41 -15
- package/src/lib/Internal.ts +17 -13
- package/src/lib/Modifiers.ts +2 -2
- package/src/lib/index.ts +5 -5
- package/src/lib/langs/JavaScript.ts +84 -31
- package/src/test/00-all.ts +10 -10
- package/src/test/01-elemental-types.ts +1111 -1110
- package/src/test/02-array-and-list.ts +75 -75
- package/src/test/03-tuple.ts +87 -87
- package/src/test/04-from-string.ts +849 -848
- package/src/test/05-string-asserts.ts +422 -422
- package/src/test/06-structure.ts +107 -107
- package/src/test/07-modifiers.ts +151 -42
- package/src/test/08-map-and-dict.ts +46 -46
- package/src/test/09-exceptions.ts +30 -9
- package/src/test/abstracts.ts +83 -45
- package/dist/typeguard.amd.d.ts +0 -588
- package/dist/typeguard.amd.d.ts.map +0 -1
- package/dist/typeguard.amd.js +0 -2069
- package/dist/typeguard.amd.js.map +0 -1
- package/dist/typeguard.system.d.ts +0 -588
- package/dist/typeguard.system.d.ts.map +0 -1
- package/dist/typeguard.system.js +0 -2185
- package/dist/typeguard.system.js.map +0 -1
- package/src/samples/quick-start.ts +0 -52
- package/tsconfig-amd.json +0 -72
- package/tsconfig-systemjs.json +0 -72
package/CHANGES.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changes Logs
|
|
2
2
|
|
|
3
|
+
## v1.3.0
|
|
4
|
+
|
|
5
|
+
- fix(project): replaced substr with slice.
|
|
6
|
+
- feat(compiler): added experimental failure tracing info.
|
|
7
|
+
|
|
8
|
+
## v1.2.0
|
|
9
|
+
|
|
10
|
+
- Added API `IInlineCompiler.addPredefinedType`.
|
|
11
|
+
- Deprecated type `TypeChecker` with new type `ITypeChecker`.
|
|
12
|
+
|
|
13
|
+
## v1.1.0
|
|
14
|
+
|
|
15
|
+
- Allows characters `.:-` in predefined type names.
|
|
16
|
+
- Removed the distribution of AMD/SystemJS modules.
|
|
17
|
+
- Improved the output of `$.or` and `$.and`.
|
|
18
|
+
|
|
3
19
|
## v1.0.1
|
|
4
20
|
|
|
5
21
|
- Fixed lack of positive expression when `any` or `true` is used.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright
|
|
2
|
+
* Copyright 2022 Angus Fenying <fenying@litert.org>
|
|
3
3
|
*
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import * as C from
|
|
17
|
-
import * as I from
|
|
16
|
+
import * as C from './Common';
|
|
17
|
+
import * as I from './Internal';
|
|
18
18
|
export declare class BuiltInTypeCompiler implements I.IBuiltInTypeCompiler {
|
|
19
|
-
private _lang;
|
|
19
|
+
private readonly _lang;
|
|
20
20
|
constructor(_lang: C.ILanguageBuilder);
|
|
21
21
|
isStringType(type: string): boolean;
|
|
22
22
|
isConstructed(type: string): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuiltInTypeCompiler.d.ts","sourceRoot":"","sources":["../src/lib/BuiltInTypeCompiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,KAAK,CAAC,MAAM,YAAY,CAAC;AAmOhC,qBAAa,mBACb,YAAW,CAAC,CAAC,oBAAoB;IAGzB,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE,CAAC,CAAC,gBAAgB;
|
|
1
|
+
{"version":3,"file":"BuiltInTypeCompiler.d.ts","sourceRoot":"","sources":["../src/lib/BuiltInTypeCompiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,KAAK,CAAC,MAAM,YAAY,CAAC;AAmOhC,qBAAa,mBACb,YAAW,CAAC,CAAC,oBAAoB;IAGzB,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,CAAC,CAAC,gBAAgB;IAGvC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAKnC,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAKpC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAKlC,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAKpC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM;IAiQrE,OAAO,CAAC,UAAU;IAiFlB,OAAO,CAAC,QAAQ;IAgEhB,OAAO,CAAC,SAAS;IA+FjB,OAAO,CAAC,iBAAiB;IAezB,OAAO,CAAC,kBAAkB;IAoB1B,OAAO,CAAC,mBAAmB;IAe3B,OAAO,CAAC,UAAU;IAuGlB,OAAO,CAAC,SAAS;CAuHpB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Copyright
|
|
3
|
+
* Copyright 2022 Angus Fenying <fenying@litert.org>
|
|
4
4
|
*
|
|
5
5
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
* you may not use this file except in compliance with the License.
|
|
@@ -15,218 +15,219 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.BuiltInTypeCompiler = void 0;
|
|
18
19
|
const I = require("./Internal");
|
|
19
20
|
const B = require("./BuiltInTypes");
|
|
20
21
|
const BUILT_IN_TYPES = {
|
|
21
22
|
[B.STRING]: {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
'kind': 'string',
|
|
24
|
+
'string': true,
|
|
25
|
+
'constructed': false,
|
|
26
|
+
'elemental': true
|
|
26
27
|
},
|
|
27
28
|
[B.ASCII_STRING]: {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
'kind': 'string',
|
|
30
|
+
'string': true,
|
|
31
|
+
'constructed': false,
|
|
32
|
+
'elemental': true
|
|
32
33
|
},
|
|
33
34
|
[B.HEX_STRING]: {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
'kind': 'string',
|
|
36
|
+
'string': true,
|
|
37
|
+
'constructed': false,
|
|
38
|
+
'elemental': true
|
|
38
39
|
},
|
|
39
40
|
[B.LATIN_STRING]: {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
'kind': 'string',
|
|
42
|
+
'string': true,
|
|
43
|
+
'constructed': false,
|
|
44
|
+
'elemental': true
|
|
44
45
|
},
|
|
45
46
|
[B.NUMERIC]: {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
'kind': 'number',
|
|
48
|
+
'string': true,
|
|
49
|
+
'constructed': false,
|
|
50
|
+
'elemental': true
|
|
50
51
|
},
|
|
51
52
|
[B.SAFE_INT]: {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
'kind': 'number',
|
|
54
|
+
'string': false,
|
|
55
|
+
'constructed': false,
|
|
56
|
+
'elemental': true
|
|
56
57
|
},
|
|
57
58
|
[B.INT]: {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
'kind': 'number',
|
|
60
|
+
'string': false,
|
|
61
|
+
'constructed': false,
|
|
62
|
+
'elemental': true
|
|
62
63
|
},
|
|
63
64
|
[B.INT8]: {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
'kind': 'number',
|
|
66
|
+
'string': false,
|
|
67
|
+
'constructed': false,
|
|
68
|
+
'elemental': true
|
|
68
69
|
},
|
|
69
70
|
[B.INT16]: {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
'kind': 'number',
|
|
72
|
+
'string': false,
|
|
73
|
+
'constructed': false,
|
|
74
|
+
'elemental': true
|
|
74
75
|
},
|
|
75
76
|
[B.INT32]: {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
'kind': 'number',
|
|
78
|
+
'string': false,
|
|
79
|
+
'constructed': false,
|
|
80
|
+
'elemental': true
|
|
80
81
|
},
|
|
81
82
|
[B.INT64]: {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
'kind': 'number',
|
|
84
|
+
'string': false,
|
|
85
|
+
'constructed': false,
|
|
86
|
+
'elemental': true
|
|
86
87
|
},
|
|
87
88
|
[B.SAFE_UINT]: {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
'kind': 'number',
|
|
90
|
+
'string': false,
|
|
91
|
+
'constructed': false,
|
|
92
|
+
'elemental': true
|
|
92
93
|
},
|
|
93
94
|
[B.UINT]: {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
'kind': 'number',
|
|
96
|
+
'string': false,
|
|
97
|
+
'constructed': false,
|
|
98
|
+
'elemental': true
|
|
98
99
|
},
|
|
99
100
|
[B.UINT8]: {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
'kind': 'number',
|
|
102
|
+
'string': false,
|
|
103
|
+
'constructed': false,
|
|
104
|
+
'elemental': true
|
|
104
105
|
},
|
|
105
106
|
[B.UINT16]: {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
'kind': 'number',
|
|
108
|
+
'string': false,
|
|
109
|
+
'constructed': false,
|
|
110
|
+
'elemental': true
|
|
110
111
|
},
|
|
111
112
|
[B.UINT32]: {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
'kind': 'number',
|
|
114
|
+
'string': false,
|
|
115
|
+
'constructed': false,
|
|
116
|
+
'elemental': true
|
|
116
117
|
},
|
|
117
118
|
[B.UINT64]: {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
'kind': 'number',
|
|
120
|
+
'string': false,
|
|
121
|
+
'constructed': false,
|
|
122
|
+
'elemental': true
|
|
122
123
|
},
|
|
123
124
|
[B.BOOLEAN]: {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
'kind': 'boolean',
|
|
126
|
+
'string': false,
|
|
127
|
+
'constructed': false,
|
|
128
|
+
'elemental': true
|
|
128
129
|
},
|
|
129
130
|
[B.ARRAY]: {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
'kind': 'array',
|
|
132
|
+
'string': false,
|
|
133
|
+
'constructed': true,
|
|
134
|
+
'elemental': false
|
|
134
135
|
},
|
|
135
136
|
[B.ANY]: {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
'kind': 'unknown',
|
|
138
|
+
'string': false,
|
|
139
|
+
'constructed': false,
|
|
140
|
+
'elemental': false
|
|
140
141
|
},
|
|
141
142
|
[B.STRUCT]: {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
'kind': 'struct',
|
|
144
|
+
'string': false,
|
|
145
|
+
'constructed': true,
|
|
146
|
+
'elemental': false
|
|
146
147
|
},
|
|
147
148
|
[B.NULL]: {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
'kind': 'null',
|
|
150
|
+
'string': false,
|
|
151
|
+
'constructed': false,
|
|
152
|
+
'elemental': false
|
|
152
153
|
},
|
|
153
154
|
[B.UNDEFINED]: {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
155
|
+
'kind': 'void',
|
|
156
|
+
'string': false,
|
|
157
|
+
'constructed': false,
|
|
158
|
+
'elemental': false
|
|
158
159
|
},
|
|
159
160
|
[B.VOID]: {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
'kind': 'void',
|
|
162
|
+
'string': false,
|
|
163
|
+
'constructed': false,
|
|
164
|
+
'elemental': false
|
|
164
165
|
},
|
|
165
166
|
[B.FALSE]: {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
'kind': 'boolean',
|
|
168
|
+
'string': false,
|
|
169
|
+
'constructed': false,
|
|
170
|
+
'elemental': true
|
|
170
171
|
},
|
|
171
172
|
[B.TRUE]: {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
'kind': 'boolean',
|
|
174
|
+
'string': false,
|
|
175
|
+
'constructed': false,
|
|
176
|
+
'elemental': true
|
|
176
177
|
},
|
|
177
178
|
[B.FALSE_VALUE]: {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
179
|
+
'kind': 'unknown',
|
|
180
|
+
'string': false,
|
|
181
|
+
'constructed': false,
|
|
182
|
+
'elemental': false
|
|
182
183
|
},
|
|
183
184
|
[B.TRUE_VALUE]: {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
185
|
+
'kind': 'unknown',
|
|
186
|
+
'string': false,
|
|
187
|
+
'constructed': false,
|
|
188
|
+
'elemental': false
|
|
188
189
|
},
|
|
189
190
|
[B.OPTIONAL]: {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
191
|
+
'kind': 'void',
|
|
192
|
+
'string': false,
|
|
193
|
+
'constructed': false,
|
|
194
|
+
'elemental': false
|
|
194
195
|
},
|
|
195
196
|
[B.REQUIRED]: {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
197
|
+
'kind': 'unknown',
|
|
198
|
+
'string': false,
|
|
199
|
+
'constructed': false,
|
|
200
|
+
'elemental': false
|
|
200
201
|
},
|
|
201
202
|
[B.DECIMAL]: {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
203
|
+
'kind': 'number',
|
|
204
|
+
'string': true,
|
|
205
|
+
'constructed': false,
|
|
206
|
+
'elemental': true
|
|
206
207
|
},
|
|
207
208
|
[B.NUMBER]: {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
209
|
+
'kind': 'number',
|
|
210
|
+
'string': false,
|
|
211
|
+
'constructed': false,
|
|
212
|
+
'elemental': true
|
|
212
213
|
},
|
|
213
214
|
[B.FLOAT]: {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
215
|
+
'kind': 'number',
|
|
216
|
+
'string': false,
|
|
217
|
+
'constructed': false,
|
|
218
|
+
'elemental': true
|
|
218
219
|
},
|
|
219
220
|
[B.UDECIMAL]: {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
221
|
+
'kind': 'number',
|
|
222
|
+
'string': true,
|
|
223
|
+
'constructed': false,
|
|
224
|
+
'elemental': true
|
|
224
225
|
},
|
|
225
226
|
[B.UFLOAT]: {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
227
|
+
'kind': 'number',
|
|
228
|
+
'string': false,
|
|
229
|
+
'constructed': false,
|
|
230
|
+
'elemental': true
|
|
230
231
|
}
|
|
231
232
|
};
|
|
232
233
|
class BuiltInTypeCompiler {
|
|
@@ -247,15 +248,15 @@ class BuiltInTypeCompiler {
|
|
|
247
248
|
}
|
|
248
249
|
compile(type, ctx, args) {
|
|
249
250
|
const fromString = !!(ctx.flags[I.EFlags.FROM_STRING] &&
|
|
250
|
-
this.isBuiltInType(type) && (BUILT_IN_TYPES[type].kind ===
|
|
251
|
-
BUILT_IN_TYPES[type].kind ===
|
|
252
|
-
BUILT_IN_TYPES[type].kind ===
|
|
251
|
+
this.isBuiltInType(type) && (BUILT_IN_TYPES[type].kind === 'number' ||
|
|
252
|
+
BUILT_IN_TYPES[type].kind === 'boolean' ||
|
|
253
|
+
BUILT_IN_TYPES[type].kind === 'null'));
|
|
253
254
|
switch (type) {
|
|
254
255
|
case B.NULL: {
|
|
255
256
|
if (fromString) {
|
|
256
257
|
return this._lang.or([
|
|
257
258
|
this._lang.isNull(ctx.vName, true),
|
|
258
|
-
this._lang.eq(ctx.vName, this._lang.literal(
|
|
259
|
+
this._lang.eq(ctx.vName, this._lang.literal('null'))
|
|
259
260
|
]);
|
|
260
261
|
}
|
|
261
262
|
return this._lang.isNull(ctx.vName, true);
|
|
@@ -270,13 +271,13 @@ class BuiltInTypeCompiler {
|
|
|
270
271
|
return this._isString(ctx, args);
|
|
271
272
|
}
|
|
272
273
|
case B.ASCII_STRING: {
|
|
273
|
-
return this._isString(ctx, args,
|
|
274
|
+
return this._isString(ctx, args, '[\\u0000-\\u007F]');
|
|
274
275
|
}
|
|
275
276
|
case B.LATIN_STRING: {
|
|
276
|
-
return this._isString(ctx, args,
|
|
277
|
+
return this._isString(ctx, args, '[\\u0000-\\u024F\\u2C60-\\u2C7F]');
|
|
277
278
|
}
|
|
278
279
|
case B.HEX_STRING: {
|
|
279
|
-
return this._isString(ctx, args,
|
|
280
|
+
return this._isString(ctx, args, '[0-9A-Fa-f]');
|
|
280
281
|
}
|
|
281
282
|
case B.UFLOAT: {
|
|
282
283
|
return this._isNumber(ctx, [0, NaN], fromString);
|
|
@@ -356,7 +357,7 @@ class BuiltInTypeCompiler {
|
|
|
356
357
|
case B.OPTIONAL:
|
|
357
358
|
case B.UNDEFINED: {
|
|
358
359
|
if (ctx.flags[I.EFlags.REQUIRED]) {
|
|
359
|
-
throw new Error(
|
|
360
|
+
throw new Error('Conflicted: Can not use "optional" with "required" type.');
|
|
360
361
|
}
|
|
361
362
|
if (ctx.flags[I.EFlags.OPTIONAL]) {
|
|
362
363
|
return this._lang.literal(true);
|
|
@@ -366,7 +367,7 @@ class BuiltInTypeCompiler {
|
|
|
366
367
|
}
|
|
367
368
|
case B.REQUIRED: {
|
|
368
369
|
if (ctx.flags[I.EFlags.OPTIONAL]) {
|
|
369
|
-
throw new Error(
|
|
370
|
+
throw new Error('Conflicted: Can not use "required" with "optional" type.');
|
|
370
371
|
}
|
|
371
372
|
if (ctx.flags[I.EFlags.REQUIRED]) {
|
|
372
373
|
return this._lang.literal(true);
|
|
@@ -394,9 +395,9 @@ class BuiltInTypeCompiler {
|
|
|
394
395
|
}
|
|
395
396
|
_isDecimal(ctx, params, unsigned = false) {
|
|
396
397
|
if (params[0] <= 0) {
|
|
397
|
-
throw new RangeError(
|
|
398
|
+
throw new RangeError('Arg 0 can not be zero for decimal.');
|
|
398
399
|
}
|
|
399
|
-
const sign = unsigned ?
|
|
400
|
+
const sign = unsigned ? '' : '[-+]?';
|
|
400
401
|
switch (params.length) {
|
|
401
402
|
default:
|
|
402
403
|
case 0: {
|
|
@@ -409,12 +410,12 @@ class BuiltInTypeCompiler {
|
|
|
409
410
|
return this._lang.and([
|
|
410
411
|
this._lang.isString(ctx.vName, true),
|
|
411
412
|
this._lang.matchRegExp(ctx.vName, `^${sign}([1-9]\\d*|0)(\\.\\d+)?$`),
|
|
412
|
-
this._lang.ifElseOp(this._lang.instr(ctx.vName, this._lang.literal(
|
|
413
|
+
this._lang.ifElseOp(this._lang.instr(ctx.vName, this._lang.literal('.')), this._lang.lte(this._lang.stringLength(ctx.vName), params[0] + 1), this._lang.lte(this._lang.stringLength(ctx.vName), params[0]))
|
|
413
414
|
]);
|
|
414
415
|
}
|
|
415
416
|
case 2: {
|
|
416
417
|
if (params[0] < params[1]) {
|
|
417
|
-
throw new RangeError(
|
|
418
|
+
throw new RangeError('Arg 0 should not be larger than arg 1 for decimal.');
|
|
418
419
|
}
|
|
419
420
|
if (params[1] === 0) {
|
|
420
421
|
return this._lang.and([
|
|
@@ -457,7 +458,7 @@ class BuiltInTypeCompiler {
|
|
|
457
458
|
];
|
|
458
459
|
if (this._checkValidUInteger(params[1], `Invalid argument "${params[1]}" for array.`)) {
|
|
459
460
|
if (params[0] > params[1]) {
|
|
460
|
-
throw new RangeError(
|
|
461
|
+
throw new RangeError('Arg 0 should not be larger than arg 1 for array.');
|
|
461
462
|
}
|
|
462
463
|
result.push(this._lang.lte(this._lang.arrayLength(ctx.vName), params[1]));
|
|
463
464
|
}
|
|
@@ -475,7 +476,7 @@ class BuiltInTypeCompiler {
|
|
|
475
476
|
if (fromString) {
|
|
476
477
|
result.push(this._lang.and([
|
|
477
478
|
this._lang.isString(ctx.vName, true),
|
|
478
|
-
this._lang.matchRegExp(ctx.vName,
|
|
479
|
+
this._lang.matchRegExp(ctx.vName, '^[-+]?\\d+(\\.\\d+)?$')
|
|
479
480
|
]));
|
|
480
481
|
}
|
|
481
482
|
return this._lang.or(result);
|
|
@@ -491,12 +492,12 @@ class BuiltInTypeCompiler {
|
|
|
491
492
|
}
|
|
492
493
|
if (this._checkValidNumber(params[1], `Invalid argument "${params[1]}".`)) {
|
|
493
494
|
if (params[0] > params[1]) {
|
|
494
|
-
throw new RangeError(
|
|
495
|
+
throw new RangeError('Arg 0 should not be larger than arg 1 for number.');
|
|
495
496
|
}
|
|
496
497
|
result.push(this._lang.lte(vName, params[1]));
|
|
497
498
|
}
|
|
498
499
|
if (result.length === 1) {
|
|
499
|
-
throw new SyntaxError(
|
|
500
|
+
throw new SyntaxError('Invalid syntax of integer.');
|
|
500
501
|
}
|
|
501
502
|
if (fromString) {
|
|
502
503
|
ctx.untrap();
|
|
@@ -505,7 +506,7 @@ class BuiltInTypeCompiler {
|
|
|
505
506
|
result[0],
|
|
506
507
|
this._lang.and([
|
|
507
508
|
this._lang.isString(ctx.vName, true),
|
|
508
|
-
this._lang.matchRegExp(ctx.vName,
|
|
509
|
+
this._lang.matchRegExp(ctx.vName, '^[-+]?\\d+(\\.\\d+)?$')
|
|
509
510
|
])
|
|
510
511
|
]),
|
|
511
512
|
result.length === 3 ? this._lang.closure([vName], [this._lang.str2Float(ctx.vName)], this._lang.returnValue(this._lang.and(result.slice(1)))) : result[1].replace(vName, this._lang.str2Float(ctx.vName))
|
|
@@ -525,7 +526,7 @@ class BuiltInTypeCompiler {
|
|
|
525
526
|
throw new TypeError(msg);
|
|
526
527
|
}
|
|
527
528
|
_checkValidInteger(v, msg) {
|
|
528
|
-
if (typeof v ===
|
|
529
|
+
if (typeof v === 'string') {
|
|
529
530
|
v = parseFloat(v);
|
|
530
531
|
}
|
|
531
532
|
if (Number.isNaN(v)) {
|
|
@@ -555,7 +556,7 @@ class BuiltInTypeCompiler {
|
|
|
555
556
|
if (fromString) {
|
|
556
557
|
result.push(this._lang.and([
|
|
557
558
|
this._lang.isString(ctx.vName, true),
|
|
558
|
-
this._lang.matchRegExp(ctx.vName,
|
|
559
|
+
this._lang.matchRegExp(ctx.vName, '^[-+]?\\d+$')
|
|
559
560
|
]));
|
|
560
561
|
}
|
|
561
562
|
return this._lang.or(result);
|
|
@@ -571,12 +572,12 @@ class BuiltInTypeCompiler {
|
|
|
571
572
|
}
|
|
572
573
|
if (this._checkValidInteger(params[1], `Invalid argument "${params[1]}" for integer.`)) {
|
|
573
574
|
if (params[0] > params[1]) {
|
|
574
|
-
throw new RangeError(
|
|
575
|
+
throw new RangeError('Arg 0 should not be larger than arg 1 for number.');
|
|
575
576
|
}
|
|
576
577
|
result.push(this._lang.lte(vName, params[1]));
|
|
577
578
|
}
|
|
578
579
|
if (result.length === 1) {
|
|
579
|
-
throw new SyntaxError(
|
|
580
|
+
throw new SyntaxError('Invalid syntax of integer.');
|
|
580
581
|
}
|
|
581
582
|
if (fromString) {
|
|
582
583
|
ctx.untrap();
|
|
@@ -585,7 +586,7 @@ class BuiltInTypeCompiler {
|
|
|
585
586
|
result[0],
|
|
586
587
|
this._lang.and([
|
|
587
588
|
this._lang.isString(ctx.vName, true),
|
|
588
|
-
this._lang.matchRegExp(ctx.vName,
|
|
589
|
+
this._lang.matchRegExp(ctx.vName, '^[-+]?\\d+$')
|
|
589
590
|
])
|
|
590
591
|
]),
|
|
591
592
|
result.length === 3 ? this._lang.closure([vName], [this._lang.str2Int(ctx.vName)], this._lang.returnValue(this._lang.and(result.slice(1)))) : result[1].replace(vName, this._lang.str2Int(ctx.vName))
|
|
@@ -623,7 +624,7 @@ class BuiltInTypeCompiler {
|
|
|
623
624
|
if (elementRegExp) {
|
|
624
625
|
if (this._checkValidUInteger(params[1], `Invalid argument "${params[1]}" for string.`)) {
|
|
625
626
|
if (params[0] > params[1]) {
|
|
626
|
-
throw new RangeError(
|
|
627
|
+
throw new RangeError('Arg 0 should not be larger than arg 1 for string.');
|
|
627
628
|
}
|
|
628
629
|
result.push(this._lang.matchRegExp(ctx.vName, `^${elementRegExp}{${params[0]},${params[1]}}$`));
|
|
629
630
|
}
|
|
@@ -634,7 +635,7 @@ class BuiltInTypeCompiler {
|
|
|
634
635
|
else {
|
|
635
636
|
if (this._checkValidUInteger(params[1], `Invalid argument "${params[1]}" for string.`)) {
|
|
636
637
|
if (params[0] > params[1]) {
|
|
637
|
-
throw new RangeError(
|
|
638
|
+
throw new RangeError('Arg 0 should not be larger than arg 1 for string.');
|
|
638
639
|
}
|
|
639
640
|
result.push(this._lang.gte(this._lang.stringLength(ctx.vName), params[0]), this._lang.lte(this._lang.stringLength(ctx.vName), params[1]));
|
|
640
641
|
}
|