@nestia/core 12.0.0-rc.1 → 12.0.0-rc.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/LICENSE +21 -21
- package/MIGRATION.md +138 -169
- package/lib/decorators/NoTransformConfigurationError.js +5 -5
- package/lib/decorators/NoTransformConfigurationError.js.map +1 -1
- package/native/cmd/ttsc-nestia/main.go +11 -11
- package/native/go.mod +32 -32
- package/native/go.sum +54 -54
- package/native/plugin/plan.go +102 -102
- package/native/transform/ast.go +32 -32
- package/native/transform/build.go +388 -380
- package/native/transform/cleanup.go +408 -408
- package/native/transform/contributor.go +97 -97
- package/native/transform/core_querify.go +231 -231
- package/native/transform/core_transform.go +1996 -1996
- package/native/transform/core_websocket.go +115 -115
- package/native/transform/exports.go +13 -13
- package/native/transform/mcp_transform.go +414 -414
- package/native/transform/node_transform.go +357 -357
- package/native/transform/path_rewrite.go +285 -285
- package/native/transform/printer.go +244 -244
- package/native/transform/rewrite.go +668 -668
- package/native/transform/run.go +73 -73
- package/native/transform/transform.go +336 -336
- package/native/transform/typia_fast.go +375 -352
- package/native/transform/typia_replacement.go +24 -24
- package/native/transform.cjs +43 -43
- package/package.json +9 -9
- package/src/adaptors/McpAdaptor.ts +276 -276
- package/src/adaptors/WebSocketAdaptor.ts +429 -429
- package/src/decorators/DynamicModule.ts +44 -44
- package/src/decorators/EncryptedBody.ts +97 -97
- package/src/decorators/EncryptedController.ts +40 -40
- package/src/decorators/EncryptedModule.ts +98 -98
- package/src/decorators/EncryptedRoute.ts +213 -213
- package/src/decorators/HumanRoute.ts +21 -21
- package/src/decorators/McpRoute.ts +154 -154
- package/src/decorators/NoTransformConfigurationError.ts +40 -40
- package/src/decorators/PlainBody.ts +76 -76
- package/src/decorators/SwaggerCustomizer.ts +97 -97
- package/src/decorators/SwaggerExample.ts +180 -180
- package/src/decorators/TypedBody.ts +57 -57
- package/src/decorators/TypedException.ts +147 -147
- package/src/decorators/TypedFormData.ts +187 -187
- package/src/decorators/TypedHeaders.ts +66 -66
- package/src/decorators/TypedParam.ts +77 -77
- package/src/decorators/TypedQuery.ts +234 -234
- package/src/decorators/TypedRoute.ts +198 -198
- package/src/decorators/WebSocketRoute.ts +242 -242
- package/src/decorators/doNotThrowTransformError.ts +5 -5
- package/src/decorators/internal/EncryptedConstant.ts +2 -2
- package/src/decorators/internal/IMcpRouteReflect.ts +40 -40
- package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -23
- package/src/decorators/internal/get_path_and_querify.ts +94 -94
- package/src/decorators/internal/get_path_and_stringify.ts +110 -110
- package/src/decorators/internal/get_text_body.ts +16 -16
- package/src/decorators/internal/headers_to_object.ts +11 -11
- package/src/decorators/internal/is_request_body_undefined.ts +12 -12
- package/src/decorators/internal/load_controller.ts +94 -94
- package/src/decorators/internal/route_error.ts +43 -43
- package/src/decorators/internal/validate_request_body.ts +64 -64
- package/src/decorators/internal/validate_request_form_data.ts +67 -67
- package/src/decorators/internal/validate_request_headers.ts +76 -76
- package/src/decorators/internal/validate_request_query.ts +83 -83
- package/src/index.ts +5 -5
- package/src/module.ts +25 -25
- package/src/options/IRequestBodyValidator.ts +20 -20
- package/src/options/IRequestFormDataProps.ts +27 -27
- package/src/options/IRequestHeadersValidator.ts +22 -22
- package/src/options/IRequestQueryValidator.ts +20 -20
- package/src/options/IResponseBodyQuerifier.ts +25 -25
- package/src/options/IResponseBodyStringifier.ts +30 -30
- package/src/transform.ts +26 -26
- package/src/typings/Creator.ts +3 -3
- package/src/typings/get-function-location.d.ts +7 -7
- package/src/utils/ArrayUtil.ts +7 -7
- package/src/utils/ExceptionManager.ts +115 -115
- package/src/utils/Singleton.ts +16 -16
- package/src/utils/SourceFinder.ts +54 -54
- package/src/utils/VersioningStrategy.ts +27 -27
- package/README.md +0 -93
|
@@ -1,244 +1,244 @@
|
|
|
1
|
-
package transform
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
shimast "github.com/microsoft/typescript-go/shim/ast"
|
|
5
|
-
shimprinter "github.com/microsoft/typescript-go/shim/printer"
|
|
6
|
-
)
|
|
7
|
-
|
|
8
|
-
const nestiaKindColonToken = shimast.KindQuestionToken + 1
|
|
9
|
-
|
|
10
|
-
func emitNestiaWithIdentifierSubstitutions(
|
|
11
|
-
node *shimast.Node,
|
|
12
|
-
sourceFile *shimast.SourceFile,
|
|
13
|
-
substitutions map[string]string,
|
|
14
|
-
) string {
|
|
15
|
-
node = stripNestiaTypeSyntax(node)
|
|
16
|
-
node = rewriteNestiaIdentifiers(node, substitutions)
|
|
17
|
-
normalizeNestiaSyntheticTokens(node)
|
|
18
|
-
return emitNestiaNode(node, sourceFile)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
func emitNestiaPreservingTypesWithIdentifierSubstitutions(
|
|
22
|
-
node *shimast.Node,
|
|
23
|
-
sourceFile *shimast.SourceFile,
|
|
24
|
-
substitutions map[string]string,
|
|
25
|
-
) string {
|
|
26
|
-
node = rewriteNestiaIdentifiers(node, substitutions)
|
|
27
|
-
normalizeNestiaSyntheticTokens(node)
|
|
28
|
-
return emitNestiaNode(node, sourceFile)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
func emitNestiaNode(node *shimast.Node, sourceFile *shimast.SourceFile) string {
|
|
32
|
-
return shimprinter.NewPrinter(shimprinter.PrinterOptions{
|
|
33
|
-
RemoveComments: true,
|
|
34
|
-
NewLine: 2,
|
|
35
|
-
}, shimprinter.PrintHandlers{}, nil).Emit(node, sourceFile)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
func stripNestiaTypeSyntax(node *shimast.Node) *shimast.Node {
|
|
39
|
-
if node == nil {
|
|
40
|
-
return nil
|
|
41
|
-
}
|
|
42
|
-
factory := shimast.NewNodeFactory(shimast.NodeFactoryHooks{})
|
|
43
|
-
var visitor *shimast.NodeVisitor
|
|
44
|
-
visitor = shimast.NewNodeVisitor(func(current *shimast.Node) *shimast.Node {
|
|
45
|
-
if current == nil {
|
|
46
|
-
return nil
|
|
47
|
-
}
|
|
48
|
-
switch current.Kind {
|
|
49
|
-
case shimast.KindAsExpression, shimast.KindSatisfiesExpression, shimast.KindTypeAssertionExpression, shimast.KindNonNullExpression:
|
|
50
|
-
return visitor.VisitNode(current.Expression())
|
|
51
|
-
case shimast.KindVariableDeclaration:
|
|
52
|
-
decl := current.AsVariableDeclaration()
|
|
53
|
-
return factory.UpdateVariableDeclaration(
|
|
54
|
-
decl,
|
|
55
|
-
visitor.VisitNode(decl.Name()),
|
|
56
|
-
nil,
|
|
57
|
-
nil,
|
|
58
|
-
visitor.VisitNode(decl.Initializer),
|
|
59
|
-
)
|
|
60
|
-
case shimast.KindParameter:
|
|
61
|
-
parameter := current.AsParameterDeclaration()
|
|
62
|
-
return factory.UpdateParameterDeclaration(
|
|
63
|
-
parameter,
|
|
64
|
-
visitor.VisitModifiers(parameter.Modifiers()),
|
|
65
|
-
visitor.VisitNode(parameter.DotDotDotToken),
|
|
66
|
-
visitor.VisitNode(parameter.Name()),
|
|
67
|
-
nil,
|
|
68
|
-
nil,
|
|
69
|
-
visitor.VisitNode(parameter.Initializer),
|
|
70
|
-
)
|
|
71
|
-
case shimast.KindArrowFunction:
|
|
72
|
-
arrow := current.AsArrowFunction()
|
|
73
|
-
return factory.UpdateArrowFunction(
|
|
74
|
-
arrow,
|
|
75
|
-
visitor.VisitModifiers(arrow.Modifiers()),
|
|
76
|
-
nil,
|
|
77
|
-
visitor.VisitNodes(arrow.Parameters),
|
|
78
|
-
nil,
|
|
79
|
-
nil,
|
|
80
|
-
visitor.VisitNode(arrow.EqualsGreaterThanToken),
|
|
81
|
-
visitor.VisitNode(arrow.Body),
|
|
82
|
-
)
|
|
83
|
-
case shimast.KindCallExpression:
|
|
84
|
-
call := current.AsCallExpression()
|
|
85
|
-
return factory.UpdateCallExpression(
|
|
86
|
-
call,
|
|
87
|
-
visitor.VisitNode(call.Expression),
|
|
88
|
-
visitor.VisitNode(call.QuestionDotToken),
|
|
89
|
-
nil,
|
|
90
|
-
visitor.VisitNodes(call.Arguments),
|
|
91
|
-
call.Flags,
|
|
92
|
-
)
|
|
93
|
-
case shimast.KindNewExpression:
|
|
94
|
-
expr := current.AsNewExpression()
|
|
95
|
-
return factory.UpdateNewExpression(
|
|
96
|
-
expr,
|
|
97
|
-
visitor.VisitNode(expr.Expression),
|
|
98
|
-
nil,
|
|
99
|
-
visitor.VisitNodes(expr.Arguments),
|
|
100
|
-
)
|
|
101
|
-
default:
|
|
102
|
-
return visitor.VisitEachChild(current)
|
|
103
|
-
}
|
|
104
|
-
}, factory, shimast.NodeVisitorHooks{})
|
|
105
|
-
return visitor.VisitNode(node)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
func rewriteNestiaIdentifiers(
|
|
109
|
-
node *shimast.Node,
|
|
110
|
-
substitutions map[string]string,
|
|
111
|
-
) *shimast.Node {
|
|
112
|
-
if node == nil || len(substitutions) == 0 {
|
|
113
|
-
return node
|
|
114
|
-
}
|
|
115
|
-
factory := shimast.NewNodeFactory(shimast.NodeFactoryHooks{})
|
|
116
|
-
var visitor *shimast.NodeVisitor
|
|
117
|
-
visitor = shimast.NewNodeVisitor(func(current *shimast.Node) *shimast.Node {
|
|
118
|
-
if current == nil {
|
|
119
|
-
return nil
|
|
120
|
-
}
|
|
121
|
-
switch current.Kind {
|
|
122
|
-
case shimast.KindIdentifier:
|
|
123
|
-
if replacement, ok := substitutions[current.Text()]; ok {
|
|
124
|
-
return rewriteNestiaIdentifierExpression(factory, replacement)
|
|
125
|
-
}
|
|
126
|
-
return current
|
|
127
|
-
case shimast.KindVariableDeclaration:
|
|
128
|
-
decl := current.AsVariableDeclaration()
|
|
129
|
-
return factory.UpdateVariableDeclaration(
|
|
130
|
-
decl,
|
|
131
|
-
decl.Name(),
|
|
132
|
-
nil,
|
|
133
|
-
nil,
|
|
134
|
-
visitor.VisitNode(decl.Initializer),
|
|
135
|
-
)
|
|
136
|
-
case shimast.KindParameter:
|
|
137
|
-
parameter := current.AsParameterDeclaration()
|
|
138
|
-
return factory.UpdateParameterDeclaration(
|
|
139
|
-
parameter,
|
|
140
|
-
parameter.Modifiers(),
|
|
141
|
-
parameter.DotDotDotToken,
|
|
142
|
-
parameter.Name(),
|
|
143
|
-
nil,
|
|
144
|
-
nil,
|
|
145
|
-
visitor.VisitNode(parameter.Initializer),
|
|
146
|
-
)
|
|
147
|
-
case shimast.KindPropertyAssignment:
|
|
148
|
-
assignment := current.AsPropertyAssignment()
|
|
149
|
-
return factory.UpdatePropertyAssignment(
|
|
150
|
-
assignment,
|
|
151
|
-
assignment.Modifiers(),
|
|
152
|
-
assignment.Name(),
|
|
153
|
-
assignment.PostfixToken,
|
|
154
|
-
nil,
|
|
155
|
-
visitor.VisitNode(assignment.Initializer),
|
|
156
|
-
)
|
|
157
|
-
case shimast.KindShorthandPropertyAssignment:
|
|
158
|
-
assignment := current.AsShorthandPropertyAssignment()
|
|
159
|
-
name := assignment.Name()
|
|
160
|
-
if name != nil && name.Kind == shimast.KindIdentifier {
|
|
161
|
-
if replacement, ok := substitutions[name.Text()]; ok &&
|
|
162
|
-
assignment.ObjectAssignmentInitializer == nil {
|
|
163
|
-
return factory.NewPropertyAssignment(
|
|
164
|
-
assignment.Modifiers(),
|
|
165
|
-
name,
|
|
166
|
-
assignment.PostfixToken,
|
|
167
|
-
nil,
|
|
168
|
-
rewriteNestiaIdentifierExpression(factory, replacement),
|
|
169
|
-
)
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return factory.UpdateShorthandPropertyAssignment(
|
|
173
|
-
assignment,
|
|
174
|
-
assignment.Modifiers(),
|
|
175
|
-
name,
|
|
176
|
-
assignment.PostfixToken,
|
|
177
|
-
nil,
|
|
178
|
-
nil,
|
|
179
|
-
visitor.VisitNode(assignment.ObjectAssignmentInitializer),
|
|
180
|
-
)
|
|
181
|
-
case shimast.KindPropertyAccessExpression:
|
|
182
|
-
access := current.AsPropertyAccessExpression()
|
|
183
|
-
return factory.UpdatePropertyAccessExpression(
|
|
184
|
-
access,
|
|
185
|
-
visitor.VisitNode(access.Expression),
|
|
186
|
-
access.QuestionDotToken,
|
|
187
|
-
access.Name(),
|
|
188
|
-
access.Flags,
|
|
189
|
-
)
|
|
190
|
-
default:
|
|
191
|
-
return visitor.VisitEachChild(current)
|
|
192
|
-
}
|
|
193
|
-
}, factory, shimast.NodeVisitorHooks{})
|
|
194
|
-
return visitor.VisitNode(node)
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
func rewriteNestiaIdentifierExpression(
|
|
198
|
-
factory *shimast.NodeFactory,
|
|
199
|
-
replacement string,
|
|
200
|
-
) *shimast.Node {
|
|
201
|
-
parts := []string{}
|
|
202
|
-
start := 0
|
|
203
|
-
for i := 0; i <= len(replacement); i++ {
|
|
204
|
-
if i == len(replacement) || replacement[i] == '.' {
|
|
205
|
-
if start < i {
|
|
206
|
-
parts = append(parts, replacement[start:i])
|
|
207
|
-
}
|
|
208
|
-
start = i + 1
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
if len(parts) == 0 {
|
|
212
|
-
return factory.NewIdentifier(replacement)
|
|
213
|
-
}
|
|
214
|
-
output := factory.NewIdentifier(parts[0])
|
|
215
|
-
for _, part := range parts[1:] {
|
|
216
|
-
output = factory.NewPropertyAccessExpression(
|
|
217
|
-
output,
|
|
218
|
-
nil,
|
|
219
|
-
factory.NewIdentifier(part),
|
|
220
|
-
shimast.NodeFlagsNone,
|
|
221
|
-
)
|
|
222
|
-
}
|
|
223
|
-
return output
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
func normalizeNestiaSyntheticTokens(node *shimast.Node) {
|
|
227
|
-
if node == nil {
|
|
228
|
-
return
|
|
229
|
-
}
|
|
230
|
-
if node.Kind == shimast.KindConditionalExpression {
|
|
231
|
-
conditional := node.AsConditionalExpression()
|
|
232
|
-
factory := shimast.NewNodeFactory(shimast.NodeFactoryHooks{})
|
|
233
|
-
if conditional.QuestionToken == nil {
|
|
234
|
-
conditional.QuestionToken = factory.NewToken(shimast.KindQuestionToken)
|
|
235
|
-
}
|
|
236
|
-
if conditional.ColonToken == nil {
|
|
237
|
-
conditional.ColonToken = factory.NewToken(nestiaKindColonToken)
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
node.ForEachChild(func(child *shimast.Node) bool {
|
|
241
|
-
normalizeNestiaSyntheticTokens(child)
|
|
242
|
-
return false
|
|
243
|
-
})
|
|
244
|
-
}
|
|
1
|
+
package transform
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
shimast "github.com/microsoft/typescript-go/shim/ast"
|
|
5
|
+
shimprinter "github.com/microsoft/typescript-go/shim/printer"
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
const nestiaKindColonToken = shimast.KindQuestionToken + 1
|
|
9
|
+
|
|
10
|
+
func emitNestiaWithIdentifierSubstitutions(
|
|
11
|
+
node *shimast.Node,
|
|
12
|
+
sourceFile *shimast.SourceFile,
|
|
13
|
+
substitutions map[string]string,
|
|
14
|
+
) string {
|
|
15
|
+
node = stripNestiaTypeSyntax(node)
|
|
16
|
+
node = rewriteNestiaIdentifiers(node, substitutions)
|
|
17
|
+
normalizeNestiaSyntheticTokens(node)
|
|
18
|
+
return emitNestiaNode(node, sourceFile)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
func emitNestiaPreservingTypesWithIdentifierSubstitutions(
|
|
22
|
+
node *shimast.Node,
|
|
23
|
+
sourceFile *shimast.SourceFile,
|
|
24
|
+
substitutions map[string]string,
|
|
25
|
+
) string {
|
|
26
|
+
node = rewriteNestiaIdentifiers(node, substitutions)
|
|
27
|
+
normalizeNestiaSyntheticTokens(node)
|
|
28
|
+
return emitNestiaNode(node, sourceFile)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
func emitNestiaNode(node *shimast.Node, sourceFile *shimast.SourceFile) string {
|
|
32
|
+
return shimprinter.NewPrinter(shimprinter.PrinterOptions{
|
|
33
|
+
RemoveComments: true,
|
|
34
|
+
NewLine: 2,
|
|
35
|
+
}, shimprinter.PrintHandlers{}, nil).Emit(node, sourceFile)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
func stripNestiaTypeSyntax(node *shimast.Node) *shimast.Node {
|
|
39
|
+
if node == nil {
|
|
40
|
+
return nil
|
|
41
|
+
}
|
|
42
|
+
factory := shimast.NewNodeFactory(shimast.NodeFactoryHooks{})
|
|
43
|
+
var visitor *shimast.NodeVisitor
|
|
44
|
+
visitor = shimast.NewNodeVisitor(func(current *shimast.Node) *shimast.Node {
|
|
45
|
+
if current == nil {
|
|
46
|
+
return nil
|
|
47
|
+
}
|
|
48
|
+
switch current.Kind {
|
|
49
|
+
case shimast.KindAsExpression, shimast.KindSatisfiesExpression, shimast.KindTypeAssertionExpression, shimast.KindNonNullExpression:
|
|
50
|
+
return visitor.VisitNode(current.Expression())
|
|
51
|
+
case shimast.KindVariableDeclaration:
|
|
52
|
+
decl := current.AsVariableDeclaration()
|
|
53
|
+
return factory.UpdateVariableDeclaration(
|
|
54
|
+
decl,
|
|
55
|
+
visitor.VisitNode(decl.Name()),
|
|
56
|
+
nil,
|
|
57
|
+
nil,
|
|
58
|
+
visitor.VisitNode(decl.Initializer),
|
|
59
|
+
)
|
|
60
|
+
case shimast.KindParameter:
|
|
61
|
+
parameter := current.AsParameterDeclaration()
|
|
62
|
+
return factory.UpdateParameterDeclaration(
|
|
63
|
+
parameter,
|
|
64
|
+
visitor.VisitModifiers(parameter.Modifiers()),
|
|
65
|
+
visitor.VisitNode(parameter.DotDotDotToken),
|
|
66
|
+
visitor.VisitNode(parameter.Name()),
|
|
67
|
+
nil,
|
|
68
|
+
nil,
|
|
69
|
+
visitor.VisitNode(parameter.Initializer),
|
|
70
|
+
)
|
|
71
|
+
case shimast.KindArrowFunction:
|
|
72
|
+
arrow := current.AsArrowFunction()
|
|
73
|
+
return factory.UpdateArrowFunction(
|
|
74
|
+
arrow,
|
|
75
|
+
visitor.VisitModifiers(arrow.Modifiers()),
|
|
76
|
+
nil,
|
|
77
|
+
visitor.VisitNodes(arrow.Parameters),
|
|
78
|
+
nil,
|
|
79
|
+
nil,
|
|
80
|
+
visitor.VisitNode(arrow.EqualsGreaterThanToken),
|
|
81
|
+
visitor.VisitNode(arrow.Body),
|
|
82
|
+
)
|
|
83
|
+
case shimast.KindCallExpression:
|
|
84
|
+
call := current.AsCallExpression()
|
|
85
|
+
return factory.UpdateCallExpression(
|
|
86
|
+
call,
|
|
87
|
+
visitor.VisitNode(call.Expression),
|
|
88
|
+
visitor.VisitNode(call.QuestionDotToken),
|
|
89
|
+
nil,
|
|
90
|
+
visitor.VisitNodes(call.Arguments),
|
|
91
|
+
call.Flags,
|
|
92
|
+
)
|
|
93
|
+
case shimast.KindNewExpression:
|
|
94
|
+
expr := current.AsNewExpression()
|
|
95
|
+
return factory.UpdateNewExpression(
|
|
96
|
+
expr,
|
|
97
|
+
visitor.VisitNode(expr.Expression),
|
|
98
|
+
nil,
|
|
99
|
+
visitor.VisitNodes(expr.Arguments),
|
|
100
|
+
)
|
|
101
|
+
default:
|
|
102
|
+
return visitor.VisitEachChild(current)
|
|
103
|
+
}
|
|
104
|
+
}, factory, shimast.NodeVisitorHooks{})
|
|
105
|
+
return visitor.VisitNode(node)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
func rewriteNestiaIdentifiers(
|
|
109
|
+
node *shimast.Node,
|
|
110
|
+
substitutions map[string]string,
|
|
111
|
+
) *shimast.Node {
|
|
112
|
+
if node == nil || len(substitutions) == 0 {
|
|
113
|
+
return node
|
|
114
|
+
}
|
|
115
|
+
factory := shimast.NewNodeFactory(shimast.NodeFactoryHooks{})
|
|
116
|
+
var visitor *shimast.NodeVisitor
|
|
117
|
+
visitor = shimast.NewNodeVisitor(func(current *shimast.Node) *shimast.Node {
|
|
118
|
+
if current == nil {
|
|
119
|
+
return nil
|
|
120
|
+
}
|
|
121
|
+
switch current.Kind {
|
|
122
|
+
case shimast.KindIdentifier:
|
|
123
|
+
if replacement, ok := substitutions[current.Text()]; ok {
|
|
124
|
+
return rewriteNestiaIdentifierExpression(factory, replacement)
|
|
125
|
+
}
|
|
126
|
+
return current
|
|
127
|
+
case shimast.KindVariableDeclaration:
|
|
128
|
+
decl := current.AsVariableDeclaration()
|
|
129
|
+
return factory.UpdateVariableDeclaration(
|
|
130
|
+
decl,
|
|
131
|
+
decl.Name(),
|
|
132
|
+
nil,
|
|
133
|
+
nil,
|
|
134
|
+
visitor.VisitNode(decl.Initializer),
|
|
135
|
+
)
|
|
136
|
+
case shimast.KindParameter:
|
|
137
|
+
parameter := current.AsParameterDeclaration()
|
|
138
|
+
return factory.UpdateParameterDeclaration(
|
|
139
|
+
parameter,
|
|
140
|
+
parameter.Modifiers(),
|
|
141
|
+
parameter.DotDotDotToken,
|
|
142
|
+
parameter.Name(),
|
|
143
|
+
nil,
|
|
144
|
+
nil,
|
|
145
|
+
visitor.VisitNode(parameter.Initializer),
|
|
146
|
+
)
|
|
147
|
+
case shimast.KindPropertyAssignment:
|
|
148
|
+
assignment := current.AsPropertyAssignment()
|
|
149
|
+
return factory.UpdatePropertyAssignment(
|
|
150
|
+
assignment,
|
|
151
|
+
assignment.Modifiers(),
|
|
152
|
+
assignment.Name(),
|
|
153
|
+
assignment.PostfixToken,
|
|
154
|
+
nil,
|
|
155
|
+
visitor.VisitNode(assignment.Initializer),
|
|
156
|
+
)
|
|
157
|
+
case shimast.KindShorthandPropertyAssignment:
|
|
158
|
+
assignment := current.AsShorthandPropertyAssignment()
|
|
159
|
+
name := assignment.Name()
|
|
160
|
+
if name != nil && name.Kind == shimast.KindIdentifier {
|
|
161
|
+
if replacement, ok := substitutions[name.Text()]; ok &&
|
|
162
|
+
assignment.ObjectAssignmentInitializer == nil {
|
|
163
|
+
return factory.NewPropertyAssignment(
|
|
164
|
+
assignment.Modifiers(),
|
|
165
|
+
name,
|
|
166
|
+
assignment.PostfixToken,
|
|
167
|
+
nil,
|
|
168
|
+
rewriteNestiaIdentifierExpression(factory, replacement),
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return factory.UpdateShorthandPropertyAssignment(
|
|
173
|
+
assignment,
|
|
174
|
+
assignment.Modifiers(),
|
|
175
|
+
name,
|
|
176
|
+
assignment.PostfixToken,
|
|
177
|
+
nil,
|
|
178
|
+
nil,
|
|
179
|
+
visitor.VisitNode(assignment.ObjectAssignmentInitializer),
|
|
180
|
+
)
|
|
181
|
+
case shimast.KindPropertyAccessExpression:
|
|
182
|
+
access := current.AsPropertyAccessExpression()
|
|
183
|
+
return factory.UpdatePropertyAccessExpression(
|
|
184
|
+
access,
|
|
185
|
+
visitor.VisitNode(access.Expression),
|
|
186
|
+
access.QuestionDotToken,
|
|
187
|
+
access.Name(),
|
|
188
|
+
access.Flags,
|
|
189
|
+
)
|
|
190
|
+
default:
|
|
191
|
+
return visitor.VisitEachChild(current)
|
|
192
|
+
}
|
|
193
|
+
}, factory, shimast.NodeVisitorHooks{})
|
|
194
|
+
return visitor.VisitNode(node)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
func rewriteNestiaIdentifierExpression(
|
|
198
|
+
factory *shimast.NodeFactory,
|
|
199
|
+
replacement string,
|
|
200
|
+
) *shimast.Node {
|
|
201
|
+
parts := []string{}
|
|
202
|
+
start := 0
|
|
203
|
+
for i := 0; i <= len(replacement); i++ {
|
|
204
|
+
if i == len(replacement) || replacement[i] == '.' {
|
|
205
|
+
if start < i {
|
|
206
|
+
parts = append(parts, replacement[start:i])
|
|
207
|
+
}
|
|
208
|
+
start = i + 1
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if len(parts) == 0 {
|
|
212
|
+
return factory.NewIdentifier(replacement)
|
|
213
|
+
}
|
|
214
|
+
output := factory.NewIdentifier(parts[0])
|
|
215
|
+
for _, part := range parts[1:] {
|
|
216
|
+
output = factory.NewPropertyAccessExpression(
|
|
217
|
+
output,
|
|
218
|
+
nil,
|
|
219
|
+
factory.NewIdentifier(part),
|
|
220
|
+
shimast.NodeFlagsNone,
|
|
221
|
+
)
|
|
222
|
+
}
|
|
223
|
+
return output
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
func normalizeNestiaSyntheticTokens(node *shimast.Node) {
|
|
227
|
+
if node == nil {
|
|
228
|
+
return
|
|
229
|
+
}
|
|
230
|
+
if node.Kind == shimast.KindConditionalExpression {
|
|
231
|
+
conditional := node.AsConditionalExpression()
|
|
232
|
+
factory := shimast.NewNodeFactory(shimast.NodeFactoryHooks{})
|
|
233
|
+
if conditional.QuestionToken == nil {
|
|
234
|
+
conditional.QuestionToken = factory.NewToken(shimast.KindQuestionToken)
|
|
235
|
+
}
|
|
236
|
+
if conditional.ColonToken == nil {
|
|
237
|
+
conditional.ColonToken = factory.NewToken(nestiaKindColonToken)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
node.ForEachChild(func(child *shimast.Node) bool {
|
|
241
|
+
normalizeNestiaSyntheticTokens(child)
|
|
242
|
+
return false
|
|
243
|
+
})
|
|
244
|
+
}
|