@litert/typeguard 1.0.0 → 1.2.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.
Files changed (74) hide show
  1. package/CHANGES.md +15 -0
  2. package/lib/BuiltInTypeCompiler.d.ts +4 -4
  3. package/lib/BuiltInTypeCompiler.d.ts.map +1 -1
  4. package/lib/BuiltInTypeCompiler.js +167 -166
  5. package/lib/BuiltInTypeCompiler.js.map +1 -1
  6. package/lib/BuiltInTypes.d.ts +1 -1
  7. package/lib/BuiltInTypes.js +37 -36
  8. package/lib/BuiltInTypes.js.map +1 -1
  9. package/lib/Common.d.ts +13 -9
  10. package/lib/Common.d.ts.map +1 -1
  11. package/lib/Common.js +1 -1
  12. package/lib/Compiler.d.ts +2 -2
  13. package/lib/Compiler.d.ts.map +1 -1
  14. package/lib/Compiler.js +77 -72
  15. package/lib/Compiler.js.map +1 -1
  16. package/lib/Context.d.ts +2 -2
  17. package/lib/Context.js +3 -2
  18. package/lib/Context.js.map +1 -1
  19. package/lib/FilterCompiler.d.ts +5 -5
  20. package/lib/FilterCompiler.d.ts.map +1 -1
  21. package/lib/FilterCompiler.js +25 -24
  22. package/lib/FilterCompiler.js.map +1 -1
  23. package/lib/InlineCompiler.d.ts +12 -5
  24. package/lib/InlineCompiler.d.ts.map +1 -1
  25. package/lib/InlineCompiler.js +14 -5
  26. package/lib/InlineCompiler.js.map +1 -1
  27. package/lib/Internal.d.ts +2 -1
  28. package/lib/Internal.d.ts.map +1 -1
  29. package/lib/Internal.js +12 -10
  30. package/lib/Internal.js.map +1 -1
  31. package/lib/Modifiers.d.ts +1 -1
  32. package/lib/Modifiers.js +2 -1
  33. package/lib/Modifiers.js.map +1 -1
  34. package/lib/index.d.ts +5 -5
  35. package/lib/index.js +19 -7
  36. package/lib/index.js.map +1 -1
  37. package/lib/langs/JavaScript.d.ts +2 -2
  38. package/lib/langs/JavaScript.d.ts.map +1 -1
  39. package/lib/langs/JavaScript.js +30 -23
  40. package/lib/langs/JavaScript.js.map +1 -1
  41. package/package.json +18 -13
  42. package/src/{samples → examples}/quick-start.ts +22 -12
  43. package/src/lib/BuiltInTypeCompiler.ts +171 -171
  44. package/src/lib/BuiltInTypes.ts +36 -36
  45. package/src/lib/Common.ts +15 -10
  46. package/src/lib/Compiler.ts +213 -208
  47. package/src/lib/Context.ts +3 -3
  48. package/src/lib/FilterCompiler.ts +84 -84
  49. package/src/lib/InlineCompiler.ts +35 -14
  50. package/src/lib/Internal.ts +12 -10
  51. package/src/lib/Modifiers.ts +2 -2
  52. package/src/lib/index.ts +5 -5
  53. package/src/lib/langs/JavaScript.ts +34 -24
  54. package/src/test/00-all.ts +11 -9
  55. package/src/test/01-elemental-types.ts +1111 -1110
  56. package/src/test/02-array-and-list.ts +75 -75
  57. package/src/test/03-tuple.ts +87 -87
  58. package/src/test/04-from-string.ts +849 -848
  59. package/src/test/05-string-asserts.ts +422 -422
  60. package/src/test/06-structure.ts +107 -107
  61. package/src/test/07-modifiers.ts +151 -42
  62. package/src/test/08-map-and-dict.ts +46 -46
  63. package/src/test/09-exceptions.ts +67 -0
  64. package/src/test/abstracts.ts +52 -43
  65. package/dist/typeguard.amd.d.ts +0 -588
  66. package/dist/typeguard.amd.d.ts.map +0 -1
  67. package/dist/typeguard.amd.js +0 -2063
  68. package/dist/typeguard.amd.js.map +0 -1
  69. package/dist/typeguard.system.d.ts +0 -588
  70. package/dist/typeguard.system.d.ts.map +0 -1
  71. package/dist/typeguard.system.js +0 -2179
  72. package/dist/typeguard.system.js.map +0 -1
  73. package/tsconfig-amd.json +0 -72
  74. package/tsconfig-systemjs.json +0 -72
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2019 Angus.Fenying <fenying@litert.org>
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.
@@ -14,13 +14,13 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import * as I from "./Internal";
18
- import * as C from "./Common";
19
- import * as M from "./Modifiers";
20
- import { Context } from "./Context";
21
- import * as B from "./BuiltInTypes";
22
- import { BuiltInTypeCompiler } from "./BuiltInTypeCompiler";
23
- import { FilterCompiler } from "./FilterCompiler";
17
+ import * as I from './Internal';
18
+ import * as C from './Common';
19
+ import * as M from './Modifiers';
20
+ import { Context } from './Context';
21
+ import * as B from './BuiltInTypes';
22
+ import { BuiltInTypeCompiler } from './BuiltInTypeCompiler';
23
+ import { FilterCompiler } from './FilterCompiler';
24
24
 
