typia 3.4.21 → 3.4.23
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/README.md +57 -23
- package/lib/programmers/AssertProgrammer.js +79 -70
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/IsProgrammer.d.ts +1 -0
- package/lib/programmers/IsProgrammer.js +4 -0
- package/lib/programmers/IsProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +68 -59
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/lib/programmers/helpers/OptionPredicator.d.ts +1 -0
- package/lib/programmers/helpers/OptionPredicator.js +4 -0
- package/lib/programmers/helpers/OptionPredicator.js.map +1 -1
- package/lib/programmers/internal/application_schema.js +23 -21
- package/lib/programmers/internal/application_schema.js.map +1 -1
- package/lib/programmers/internal/check_dynamic_properties.js +5 -0
- package/lib/programmers/internal/check_dynamic_properties.js.map +1 -1
- package/lib/programmers/internal/check_object.d.ts +1 -0
- package/lib/programmers/internal/check_object.js.map +1 -1
- package/lib/transformers/ITransformOptions.d.ts +10 -0
- package/package.json +2 -2
- package/src/IValidation.ts +21 -21
- package/src/Primitive.ts +82 -82
- package/src/TypeGuardError.ts +36 -36
- package/src/executable/internal/CommandParser.ts +15 -15
- package/src/factories/CommentFactory.ts +10 -10
- package/src/factories/ExpressionFactory.ts +66 -66
- package/src/factories/IdentifierFactory.ts +72 -72
- package/src/factories/LiteralFactory.ts +44 -44
- package/src/factories/StatementFactory.ts +60 -60
- package/src/factories/TemplateFactory.ts +56 -56
- package/src/factories/TypeFactory.ts +101 -101
- package/src/factories/ValueFactory.ts +12 -12
- package/src/functional/$every.ts +11 -11
- package/src/functional/$is_email.ts +5 -5
- package/src/functional/$is_ipv4.ts +5 -5
- package/src/functional/$is_ipv6.ts +5 -5
- package/src/functional/$is_url.ts +5 -5
- package/src/functional/$is_uuid.ts +5 -5
- package/src/functional/$join.ts +50 -50
- package/src/functional/$report.ts +15 -15
- package/src/functional/$rest.ts +3 -3
- package/src/functional/$string.ts +37 -37
- package/src/functional/$tail.ts +6 -6
- package/src/index.ts +4 -4
- package/src/metadata/IJsDocTagInfo.ts +10 -10
- package/src/metadata/IMetadata.ts +25 -25
- package/src/metadata/IMetadataApplication.ts +7 -7
- package/src/metadata/IMetadataConstant.ts +16 -16
- package/src/metadata/IMetadataEntry.ts +6 -6
- package/src/metadata/IMetadataObject.ts +29 -29
- package/src/metadata/IMetadataProperty.ts +11 -11
- package/src/metadata/MetadataConstant.ts +3 -3
- package/src/metadata/MetadataObject.ts +131 -131
- package/src/metadata/MetadataProperty.ts +64 -64
- package/src/programmers/ApplicationProgrammer.ts +55 -55
- package/src/programmers/AssertProgrammer.ts +36 -29
- package/src/programmers/IsProgrammer.ts +5 -0
- package/src/programmers/ValidateProgrammer.ts +36 -29
- package/src/programmers/helpers/AtomicPredicator.ts +15 -15
- package/src/programmers/helpers/FunctionImporeter.ts +31 -31
- package/src/programmers/helpers/IExpressionEntry.ts +10 -10
- package/src/programmers/helpers/OptionPredicator.ts +4 -0
- package/src/programmers/helpers/StringifyJoinder.ts +111 -111
- package/src/programmers/helpers/StringifyPredicator.ts +18 -18
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/internal/application_array.ts +47 -47
- package/src/programmers/internal/application_boolean.ts +17 -17
- package/src/programmers/internal/application_constant.ts +29 -29
- package/src/programmers/internal/application_default_string.ts +32 -32
- package/src/programmers/internal/application_native.ts +29 -29
- package/src/programmers/internal/application_number.ts +76 -76
- package/src/programmers/internal/application_schema.ts +9 -6
- package/src/programmers/internal/application_string.ts +49 -49
- package/src/programmers/internal/application_templates.ts +27 -27
- package/src/programmers/internal/application_tuple.ts +29 -29
- package/src/programmers/internal/check_dynamic_properties.ts +164 -146
- package/src/programmers/internal/check_everything.ts +25 -25
- package/src/programmers/internal/check_length.ts +46 -46
- package/src/programmers/internal/check_native.ts +9 -9
- package/src/programmers/internal/check_object.ts +43 -42
- package/src/programmers/internal/check_string.ts +24 -24
- package/src/programmers/internal/check_string_tags.ts +63 -63
- package/src/programmers/internal/check_template.ts +50 -50
- package/src/programmers/internal/decode_union_object.ts +73 -73
- package/src/programmers/internal/feature_object_entries.ts +49 -49
- package/src/programmers/internal/metadata_to_pattern.ts +31 -31
- package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
- package/src/programmers/internal/stringify_native.ts +8 -8
- package/src/programmers/internal/stringify_regular_properties.ts +81 -81
- package/src/programmers/internal/template_to_pattern.ts +15 -15
- package/src/schemas/IJsonApplication.ts +9 -9
- package/src/schemas/IJsonComponents.ts +26 -26
- package/src/transform.ts +20 -20
- package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
- package/src/transformers/FileTransformer.ts +49 -49
- package/src/transformers/IProject.ts +11 -11
- package/src/transformers/ITransformOptions.ts +11 -0
- package/src/transformers/NodeTransformer.ts +19 -19
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
- package/src/transformers/features/parsers/AssertParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateIsParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/IsParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/ValidateParseTransformer.ts +36 -36
- package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +31 -31
- package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +32 -32
- package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +38 -38
- package/src/transformers/features/validators/AssertTransformer.ts +43 -43
- package/src/transformers/features/validators/CreateAssertTransformer.ts +35 -35
- package/src/transformers/features/validators/CreateIsTransformer.ts +35 -35
- package/src/transformers/features/validators/CreateValidateTransformer.ts +35 -35
- package/src/transformers/features/validators/IsTransformer.ts +43 -43
- package/src/transformers/features/validators/ValidateTransformer.ts +43 -43
- package/src/typings/Atomic.ts +17 -17
- package/src/typings/ClassProperties.ts +5 -5
- package/src/typings/OmitNever.ts +3 -3
- package/src/typings/SpecialFields.ts +3 -3
- package/src/typings/Writable.ts +11 -11
- package/src/utils/ArrayUtil.ts +49 -49
- package/src/utils/Escaper.ts +50 -50
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/PatternUtil.ts +30 -30
- package/src/utils/Singleton.ts +17 -17
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace ExpressionFactory {
|
|
4
|
-
export function isRequired(input: ts.Expression): ts.Expression {
|
|
5
|
-
return ts.factory.createStrictInequality(
|
|
6
|
-
ts.factory.createIdentifier("undefined"),
|
|
7
|
-
input,
|
|
8
|
-
);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function isArray(input: ts.Expression): ts.Expression {
|
|
12
|
-
return ts.factory.createCallExpression(
|
|
13
|
-
ts.factory.createIdentifier("Array.isArray"),
|
|
14
|
-
undefined,
|
|
15
|
-
[input],
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function isObject(
|
|
20
|
-
input: ts.Expression,
|
|
21
|
-
options: {
|
|
22
|
-
checkNull: boolean;
|
|
23
|
-
checkArray: boolean;
|
|
24
|
-
},
|
|
25
|
-
): ts.Expression {
|
|
26
|
-
const conditions: ts.Expression[] = [
|
|
27
|
-
ts.factory.createStrictEquality(
|
|
28
|
-
ts.factory.createStringLiteral("object"),
|
|
29
|
-
ts.factory.createTypeOfExpression(input),
|
|
30
|
-
),
|
|
31
|
-
];
|
|
32
|
-
if (options.checkNull === true)
|
|
33
|
-
conditions.push(
|
|
34
|
-
ts.factory.createStrictInequality(
|
|
35
|
-
ts.factory.createNull(),
|
|
36
|
-
input,
|
|
37
|
-
),
|
|
38
|
-
);
|
|
39
|
-
if (options.checkArray === true)
|
|
40
|
-
conditions.push(
|
|
41
|
-
ts.factory.createStrictEquality(
|
|
42
|
-
ts.factory.createFalse(),
|
|
43
|
-
ts.factory.createCallExpression(
|
|
44
|
-
ts.factory.createIdentifier("Array.isArray"),
|
|
45
|
-
undefined,
|
|
46
|
-
[input],
|
|
47
|
-
),
|
|
48
|
-
),
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
return conditions.length === 1
|
|
52
|
-
? conditions[0]!
|
|
53
|
-
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function isInstanceOf(
|
|
57
|
-
input: ts.Expression,
|
|
58
|
-
type: string,
|
|
59
|
-
): ts.Expression {
|
|
60
|
-
return ts.factory.createBinaryExpression(
|
|
61
|
-
input,
|
|
62
|
-
ts.factory.createToken(ts.SyntaxKind.InstanceOfKeyword),
|
|
63
|
-
ts.factory.createIdentifier(type),
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace ExpressionFactory {
|
|
4
|
+
export function isRequired(input: ts.Expression): ts.Expression {
|
|
5
|
+
return ts.factory.createStrictInequality(
|
|
6
|
+
ts.factory.createIdentifier("undefined"),
|
|
7
|
+
input,
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isArray(input: ts.Expression): ts.Expression {
|
|
12
|
+
return ts.factory.createCallExpression(
|
|
13
|
+
ts.factory.createIdentifier("Array.isArray"),
|
|
14
|
+
undefined,
|
|
15
|
+
[input],
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function isObject(
|
|
20
|
+
input: ts.Expression,
|
|
21
|
+
options: {
|
|
22
|
+
checkNull: boolean;
|
|
23
|
+
checkArray: boolean;
|
|
24
|
+
},
|
|
25
|
+
): ts.Expression {
|
|
26
|
+
const conditions: ts.Expression[] = [
|
|
27
|
+
ts.factory.createStrictEquality(
|
|
28
|
+
ts.factory.createStringLiteral("object"),
|
|
29
|
+
ts.factory.createTypeOfExpression(input),
|
|
30
|
+
),
|
|
31
|
+
];
|
|
32
|
+
if (options.checkNull === true)
|
|
33
|
+
conditions.push(
|
|
34
|
+
ts.factory.createStrictInequality(
|
|
35
|
+
ts.factory.createNull(),
|
|
36
|
+
input,
|
|
37
|
+
),
|
|
38
|
+
);
|
|
39
|
+
if (options.checkArray === true)
|
|
40
|
+
conditions.push(
|
|
41
|
+
ts.factory.createStrictEquality(
|
|
42
|
+
ts.factory.createFalse(),
|
|
43
|
+
ts.factory.createCallExpression(
|
|
44
|
+
ts.factory.createIdentifier("Array.isArray"),
|
|
45
|
+
undefined,
|
|
46
|
+
[input],
|
|
47
|
+
),
|
|
48
|
+
),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return conditions.length === 1
|
|
52
|
+
? conditions[0]!
|
|
53
|
+
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function isInstanceOf(
|
|
57
|
+
input: ts.Expression,
|
|
58
|
+
type: string,
|
|
59
|
+
): ts.Expression {
|
|
60
|
+
return ts.factory.createBinaryExpression(
|
|
61
|
+
input,
|
|
62
|
+
ts.factory.createToken(ts.SyntaxKind.InstanceOfKeyword),
|
|
63
|
+
ts.factory.createIdentifier(type),
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Escaper } from "../utils/Escaper";
|
|
4
|
-
|
|
5
|
-
export namespace IdentifierFactory {
|
|
6
|
-
export function generate(name: string) {
|
|
7
|
-
return Escaper.variable(name)
|
|
8
|
-
? ts.factory.createIdentifier(name)
|
|
9
|
-
: ts.factory.createStringLiteral(name);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function join(prefix: ts.Expression, name: string) {
|
|
13
|
-
const postfix = generate(name);
|
|
14
|
-
return ts.isStringLiteral(postfix)
|
|
15
|
-
? ts.factory.createElementAccessExpression(prefix, postfix)
|
|
16
|
-
: ts.factory.createPropertyAccessExpression(prefix, postfix);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function postfix(str: string): string {
|
|
20
|
-
return Escaper.variable(str)
|
|
21
|
-
? `".${str}"`
|
|
22
|
-
: `"[${JSON.stringify(str).split('"').join('\\"')}]"`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function parameter(
|
|
26
|
-
name: string | ts.BindingName,
|
|
27
|
-
init?: ts.Expression,
|
|
28
|
-
) {
|
|
29
|
-
if (ts.version >= "4.8")
|
|
30
|
-
return ts.factory.createParameterDeclaration(
|
|
31
|
-
undefined,
|
|
32
|
-
undefined,
|
|
33
|
-
name,
|
|
34
|
-
undefined,
|
|
35
|
-
undefined,
|
|
36
|
-
init,
|
|
37
|
-
);
|
|
38
|
-
// eslint-disable-next-line
|
|
39
|
-
return ts.factory.createParameterDeclaration(
|
|
40
|
-
undefined,
|
|
41
|
-
undefined,
|
|
42
|
-
undefined,
|
|
43
|
-
name,
|
|
44
|
-
undefined,
|
|
45
|
-
undefined,
|
|
46
|
-
init,
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// export function property(
|
|
51
|
-
// name: string | ts.PropertyName,
|
|
52
|
-
// value: ts.Expression,
|
|
53
|
-
// ): ts.PropertyDeclaration {
|
|
54
|
-
// if (ts.version >= "4.8")
|
|
55
|
-
// return ts.factory.createPropertyDeclaration(
|
|
56
|
-
// undefined,
|
|
57
|
-
// name,
|
|
58
|
-
// undefined,
|
|
59
|
-
// undefined,
|
|
60
|
-
// value,
|
|
61
|
-
// );
|
|
62
|
-
// // eslint-disable-next-line
|
|
63
|
-
// return ts.factory.createPropertyDeclaration(
|
|
64
|
-
// undefined,
|
|
65
|
-
// undefined,
|
|
66
|
-
// name,
|
|
67
|
-
// undefined,
|
|
68
|
-
// undefined,
|
|
69
|
-
// value,
|
|
70
|
-
// );
|
|
71
|
-
// }
|
|
72
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Escaper } from "../utils/Escaper";
|
|
4
|
+
|
|
5
|
+
export namespace IdentifierFactory {
|
|
6
|
+
export function generate(name: string) {
|
|
7
|
+
return Escaper.variable(name)
|
|
8
|
+
? ts.factory.createIdentifier(name)
|
|
9
|
+
: ts.factory.createStringLiteral(name);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function join(prefix: ts.Expression, name: string) {
|
|
13
|
+
const postfix = generate(name);
|
|
14
|
+
return ts.isStringLiteral(postfix)
|
|
15
|
+
? ts.factory.createElementAccessExpression(prefix, postfix)
|
|
16
|
+
: ts.factory.createPropertyAccessExpression(prefix, postfix);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function postfix(str: string): string {
|
|
20
|
+
return Escaper.variable(str)
|
|
21
|
+
? `".${str}"`
|
|
22
|
+
: `"[${JSON.stringify(str).split('"').join('\\"')}]"`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function parameter(
|
|
26
|
+
name: string | ts.BindingName,
|
|
27
|
+
init?: ts.Expression,
|
|
28
|
+
) {
|
|
29
|
+
if (ts.version >= "4.8")
|
|
30
|
+
return ts.factory.createParameterDeclaration(
|
|
31
|
+
undefined,
|
|
32
|
+
undefined,
|
|
33
|
+
name,
|
|
34
|
+
undefined,
|
|
35
|
+
undefined,
|
|
36
|
+
init,
|
|
37
|
+
);
|
|
38
|
+
// eslint-disable-next-line
|
|
39
|
+
return ts.factory.createParameterDeclaration(
|
|
40
|
+
undefined,
|
|
41
|
+
undefined,
|
|
42
|
+
undefined,
|
|
43
|
+
name,
|
|
44
|
+
undefined,
|
|
45
|
+
undefined,
|
|
46
|
+
init,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// export function property(
|
|
51
|
+
// name: string | ts.PropertyName,
|
|
52
|
+
// value: ts.Expression,
|
|
53
|
+
// ): ts.PropertyDeclaration {
|
|
54
|
+
// if (ts.version >= "4.8")
|
|
55
|
+
// return ts.factory.createPropertyDeclaration(
|
|
56
|
+
// undefined,
|
|
57
|
+
// name,
|
|
58
|
+
// undefined,
|
|
59
|
+
// undefined,
|
|
60
|
+
// value,
|
|
61
|
+
// );
|
|
62
|
+
// // eslint-disable-next-line
|
|
63
|
+
// return ts.factory.createPropertyDeclaration(
|
|
64
|
+
// undefined,
|
|
65
|
+
// undefined,
|
|
66
|
+
// name,
|
|
67
|
+
// undefined,
|
|
68
|
+
// undefined,
|
|
69
|
+
// value,
|
|
70
|
+
// );
|
|
71
|
+
// }
|
|
72
|
+
}
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "./IdentifierFactory";
|
|
4
|
-
|
|
5
|
-
export namespace LiteralFactory {
|
|
6
|
-
export function generate(input: any): ts.Expression {
|
|
7
|
-
if (input === null) return ts.factory.createNull();
|
|
8
|
-
else if (ts.isIdentifier(input)) return input;
|
|
9
|
-
else if (input instanceof Array) return generate_array(input);
|
|
10
|
-
else if (typeof input === "object") return generate_object(input);
|
|
11
|
-
else if (typeof input === "string") return generate_string(input);
|
|
12
|
-
else if (typeof input === "boolean") return generate_value(input);
|
|
13
|
-
else if (typeof input === "number") return generate_value(input);
|
|
14
|
-
else if (typeof input === "bigint") return generate_value(input);
|
|
15
|
-
else throw new Error("Unknown type.");
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function generate_object(obj: object): ts.ObjectLiteralExpression {
|
|
19
|
-
const properties = Object.entries(obj)
|
|
20
|
-
.filter((tuple) => tuple[1] !== undefined)
|
|
21
|
-
.map(([key, value]) =>
|
|
22
|
-
ts.factory.createPropertyAssignment(
|
|
23
|
-
IdentifierFactory.generate(key),
|
|
24
|
-
generate(value),
|
|
25
|
-
),
|
|
26
|
-
);
|
|
27
|
-
return ts.factory.createObjectLiteralExpression(properties, true);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function generate_array(array: any[]): ts.ArrayLiteralExpression {
|
|
31
|
-
return ts.factory.createArrayLiteralExpression(
|
|
32
|
-
array.map(generate),
|
|
33
|
-
true,
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function generate_value(value: number | boolean | bigint): ts.Identifier {
|
|
38
|
-
return ts.factory.createIdentifier(value.toString());
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function generate_string(value: string): ts.StringLiteral {
|
|
42
|
-
return ts.factory.createStringLiteral(value);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "./IdentifierFactory";
|
|
4
|
+
|
|
5
|
+
export namespace LiteralFactory {
|
|
6
|
+
export function generate(input: any): ts.Expression {
|
|
7
|
+
if (input === null) return ts.factory.createNull();
|
|
8
|
+
else if (ts.isIdentifier(input)) return input;
|
|
9
|
+
else if (input instanceof Array) return generate_array(input);
|
|
10
|
+
else if (typeof input === "object") return generate_object(input);
|
|
11
|
+
else if (typeof input === "string") return generate_string(input);
|
|
12
|
+
else if (typeof input === "boolean") return generate_value(input);
|
|
13
|
+
else if (typeof input === "number") return generate_value(input);
|
|
14
|
+
else if (typeof input === "bigint") return generate_value(input);
|
|
15
|
+
else throw new Error("Unknown type.");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function generate_object(obj: object): ts.ObjectLiteralExpression {
|
|
19
|
+
const properties = Object.entries(obj)
|
|
20
|
+
.filter((tuple) => tuple[1] !== undefined)
|
|
21
|
+
.map(([key, value]) =>
|
|
22
|
+
ts.factory.createPropertyAssignment(
|
|
23
|
+
IdentifierFactory.generate(key),
|
|
24
|
+
generate(value),
|
|
25
|
+
),
|
|
26
|
+
);
|
|
27
|
+
return ts.factory.createObjectLiteralExpression(properties, true);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function generate_array(array: any[]): ts.ArrayLiteralExpression {
|
|
31
|
+
return ts.factory.createArrayLiteralExpression(
|
|
32
|
+
array.map(generate),
|
|
33
|
+
true,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function generate_value(value: number | boolean | bigint): ts.Identifier {
|
|
38
|
+
return ts.factory.createIdentifier(value.toString());
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function generate_string(value: string): ts.StringLiteral {
|
|
42
|
+
return ts.factory.createStringLiteral(value);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace StatementFactory {
|
|
4
|
-
export function constant(name: string, initializer?: ts.Expression) {
|
|
5
|
-
return ts.factory.createVariableStatement(
|
|
6
|
-
undefined,
|
|
7
|
-
ts.factory.createVariableDeclarationList(
|
|
8
|
-
[
|
|
9
|
-
ts.factory.createVariableDeclaration(
|
|
10
|
-
name,
|
|
11
|
-
undefined,
|
|
12
|
-
undefined,
|
|
13
|
-
initializer,
|
|
14
|
-
),
|
|
15
|
-
],
|
|
16
|
-
ts.NodeFlags.Const,
|
|
17
|
-
),
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function transpile(script: string) {
|
|
22
|
-
return ts.factory.createExpressionStatement(
|
|
23
|
-
ts.factory.createIdentifier(ts.transpile(script)),
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// export function require(variable: string, location: string) {
|
|
28
|
-
// return ts.factory.createImportDeclaration(
|
|
29
|
-
// undefined,
|
|
30
|
-
// undefined,
|
|
31
|
-
// ts.factory.createImportClause(
|
|
32
|
-
// false,
|
|
33
|
-
// undefined,
|
|
34
|
-
// ts.factory.createNamespaceImport(
|
|
35
|
-
// ts.factory.createIdentifier(variable),
|
|
36
|
-
// ),
|
|
37
|
-
// ),
|
|
38
|
-
// ts.factory.createStringLiteral(location),
|
|
39
|
-
// );
|
|
40
|
-
// }
|
|
41
|
-
|
|
42
|
-
// export function importModulo(variable: string, location: string) {
|
|
43
|
-
// return ts.factory.createImportDeclaration(
|
|
44
|
-
// undefined,
|
|
45
|
-
// undefined,
|
|
46
|
-
// ts.factory.createImportClause(
|
|
47
|
-
// false,
|
|
48
|
-
// undefined,
|
|
49
|
-
// ts.factory.createNamedImports([
|
|
50
|
-
// ts.factory.createImportSpecifier(
|
|
51
|
-
// false,
|
|
52
|
-
// undefined,
|
|
53
|
-
// ts.factory.createIdentifier(variable),
|
|
54
|
-
// ),
|
|
55
|
-
// ]),
|
|
56
|
-
// ),
|
|
57
|
-
// ts.factory.createStringLiteral(location),
|
|
58
|
-
// );
|
|
59
|
-
// }
|
|
60
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace StatementFactory {
|
|
4
|
+
export function constant(name: string, initializer?: ts.Expression) {
|
|
5
|
+
return ts.factory.createVariableStatement(
|
|
6
|
+
undefined,
|
|
7
|
+
ts.factory.createVariableDeclarationList(
|
|
8
|
+
[
|
|
9
|
+
ts.factory.createVariableDeclaration(
|
|
10
|
+
name,
|
|
11
|
+
undefined,
|
|
12
|
+
undefined,
|
|
13
|
+
initializer,
|
|
14
|
+
),
|
|
15
|
+
],
|
|
16
|
+
ts.NodeFlags.Const,
|
|
17
|
+
),
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function transpile(script: string) {
|
|
22
|
+
return ts.factory.createExpressionStatement(
|
|
23
|
+
ts.factory.createIdentifier(ts.transpile(script)),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// export function require(variable: string, location: string) {
|
|
28
|
+
// return ts.factory.createImportDeclaration(
|
|
29
|
+
// undefined,
|
|
30
|
+
// undefined,
|
|
31
|
+
// ts.factory.createImportClause(
|
|
32
|
+
// false,
|
|
33
|
+
// undefined,
|
|
34
|
+
// ts.factory.createNamespaceImport(
|
|
35
|
+
// ts.factory.createIdentifier(variable),
|
|
36
|
+
// ),
|
|
37
|
+
// ),
|
|
38
|
+
// ts.factory.createStringLiteral(location),
|
|
39
|
+
// );
|
|
40
|
+
// }
|
|
41
|
+
|
|
42
|
+
// export function importModulo(variable: string, location: string) {
|
|
43
|
+
// return ts.factory.createImportDeclaration(
|
|
44
|
+
// undefined,
|
|
45
|
+
// undefined,
|
|
46
|
+
// ts.factory.createImportClause(
|
|
47
|
+
// false,
|
|
48
|
+
// undefined,
|
|
49
|
+
// ts.factory.createNamedImports([
|
|
50
|
+
// ts.factory.createImportSpecifier(
|
|
51
|
+
// false,
|
|
52
|
+
// undefined,
|
|
53
|
+
// ts.factory.createIdentifier(variable),
|
|
54
|
+
// ),
|
|
55
|
+
// ]),
|
|
56
|
+
// ),
|
|
57
|
+
// ts.factory.createStringLiteral(location),
|
|
58
|
+
// );
|
|
59
|
+
// }
|
|
60
|
+
}
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace TemplateFactory {
|
|
4
|
-
export function generate(expressions: ts.Expression[]): ts.Expression {
|
|
5
|
-
if (expressions.every((exp) => ts.isStringLiteral(exp)))
|
|
6
|
-
return ts.factory.createStringLiteral(
|
|
7
|
-
(expressions as ts.StringLiteral[])
|
|
8
|
-
.map((str) => str.text)
|
|
9
|
-
.join(""),
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
const it: IIerator = {
|
|
13
|
-
value: "",
|
|
14
|
-
index: 0,
|
|
15
|
-
};
|
|
16
|
-
gather(expressions, it);
|
|
17
|
-
|
|
18
|
-
const head: ts.TemplateHead = ts.factory.createTemplateHead(it.value);
|
|
19
|
-
const spans: ts.TemplateSpan[] = [];
|
|
20
|
-
|
|
21
|
-
while (true) {
|
|
22
|
-
const elem: ts.Expression = expressions[it.index++]!;
|
|
23
|
-
gather(expressions, it);
|
|
24
|
-
|
|
25
|
-
const broken: boolean = it.index === expressions.length;
|
|
26
|
-
spans.push(
|
|
27
|
-
ts.factory.createTemplateSpan(
|
|
28
|
-
elem,
|
|
29
|
-
broken
|
|
30
|
-
? ts.factory.createTemplateTail(it.value)
|
|
31
|
-
: ts.factory.createTemplateMiddle(it.value),
|
|
32
|
-
),
|
|
33
|
-
);
|
|
34
|
-
if (broken === true) break;
|
|
35
|
-
}
|
|
36
|
-
return ts.factory.createTemplateExpression(head, spans);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function gather(expressions: ts.Expression[], it: IIerator): void {
|
|
40
|
-
const found: number = expressions.findIndex(
|
|
41
|
-
(elem, index) => index >= it.index && !ts.isStringLiteral(elem),
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
const last: number = found !== -1 ? found : expressions.length;
|
|
45
|
-
it.value = expressions
|
|
46
|
-
.slice(it.index, last)
|
|
47
|
-
.map((elem) => (elem as ts.StringLiteral).text)
|
|
48
|
-
.reduce((x, y) => x + y, "");
|
|
49
|
-
it.index = last;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
interface IIerator {
|
|
53
|
-
value: string;
|
|
54
|
-
index: number;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace TemplateFactory {
|
|
4
|
+
export function generate(expressions: ts.Expression[]): ts.Expression {
|
|
5
|
+
if (expressions.every((exp) => ts.isStringLiteral(exp)))
|
|
6
|
+
return ts.factory.createStringLiteral(
|
|
7
|
+
(expressions as ts.StringLiteral[])
|
|
8
|
+
.map((str) => str.text)
|
|
9
|
+
.join(""),
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
const it: IIerator = {
|
|
13
|
+
value: "",
|
|
14
|
+
index: 0,
|
|
15
|
+
};
|
|
16
|
+
gather(expressions, it);
|
|
17
|
+
|
|
18
|
+
const head: ts.TemplateHead = ts.factory.createTemplateHead(it.value);
|
|
19
|
+
const spans: ts.TemplateSpan[] = [];
|
|
20
|
+
|
|
21
|
+
while (true) {
|
|
22
|
+
const elem: ts.Expression = expressions[it.index++]!;
|
|
23
|
+
gather(expressions, it);
|
|
24
|
+
|
|
25
|
+
const broken: boolean = it.index === expressions.length;
|
|
26
|
+
spans.push(
|
|
27
|
+
ts.factory.createTemplateSpan(
|
|
28
|
+
elem,
|
|
29
|
+
broken
|
|
30
|
+
? ts.factory.createTemplateTail(it.value)
|
|
31
|
+
: ts.factory.createTemplateMiddle(it.value),
|
|
32
|
+
),
|
|
33
|
+
);
|
|
34
|
+
if (broken === true) break;
|
|
35
|
+
}
|
|
36
|
+
return ts.factory.createTemplateExpression(head, spans);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function gather(expressions: ts.Expression[], it: IIerator): void {
|
|
40
|
+
const found: number = expressions.findIndex(
|
|
41
|
+
(elem, index) => index >= it.index && !ts.isStringLiteral(elem),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const last: number = found !== -1 ? found : expressions.length;
|
|
45
|
+
it.value = expressions
|
|
46
|
+
.slice(it.index, last)
|
|
47
|
+
.map((elem) => (elem as ts.StringLiteral).text)
|
|
48
|
+
.reduce((x, y) => x + y, "");
|
|
49
|
+
it.index = last;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface IIerator {
|
|
53
|
+
value: string;
|
|
54
|
+
index: number;
|
|
55
|
+
}
|
|
56
|
+
}
|