typia 13.0.0-dev.20260604.1 → 13.0.0-dev.20260605.1
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/native/core/context/EmitFactory.go +39 -0
- package/native/core/context/ImportProgrammer.go +25 -23
- package/native/core/factories/ExpressionFactory.go +84 -53
- package/native/core/factories/IdentifierFactory.go +23 -14
- package/native/core/factories/LiteralFactory.go +55 -48
- package/native/core/factories/NumericRangeFactory.go +55 -43
- package/native/core/factories/StatementFactory.go +41 -32
- package/native/core/factories/TemplateFactory.go +11 -8
- package/native/core/factories/TypeFactory.go +5 -2
- package/native/core/factories/ValueFactory.go +19 -12
- package/native/core/programmers/AssertProgrammer.go +109 -87
- package/native/core/programmers/IsProgrammer.go +48 -31
- package/native/core/programmers/RandomProgrammer.go +207 -170
- package/native/core/programmers/ValidateProgrammer.go +127 -104
- package/native/core/programmers/functional/FunctionalAssertFunctionProgrammer.go +35 -32
- package/native/core/programmers/functional/FunctionalAssertParametersProgrammer.go +21 -16
- package/native/core/programmers/functional/FunctionalAssertReturnProgrammer.go +18 -13
- package/native/core/programmers/functional/FunctionalIsFunctionProgrammer.go +19 -13
- package/native/core/programmers/functional/FunctionalIsParametersProgrammer.go +35 -27
- package/native/core/programmers/functional/FunctionalIsReturnProgrammer.go +25 -21
- package/native/core/programmers/functional/FunctionalValidateFunctionProgrammer.go +33 -26
- package/native/core/programmers/functional/FunctionalValidateParametersProgrammer.go +80 -76
- package/native/core/programmers/functional/FunctionalValidateReturnProgrammer.go +31 -26
- package/native/core/programmers/helpers/CloneJoiner.go +64 -54
- package/native/core/programmers/helpers/FunctionProgrammer.go +16 -6
- package/native/core/programmers/helpers/NotationJoiner.go +64 -54
- package/native/core/programmers/helpers/PruneJoiner.go +90 -74
- package/native/core/programmers/helpers/RandomJoiner.go +42 -32
- package/native/core/programmers/helpers/StringifyJoinder.go +125 -110
- package/native/core/programmers/helpers/UnionExplorer.go +163 -139
- package/native/core/programmers/http/HttpAssertFormDataProgrammer.go +14 -13
- package/native/core/programmers/http/HttpAssertHeadersProgrammer.go +1 -1
- package/native/core/programmers/http/HttpAssertQueryProgrammer.go +1 -1
- package/native/core/programmers/http/HttpFormDataProgrammer.go +52 -43
- package/native/core/programmers/http/HttpHeadersProgrammer.go +61 -49
- package/native/core/programmers/http/HttpIsFormDataProgrammer.go +24 -22
- package/native/core/programmers/http/HttpIsHeadersProgrammer.go +2 -2
- package/native/core/programmers/http/HttpIsQueryProgrammer.go +2 -2
- package/native/core/programmers/http/HttpParameterProgrammer.go +17 -16
- package/native/core/programmers/http/HttpQueryProgrammer.go +92 -81
- package/native/core/programmers/http/HttpValidateFormDataProgrammer.go +13 -12
- package/native/core/programmers/http/HttpValidateHeadersProgrammer.go +1 -1
- package/native/core/programmers/http/HttpValidateQueryProgrammer.go +1 -1
- package/native/core/programmers/internal/CheckerProgrammer.go +161 -108
- package/native/core/programmers/internal/FeatureProgrammer.go +72 -51
- package/native/core/programmers/iterate/check_bigint.go +5 -4
- package/native/core/programmers/iterate/check_dynamic_key.go +62 -49
- package/native/core/programmers/iterate/check_dynamic_properties.go +79 -70
- package/native/core/programmers/iterate/check_everything.go +11 -8
- package/native/core/programmers/iterate/check_native.go +10 -6
- package/native/core/programmers/iterate/check_number.go +14 -13
- package/native/core/programmers/iterate/check_object.go +7 -5
- package/native/core/programmers/iterate/check_string.go +5 -4
- package/native/core/programmers/iterate/check_template.go +18 -13
- package/native/core/programmers/iterate/check_union_array_like.go +98 -92
- package/native/core/programmers/iterate/decode_union_object.go +18 -11
- package/native/core/programmers/iterate/feature_object_entries.go +11 -8
- package/native/core/programmers/iterate/prune_object_properties.go +33 -29
- package/native/core/programmers/iterate/stringify_dynamic_properties.go +80 -73
- package/native/core/programmers/iterate/stringify_native.go +8 -3
- package/native/core/programmers/iterate/stringify_regular_properties.go +23 -19
- package/native/core/programmers/json/JsonApplicationProgrammer.go +1 -1
- package/native/core/programmers/json/JsonAssertParseProgrammer.go +16 -15
- package/native/core/programmers/json/JsonAssertStringifyProgrammer.go +16 -15
- package/native/core/programmers/json/JsonIsParseProgrammer.go +32 -30
- package/native/core/programmers/json/JsonIsStringifyProgrammer.go +20 -20
- package/native/core/programmers/json/JsonSchemaProgrammer.go +1 -1
- package/native/core/programmers/json/JsonSchemasProgrammer.go +1 -1
- package/native/core/programmers/json/JsonStringifyProgrammer.go +168 -125
- package/native/core/programmers/json/JsonValidateParseProgrammer.go +16 -15
- package/native/core/programmers/json/JsonValidateStringifyProgrammer.go +25 -24
- package/native/core/programmers/llm/LlmApplicationProgrammer.go +7 -6
- package/native/core/programmers/llm/LlmCoerceProgrammer.go +13 -12
- package/native/core/programmers/llm/LlmControllerProgrammer.go +8 -7
- package/native/core/programmers/llm/LlmParametersProgrammer.go +5 -4
- package/native/core/programmers/llm/LlmParseProgrammer.go +16 -14
- package/native/core/programmers/llm/LlmSchemaProgrammer.go +33 -27
- package/native/core/programmers/llm/LlmStructuredOutputProgrammer.go +28 -27
- package/native/core/programmers/misc/MiscAssertCloneProgrammer.go +15 -14
- package/native/core/programmers/misc/MiscAssertPruneProgrammer.go +24 -23
- package/native/core/programmers/misc/MiscCloneProgrammer.go +154 -118
- package/native/core/programmers/misc/MiscIsCloneProgrammer.go +21 -20
- package/native/core/programmers/misc/MiscIsPruneProgrammer.go +22 -21
- package/native/core/programmers/misc/MiscLiteralsProgrammer.go +5 -4
- package/native/core/programmers/misc/MiscPruneProgrammer.go +77 -53
- package/native/core/programmers/misc/MiscValidateCloneProgrammer.go +26 -25
- package/native/core/programmers/misc/MiscValidatePruneProgrammer.go +22 -21
- package/native/core/programmers/notations/NotationAssertGeneralProgrammer.go +15 -14
- package/native/core/programmers/notations/NotationGeneralProgrammer.go +141 -106
- package/native/core/programmers/notations/NotationIsGeneralProgrammer.go +21 -20
- package/native/core/programmers/notations/NotationValidateGeneralProgrammer.go +28 -27
- package/native/core/programmers/protobuf/ProtobufAssertDecodeProgrammer.go +14 -13
- package/native/core/programmers/protobuf/ProtobufAssertEncodeProgrammer.go +16 -15
- package/native/core/programmers/protobuf/ProtobufDecodeProgrammer.go +184 -159
- package/native/core/programmers/protobuf/ProtobufEncodeProgrammer.go +196 -170
- package/native/core/programmers/protobuf/ProtobufIsDecodeProgrammer.go +22 -21
- package/native/core/programmers/protobuf/ProtobufIsEncodeProgrammer.go +20 -20
- package/native/core/programmers/protobuf/ProtobufMessageProgrammer.go +7 -5
- package/native/core/programmers/protobuf/ProtobufValidateDecodeProgrammer.go +14 -13
- package/native/core/programmers/protobuf/ProtobufValidateEncodeProgrammer.go +28 -26
- package/native/go.work.sum +6 -0
- package/native/transform/FileTransformer.go +5 -11
- package/native/transform/ImportTransformer.go +9 -6
- package/native/transform/features/RandomTransformer.go +4 -2
- package/native/transform/features/llm/LlmCoerceTransformer.go +3 -1
- package/native/transform/features/llm/LlmParseTransformer.go +3 -1
- package/native/transform/features/llm/LlmSchemaTransformer.go +3 -2
- package/native/transform/features/reflect/ReflectMetadataTransformer.go +1 -1
- package/native/transform/features/reflect/ReflectNameTransformer.go +2 -1
- package/native/transform/features/reflect/ReflectSchemaTransformer.go +4 -3
- package/native/transform/features/reflect/ReflectSchemasTransformer.go +1 -1
- package/native/transform/internal/GenericTransformer.go +2 -1
- package/package.json +4 -4
- package/native/internal/printer/printer.go +0 -35
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
package context
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
shimast "github.com/microsoft/typescript-go/shim/ast"
|
|
5
|
+
shimprinter "github.com/microsoft/typescript-go/shim/printer"
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
// EmitFactory resolves the node factory a node-creating helper should use.
|
|
9
|
+
//
|
|
10
|
+
// When an emit EmitContext is present (emit stage / AST-integration mode) its
|
|
11
|
+
// Factory is returned so every created node carries original-node tracking and
|
|
12
|
+
// emit metadata (parent links, comments, source maps, const-enum constants,
|
|
13
|
+
// namespace alias) that the tsgo emit pipeline relies on. When ec is nil (legacy
|
|
14
|
+
// text emit, analysis-only or test paths) the caller's standalone fallback
|
|
15
|
+
// factory is returned unchanged.
|
|
16
|
+
//
|
|
17
|
+
// This is the single-resolver form of ImportProgrammer's `if p.emit_ != nil`
|
|
18
|
+
// branch: the embedded ast.NodeFactory inside printer.NodeFactory carries the
|
|
19
|
+
// emit hooks, so &ec.Factory.NodeFactory produces metadata-bearing nodes while
|
|
20
|
+
// printing identically to the fallback (token text/structure unchanged).
|
|
21
|
+
func EmitFactory(ec *shimprinter.EmitContext, fallback *shimast.NodeFactory) *shimast.NodeFactory {
|
|
22
|
+
if ec != nil {
|
|
23
|
+
return &ec.Factory.NodeFactory
|
|
24
|
+
}
|
|
25
|
+
return fallback
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// EmitFactoryOf is the variadic form for node-creating free helpers and shared
|
|
29
|
+
// static factories that receive the emit context through an optional `emit
|
|
30
|
+
// ...*EmitContext` parameter. Passing no context (or a nil one) selects the
|
|
31
|
+
// standalone fallback, which is the legacy / analysis-only / test path; passing
|
|
32
|
+
// a live context routes creation through ec.Factory. This lets call sites thread
|
|
33
|
+
// the real context in progressively while the build stays green at every step.
|
|
34
|
+
func EmitFactoryOf(fallback *shimast.NodeFactory, emit ...*shimprinter.EmitContext) *shimast.NodeFactory {
|
|
35
|
+
if len(emit) != 0 && emit[0] != nil {
|
|
36
|
+
return &emit[0].Factory.NodeFactory
|
|
37
|
+
}
|
|
38
|
+
return fallback
|
|
39
|
+
}
|
|
@@ -111,7 +111,7 @@ func (p *ImportProgrammer) Default(props ImportProgrammer_IDefault) *shimast.Nod
|
|
|
111
111
|
if p.emit_ != nil {
|
|
112
112
|
return p.member(asset, "default")
|
|
113
113
|
}
|
|
114
|
-
return importProgrammer_factory.NewIdentifier(asset.Default.Name)
|
|
114
|
+
return EmitFactory(p.emit_, importProgrammer_factory).NewIdentifier(asset.Default.Name)
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
func (p *ImportProgrammer) Instance(props ImportProgrammer_IInstance) *shimast.Node {
|
|
@@ -127,7 +127,7 @@ func (p *ImportProgrammer) Instance(props ImportProgrammer_IInstance) *shimast.N
|
|
|
127
127
|
if p.emit_ != nil {
|
|
128
128
|
return p.member(asset, props.Name)
|
|
129
129
|
}
|
|
130
|
-
return importProgrammer_factory.NewIdentifier(alias)
|
|
130
|
+
return EmitFactory(p.emit_, importProgrammer_factory).NewIdentifier(alias)
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
func (p *ImportProgrammer) Namespace(props ImportProgrammer_INamespace) *shimast.Node {
|
|
@@ -139,14 +139,15 @@ func (p *ImportProgrammer) Namespace(props ImportProgrammer_INamespace) *shimast
|
|
|
139
139
|
if p.emit_ != nil {
|
|
140
140
|
return p.emit_.Factory.NewGeneratedNameForNode(p.moduleSpecifier(asset))
|
|
141
141
|
}
|
|
142
|
-
return importProgrammer_factory.NewIdentifier(asset.namespace.Name)
|
|
142
|
+
return EmitFactory(p.emit_, importProgrammer_factory).NewIdentifier(asset.namespace.Name)
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
func (p *ImportProgrammer) Type(props ImportProgrammer_TypeProps) *shimast.Node {
|
|
146
|
+
f := EmitFactory(p.emit_, importProgrammer_factory)
|
|
146
147
|
var qualifier *shimast.EntityName
|
|
147
148
|
switch name := props.Name.(type) {
|
|
148
149
|
case string:
|
|
149
|
-
qualifier =
|
|
150
|
+
qualifier = f.NewIdentifier(name)
|
|
150
151
|
case *shimast.Node:
|
|
151
152
|
qualifier = name
|
|
152
153
|
}
|
|
@@ -154,14 +155,14 @@ func (p *ImportProgrammer) Type(props ImportProgrammer_TypeProps) *shimast.Node
|
|
|
154
155
|
for _, arg := range props.Arguments {
|
|
155
156
|
args = append(args, arg)
|
|
156
157
|
}
|
|
157
|
-
return
|
|
158
|
+
return f.NewImportTypeNode(
|
|
158
159
|
false,
|
|
159
|
-
|
|
160
|
-
|
|
160
|
+
f.NewLiteralTypeNode(
|
|
161
|
+
f.NewStringLiteral(props.File, shimast.TokenFlagsNone),
|
|
161
162
|
),
|
|
162
163
|
nil,
|
|
163
164
|
qualifier,
|
|
164
|
-
|
|
165
|
+
f.NewNodeList(args),
|
|
165
166
|
)
|
|
166
167
|
}
|
|
167
168
|
|
|
@@ -191,6 +192,7 @@ func (p *ImportProgrammer) GetInternalText(name string) string {
|
|
|
191
192
|
}
|
|
192
193
|
|
|
193
194
|
func (p *ImportProgrammer) ToStatements() []*shimast.Node {
|
|
195
|
+
f := EmitFactory(p.emit_, importProgrammer_factory)
|
|
194
196
|
statements := []*shimast.Node{}
|
|
195
197
|
order := append([]string{}, p.order_...)
|
|
196
198
|
indices := map[string]int{}
|
|
@@ -224,14 +226,14 @@ func (p *ImportProgrammer) ToStatements() []*shimast.Node {
|
|
|
224
226
|
continue
|
|
225
227
|
}
|
|
226
228
|
if asset.namespace != nil {
|
|
227
|
-
statements = append(statements,
|
|
229
|
+
statements = append(statements, f.NewImportDeclaration(
|
|
228
230
|
nil,
|
|
229
|
-
|
|
231
|
+
f.NewImportClause(
|
|
230
232
|
0,
|
|
231
233
|
nil,
|
|
232
|
-
|
|
234
|
+
f.NewNamespaceImport(f.NewIdentifier(asset.namespace.Name)),
|
|
233
235
|
),
|
|
234
|
-
|
|
236
|
+
f.NewStringLiteral(asset.file, shimast.TokenFlagsNone),
|
|
235
237
|
nil,
|
|
236
238
|
))
|
|
237
239
|
}
|
|
@@ -240,14 +242,14 @@ func (p *ImportProgrammer) ToStatements() []*shimast.Node {
|
|
|
240
242
|
if asset.Default.Type {
|
|
241
243
|
phase = shimast.KindTypeKeyword
|
|
242
244
|
}
|
|
243
|
-
statements = append(statements,
|
|
245
|
+
statements = append(statements, f.NewImportDeclaration(
|
|
244
246
|
nil,
|
|
245
|
-
|
|
247
|
+
f.NewImportClause(
|
|
246
248
|
phase,
|
|
247
|
-
|
|
249
|
+
f.NewIdentifier(asset.Default.Name),
|
|
248
250
|
nil,
|
|
249
251
|
),
|
|
250
|
-
|
|
252
|
+
f.NewStringLiteral(asset.file, shimast.TokenFlagsNone),
|
|
251
253
|
nil,
|
|
252
254
|
))
|
|
253
255
|
}
|
|
@@ -257,22 +259,22 @@ func (p *ImportProgrammer) ToStatements() []*shimast.Node {
|
|
|
257
259
|
ins := asset.instances[alias]
|
|
258
260
|
var propertyName *shimast.ModuleExportName
|
|
259
261
|
if ins.Alias != nil {
|
|
260
|
-
propertyName =
|
|
262
|
+
propertyName = f.NewIdentifier(ins.Name)
|
|
261
263
|
}
|
|
262
|
-
specifiers = append(specifiers,
|
|
264
|
+
specifiers = append(specifiers, f.NewImportSpecifier(
|
|
263
265
|
false,
|
|
264
266
|
propertyName,
|
|
265
|
-
|
|
267
|
+
f.NewIdentifier(alias),
|
|
266
268
|
))
|
|
267
269
|
}
|
|
268
|
-
statements = append(statements,
|
|
270
|
+
statements = append(statements, f.NewImportDeclaration(
|
|
269
271
|
nil,
|
|
270
|
-
|
|
272
|
+
f.NewImportClause(
|
|
271
273
|
0,
|
|
272
274
|
nil,
|
|
273
|
-
|
|
275
|
+
f.NewNamedImports(f.NewNodeList(specifiers)),
|
|
274
276
|
),
|
|
275
|
-
|
|
277
|
+
f.NewStringLiteral(asset.file, shimast.TokenFlagsNone),
|
|
276
278
|
nil,
|
|
277
279
|
))
|
|
278
280
|
}
|
|
@@ -11,6 +11,7 @@ import (
|
|
|
11
11
|
shimast "github.com/microsoft/typescript-go/shim/ast"
|
|
12
12
|
shimcore "github.com/microsoft/typescript-go/shim/core"
|
|
13
13
|
shimparser "github.com/microsoft/typescript-go/shim/parser"
|
|
14
|
+
shimprinter "github.com/microsoft/typescript-go/shim/printer"
|
|
14
15
|
nativecontext "github.com/samchon/typia/packages/typia/native/core/context"
|
|
15
16
|
)
|
|
16
17
|
|
|
@@ -53,75 +54,80 @@ type ExpressionFactory_GetEscapedTextProps struct {
|
|
|
53
54
|
|
|
54
55
|
var expressionFactory_factory = shimast.NewNodeFactory(shimast.NodeFactoryHooks{})
|
|
55
56
|
|
|
56
|
-
func (expressionFactoryNamespace) Number(value any) *shimast.Node {
|
|
57
|
+
func (expressionFactoryNamespace) Number(value any, emit ...*shimprinter.EmitContext) *shimast.Node {
|
|
58
|
+
f := nativecontext.EmitFactoryOf(expressionFactory_factory, emit...)
|
|
57
59
|
text, numeric := expressionFactory_number_text(value)
|
|
58
60
|
if numeric < 0 {
|
|
59
|
-
return
|
|
61
|
+
return f.NewPrefixUnaryExpression(
|
|
60
62
|
shimast.KindMinusToken,
|
|
61
|
-
|
|
63
|
+
f.NewNumericLiteral(expressionFactory_number_abs_text(numeric), shimast.TokenFlagsNone),
|
|
62
64
|
)
|
|
63
65
|
}
|
|
64
|
-
return
|
|
66
|
+
return f.NewNumericLiteral(text, shimast.TokenFlagsNone)
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
func (expressionFactoryNamespace) Bigint(value any) *shimast.Node {
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
func (expressionFactoryNamespace) Bigint(value any, emit ...*shimprinter.EmitContext) *shimast.Node {
|
|
70
|
+
f := nativecontext.EmitFactoryOf(expressionFactory_factory, emit...)
|
|
71
|
+
return f.NewCallExpression(
|
|
72
|
+
f.NewIdentifier("BigInt"),
|
|
70
73
|
nil,
|
|
71
74
|
nil,
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
f.NewNodeList([]*shimast.Node{
|
|
76
|
+
f.NewIdentifier(fmt.Sprint(value)),
|
|
74
77
|
}),
|
|
75
78
|
shimast.NodeFlagsNone,
|
|
76
79
|
)
|
|
77
80
|
}
|
|
78
81
|
|
|
79
|
-
func (expressionFactoryNamespace) IsRequired(input *shimast.Expression) *shimast.Node {
|
|
80
|
-
|
|
82
|
+
func (expressionFactoryNamespace) IsRequired(input *shimast.Expression, emit ...*shimprinter.EmitContext) *shimast.Node {
|
|
83
|
+
f := nativecontext.EmitFactoryOf(expressionFactory_factory, emit...)
|
|
84
|
+
return f.NewBinaryExpression(
|
|
81
85
|
nil,
|
|
82
|
-
|
|
86
|
+
f.NewIdentifier("undefined"),
|
|
83
87
|
nil,
|
|
84
|
-
|
|
88
|
+
f.NewToken(shimast.KindExclamationEqualsEqualsToken),
|
|
85
89
|
input,
|
|
86
90
|
)
|
|
87
91
|
}
|
|
88
92
|
|
|
89
|
-
func (expressionFactoryNamespace) IsArray(input *shimast.Expression) *shimast.Node {
|
|
90
|
-
|
|
91
|
-
|
|
93
|
+
func (expressionFactoryNamespace) IsArray(input *shimast.Expression, emit ...*shimprinter.EmitContext) *shimast.Node {
|
|
94
|
+
f := nativecontext.EmitFactoryOf(expressionFactory_factory, emit...)
|
|
95
|
+
return f.NewCallExpression(
|
|
96
|
+
f.NewIdentifier("Array.isArray"),
|
|
92
97
|
nil,
|
|
93
98
|
nil,
|
|
94
|
-
|
|
99
|
+
f.NewNodeList([]*shimast.Node{input}),
|
|
95
100
|
shimast.NodeFlagsNone,
|
|
96
101
|
)
|
|
97
102
|
}
|
|
98
103
|
|
|
99
|
-
func (expressionFactoryNamespace) IsObject(props ExpressionFactory_IsObjectProps) *shimast.Node {
|
|
104
|
+
func (expressionFactoryNamespace) IsObject(props ExpressionFactory_IsObjectProps, emit ...*shimprinter.EmitContext) *shimast.Node {
|
|
105
|
+
f := nativecontext.EmitFactoryOf(expressionFactory_factory, emit...)
|
|
100
106
|
conditions := []*shimast.Node{
|
|
101
|
-
|
|
107
|
+
f.NewBinaryExpression(
|
|
102
108
|
nil,
|
|
103
|
-
|
|
109
|
+
f.NewStringLiteral("object", shimast.TokenFlagsNone),
|
|
104
110
|
nil,
|
|
105
|
-
|
|
106
|
-
|
|
111
|
+
f.NewToken(shimast.KindEqualsEqualsEqualsToken),
|
|
112
|
+
f.NewTypeOfExpression(props.Input),
|
|
107
113
|
),
|
|
108
114
|
}
|
|
109
115
|
if props.CheckNull {
|
|
110
|
-
conditions = append(conditions,
|
|
116
|
+
conditions = append(conditions, f.NewBinaryExpression(
|
|
111
117
|
nil,
|
|
112
|
-
|
|
118
|
+
f.NewKeywordExpression(shimast.KindNullKeyword),
|
|
113
119
|
nil,
|
|
114
|
-
|
|
120
|
+
f.NewToken(shimast.KindExclamationEqualsEqualsToken),
|
|
115
121
|
props.Input,
|
|
116
122
|
))
|
|
117
123
|
}
|
|
118
124
|
if props.CheckArray {
|
|
119
|
-
conditions = append(conditions,
|
|
125
|
+
conditions = append(conditions, f.NewBinaryExpression(
|
|
120
126
|
nil,
|
|
121
|
-
|
|
127
|
+
f.NewKeywordExpression(shimast.KindFalseKeyword),
|
|
122
128
|
nil,
|
|
123
|
-
|
|
124
|
-
ExpressionFactory.IsArray(props.Input),
|
|
129
|
+
f.NewToken(shimast.KindEqualsEqualsEqualsToken),
|
|
130
|
+
ExpressionFactory.IsArray(props.Input, emit...),
|
|
125
131
|
))
|
|
126
132
|
}
|
|
127
133
|
if len(conditions) == 1 {
|
|
@@ -129,79 +135,103 @@ func (expressionFactoryNamespace) IsObject(props ExpressionFactory_IsObjectProps
|
|
|
129
135
|
}
|
|
130
136
|
output := conditions[0]
|
|
131
137
|
for _, condition := range conditions[1:] {
|
|
132
|
-
output =
|
|
138
|
+
output = f.NewBinaryExpression(
|
|
133
139
|
nil,
|
|
134
140
|
output,
|
|
135
141
|
nil,
|
|
136
|
-
|
|
142
|
+
f.NewToken(shimast.KindAmpersandAmpersandToken),
|
|
137
143
|
condition,
|
|
138
144
|
)
|
|
139
145
|
}
|
|
140
146
|
return output
|
|
141
147
|
}
|
|
142
148
|
|
|
143
|
-
func (expressionFactoryNamespace) IsInstanceOf(t string, input *shimast.Expression) *shimast.Node {
|
|
144
|
-
|
|
149
|
+
func (expressionFactoryNamespace) IsInstanceOf(t string, input *shimast.Expression, emit ...*shimprinter.EmitContext) *shimast.Node {
|
|
150
|
+
f := nativecontext.EmitFactoryOf(expressionFactory_factory, emit...)
|
|
151
|
+
return f.NewBinaryExpression(
|
|
145
152
|
nil,
|
|
146
153
|
input,
|
|
147
154
|
nil,
|
|
148
|
-
|
|
149
|
-
|
|
155
|
+
f.NewToken(shimast.KindInstanceOfKeyword),
|
|
156
|
+
f.NewIdentifier(t),
|
|
150
157
|
)
|
|
151
158
|
}
|
|
152
159
|
|
|
153
|
-
func (expressionFactoryNamespace) Coalesce(x *shimast.Expression, y *shimast.Expression) *shimast.Node {
|
|
154
|
-
|
|
160
|
+
func (expressionFactoryNamespace) Coalesce(x *shimast.Expression, y *shimast.Expression, emit ...*shimprinter.EmitContext) *shimast.Node {
|
|
161
|
+
f := nativecontext.EmitFactoryOf(expressionFactory_factory, emit...)
|
|
162
|
+
return f.NewBinaryExpression(
|
|
155
163
|
nil,
|
|
156
164
|
x,
|
|
157
165
|
nil,
|
|
158
|
-
|
|
166
|
+
f.NewToken(shimast.KindQuestionQuestionToken),
|
|
159
167
|
y,
|
|
160
168
|
)
|
|
161
169
|
}
|
|
162
170
|
|
|
163
|
-
|
|
171
|
+
// Conditional builds `condition ? whenTrue : whenFalse` with its operator tokens
|
|
172
|
+
// supplied at construction. typia's programmers historically built conditional
|
|
173
|
+
// expressions with nil `?`/`:` tokens and relied on a post-emit tree walk
|
|
174
|
+
// (NormalizeSyntheticTokens) to fill them in; constructing them well-formed here
|
|
175
|
+
// removes that workaround. The node is structurally identical to the patched-up
|
|
176
|
+
// form, so emitted text is unchanged.
|
|
177
|
+
func (expressionFactoryNamespace) Conditional(condition *shimast.Expression, whenTrue *shimast.Expression, whenFalse *shimast.Expression, emit ...*shimprinter.EmitContext) *shimast.Node {
|
|
178
|
+
f := nativecontext.EmitFactoryOf(expressionFactory_factory, emit...)
|
|
179
|
+
return f.NewConditionalExpression(
|
|
180
|
+
condition,
|
|
181
|
+
f.NewToken(shimast.KindQuestionToken),
|
|
182
|
+
whenTrue,
|
|
183
|
+
f.NewToken(shimast.KindColonToken),
|
|
184
|
+
whenFalse,
|
|
185
|
+
)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
func (expressionFactoryNamespace) Currying(props ExpressionFactory_CurryingProps, emit ...*shimprinter.EmitContext) *shimast.Node {
|
|
189
|
+
f := nativecontext.EmitFactoryOf(expressionFactory_factory, emit...)
|
|
164
190
|
if len(props.Arguments) == 0 {
|
|
165
|
-
return
|
|
191
|
+
return f.NewCallExpression(props.Function, nil, nil, nil, shimast.NodeFlagsNone)
|
|
166
192
|
}
|
|
167
|
-
prev :=
|
|
193
|
+
prev := f.NewCallExpression(
|
|
168
194
|
props.Function,
|
|
169
195
|
nil,
|
|
170
196
|
nil,
|
|
171
|
-
|
|
197
|
+
f.NewNodeList([]*shimast.Node{props.Arguments[0]}),
|
|
172
198
|
shimast.NodeFlagsNone,
|
|
173
199
|
)
|
|
174
200
|
for _, param := range props.Arguments[1:] {
|
|
175
|
-
prev =
|
|
201
|
+
prev = f.NewCallExpression(
|
|
176
202
|
prev,
|
|
177
203
|
nil,
|
|
178
204
|
nil,
|
|
179
|
-
|
|
205
|
+
f.NewNodeList([]*shimast.Node{param}),
|
|
180
206
|
shimast.NodeFlagsNone,
|
|
181
207
|
)
|
|
182
208
|
}
|
|
183
209
|
return prev
|
|
184
210
|
}
|
|
185
211
|
|
|
186
|
-
|
|
212
|
+
// SelfCall takes a required emit context (nil for context-free callers) for the
|
|
213
|
+
// same reason as IdentifierFactory.Access: its trailing typeNode variadic blocks
|
|
214
|
+
// the optional-emit form.
|
|
215
|
+
func (expressionFactoryNamespace) SelfCall(ec *shimprinter.EmitContext, body *shimast.ConciseBody, typeNode ...*shimast.TypeNode) *shimast.Node {
|
|
187
216
|
if body != nil && body.Kind == shimast.KindCallExpression {
|
|
188
217
|
return body
|
|
189
218
|
}
|
|
219
|
+
f := nativecontext.EmitFactory(ec, expressionFactory_factory)
|
|
190
220
|
var output *shimast.TypeNode
|
|
191
221
|
if len(typeNode) != 0 {
|
|
192
222
|
output = typeNode[0]
|
|
193
223
|
}
|
|
194
|
-
arrow :=
|
|
224
|
+
arrow := f.NewArrowFunction(
|
|
195
225
|
nil,
|
|
196
226
|
nil,
|
|
197
|
-
|
|
227
|
+
f.NewNodeList(nil),
|
|
198
228
|
output,
|
|
199
229
|
nil,
|
|
200
|
-
|
|
230
|
+
f.NewToken(shimast.KindEqualsGreaterThanToken),
|
|
201
231
|
body,
|
|
202
232
|
)
|
|
203
|
-
return
|
|
204
|
-
|
|
233
|
+
return f.NewCallExpression(
|
|
234
|
+
f.NewParenthesizedExpression(arrow),
|
|
205
235
|
nil,
|
|
206
236
|
nil,
|
|
207
237
|
nil,
|
|
@@ -219,7 +249,8 @@ func (expressionFactoryNamespace) GetEscapedText(props ExpressionFactory_GetEsca
|
|
|
219
249
|
return IdentifierFactory.GetName(props.Input)
|
|
220
250
|
}
|
|
221
251
|
|
|
222
|
-
func (expressionFactoryNamespace) Transpile(props ExpressionFactory_TranspileProps) func(input *shimast.Expression) *shimast.Node {
|
|
252
|
+
func (expressionFactoryNamespace) Transpile(props ExpressionFactory_TranspileProps, emit ...*shimprinter.EmitContext) func(input *shimast.Expression) *shimast.Node {
|
|
253
|
+
f := nativecontext.EmitFactoryOf(expressionFactory_factory, emit...)
|
|
223
254
|
file := shimparser.ParseSourceFile(
|
|
224
255
|
shimast.SourceFileParseOptions{FileName: filepath.Join(os.TempDir(), expressionFactory_random_format_uuid()+".ts")},
|
|
225
256
|
props.Script,
|
|
@@ -232,7 +263,7 @@ func (expressionFactoryNamespace) Transpile(props ExpressionFactory_TranspilePro
|
|
|
232
263
|
if statement.Kind != shimast.KindExpressionStatement {
|
|
233
264
|
panic("Error on ExpressionFactory.transpile(): statement is not an expression statement.")
|
|
234
265
|
}
|
|
235
|
-
expression :=
|
|
266
|
+
expression := f.DeepCloneNode(statement.AsExpressionStatement().Expression)
|
|
236
267
|
return func(input *shimast.Expression) *shimast.Node {
|
|
237
268
|
var visitor *shimast.NodeVisitor
|
|
238
269
|
visitor = shimast.NewNodeVisitor(func(node *shimast.Node) *shimast.Node {
|
|
@@ -248,7 +279,7 @@ func (expressionFactoryNamespace) Transpile(props ExpressionFactory_TranspilePro
|
|
|
248
279
|
}
|
|
249
280
|
}
|
|
250
281
|
return node.VisitEachChild(visitor)
|
|
251
|
-
},
|
|
282
|
+
}, f, shimast.NodeVisitorHooks{})
|
|
252
283
|
return visitor.VisitNode(expression)
|
|
253
284
|
}
|
|
254
285
|
}
|
|
@@ -5,6 +5,8 @@ import (
|
|
|
5
5
|
"strings"
|
|
6
6
|
|
|
7
7
|
shimast "github.com/microsoft/typescript-go/shim/ast"
|
|
8
|
+
shimprinter "github.com/microsoft/typescript-go/shim/printer"
|
|
9
|
+
nativecontext "github.com/samchon/typia/packages/typia/native/core/context"
|
|
8
10
|
)
|
|
9
11
|
|
|
10
12
|
type identifierFactoryNamespace struct{}
|
|
@@ -13,31 +15,37 @@ var IdentifierFactory = identifierFactoryNamespace{}
|
|
|
13
15
|
|
|
14
16
|
var identifierFactory_factory = shimast.NewNodeFactory(shimast.NodeFactoryHooks{})
|
|
15
17
|
|
|
16
|
-
func (identifierFactoryNamespace) Identifier(name string) *shimast.Node {
|
|
18
|
+
func (identifierFactoryNamespace) Identifier(name string, emit ...*shimprinter.EmitContext) *shimast.Node {
|
|
19
|
+
f := nativecontext.EmitFactoryOf(identifierFactory_factory, emit...)
|
|
17
20
|
if identifierFactory_variable(name) {
|
|
18
|
-
return
|
|
21
|
+
return f.NewIdentifier(name)
|
|
19
22
|
}
|
|
20
|
-
return
|
|
23
|
+
return f.NewStringLiteral(name, shimast.TokenFlagsNone)
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
// Access takes a required emit context (nil for genuinely context-free callers)
|
|
27
|
+
// because its trailing `chain` variadic blocks the optional-emit form the other
|
|
28
|
+
// factories use; a required parameter also makes a forgotten context a compile
|
|
29
|
+
// error rather than a silent metadata gap.
|
|
30
|
+
func (identifierFactoryNamespace) Access(ec *shimprinter.EmitContext, input *shimast.Expression, key string, chain ...bool) *shimast.Node {
|
|
31
|
+
f := nativecontext.EmitFactory(ec, identifierFactory_factory)
|
|
32
|
+
postfix := IdentifierFactory.Identifier(key, ec)
|
|
25
33
|
optional := len(chain) != 0 && chain[0]
|
|
26
34
|
var questionDot *shimast.QuestionDotToken
|
|
27
35
|
flags := shimast.NodeFlagsNone
|
|
28
36
|
if optional {
|
|
29
|
-
questionDot =
|
|
37
|
+
questionDot = f.NewToken(shimast.KindQuestionDotToken)
|
|
30
38
|
flags = shimast.NodeFlagsOptionalChain
|
|
31
39
|
}
|
|
32
40
|
if shimast.IsStringLiteral(postfix) {
|
|
33
|
-
return
|
|
41
|
+
return f.NewElementAccessExpression(
|
|
34
42
|
input,
|
|
35
43
|
questionDot,
|
|
36
44
|
postfix,
|
|
37
45
|
flags,
|
|
38
46
|
)
|
|
39
47
|
}
|
|
40
|
-
return
|
|
48
|
+
return f.NewPropertyAccessExpression(
|
|
41
49
|
input,
|
|
42
50
|
questionDot,
|
|
43
51
|
postfix,
|
|
@@ -71,27 +79,28 @@ func (identifierFactoryNamespace) Postfix(str string) string {
|
|
|
71
79
|
return "\"[" + quoted + "]\""
|
|
72
80
|
}
|
|
73
81
|
|
|
74
|
-
func (identifierFactoryNamespace) Parameter(name any, typeNode *shimast.TypeNode, init *shimast.Node) *shimast.Node {
|
|
82
|
+
func (identifierFactoryNamespace) Parameter(name any, typeNode *shimast.TypeNode, init *shimast.Node, emit ...*shimprinter.EmitContext) *shimast.Node {
|
|
83
|
+
f := nativecontext.EmitFactoryOf(identifierFactory_factory, emit...)
|
|
75
84
|
var binding *shimast.BindingName
|
|
76
85
|
switch v := name.(type) {
|
|
77
86
|
case string:
|
|
78
|
-
binding =
|
|
87
|
+
binding = f.NewIdentifier(v)
|
|
79
88
|
case *shimast.Node:
|
|
80
89
|
binding = v
|
|
81
90
|
default:
|
|
82
|
-
binding =
|
|
91
|
+
binding = f.NewIdentifier("input")
|
|
83
92
|
}
|
|
84
93
|
if typeNode == nil {
|
|
85
|
-
typeNode = TypeFactory.Keyword("any")
|
|
94
|
+
typeNode = TypeFactory.Keyword("any", emit...)
|
|
86
95
|
}
|
|
87
96
|
var question *shimast.QuestionToken
|
|
88
97
|
var initializer *shimast.Expression
|
|
89
98
|
if init != nil && init.Kind == shimast.KindQuestionToken {
|
|
90
|
-
question =
|
|
99
|
+
question = f.NewToken(shimast.KindQuestionToken)
|
|
91
100
|
} else {
|
|
92
101
|
initializer = init
|
|
93
102
|
}
|
|
94
|
-
return
|
|
103
|
+
return f.NewParameterDeclaration(
|
|
95
104
|
nil,
|
|
96
105
|
nil,
|
|
97
106
|
binding,
|