typia 3.7.2 → 3.7.3
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/lib/programmers/AssertProgrammer.js +4 -2
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +3 -2
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/package.json +4 -2
- package/src/IRandomGenerator.ts +33 -33
- package/src/factories/IdentifierFactory.ts +81 -81
- package/src/factories/MetadataTagFactory.ts +302 -302
- package/src/metadata/ICommentTag.ts +4 -4
- package/src/programmers/AssertProgrammer.ts +38 -10
- package/src/programmers/LiteralsProgrammer.ts +65 -65
- package/src/programmers/RandomProgrammer.ts +413 -413
- package/src/programmers/ValidateProgrammer.ts +36 -9
- package/src/programmers/helpers/RandomJoiner.ts +161 -161
- package/src/programmers/helpers/RandomRanger.ts +216 -216
- package/src/programmers/internal/application_native.ts +32 -32
- package/src/programmers/internal/check_array.ts +30 -30
- package/src/programmers/internal/check_array_length.ts +35 -35
- package/src/programmers/internal/check_custom.ts +33 -33
- package/src/programmers/internal/check_number.ts +177 -177
- package/src/programmers/internal/check_object.ts +55 -55
- package/src/programmers/internal/check_union_array_like.ts +272 -272
- package/src/programmers/internal/feature_object_entries.ts +63 -63
- package/src/programmers/internal/get_comment_tags.ts +23 -23
- package/src/programmers/internal/metadata_to_pattern.ts +34 -34
- package/src/programmers/internal/random_custom.ts +30 -30
- package/src/programmers/internal/stringify_dynamic_properties.ts +168 -168
- package/src/programmers/internal/stringify_regular_properties.ts +84 -84
- package/src/transformers/CallExpressionTransformer.ts +174 -174
- package/src/transformers/features/miscellaneous/CreateRandomTransformer.ts +41 -41
- package/src/transformers/features/miscellaneous/LiteralsTransformer.ts +30 -30
- package/src/typings/Customizable.ts +5 -5
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { MetadataTagFactory } from "../../factories/MetadataTagFactory";
|
|
2
|
-
|
|
3
|
-
import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @internal
|
|
7
|
-
*/
|
|
8
|
-
export const get_comment_tags =
|
|
9
|
-
(excludeMetaTags: boolean) => (jsDocTags: IJsDocTagInfo[]) =>
|
|
10
|
-
jsDocTags
|
|
11
|
-
.filter(
|
|
12
|
-
(tag) =>
|
|
13
|
-
tag.name !== "random" &&
|
|
14
|
-
(!tag.text?.length ||
|
|
15
|
-
(tag.text?.length === 1 &&
|
|
16
|
-
tag.text?.[0]?.kind === "text")) &&
|
|
17
|
-
(!excludeMetaTags ||
|
|
18
|
-
MetadataTagFactory._PARSER[tag.name] === undefined),
|
|
19
|
-
)
|
|
20
|
-
.map((tag) => ({
|
|
21
|
-
name: tag.name,
|
|
22
|
-
value: tag.text?.[0]?.text,
|
|
23
|
-
}));
|
|
1
|
+
import { MetadataTagFactory } from "../../factories/MetadataTagFactory";
|
|
2
|
+
|
|
3
|
+
import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export const get_comment_tags =
|
|
9
|
+
(excludeMetaTags: boolean) => (jsDocTags: IJsDocTagInfo[]) =>
|
|
10
|
+
jsDocTags
|
|
11
|
+
.filter(
|
|
12
|
+
(tag) =>
|
|
13
|
+
tag.name !== "random" &&
|
|
14
|
+
(!tag.text?.length ||
|
|
15
|
+
(tag.text?.length === 1 &&
|
|
16
|
+
tag.text?.[0]?.kind === "text")) &&
|
|
17
|
+
(!excludeMetaTags ||
|
|
18
|
+
MetadataTagFactory._PARSER[tag.name] === undefined),
|
|
19
|
+
)
|
|
20
|
+
.map((tag) => ({
|
|
21
|
+
name: tag.name,
|
|
22
|
+
value: tag.text?.[0]?.text,
|
|
23
|
+
}));
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
-
|
|
3
|
-
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
4
|
-
import { PatternUtil } from "../../utils/PatternUtil";
|
|
5
|
-
|
|
6
|
-
import { template_to_pattern } from "./template_to_pattern";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
export const metadata_to_pattern =
|
|
12
|
-
(top: boolean) =>
|
|
13
|
-
(meta: Metadata): string => {
|
|
14
|
-
if (meta.atomics.find((type) => type === "string") !== undefined)
|
|
15
|
-
return "(.*)";
|
|
16
|
-
|
|
17
|
-
const values: string[] = ArrayUtil.flat(
|
|
18
|
-
meta.constants.map((c) => {
|
|
19
|
-
if (c.type !== "string")
|
|
20
|
-
return c.values.map((v) => v.toString());
|
|
21
|
-
return c.values.map((str) => PatternUtil.escape(str));
|
|
22
|
-
}),
|
|
23
|
-
);
|
|
24
|
-
for (const type of meta.atomics)
|
|
25
|
-
if (type === "number" || type === "bigint")
|
|
26
|
-
values.push(PatternUtil.NUMBER);
|
|
27
|
-
else if (type === "boolean") values.push(PatternUtil.BOOLEAN);
|
|
28
|
-
for (const childTpl of meta.templates)
|
|
29
|
-
values.push("(" + template_to_pattern(false)(childTpl) + ")");
|
|
30
|
-
|
|
31
|
-
const pattern: string =
|
|
32
|
-
values.length === 1 ? values[0]! : "(" + values.join("|") + ")";
|
|
33
|
-
return top ? PatternUtil.fix(pattern) : pattern;
|
|
34
|
-
};
|
|
1
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
+
|
|
3
|
+
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
4
|
+
import { PatternUtil } from "../../utils/PatternUtil";
|
|
5
|
+
|
|
6
|
+
import { template_to_pattern } from "./template_to_pattern";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export const metadata_to_pattern =
|
|
12
|
+
(top: boolean) =>
|
|
13
|
+
(meta: Metadata): string => {
|
|
14
|
+
if (meta.atomics.find((type) => type === "string") !== undefined)
|
|
15
|
+
return "(.*)";
|
|
16
|
+
|
|
17
|
+
const values: string[] = ArrayUtil.flat(
|
|
18
|
+
meta.constants.map((c) => {
|
|
19
|
+
if (c.type !== "string")
|
|
20
|
+
return c.values.map((v) => v.toString());
|
|
21
|
+
return c.values.map((str) => PatternUtil.escape(str));
|
|
22
|
+
}),
|
|
23
|
+
);
|
|
24
|
+
for (const type of meta.atomics)
|
|
25
|
+
if (type === "number" || type === "bigint")
|
|
26
|
+
values.push(PatternUtil.NUMBER);
|
|
27
|
+
else if (type === "boolean") values.push(PatternUtil.BOOLEAN);
|
|
28
|
+
for (const childTpl of meta.templates)
|
|
29
|
+
values.push("(" + template_to_pattern(false)(childTpl) + ")");
|
|
30
|
+
|
|
31
|
+
const pattern: string =
|
|
32
|
+
values.length === 1 ? values[0]! : "(" + values.join("|") + ")";
|
|
33
|
+
return top ? PatternUtil.fix(pattern) : pattern;
|
|
34
|
+
};
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
-
import { LiteralFactory } from "../../factories/LiteralFactory";
|
|
5
|
-
|
|
6
|
-
import { ICommentTag } from "../../metadata/ICommentTag";
|
|
7
|
-
|
|
8
|
-
import { Customizable } from "../../typings/Customizable";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
export const random_custom =
|
|
14
|
-
(accessor: (name: string) => ts.Expression) =>
|
|
15
|
-
(type: keyof Customizable) =>
|
|
16
|
-
(comments: ICommentTag[]) =>
|
|
17
|
-
(expression: ts.Expression) =>
|
|
18
|
-
ExpressionFactory.coalesce(
|
|
19
|
-
ts.factory.createCallChain(
|
|
20
|
-
ts.factory.createPropertyAccessChain(
|
|
21
|
-
accessor("customs"),
|
|
22
|
-
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
|
|
23
|
-
ts.factory.createIdentifier(type),
|
|
24
|
-
),
|
|
25
|
-
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
|
|
26
|
-
undefined,
|
|
27
|
-
[LiteralFactory.generate(comments)],
|
|
28
|
-
),
|
|
29
|
-
expression,
|
|
30
|
-
);
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
+
import { LiteralFactory } from "../../factories/LiteralFactory";
|
|
5
|
+
|
|
6
|
+
import { ICommentTag } from "../../metadata/ICommentTag";
|
|
7
|
+
|
|
8
|
+
import { Customizable } from "../../typings/Customizable";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export const random_custom =
|
|
14
|
+
(accessor: (name: string) => ts.Expression) =>
|
|
15
|
+
(type: keyof Customizable) =>
|
|
16
|
+
(comments: ICommentTag[]) =>
|
|
17
|
+
(expression: ts.Expression) =>
|
|
18
|
+
ExpressionFactory.coalesce(
|
|
19
|
+
ts.factory.createCallChain(
|
|
20
|
+
ts.factory.createPropertyAccessChain(
|
|
21
|
+
accessor("customs"),
|
|
22
|
+
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
|
|
23
|
+
ts.factory.createIdentifier(type),
|
|
24
|
+
),
|
|
25
|
+
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
|
|
26
|
+
undefined,
|
|
27
|
+
[LiteralFactory.generate(comments)],
|
|
28
|
+
),
|
|
29
|
+
expression,
|
|
30
|
+
);
|
|
@@ -1,168 +1,168 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
-
import { TemplateFactory } from "../../factories/TemplateFactory";
|
|
5
|
-
|
|
6
|
-
import { IExpressionEntry } from "../helpers/IExpressionEntry";
|
|
7
|
-
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
export function stringify_dynamic_properties(
|
|
13
|
-
dynamic: IExpressionEntry<ts.Expression>[],
|
|
14
|
-
regular: string[],
|
|
15
|
-
): ts.Expression {
|
|
16
|
-
// BASIC STATMEMENT, CHECK UNDEFINED
|
|
17
|
-
const statements: ts.Statement[] = [
|
|
18
|
-
ts.factory.createIfStatement(
|
|
19
|
-
ts.factory.createStrictEquality(
|
|
20
|
-
ts.factory.createIdentifier("undefined"),
|
|
21
|
-
ts.factory.createIdentifier("value"),
|
|
22
|
-
),
|
|
23
|
-
ts.factory.createReturnStatement(
|
|
24
|
-
ts.factory.createStringLiteral(""),
|
|
25
|
-
),
|
|
26
|
-
),
|
|
27
|
-
];
|
|
28
|
-
|
|
29
|
-
// PREPARE RETURN FUNCTION
|
|
30
|
-
const output = () => {
|
|
31
|
-
const mapped = ts.factory.createCallExpression(
|
|
32
|
-
IdentifierFactory.join(
|
|
33
|
-
ts.factory.createCallExpression(
|
|
34
|
-
ts.factory.createIdentifier("Object.entries"),
|
|
35
|
-
undefined,
|
|
36
|
-
[ts.factory.createIdentifier("input")],
|
|
37
|
-
),
|
|
38
|
-
"map",
|
|
39
|
-
),
|
|
40
|
-
undefined,
|
|
41
|
-
[
|
|
42
|
-
ts.factory.createArrowFunction(
|
|
43
|
-
undefined,
|
|
44
|
-
undefined,
|
|
45
|
-
[
|
|
46
|
-
IdentifierFactory.parameter(
|
|
47
|
-
ts.factory.createArrayBindingPattern([
|
|
48
|
-
ts.factory.createBindingElement(
|
|
49
|
-
undefined,
|
|
50
|
-
undefined,
|
|
51
|
-
"key",
|
|
52
|
-
),
|
|
53
|
-
ts.factory.createBindingElement(
|
|
54
|
-
undefined,
|
|
55
|
-
undefined,
|
|
56
|
-
"value",
|
|
57
|
-
),
|
|
58
|
-
]),
|
|
59
|
-
ts.factory.createTypeReferenceNode("[string, any]"),
|
|
60
|
-
),
|
|
61
|
-
],
|
|
62
|
-
undefined,
|
|
63
|
-
undefined,
|
|
64
|
-
ts.factory.createBlock(statements),
|
|
65
|
-
),
|
|
66
|
-
],
|
|
67
|
-
);
|
|
68
|
-
const filtered = ts.factory.createCallExpression(
|
|
69
|
-
IdentifierFactory.join(mapped, "filter"),
|
|
70
|
-
undefined,
|
|
71
|
-
[
|
|
72
|
-
ts.factory.createArrowFunction(
|
|
73
|
-
undefined,
|
|
74
|
-
undefined,
|
|
75
|
-
[IdentifierFactory.parameter("str")],
|
|
76
|
-
undefined,
|
|
77
|
-
undefined,
|
|
78
|
-
ts.factory.createStrictInequality(
|
|
79
|
-
ts.factory.createStringLiteral(""),
|
|
80
|
-
ts.factory.createIdentifier("str"),
|
|
81
|
-
),
|
|
82
|
-
),
|
|
83
|
-
],
|
|
84
|
-
);
|
|
85
|
-
return ts.factory.createCallExpression(
|
|
86
|
-
IdentifierFactory.join(filtered, "join"),
|
|
87
|
-
undefined,
|
|
88
|
-
[ts.factory.createStringLiteral(",")],
|
|
89
|
-
);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
// WHEN REGULAR PROPERTY EXISTS
|
|
93
|
-
if (regular.length)
|
|
94
|
-
statements.push(
|
|
95
|
-
ts.factory.createIfStatement(
|
|
96
|
-
ts.factory.createCallExpression(
|
|
97
|
-
IdentifierFactory.join(
|
|
98
|
-
ts.factory.createArrayLiteralExpression(
|
|
99
|
-
regular.map((key) =>
|
|
100
|
-
ts.factory.createStringLiteral(key),
|
|
101
|
-
),
|
|
102
|
-
),
|
|
103
|
-
"some",
|
|
104
|
-
),
|
|
105
|
-
undefined,
|
|
106
|
-
[
|
|
107
|
-
ts.factory.createArrowFunction(
|
|
108
|
-
undefined,
|
|
109
|
-
undefined,
|
|
110
|
-
[IdentifierFactory.parameter("regular")],
|
|
111
|
-
undefined,
|
|
112
|
-
undefined,
|
|
113
|
-
ts.factory.createStrictEquality(
|
|
114
|
-
ts.factory.createIdentifier("regular"),
|
|
115
|
-
ts.factory.createIdentifier("key"),
|
|
116
|
-
),
|
|
117
|
-
),
|
|
118
|
-
],
|
|
119
|
-
),
|
|
120
|
-
ts.factory.createReturnStatement(
|
|
121
|
-
ts.factory.createStringLiteral(""),
|
|
122
|
-
),
|
|
123
|
-
),
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
// ONLY STRING TYPED KEY EXISTS
|
|
127
|
-
const simple: boolean =
|
|
128
|
-
dynamic.length === 1 &&
|
|
129
|
-
dynamic[0]!.key.size() === 1 &&
|
|
130
|
-
dynamic[0]!.key.atomics[0] === "string";
|
|
131
|
-
if (simple === true) {
|
|
132
|
-
statements.push(stringify(dynamic[0]!));
|
|
133
|
-
return output();
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// COMPOSITE TEMPLATE LITERAL TYPES
|
|
137
|
-
for (const entry of dynamic) {
|
|
138
|
-
const condition: ts.IfStatement = ts.factory.createIfStatement(
|
|
139
|
-
ts.factory.createCallExpression(
|
|
140
|
-
ts.factory.createIdentifier(
|
|
141
|
-
`RegExp(/${metadata_to_pattern(true)(entry.key)}/).test`,
|
|
142
|
-
),
|
|
143
|
-
undefined,
|
|
144
|
-
[ts.factory.createIdentifier("key")],
|
|
145
|
-
),
|
|
146
|
-
stringify(entry),
|
|
147
|
-
);
|
|
148
|
-
statements.push(condition);
|
|
149
|
-
}
|
|
150
|
-
return output();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* @internal
|
|
155
|
-
*/
|
|
156
|
-
function stringify(entry: IExpressionEntry<ts.Expression>): ts.ReturnStatement {
|
|
157
|
-
return ts.factory.createReturnStatement(
|
|
158
|
-
TemplateFactory.generate([
|
|
159
|
-
ts.factory.createCallExpression(
|
|
160
|
-
ts.factory.createIdentifier("JSON.stringify"),
|
|
161
|
-
[],
|
|
162
|
-
[ts.factory.createIdentifier("key")],
|
|
163
|
-
),
|
|
164
|
-
ts.factory.createStringLiteral(":"),
|
|
165
|
-
entry.expression,
|
|
166
|
-
]),
|
|
167
|
-
);
|
|
168
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
import { TemplateFactory } from "../../factories/TemplateFactory";
|
|
5
|
+
|
|
6
|
+
import { IExpressionEntry } from "../helpers/IExpressionEntry";
|
|
7
|
+
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export function stringify_dynamic_properties(
|
|
13
|
+
dynamic: IExpressionEntry<ts.Expression>[],
|
|
14
|
+
regular: string[],
|
|
15
|
+
): ts.Expression {
|
|
16
|
+
// BASIC STATMEMENT, CHECK UNDEFINED
|
|
17
|
+
const statements: ts.Statement[] = [
|
|
18
|
+
ts.factory.createIfStatement(
|
|
19
|
+
ts.factory.createStrictEquality(
|
|
20
|
+
ts.factory.createIdentifier("undefined"),
|
|
21
|
+
ts.factory.createIdentifier("value"),
|
|
22
|
+
),
|
|
23
|
+
ts.factory.createReturnStatement(
|
|
24
|
+
ts.factory.createStringLiteral(""),
|
|
25
|
+
),
|
|
26
|
+
),
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
// PREPARE RETURN FUNCTION
|
|
30
|
+
const output = () => {
|
|
31
|
+
const mapped = ts.factory.createCallExpression(
|
|
32
|
+
IdentifierFactory.join(
|
|
33
|
+
ts.factory.createCallExpression(
|
|
34
|
+
ts.factory.createIdentifier("Object.entries"),
|
|
35
|
+
undefined,
|
|
36
|
+
[ts.factory.createIdentifier("input")],
|
|
37
|
+
),
|
|
38
|
+
"map",
|
|
39
|
+
),
|
|
40
|
+
undefined,
|
|
41
|
+
[
|
|
42
|
+
ts.factory.createArrowFunction(
|
|
43
|
+
undefined,
|
|
44
|
+
undefined,
|
|
45
|
+
[
|
|
46
|
+
IdentifierFactory.parameter(
|
|
47
|
+
ts.factory.createArrayBindingPattern([
|
|
48
|
+
ts.factory.createBindingElement(
|
|
49
|
+
undefined,
|
|
50
|
+
undefined,
|
|
51
|
+
"key",
|
|
52
|
+
),
|
|
53
|
+
ts.factory.createBindingElement(
|
|
54
|
+
undefined,
|
|
55
|
+
undefined,
|
|
56
|
+
"value",
|
|
57
|
+
),
|
|
58
|
+
]),
|
|
59
|
+
ts.factory.createTypeReferenceNode("[string, any]"),
|
|
60
|
+
),
|
|
61
|
+
],
|
|
62
|
+
undefined,
|
|
63
|
+
undefined,
|
|
64
|
+
ts.factory.createBlock(statements),
|
|
65
|
+
),
|
|
66
|
+
],
|
|
67
|
+
);
|
|
68
|
+
const filtered = ts.factory.createCallExpression(
|
|
69
|
+
IdentifierFactory.join(mapped, "filter"),
|
|
70
|
+
undefined,
|
|
71
|
+
[
|
|
72
|
+
ts.factory.createArrowFunction(
|
|
73
|
+
undefined,
|
|
74
|
+
undefined,
|
|
75
|
+
[IdentifierFactory.parameter("str")],
|
|
76
|
+
undefined,
|
|
77
|
+
undefined,
|
|
78
|
+
ts.factory.createStrictInequality(
|
|
79
|
+
ts.factory.createStringLiteral(""),
|
|
80
|
+
ts.factory.createIdentifier("str"),
|
|
81
|
+
),
|
|
82
|
+
),
|
|
83
|
+
],
|
|
84
|
+
);
|
|
85
|
+
return ts.factory.createCallExpression(
|
|
86
|
+
IdentifierFactory.join(filtered, "join"),
|
|
87
|
+
undefined,
|
|
88
|
+
[ts.factory.createStringLiteral(",")],
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// WHEN REGULAR PROPERTY EXISTS
|
|
93
|
+
if (regular.length)
|
|
94
|
+
statements.push(
|
|
95
|
+
ts.factory.createIfStatement(
|
|
96
|
+
ts.factory.createCallExpression(
|
|
97
|
+
IdentifierFactory.join(
|
|
98
|
+
ts.factory.createArrayLiteralExpression(
|
|
99
|
+
regular.map((key) =>
|
|
100
|
+
ts.factory.createStringLiteral(key),
|
|
101
|
+
),
|
|
102
|
+
),
|
|
103
|
+
"some",
|
|
104
|
+
),
|
|
105
|
+
undefined,
|
|
106
|
+
[
|
|
107
|
+
ts.factory.createArrowFunction(
|
|
108
|
+
undefined,
|
|
109
|
+
undefined,
|
|
110
|
+
[IdentifierFactory.parameter("regular")],
|
|
111
|
+
undefined,
|
|
112
|
+
undefined,
|
|
113
|
+
ts.factory.createStrictEquality(
|
|
114
|
+
ts.factory.createIdentifier("regular"),
|
|
115
|
+
ts.factory.createIdentifier("key"),
|
|
116
|
+
),
|
|
117
|
+
),
|
|
118
|
+
],
|
|
119
|
+
),
|
|
120
|
+
ts.factory.createReturnStatement(
|
|
121
|
+
ts.factory.createStringLiteral(""),
|
|
122
|
+
),
|
|
123
|
+
),
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
// ONLY STRING TYPED KEY EXISTS
|
|
127
|
+
const simple: boolean =
|
|
128
|
+
dynamic.length === 1 &&
|
|
129
|
+
dynamic[0]!.key.size() === 1 &&
|
|
130
|
+
dynamic[0]!.key.atomics[0] === "string";
|
|
131
|
+
if (simple === true) {
|
|
132
|
+
statements.push(stringify(dynamic[0]!));
|
|
133
|
+
return output();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// COMPOSITE TEMPLATE LITERAL TYPES
|
|
137
|
+
for (const entry of dynamic) {
|
|
138
|
+
const condition: ts.IfStatement = ts.factory.createIfStatement(
|
|
139
|
+
ts.factory.createCallExpression(
|
|
140
|
+
ts.factory.createIdentifier(
|
|
141
|
+
`RegExp(/${metadata_to_pattern(true)(entry.key)}/).test`,
|
|
142
|
+
),
|
|
143
|
+
undefined,
|
|
144
|
+
[ts.factory.createIdentifier("key")],
|
|
145
|
+
),
|
|
146
|
+
stringify(entry),
|
|
147
|
+
);
|
|
148
|
+
statements.push(condition);
|
|
149
|
+
}
|
|
150
|
+
return output();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @internal
|
|
155
|
+
*/
|
|
156
|
+
function stringify(entry: IExpressionEntry<ts.Expression>): ts.ReturnStatement {
|
|
157
|
+
return ts.factory.createReturnStatement(
|
|
158
|
+
TemplateFactory.generate([
|
|
159
|
+
ts.factory.createCallExpression(
|
|
160
|
+
ts.factory.createIdentifier("JSON.stringify"),
|
|
161
|
+
[],
|
|
162
|
+
[ts.factory.createIdentifier("key")],
|
|
163
|
+
),
|
|
164
|
+
ts.factory.createStringLiteral(":"),
|
|
165
|
+
entry.expression,
|
|
166
|
+
]),
|
|
167
|
+
);
|
|
168
|
+
}
|