25
25
  class Compiler
26
26
  implements C.ICompiler {
@@ -28,9 +28,9 @@ implements C.ICompiler {
28
28
  private _defTypes: Record<string, C.ICompileResult>;
29
29
 
30
30
  public constructor(
31
- private _lang: C.ILanguageBuilder,
32
- private _builtInTypes: I.IBuiltInTypeCompiler,
33
- private _filters: I.IFilterCompiler
31
+ private readonly _lang: C.ILanguageBuilder,
32
+ private readonly _builtInTypes: I.IBuiltInTypeCompiler,
33
+ private readonly _filters: I.IFilterCompiler
34
34
  ) {
35
35
  this._defTypes = {};
36
36
  }
@@ -50,8 +50,8 @@ implements C.ICompiler {
50
50
  const referredTypes: Record<string, true> = {};
51
51
 
52
52
  const ctx: I.IContext = new Context(
53
- this._lang.varName("entry"),
54
- this._lang.varName("types"),
53
+ this._lang.varName('entry'),
54
+ this._lang.varName('types'),
55
55
  referredTypes
56
56
  );
57
57
 
@@ -68,10 +68,10 @@ implements C.ICompiler {
68
68
 
69
69
  const ret: C.ICompileResult = {
70
70
 
71
- source: "",
71
+ source: '',
72
72
  arguments: [{
73
- "name": ctx.vName,
74
- "type": "unknown"
73
+ 'name': ctx.vName,
74
+ 'type': 'unknown'
75
75
  }],
76
76
  typeSlotName: ctx.typeSlotName,
77
77
  referredTypes: []
@@ -91,82 +91,85 @@ implements C.ICompiler {
91
91
  private _compile(ctx: I.IContext, rules: any): string {
92
92
 
93
93
  switch (typeof rules) {
94
- case "string":
94
+ case 'string':
95
95
 
96
- return this._compileStringRule(ctx, rules);
96
+ return this._compileStringRule(ctx, rules);
97
97
 
98
- case "boolean":
98
+ case 'boolean':
99
99
 
100
- if (ctx.flags[I.EFlags.FROM_STRING]) {
101
-
102
- return this._lang.or([
103
- this._lang.eq(
104
- ctx.vName,
105
- this._lang.literal(rules)
106
- ),
107
- this._lang.eq(
108
- this._lang.str2Bool(ctx.vName),
109
- this._lang.literal(rules)
110
- )
111
- ]);
112
- }
113
-
114
- return this._lang.eq(
115
- ctx.vName,
116
- this._lang.literal(rules)
117
- );
118
-
119
- case "number":
120
-
121
- if (ctx.flags[I.EFlags.FROM_STRING]) {
122
-
123
- return this._lang.or([
124
- this._lang.eq(
125
- ctx.vName,
126
- this._lang.literal(rules)
127
- ),
128
- this._lang.eq(
129
- this._lang.str2Float(ctx.vName),
130
- this._lang.literal(rules)
131
- )
132
- ]);
133
- }
134
-
135
- return this._lang.eq(
136
- ctx.vName,
137
- this._lang.literal(rules)
138
- );
100
+ if (ctx.flags[I.EFlags.FROM_STRING]) {
139
101
 
140
- case "object":
102
+ return this._lang.or([
103
+ this._lang.eq(
104
+ ctx.vName,
105
+ this._lang.literal(rules)
106
+ ),
107
+ this._lang.eq(
108
+ this._lang.str2Bool(ctx.vName),
109
+ this._lang.literal(rules)
110
+ )
111
+ ]);
112
+ }
141
113
 
142
- if (Array.isArray(rules)) {
114
+ return this._lang.eq(
115
+ ctx.vName,
116
+ this._lang.literal(rules)
117
+ );
143
118
 
144
- return this._compileModifiedRule(ctx, rules);
145
- }
146
- else if (rules === null) {
119
+ case 'number':
147
120
 
148
121
  if (ctx.flags[I.EFlags.FROM_STRING]) {
149
122
 
150
123
  return this._lang.or([
151
- this._lang.isNull(ctx.vName, true),
152
124
  this._lang.eq(
153
125
  ctx.vName,
154
- this._lang.literal("null")
126
+ this._lang.literal(rules)
127
+ ),
128
+ this._lang.eq(
129
+ this._lang.str2Float(ctx.vName),
130
+ this._lang.literal(rules)
155
131
  )
156
132
  ]);
157
133
  }
158
134
 
159
- return this._lang.isNull(ctx.vName, true);
160
- }
135
+ return this._lang.eq(
136
+ ctx.vName,
137
+ this._lang.literal(rules)
138
+ );
139
+
140
+ case 'object':
141
+
142
+ if (Array.isArray(rules)) {
161
143
 
162
- return this._compileStructuredRule(ctx, rules);
144
+ return this._compileModifiedRule(ctx, rules);
145
+ }
146
+ else if (rules === null) {
147
+
148
+ if (ctx.flags[I.EFlags.FROM_STRING]) {
163
149
 
164
- case "undefined":
150
+ return this._lang.or([
151
+ this._lang.isNull(ctx.vName, true),
152
+ this._lang.eq(
153
+ ctx.vName,
154
+ this._lang.literal('null')
155
+ )
156
+ ]);
157
+ }
165
158
 
166
- return this._lang.isUndefined(ctx.vName, true);
159
+ return this._lang.isNull(ctx.vName, true);
160
+ }
161
+
162
+ return this._compileStructuredRule(ctx, rules);
163
+
164
+ case 'undefined':
165
+
166
+ return this._lang.isUndefined(ctx.vName, true);
167
+
168
+ default:
169
+ break;
167
170
  }
168
171
 
169
- throw new TypeError("Unknwn rules.");
172
+ throw new TypeError('Unknwn rules.');
170
173
  }
171
174
 
172
175
  private _compileStringRule(ctx: I.IContext, rule: string): string {
@@ -181,7 +184,7 @@ implements C.ICompiler {
181
184
  ]);
182
185
  }
183
186
 
184
- if (rule[0] === I.IMPLICIT_SYMBOL) {
187
+ if (rule.startsWith(I.IMPLICIT_SYMBOL)) {
185
188
 
186
189
  return this._lang.or([
187
190
  this._builtInTypes.compile(B.VOID, ctx, []),
@@ -189,21 +192,21 @@ implements C.ICompiler {
189
192
  ]);
190
193
  }
191
194
 
192
- if (rule[0] === I.NEGATIVE_SYMBOL) {
195
+ if (rule.startsWith(I.NEGATIVE_SYMBOL)) {
193
196
 
194
197
  return this._lang.not(this._compileStringRule(ctx, rule.slice(1)));
195
198
  }
196
199
 
197
- let regResult: RegExpMatchArray | null;
200
+ let regResult: RegExpMatchArray | null = /\[\s*(\d*|\d+\s*,\s*\d*)\s*\]$/.exec(rule);
198
201
 
199
202
  /**
200
203
  * For rules like `xxx[123]` or `xxx[1,5]`.
201
204
  */
202
- if (regResult = rule.match(/\[\s*(\d*|\d+\s*,\s*\d*)\s*\]$/)) {
205
+ if (regResult) {
203
206
 
204
207
  if (regResult[1]) {
205
208
 
206
- let range = regResult[1].split(",").map((x) => parseInt(x.trim()));
209
+ const range = regResult[1].split(',').map((x) => parseInt(x.trim()));
207
210
 
208
211
  if (range.length === 1) {
209
212
 
@@ -252,11 +255,13 @@ implements C.ICompiler {
252
255
  ]);
253
256
  }
254
257
 
255
- if (rule[0] === I.PREDEF_TYPE_SYMBOL) {
258
+ if (rule.startsWith(I.PREDEF_TYPE_SYMBOL)) {
256
259
 
257
260
  return this._usePredefinedType(ctx, rule.slice(1));
258
261
  }
259
262
 
263
+ regResult = /^(\w+)(\(\s*(-?\d+(\.\d+)?)?\s*,?\s*(-?\d+(\.\d+)?)?\s*\))?$/.exec(rule);
264
+
260
265
  /**
261
266
  * For built-in-type rules like:
262
267
  *
@@ -265,11 +270,11 @@ implements C.ICompiler {
265
270
  * - `string`
266
271
  * - `int(12, 34)`
267
272
  */
268
- if (regResult = rule.match(/^(\w+)(\(\s*(-?\d+(\.\d+)?)?\s*,?\s*(-?\d+(\.\d+)?)?\s*\))?$/)) {
273
+ if (regResult) {
269
274
 
270
275
  if (regResult[2]) {
271
276
 
272
- const args = regResult[2].slice(1, -1).trim().split(",").map(
277
+ const args = regResult[2].slice(1, -1).trim().split(',').map(
273
278
  (x) => parseFloat(x.trim())
274
279
  );
275
280
 
@@ -287,7 +292,7 @@ implements C.ICompiler {
287
292
  );
288
293
  }
289
294
 
290
- if (rule[0] === I.FILTER_PREFIX) {
295
+ if (rule.startsWith(I.FILTER_PREFIX)) {
291
296
 
292
297
  return this._filters.compile(rule, ctx);
293
298
  }
@@ -318,162 +323,162 @@ implements C.ICompiler {
318
323
  rule: string
319
324
  ): string | false {
320
325
 
321
- const assertRule = rule.match(/^:([-\w]+):/);
326
+ const assertRule = /^:([-\w]+):/.exec(rule);
322
327
 
323
328
  const offset = assertRule ? assertRule[1].length + 2 : 2;
324
329
 
325
- switch ((assertRule && assertRule[1]) || rule.substr(0, 2)) {
326
- case "==":
327
- case "equal":
330
+ switch ((assertRule?.[1]) ?? rule.substr(0, 2)) {
331
+ case '==':
332
+ case 'equal':
328
333
 
329
- return this._lang.eq(
330
- ctx.vName,
331
- this._lang.literal(rule.slice(offset))
332
- );
334
+ return this._lang.eq(
335
+ ctx.vName,
336
+ this._lang.literal(rule.slice(offset))
337
+ );
333
338
 
334
- case "%=":
335
- case "equal-i":
339
+ case '%=':
340
+ case 'equal-i':
336
341
 
337
- return this._lang.eq(
338
- this._lang.lowerCase(ctx.vName),
339
- this._lang.literal(rule.slice(offset).toLowerCase())
340
- );
342
+ return this._lang.eq(
343
+ this._lang.lowerCase(ctx.vName),
344
+ this._lang.literal(rule.slice(offset).toLowerCase())
345
+ );
341
346
 
342
- case "!=":
343
- case "not-equal":
347
+ case '!=':
348
+ case 'not-equal':
344
349
 
345
- return this._lang.ne(
346
- ctx.vName,
347
- this._lang.literal(rule.slice(offset))
348
- );
350
+ return this._lang.ne(
351
+ ctx.vName,
352
+ this._lang.literal(rule.slice(offset))
353
+ );
349
354
 
350
- case "%!":
351
- case "not-equal-i":
355
+ case '%!':
356
+ case 'not-equal-i':
352
357
 
353
- return this._lang.ne(
354
- this._lang.lowerCase(ctx.vName),
355
- this._lang.literal(rule.slice(offset).toLowerCase())
356
- );
358
+ return this._lang.ne(
359
+ this._lang.lowerCase(ctx.vName),
360
+ this._lang.literal(rule.slice(offset).toLowerCase())
361
+ );
357
362
 
358
- case "~=":
359
- case "match":
363
+ case '~=':
364
+ case 'match':
360
365
 
361
- return this._lang.matchRegExp(
362
- ctx.vName,
363
- rule.slice(offset)
364
- );
366
+ return this._lang.matchRegExp(
367
+ ctx.vName,
368
+ rule.slice(offset)
369
+ );
365
370
 
366
- case "~!":
367
- case "not-match":
371
+ case '~!':
372
+ case 'not-match':
368
373
 
369
- return this._lang.not(this._lang.matchRegExp(
370
- ctx.vName,
371
- rule.slice(offset)
372
- ));
374
+ return this._lang.not(this._lang.matchRegExp(
375
+ ctx.vName,
376
+ rule.slice(offset)
377
+ ));
373
378
 
374
- case "?=":
375
- case "include":
379
+ case '?=':
380
+ case 'include':
376
381
 
377
- return this._lang.instr(
378
- ctx.vName,
379
- this._lang.literal(rule.slice(offset))
380
- );
382
+ return this._lang.instr(
383
+ ctx.vName,
384
+ this._lang.literal(rule.slice(offset))
385
+ );
381
386
 
382
- case "?!":
383
- case "not-include":
387
+ case '?!':
388
+ case 'not-include':
384
389
 
385
- return this._lang.not(this._lang.instr(
386
- ctx.vName,
387
- this._lang.literal(rule.slice(offset))
388
- ));
390
+ return this._lang.not(this._lang.instr(
391
+ ctx.vName,
392
+ this._lang.literal(rule.slice(offset))
393
+ ));
389
394
 
390
- case "*=":
391
- case "include-i":
395
+ case '*=':
396
+ case 'include-i':
392
397
 
393
- return this._lang.instr(
394
- this._lang.lowerCase(ctx.vName),
395
- this._lang.literal(rule.slice(offset).toLowerCase())
396
- );
398
+ return this._lang.instr(
399
+ this._lang.lowerCase(ctx.vName),
400
+ this._lang.literal(rule.slice(offset).toLowerCase())
401
+ );
397
402
 
398
- case "*!":
399
- case "not-include-i":
403
+ case '*!':
404
+ case 'not-include-i':
400
405
 
401
- return this._lang.not(this._lang.instr(
402
- this._lang.lowerCase(ctx.vName),
403
- this._lang.literal(rule.slice(offset).toLowerCase())
404
- ));
406
+ return this._lang.not(this._lang.instr(
407
+ this._lang.lowerCase(ctx.vName),
408
+ this._lang.literal(rule.slice(offset).toLowerCase())
409
+ ));
405
410
 
406
- case "^=":
407
- case "start-with":
411
+ case '^=':
412
+ case 'start-with':
408
413
 
409
- return this._lang.startsWith(
410
- ctx.vName,
411
- this._lang.literal(rule.slice(offset))
412
- );
414
+ return this._lang.startsWith(
415
+ ctx.vName,
416
+ this._lang.literal(rule.slice(offset))
417
+ );
413
418
 
414
- case "start-with-i":
419
+ case 'start-with-i':
415
420
 
416
- return this._lang.startsWith(
417
- this._lang.lowerCase(ctx.vName),
418
- this._lang.literal(rule.slice(offset).toLowerCase())
419
- );
421
+ return this._lang.startsWith(
422
+ this._lang.lowerCase(ctx.vName),
423
+ this._lang.literal(rule.slice(offset).toLowerCase())
424
+ );
420
425
 
421
- case "^!":
422
- case "not-start-with":
426
+ case '^!':
427
+ case 'not-start-with':
423
428
 
424
- return this._lang.not(this._lang.startsWith(
425
- ctx.vName,
426
- this._lang.literal(rule.slice(offset))
427
- ));
429
+ return this._lang.not(this._lang.startsWith(
430
+ ctx.vName,
431
+ this._lang.literal(rule.slice(offset))
432
+ ));
428
433
 
429
- case "not-start-with-i":
434
+ case 'not-start-with-i':
430
435
 
431
- return this._lang.not(this._lang.startsWith(
432
- this._lang.lowerCase(ctx.vName),
433
- this._lang.literal(rule.slice(offset).toLowerCase())
434
- ));
436
+ return this._lang.not(this._lang.startsWith(
437
+ this._lang.lowerCase(ctx.vName),
438
+ this._lang.literal(rule.slice(offset).toLowerCase())
439
+ ));
435
440
 
436
- case "$=":
437
- case "end-with":
441
+ case '$=':
442
+ case 'end-with':
438
443
 
439
- return this._lang.endsWith(
440
- ctx.vName,
441
- this._lang.literal(rule.slice(offset))
442
- );
444
+ return this._lang.endsWith(
445
+ ctx.vName,
446
+ this._lang.literal(rule.slice(offset))
447
+ );
443
448
 
444
- case "end-with-i":
449
+ case 'end-with-i':
445
450
 
446
- return this._lang.endsWith(
447
- this._lang.lowerCase(ctx.vName),
448
- this._lang.literal(rule.slice(offset).toLowerCase())
449
- );
451
+ return this._lang.endsWith(
452
+ this._lang.lowerCase(ctx.vName),
453
+ this._lang.literal(rule.slice(offset).toLowerCase())
454
+ );
450
455
 
451
- case "$!":
452
- case "not-end-with":
456
+ case '$!':
457
+ case 'not-end-with':
453
458
 
454
- return this._lang.not(this._lang.endsWith(
455
- ctx.vName,
456
- this._lang.literal(rule.slice(offset))
457
- ));
459
+ return this._lang.not(this._lang.endsWith(
460
+ ctx.vName,
461
+ this._lang.literal(rule.slice(offset))
462
+ ));
458
463
 
459
- case "not-end-with-i":
464
+ case 'not-end-with-i':
460
465
 
461
- return this._lang.not(this._lang.endsWith(
462
- this._lang.lowerCase(ctx.vName),
463
- this._lang.literal(rule.slice(offset).toLowerCase())
464
- ));
466
+ return this._lang.not(this._lang.endsWith(
467
+ this._lang.lowerCase(ctx.vName),
468
+ this._lang.literal(rule.slice(offset).toLowerCase())
469
+ ));
465
470
 
466
- default:
471
+ default:
467
472
 
468
- if (rule.startsWith("=")) {
473
+ if (rule.startsWith('=')) {
469
474
 
470
- return this._lang.eq(ctx.vName, this._lang.literal(rule.slice(1)));
471
- }
475
+ return this._lang.eq(ctx.vName, this._lang.literal(rule.slice(1)));
476
+ }
472
477
 
473
- if (rule.startsWith("~")) {
478
+ if (rule.startsWith('~')) {
474
479
 
475
- return this._lang.matchRegExp(ctx.vName, rule.slice(1));
476
- }
480
+ return this._lang.matchRegExp(ctx.vName, rule.slice(1));
481
+ }
477
482
  }
478
483
 
479
484
  return false;
@@ -483,14 +488,14 @@ implements C.ICompiler {
483
488
 
484
489
  if (!rules.length) {
485
490
 
486
- throw new TypeError(`Unknwon type "[]".`);
491
+ throw new TypeError('Unknwon type "[]".');
487
492
  }
488
493
 
489
494
  /**
490
495
  * By default, use OR modifier.
491
496
  */
492
497
  if (
493
- typeof rules[0] !== "string" ||
498
+ typeof rules[0] !== 'string' ||
494
499
  !rules[0].startsWith(I.MODIFIER_PREFIX)
495
500
  ) {
496
501
 
@@ -574,7 +579,7 @@ implements C.ICompiler {
574
579
 
575
580
  private _compileModifierOR(ctx: I.IContext, rules: any[]): string {
576
581
 
577
- let result: string[] = [];
582
+ const result: string[] = [];
578
583
 
579
584
  for (const r of rules) {
580
585
 
@@ -791,18 +796,18 @@ implements C.ICompiler {
791
796
  break;
792
797
  }
793
798
 
794
- if (typeof type === "string" && type.startsWith("...")) {
799
+ if (typeof type === 'string' && type.startsWith('...')) {
795
800
 
796
801
  throw new TypeError(`Invalid syntax for tuple: ${JSON.stringify(rules)}`);
797
802
  }
798
803
 
799
- if (typeof types[0] === "string" && types[0].startsWith("...")) {
804
+ if (typeof types[0] === 'string' && types[0].startsWith('...')) {
800
805
 
801
806
  ctx.trap();
802
807
 
803
808
  dots = types.shift();
804
809
 
805
- if (dots === "...") {
810
+ if (dots === '...') {
806
811
 
807
812
  /**
808
813
  * No more elements because "..." means all rest elements.
@@ -814,7 +819,7 @@ implements C.ICompiler {
814
819
 
815
820
  ctx.vName = this._lang.arraySlice(ctx.vName, i);
816
821
 
817
- if (type !== "any") {
822
+ if (type !== 'any') {
818
823
 
819
824
  result.push(this._compileModifierLIST(
820
825
  ctx, type
@@ -880,7 +885,7 @@ implements C.ICompiler {
880
885
 
881
886
  private _validateTypeName(name: unknown): void {
882
887
 
883
- if (typeof name !== "string" || !/^\w+$/.test(name)) {
888
+ if (typeof name !== 'string' || !I.RE_VALID_CUSTOM_TYPE_NAME.test(name)) {
884
889
 
885
890
  throw new TypeError(`Invalid name ${
886
891
  JSON.stringify(name)
@@ -986,7 +991,7 @@ implements C.ICompiler {
986
991
  throw new SyntaxError(`Invalid dict ${JSON.stringify(rules)}.`);
987
992
  }
988
993
 
989
- let tmp: Record<string, string> = {};
994
+ const tmp: Record<string, string> = {};
990
995
 
991
996
  const id = `${Date.now()}${Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)}`;
992
997
 
@@ -997,9 +1002,9 @@ implements C.ICompiler {
997
1002
 
998
1003
  const type = `${I.PREDEF_TYPE_SYMBOL}${this._lang.varName(id)}`;
999
1004
 
1000
- for (let key of rules[0]) {
1005
+ for (const key of rules[0]) {
1001
1006
 
1002
- if (typeof key !== "string") {
1007
+ if (typeof key !== 'string') {
1003
1008
 
1004
1009
  throw new SyntaxError(`Invalid key ${JSON.stringify(key)} for dict.`);
1005
1010
  }
@@ -1059,7 +1064,7 @@ implements C.ICompiler {
1059
1064
  }
1060
1065
  else {
1061
1066
 
1062
- const matchResult = k.match(I.KEY_ARRAY_SUFFIX);
1067
+ const matchResult = I.KEY_ARRAY_SUFFIX.exec(k);
1063
1068
 
1064
1069
  if (matchResult) {
1065
1070
 
@@ -1132,7 +1137,7 @@ implements C.ICompiler {
1132
1137
 
1133
1138
  if (mapSymbol.length > 1) {
1134
1139
 
1135
- throw new SyntaxError("Only one '$.map' is allowed as rest-mapping.");
1140
+ throw new SyntaxError('Only one \'$.map\' is allowed as rest-mapping.');
1136
1141
  }
1137
1142
  else if (mapSymbol.length === 0) {
1138
1143
 
@@ -1193,7 +1198,7 @@ implements C.ICompiler {
1193
1198
  }
1194
1199
  else {
1195
1200
 
1196
- const matchResult = k.match(I.KEY_ARRAY_SUFFIX);
1201
+ const matchResult = I.KEY_ARRAY_SUFFIX.exec(k);
1197
1202
 
1198
1203
  if (matchResult) {
1199
1204
 
@@ -1291,7 +1296,7 @@ implements C.ICompiler {
1291
1296
 
1292
1297
  return Array.isArray(rule) && (
1293
1298
  rule[0] === M.OR ||
1294
- typeof rule[0] !== "string" ||
1299
+ typeof rule[0] !== 'string' ||
1295
1300
  !rule[0].startsWith(I.MODIFIER_PREFIX)
1296
1301
  );
1297
1302
  }