Skip to content

Commit fa9e70a

Browse files
committed
fix(ts): resolve all imports
1 parent e57af30 commit fa9e70a

3 files changed

Lines changed: 32 additions & 18 deletions

File tree

chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,10 +782,12 @@ singleExpression
782782
| jsxArrowFunction # JsxArrowFunctionExpression
783783
| Class Identifier? classTail # ClassExpression
784784
// this.form.value?.id?.[0]
785-
| singleExpression '?'? '!'? '.''[' expressionSequence ']' # MemberIndexExpression
785+
| singleExpression '?'? '!'? '.'? '[' expressionSequence ']' # MemberIndexExpression
786786
// for: `onHotUpdateSuccess?.();`
787787
// onChange?.(userName || password || null)
788-
| singleExpression '?'? '!'? '.' '#'? identifierName? nestedTypeGeneric? # MemberDotExpression
788+
| singleExpression '?'? '!'? '.' '#'? identifierName? nestedTypeGeneric? # MemberDotExpression
789+
// for: `onHotUpdateSuccess?.();`
790+
| singleExpression '?'? '!'? '.' '#'? '(' identifierName? ')' # MemberDotExpression
789791

790792
// samples: `error?.response?.data?.message ?? error.message;`
791793
| singleExpression '??' singleExpression # NullCoalesceExpression
@@ -835,6 +837,7 @@ singleExpression
835837
| arrayLiteral # ArrayLiteralExpression
836838
| objectLiteral # ObjectLiteralExpression
837839
| '(' expressionSequence ')' # ParenthesizedExpression
840+
| Of '(' expressionSequence ')' # OfParenthesizedExpression
838841
| typeArguments expressionSequence? # GenericTypes
839842
| singleExpression As asExpression # CastAsExpression
840843
| htmlElements # HtmlElementExpression

chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
7474

7575
}
7676
else -> {
77-
println("enterVariableStatement: ${it::class.java.simpleName} === ${it.text}")
77+
// println("enterVariableStatement: ${it::class.java.simpleName} === ${it.text}")
7878
}
7979
}
8080
}
@@ -116,7 +116,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
116116
}
117117
}
118118
else -> {
119-
println("variableToFields -> ${lastExpr.text} === ${lastExpr.javaClass.simpleName}")
119+
// println("variableToFields -> ${lastExpr.text} === ${lastExpr.javaClass.simpleName}")
120120
}
121121
}
122122

@@ -144,7 +144,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
144144
field.Calls += CodeCall("", CallType.FIELD, "", identExpr.identifierName().text)
145145
}
146146
else -> {
147-
println("todo -> var -> decl call: $name")
147+
// println("todo -> var -> decl call: $name")
148148
}
149149
}
150150
}
@@ -236,7 +236,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
236236
currentNode.Functions += codeFunction
237237
}
238238
else -> {
239-
println("handleClassBodyElements -> childElementType : $childElementType")
239+
// println("handleClassBodyElements -> childElementType : $childElementType")
240240
}
241241
}
242242
}
@@ -319,7 +319,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
319319
currentNode.Functions += func
320320
}
321321
else -> {
322-
println("enterInterfaceDeclaration -> buildInterfaceBody")
322+
// println("enterInterfaceDeclaration -> buildInterfaceBody")
323323
}
324324
}
325325
}
@@ -494,7 +494,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
494494
}
495495
else -> {
496496
val text = statementParent.text
497-
println("enterArrowFunctionDeclaration -> $parentName, $text")
497+
// println("enterArrowFunctionDeclaration -> $parentName, $text")
498498
}
499499
}
500500

@@ -589,7 +589,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
589589
defaultNode.Functions += currentFunc
590590
}
591591
else -> {
592-
println("enterFunctionExpressionDeclaration -> $parentName, ${statementParent.text} ")
592+
// println("enterFunctionExpressionDeclaration -> $parentName, ${statementParent.text} ")
593593
}
594594
}
595595
}
@@ -655,7 +655,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
655655
currentFunc.FunctionCalls += CodeCall("", CallType.FUNCTION, "", currentExprIdent, parameters)
656656
}
657657
else -> {
658-
println("todo -> need support type: ${ctx::class.java.simpleName} ==== ${ctx.text}")
658+
// println("todo -> need support type: ${ctx::class.java.simpleName} ==== ${ctx.text}")
659659
}
660660
}
661661
}
@@ -708,7 +708,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
708708
currentExprIdent = ident.identifierName().text
709709
}
710710
else -> {
711-
println("MemberDotExpressionContext: -> $subName")
711+
// println("MemberDotExpressionContext: -> $subName")
712712
}
713713
}
714714

@@ -722,7 +722,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
722722

723723
}
724724
else -> {
725-
println("singleExpression -> ArgumentsExpressionContext -> $childName")
725+
// println("singleExpression -> ArgumentsExpressionContext -> $childName")
726726
}
727727
}
728728
}
@@ -762,7 +762,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
762762
parameter = CodeProperty(TypeValue = singleExpToText(subSingle), TypeType = "string")
763763
}
764764
else -> {
765-
println("todo -> ParenthesizedExpressionContext: $simpleName, text: ${subSingle.text}")
765+
// println("todo -> ParenthesizedExpressionContext: $simpleName, text: ${subSingle.text}")
766766
}
767767
}
768768

@@ -791,7 +791,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
791791
root += prop
792792
}
793793
else -> {
794-
println(propName)
794+
// println(propName)
795795
}
796796
}
797797
}
@@ -847,10 +847,10 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
847847
currentFunc.FunctionCalls += codeCall
848848
}
849849
"IdentifierExpressionContext" -> {
850-
println("enterExpressionStatement -> IdentifierExpressionContext: ${singleExprCtx.text}")
850+
// println("enterExpressionStatement -> IdentifierExpressionContext: ${singleExprCtx.text}")
851851
}
852852
else -> {
853-
println("enterExpressionStatement : $singleCtxType")
853+
// println("enterExpressionStatement : $singleCtxType")
854854
}
855855
}
856856

@@ -918,7 +918,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
918918
parseSingleExpression(identExpr.singleExpression())
919919
}
920920
else -> {
921-
println("IdentifierExpressionContext -> others variable decl: $identExprText ==== ${singleExprCtx.text}")
921+
// println("IdentifierExpressionContext -> others variable decl: $identExprText ==== ${singleExprCtx.text}")
922922
}
923923
}
924924
}
@@ -936,7 +936,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
936936
parseParenthesizedExpression(singleExprCtx as ParenthesizedExpressionContext)
937937
}
938938
else -> {
939-
println("enterVariableDeclaration : $singleCtxType === ${ctx.text}")
939+
// println("enterVariableDeclaration : $singleCtxType === ${ctx.text}")
940940
}
941941
}
942942
}

chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptRegressionTest.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ if (node in graph) {
2929
3030
}
3131
}
32+
33+
of(data)
3234
"""
3335

3436
TypeScriptAnalyser().analysis(code, "index.tsx")
@@ -63,6 +65,15 @@ if (node in graph) {
6365
TypeScriptAnalyser().analysis(code, "index.tsx")
6466
}
6567

68+
@Test
69+
fun array_in_for_loop() {
70+
val code = """this.names.forEach((it, index) => {
71+
multiSelect('', this.accessor[index])
72+
})
73+
"""
74+
TypeScriptAnalyser().analysis(code, "index.tsx")
75+
}
76+
6677
@Test
6778
fun query_array_literal() {
6879
val code = """

0 commit comments

Comments
 (0)