typia 13.0.0-dev.20260601.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/adapter/adapter.go +0 -203
- package/native/cmd/ttsc-typia/build.go +28 -90
- package/native/cmd/ttsc-typia/main.go +2 -2
- package/native/cmd/ttsc-typia/transform.go +132 -280
- package/native/core/context/EmitFactory.go +39 -0
- package/native/core/context/ITypiaContext.go +9 -4
- package/native/core/{programmers → context}/ImportProgrammer.go +105 -28
- package/native/core/factories/ExpressionFactory.go +93 -74
- package/native/core/factories/IdentifierFactory.go +25 -16
- package/native/core/factories/JsonMetadataFactory.go +5 -7
- package/native/core/factories/LiteralFactory.go +89 -41
- package/native/core/factories/MetadataFactory.go +13 -17
- package/native/core/factories/NumericRangeFactory.go +55 -43
- package/native/core/factories/ProtobufFactory.go +5 -7
- package/native/core/factories/StatementFactory.go +41 -32
- package/native/core/factories/TemplateFactory.go +15 -10
- package/native/core/factories/TypeFactory.go +5 -2
- package/native/core/factories/ValueFactory.go +19 -12
- package/native/core/factories/internal/metadata/MetadataHelper.go +53 -0
- package/native/core/factories/internal/metadata/iterate_metadata_constant.go +17 -1
- package/native/core/factories/internal/metadata/iterate_metadata_map.go +1 -1
- package/native/core/factories/internal/metadata/iterate_metadata_set.go +1 -1
- package/native/core/programmers/AssertProgrammer.go +115 -98
- package/native/core/programmers/IsProgrammer.go +49 -35
- package/native/core/programmers/RandomProgrammer.go +214 -183
- package/native/core/programmers/ValidateProgrammer.go +132 -114
- package/native/core/programmers/functional/FunctionalAssertFunctionProgrammer.go +36 -33
- 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 +37 -33
- package/native/core/programmers/functional/FunctionalValidateParametersProgrammer.go +81 -77
- 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/ModuloText.go +23 -0
- 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 +126 -111
- 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 +57 -55
- package/native/core/programmers/http/HttpHeadersProgrammer.go +63 -53
- 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 +20 -23
- package/native/core/programmers/http/HttpQueryProgrammer.go +96 -87
- package/native/core/programmers/http/HttpValidateFormDataProgrammer.go +14 -13
- 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 +178 -124
- package/native/core/programmers/internal/FeatureProgrammer.go +72 -51
- package/native/core/programmers/iterate/check_array_length.go +3 -4
- package/native/core/programmers/iterate/check_bigint.go +8 -8
- package/native/core/programmers/iterate/check_dynamic_key.go +63 -50
- package/native/core/programmers/iterate/check_dynamic_properties.go +80 -71
- 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 +17 -17
- package/native/core/programmers/iterate/check_object.go +7 -5
- package/native/core/programmers/iterate/check_string.go +8 -8
- 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 +13 -10
- package/native/core/programmers/iterate/json_schema_alias.go +1 -0
- package/native/core/programmers/iterate/json_schema_array.go +1 -0
- package/native/core/programmers/iterate/json_schema_native.go +48 -1
- package/native/core/programmers/iterate/json_schema_object.go +1 -0
- 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 +7 -1
- package/native/core/programmers/json/JsonAssertParseProgrammer.go +21 -24
- package/native/core/programmers/json/JsonAssertStringifyProgrammer.go +16 -15
- package/native/core/programmers/json/JsonIsParseProgrammer.go +36 -39
- package/native/core/programmers/json/JsonIsStringifyProgrammer.go +20 -20
- package/native/core/programmers/json/JsonSchemaProgrammer.go +2 -2
- package/native/core/programmers/json/JsonSchemasProgrammer.go +2 -2
- package/native/core/programmers/json/JsonStringifyProgrammer.go +173 -134
- package/native/core/programmers/json/JsonValidateParseProgrammer.go +19 -21
- package/native/core/programmers/json/JsonValidateStringifyProgrammer.go +26 -25
- package/native/core/programmers/llm/LlmApplicationProgrammer.go +8 -7
- package/native/core/programmers/llm/LlmCoerceProgrammer.go +13 -12
- package/native/core/programmers/llm/LlmControllerProgrammer.go +9 -9
- package/native/core/programmers/llm/LlmMetadataFactory.go +1 -2
- package/native/core/programmers/llm/LlmParametersProgrammer.go +6 -6
- package/native/core/programmers/llm/LlmParseProgrammer.go +18 -17
- package/native/core/programmers/llm/LlmSchemaProgrammer.go +38 -38
- package/native/core/programmers/llm/LlmStructuredOutputProgrammer.go +30 -29
- 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 +160 -130
- 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 +6 -6
- package/native/core/programmers/misc/MiscPruneProgrammer.go +78 -55
- package/native/core/programmers/misc/MiscValidateCloneProgrammer.go +27 -26
- package/native/core/programmers/misc/MiscValidatePruneProgrammer.go +23 -22
- package/native/core/programmers/notations/NotationAssertGeneralProgrammer.go +15 -14
- package/native/core/programmers/notations/NotationGeneralProgrammer.go +147 -118
- package/native/core/programmers/notations/NotationIsGeneralProgrammer.go +21 -20
- package/native/core/programmers/notations/NotationValidateGeneralProgrammer.go +29 -28
- package/native/core/programmers/protobuf/ProtobufAssertDecodeProgrammer.go +14 -13
- package/native/core/programmers/protobuf/ProtobufAssertEncodeProgrammer.go +17 -19
- package/native/core/programmers/protobuf/ProtobufDecodeProgrammer.go +193 -177
- package/native/core/programmers/protobuf/ProtobufEncodeProgrammer.go +205 -187
- 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 +11 -10
- package/native/core/programmers/protobuf/ProtobufValidateDecodeProgrammer.go +15 -14
- package/native/core/programmers/protobuf/ProtobufValidateEncodeProgrammer.go +31 -31
- package/native/core/schemas/metadata/MetadataCollection.go +20 -3
- package/native/go.work.sum +6 -0
- package/native/transform/CallExpressionTransformer.go +6 -5
- package/native/transform/FileTransformer.go +38 -12
- package/native/transform/ImportTransformer.go +9 -6
- package/native/transform/TypiaGenerator.go +1 -1
- package/native/transform/features/RandomTransformer.go +7 -4
- package/native/transform/features/json/JsonApplicationTransformer.go +1 -2
- package/native/transform/features/json/JsonSchemaTransformer.go +1 -2
- package/native/transform/features/json/JsonSchemasTransformer.go +1 -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 +4 -4
- package/native/transform/features/reflect/ReflectMetadataTransformer.go +2 -3
- package/native/transform/features/reflect/ReflectNameTransformer.go +3 -3
- package/native/transform/features/reflect/ReflectSchemaTransformer.go +5 -5
- package/native/transform/features/reflect/ReflectSchemasTransformer.go +2 -3
- package/native/transform/internal/GenericTransformer.go +2 -1
- package/native/transform/transform.go +7 -2
- package/package.json +4 -7
- package/native/adapter/cleanup.go +0 -333
- package/native/adapter/imports.go +0 -102
- package/native/cmd/ttsc-typia/transform_test.go +0 -40
- package/native/internal/printer/printer.go +0 -229
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
package adapter
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
-
"fmt"
|
|
5
|
-
"os"
|
|
6
|
-
"runtime/debug"
|
|
7
|
-
"strings"
|
|
8
|
-
|
|
9
|
-
shimast "github.com/microsoft/typescript-go/shim/ast"
|
|
10
|
-
"github.com/samchon/ttsc/packages/ttsc/driver"
|
|
11
4
|
nativecontext "github.com/samchon/typia/packages/typia/native/core/context"
|
|
12
|
-
nativeprogrammers "github.com/samchon/typia/packages/typia/native/core/programmers"
|
|
13
|
-
nativeprinter "github.com/samchon/typia/packages/typia/native/internal/printer"
|
|
14
|
-
nativetransform "github.com/samchon/typia/packages/typia/native/transform"
|
|
15
5
|
)
|
|
16
6
|
|
|
17
7
|
type PluginOptions struct {
|
|
@@ -37,196 +27,3 @@ func boolPointer(value bool) *bool {
|
|
|
37
27
|
}
|
|
38
28
|
return &value
|
|
39
29
|
}
|
|
40
|
-
|
|
41
|
-
func EmitCallWithOptions(program *driver.Program, site CallSite, plugin PluginOptions) (text string, handled bool, err error) {
|
|
42
|
-
return emitCallWithOptions(program, site, plugin, false)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
func EmitCallWithOptionsPreservingTypes(program *driver.Program, site CallSite, plugin PluginOptions) (text string, handled bool, err error) {
|
|
46
|
-
return emitCallWithOptions(program, site, plugin, true)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
func emitCallWithOptions(program *driver.Program, site CallSite, plugin PluginOptions, preserveTypes bool) (text string, handled bool, err error) {
|
|
50
|
-
if program == nil || program.Checker == nil || site.Call == nil {
|
|
51
|
-
return "", false, nil
|
|
52
|
-
}
|
|
53
|
-
importer := nativeprogrammers.NewImportProgrammer(nativeprogrammers.ImportProgrammer_IOptions{
|
|
54
|
-
InternalPrefix: "typia_transform_",
|
|
55
|
-
Runtime: "typia",
|
|
56
|
-
})
|
|
57
|
-
context := nativecontext.ITypiaContext{
|
|
58
|
-
Program: program,
|
|
59
|
-
CompilerOptions: program.ParsedConfig.ParsedConfig.CompilerOptions,
|
|
60
|
-
Checker: program.Checker,
|
|
61
|
-
Options: plugin.TransformOptions(),
|
|
62
|
-
Importer: importer,
|
|
63
|
-
}
|
|
64
|
-
defer func() {
|
|
65
|
-
if exp := recover(); exp != nil {
|
|
66
|
-
if e, ok := exp.(*nativetransform.TransformerError); ok {
|
|
67
|
-
text = ""
|
|
68
|
-
handled = true
|
|
69
|
-
err = e
|
|
70
|
-
return
|
|
71
|
-
}
|
|
72
|
-
text = ""
|
|
73
|
-
handled = true
|
|
74
|
-
if os.Getenv("TYPIA_NATIVE_DEBUG_STACK") != "" {
|
|
75
|
-
err = fmt.Errorf("%v\n%s", exp, debug.Stack())
|
|
76
|
-
} else {
|
|
77
|
-
err = fmt.Errorf("%v", exp)
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}()
|
|
81
|
-
var node *shimast.Node
|
|
82
|
-
if site.Module != "" && site.Method != "" {
|
|
83
|
-
node = nativetransform.CallExpressionTransformer.TransformKnown(nativetransform.CallExpressionTransformer_TransformKnownProps{
|
|
84
|
-
Context: context,
|
|
85
|
-
Expression: site.Call,
|
|
86
|
-
Module: site.Module,
|
|
87
|
-
Method: site.Method,
|
|
88
|
-
})
|
|
89
|
-
} else {
|
|
90
|
-
node = nativetransform.CallExpressionTransformer.Transform(nativetransform.CallExpressionTransformer_TransformProps{
|
|
91
|
-
Context: context,
|
|
92
|
-
Expression: site.Call,
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
if node == nil || node == site.Call.AsNode() {
|
|
96
|
-
return "", false, nil
|
|
97
|
-
}
|
|
98
|
-
if preserveTypes {
|
|
99
|
-
return cleanupPrintedExpression(nativeprinter.EmitPreservingTypesWithIdentifierSubstitutions(
|
|
100
|
-
node,
|
|
101
|
-
site.File,
|
|
102
|
-
nil,
|
|
103
|
-
)), true, nil
|
|
104
|
-
}
|
|
105
|
-
return cleanupPrintedExpression(nativeprinter.EmitWithIdentifierSubstitutions(
|
|
106
|
-
node,
|
|
107
|
-
site.File,
|
|
108
|
-
identifierSubstitutionsForEmit(program, site.File),
|
|
109
|
-
)), true, nil
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
func identifierSubstitutionsForEmit(program *driver.Program, file any) map[string]string {
|
|
113
|
-
if program == nil ||
|
|
114
|
-
program.ParsedConfig == nil ||
|
|
115
|
-
program.ParsedConfig.ParsedConfig == nil ||
|
|
116
|
-
program.ParsedConfig.ParsedConfig.CompilerOptions == nil ||
|
|
117
|
-
program.ParsedConfig.ParsedConfig.CompilerOptions.GetEmitModuleKind().String() != "CommonJS" {
|
|
118
|
-
return nil
|
|
119
|
-
}
|
|
120
|
-
sourceFile, ok := file.(*shimast.SourceFile)
|
|
121
|
-
if ok == false {
|
|
122
|
-
return nil
|
|
123
|
-
}
|
|
124
|
-
return commonJSImportIdentifierSubstitutions(sourceFile)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
func cleanupPrintedExpression(text string) string {
|
|
128
|
-
text = strings.TrimSpace(text)
|
|
129
|
-
text = strings.TrimSuffix(text, ";")
|
|
130
|
-
text = parenthesizeSingleParameterArrows(text)
|
|
131
|
-
if strings.HasPrefix(text, "(") && strings.HasSuffix(text, ")") {
|
|
132
|
-
return text
|
|
133
|
-
}
|
|
134
|
-
if strings.Contains(text, "=>") || strings.Contains(text, "function") {
|
|
135
|
-
return "(" + text + ")"
|
|
136
|
-
}
|
|
137
|
-
return text
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// parenthesizeSingleParameterArrows wraps a bare single-parameter arrow head
|
|
141
|
-
// `x =>` into `(x) =>`. It reproduces the regex
|
|
142
|
-
// `(^|[\s(=,:?])([A-Za-z_$][A-Za-z0-9_$]*) =>` -> `${1}(${2}) =>` with a manual
|
|
143
|
-
// byte scan: the printed call-site expression is large and this pass ran on
|
|
144
|
-
// every site, where the regex backtracker dominated the cleanup CPU.
|
|
145
|
-
func parenthesizeSingleParameterArrows(text string) string {
|
|
146
|
-
arrow := strings.Index(text, " =>")
|
|
147
|
-
if arrow < 0 {
|
|
148
|
-
return text
|
|
149
|
-
}
|
|
150
|
-
var b strings.Builder
|
|
151
|
-
last := 0
|
|
152
|
-
for arrow >= 0 {
|
|
153
|
-
end := arrow // identifier ends just before the space of " =>"
|
|
154
|
-
start := end
|
|
155
|
-
for start > 0 && isArrowIdentByte(text[start-1]) {
|
|
156
|
-
start--
|
|
157
|
-
}
|
|
158
|
-
if end > start && isArrowIdentStart(text[start]) &&
|
|
159
|
-
(start == 0 || isArrowBoundaryByte(text[start-1])) {
|
|
160
|
-
if b.Cap() == 0 {
|
|
161
|
-
b.Grow(len(text) + 16)
|
|
162
|
-
}
|
|
163
|
-
b.WriteString(text[last:start])
|
|
164
|
-
b.WriteByte('(')
|
|
165
|
-
b.WriteString(text[start:end])
|
|
166
|
-
b.WriteByte(')')
|
|
167
|
-
last = end
|
|
168
|
-
}
|
|
169
|
-
next := strings.Index(text[arrow+3:], " =>")
|
|
170
|
-
if next < 0 {
|
|
171
|
-
break
|
|
172
|
-
}
|
|
173
|
-
arrow += 3 + next
|
|
174
|
-
}
|
|
175
|
-
if last == 0 {
|
|
176
|
-
return text
|
|
177
|
-
}
|
|
178
|
-
b.WriteString(text[last:])
|
|
179
|
-
return b.String()
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
func isArrowIdentStart(c byte) bool {
|
|
183
|
-
return c == '_' || c == '$' ||
|
|
184
|
-
(c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
func isArrowIdentByte(c byte) bool {
|
|
188
|
-
return isArrowIdentStart(c) || (c >= '0' && c <= '9')
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// isArrowBoundaryByte matches the regex class [\s(=,:?] (RE2 `\s` is
|
|
192
|
-
// [\t\n\f\r ], i.e. no vertical tab).
|
|
193
|
-
func isArrowBoundaryByte(c byte) bool {
|
|
194
|
-
switch c {
|
|
195
|
-
case ' ', '\t', '\n', '\f', '\r', '(', '=', ',', ':', '?':
|
|
196
|
-
return true
|
|
197
|
-
}
|
|
198
|
-
return false
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
func UnsupportedReason(site CallSite) string {
|
|
202
|
-
if site.Call == nil {
|
|
203
|
-
return "invalid call expression"
|
|
204
|
-
}
|
|
205
|
-
if site.Call.TypeArguments == nil || len(site.Call.TypeArguments.Nodes) == 0 {
|
|
206
|
-
switch site.Module {
|
|
207
|
-
case "module":
|
|
208
|
-
switch site.Method {
|
|
209
|
-
case "assert", "assertEquals", "assertGuard", "assertGuardEquals", "assertType", "equals", "is", "validate", "validateEquals":
|
|
210
|
-
return ""
|
|
211
|
-
}
|
|
212
|
-
case "json":
|
|
213
|
-
switch site.Method {
|
|
214
|
-
case "stringify", "assertStringify", "isStringify", "validateStringify":
|
|
215
|
-
return ""
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return "generic argument is not specified."
|
|
219
|
-
}
|
|
220
|
-
return ""
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
func FormatTransformError(site CallSite, err error) string {
|
|
224
|
-
if err == nil {
|
|
225
|
-
return ""
|
|
226
|
-
}
|
|
227
|
-
code := "typia." + site.Method
|
|
228
|
-
if site.Module != "" {
|
|
229
|
-
code = "typia." + site.Module + "." + site.Method
|
|
230
|
-
}
|
|
231
|
-
return fmt.Sprintf("error TS(%s): %s", code, err.Error())
|
|
232
|
-
}
|
|
@@ -9,10 +9,13 @@ import (
|
|
|
9
9
|
"path/filepath"
|
|
10
10
|
"regexp"
|
|
11
11
|
|
|
12
|
+
shimast "github.com/microsoft/typescript-go/shim/ast"
|
|
12
13
|
shimcompiler "github.com/microsoft/typescript-go/shim/compiler"
|
|
13
|
-
|
|
14
|
+
shimprinter "github.com/microsoft/typescript-go/shim/printer"
|
|
14
15
|
"github.com/samchon/ttsc/packages/ttsc/driver"
|
|
15
16
|
typiaadapter "github.com/samchon/typia/packages/typia/native/adapter"
|
|
17
|
+
nativecontext "github.com/samchon/typia/packages/typia/native/core/context"
|
|
18
|
+
nativetransform "github.com/samchon/typia/packages/typia/native/transform"
|
|
16
19
|
)
|
|
17
20
|
|
|
18
21
|
func runBuild(args []string) int {
|
|
@@ -71,30 +74,35 @@ func runBuild(args []string) int {
|
|
|
71
74
|
return 2
|
|
72
75
|
}
|
|
73
76
|
|
|
74
|
-
rewrites := driver.NewRewriteSet()
|
|
75
|
-
transformDiags := []typiaTransformDiagnostic{}
|
|
76
|
-
sites, recognized := 0, 0
|
|
77
77
|
shouldEmit := !prog.ParsedConfig.ParsedConfig.CompilerOptions.NoEmit.IsTrue()
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
78
|
+
transformDiags := []typiaTransformDiagnostic{}
|
|
79
|
+
pluginOptions := readTypiaPluginOptions(cwd, *tsconfigPath)
|
|
80
|
+
transformOptions := pluginOptions.TransformOptions()
|
|
81
|
+
extras := nativecontext.ITypiaContext_Extras{
|
|
82
|
+
AddDiagnostic: func(diag *shimast.Diagnostic) int {
|
|
83
|
+
transformDiags = append(transformDiags, typiaTransformDiagnostic{Message: "typia transform error"})
|
|
84
|
+
return len(transformDiags)
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
// AST-integration emit: typia's per-file transformer runs inside tsgo's emit
|
|
88
|
+
// pipeline (sharing the EmitContext), so it returns AST and tsgo's module-
|
|
89
|
+
// transform aliases the injected namespace imports. No text-splice RewriteSet.
|
|
90
|
+
typiaTransform := func(ec *shimprinter.EmitContext, sf *shimast.SourceFile) *shimast.SourceFile {
|
|
91
|
+
if *rewriteMode != "typia" {
|
|
92
|
+
return sf
|
|
93
|
+
}
|
|
94
|
+
return nativetransform.Transform(prog, &transformOptions, extras, ec)(sf)
|
|
88
95
|
}
|
|
89
96
|
if !*quiet {
|
|
90
|
-
fmt.Fprintf(stdout, "// ttsc-typia build: tsconfig=%s cwd=%s
|
|
97
|
+
fmt.Fprintf(stdout, "// ttsc-typia build: tsconfig=%s cwd=%s emit=%v rewrite=%s\n", *tsconfigPath, cwd, shouldEmit, *rewriteMode)
|
|
91
98
|
}
|
|
92
99
|
if shouldEmit {
|
|
100
|
+
emitted := []string{}
|
|
93
101
|
writeFile := shimcompiler.WriteFile(func(fileName, text string, data *shimcompiler.WriteFileData) error {
|
|
94
|
-
|
|
102
|
+
emitted = append(emitted, fileName)
|
|
95
103
|
return driver.DefaultWriteFile(fileName, text)
|
|
96
104
|
})
|
|
97
|
-
|
|
105
|
+
eDiags, err := prog.EmitWithPluginTransformers([]driver.PluginTransform{typiaTransform}, writeFile)
|
|
98
106
|
if err != nil {
|
|
99
107
|
fmt.Fprintf(stderr, "ttsc-typia build: emit failed: %v\n", err)
|
|
100
108
|
return 3
|
|
@@ -103,8 +111,8 @@ func runBuild(args []string) int {
|
|
|
103
111
|
fmt.Fprintln(stderr, " -", d.String())
|
|
104
112
|
}
|
|
105
113
|
if !*quiet {
|
|
106
|
-
fmt.Fprintf(stdout, "// ttsc-typia build: emitted=%d files\n", len(
|
|
107
|
-
for _, f := range
|
|
114
|
+
fmt.Fprintf(stdout, "// ttsc-typia build: emitted=%d files\n", len(emitted))
|
|
115
|
+
for _, f := range emitted {
|
|
108
116
|
rel := f
|
|
109
117
|
if abs, err := filepath.Rel(cwd, f); err == nil {
|
|
110
118
|
rel = abs
|
|
@@ -113,7 +121,7 @@ func runBuild(args []string) int {
|
|
|
113
121
|
}
|
|
114
122
|
}
|
|
115
123
|
if *manifestPath != "" {
|
|
116
|
-
data, err := json.Marshal(
|
|
124
|
+
data, err := json.Marshal(emitted)
|
|
117
125
|
if err != nil {
|
|
118
126
|
fmt.Fprintf(stderr, "ttsc-typia build: manifest marshal failed: %v\n", err)
|
|
119
127
|
return 3
|
|
@@ -132,9 +140,6 @@ func runBuild(args []string) int {
|
|
|
132
140
|
writeTypiaTransformDiagnostics(stderr, transformDiags, cwd)
|
|
133
141
|
return 3
|
|
134
142
|
}
|
|
135
|
-
if !*quiet {
|
|
136
|
-
fmt.Fprintf(stdout, "// ttsc-typia build: recognized=%d total=%d rewrites=%d\n", recognized, sites, rewrites.Len())
|
|
137
|
-
}
|
|
138
143
|
return 0
|
|
139
144
|
}
|
|
140
145
|
|
|
@@ -163,73 +168,6 @@ func writeTypiaTransformDiagnostics(out io.Writer, diagnostics []typiaTransformD
|
|
|
163
168
|
}
|
|
164
169
|
}
|
|
165
170
|
|
|
166
|
-
func newTypiaTransformDiagnostic(site typiaadapter.CallSite, message string) typiaTransformDiagnostic {
|
|
167
|
-
line, column := 0, 0
|
|
168
|
-
if site.File != nil && site.Call != nil {
|
|
169
|
-
pos := site.Call.AsNode().Pos()
|
|
170
|
-
if pos >= 0 {
|
|
171
|
-
l, c := shimscanner.GetECMALineAndByteOffsetOfPosition(site.File, pos)
|
|
172
|
-
line, column = l+1, c+1
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return typiaTransformDiagnostic{
|
|
176
|
-
File: site.FilePath,
|
|
177
|
-
Line: line,
|
|
178
|
-
Column: column,
|
|
179
|
-
Code: "typia." + site.Module + "." + site.Method,
|
|
180
|
-
Message: message,
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
func collectTypiaRewrites(
|
|
185
|
-
prog *driver.Program,
|
|
186
|
-
cwd string,
|
|
187
|
-
emit bool,
|
|
188
|
-
quiet bool,
|
|
189
|
-
onlyFile string,
|
|
190
|
-
rewrites *driver.RewriteSet,
|
|
191
|
-
pluginOptions typiaadapter.PluginOptions,
|
|
192
|
-
) (int, int, []typiaTransformDiagnostic) {
|
|
193
|
-
sites := typiaadapter.CollectCallSites(prog.SourceFiles(), prog.Checker)
|
|
194
|
-
recognized := 0
|
|
195
|
-
diagnostics := []typiaTransformDiagnostic{}
|
|
196
|
-
for _, site := range sites {
|
|
197
|
-
if onlyFile != "" && filepath.ToSlash(site.FilePath) != filepath.ToSlash(onlyFile) {
|
|
198
|
-
continue
|
|
199
|
-
}
|
|
200
|
-
rel := site.FilePath
|
|
201
|
-
if abs, err := filepath.Rel(cwd, rel); err == nil {
|
|
202
|
-
rel = abs
|
|
203
|
-
}
|
|
204
|
-
if reason := typiaadapter.UnsupportedReason(site); reason != "" {
|
|
205
|
-
diagnostics = append(diagnostics, newTypiaTransformDiagnostic(site, reason))
|
|
206
|
-
continue
|
|
207
|
-
}
|
|
208
|
-
expr, handled, err := typiaadapter.EmitCallWithOptions(prog, site, pluginOptions)
|
|
209
|
-
if !handled {
|
|
210
|
-
diagnostics = append(diagnostics, newTypiaTransformDiagnostic(site, "method not covered"))
|
|
211
|
-
continue
|
|
212
|
-
}
|
|
213
|
-
if err != nil {
|
|
214
|
-
diagnostics = append(diagnostics, newTypiaTransformDiagnostic(site, err.Error()))
|
|
215
|
-
continue
|
|
216
|
-
}
|
|
217
|
-
rewrites.Add(driver.Rewrite{
|
|
218
|
-
File: site.File,
|
|
219
|
-
RootName: site.RootName,
|
|
220
|
-
Namespaces: site.Namespaces,
|
|
221
|
-
Method: site.Method,
|
|
222
|
-
Replacement: expr,
|
|
223
|
-
ConsumeParens: true,
|
|
224
|
-
})
|
|
225
|
-
if !emit && !quiet {
|
|
226
|
-
fmt.Fprintf(stdout, "%s: typia.%s<T> -> %s\n", rel, site.Method, expr)
|
|
227
|
-
}
|
|
228
|
-
recognized++
|
|
229
|
-
}
|
|
230
|
-
return len(sites), recognized, diagnostics
|
|
231
|
-
}
|
|
232
|
-
|
|
233
171
|
func readTypiaPluginOptions(cwd, tsconfigPath string) typiaadapter.PluginOptions {
|
|
234
172
|
path := tsconfigPath
|
|
235
173
|
if !filepath.IsAbs(path) {
|
|
@@ -41,10 +41,10 @@ func run(args []string) int {
|
|
|
41
41
|
return runDemo(args[1:])
|
|
42
42
|
case "build":
|
|
43
43
|
return runBuild(args[1:])
|
|
44
|
-
case "check":
|
|
45
|
-
return runBuild(append([]string{"--noEmit"}, args[1:]...))
|
|
46
44
|
case "transform":
|
|
47
45
|
return runTransform(args[1:])
|
|
46
|
+
case "check":
|
|
47
|
+
return runBuild(append([]string{"--noEmit"}, args[1:]...))
|
|
48
48
|
case "-p", "--project":
|
|
49
49
|
if len(args) < 2 {
|
|
50
50
|
fmt.Fprintln(stderr, "ttsc-typia: -p/--project requires a path argument")
|