From e089ac60917cd0b0e4a23381a074aa98053ca7c7 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Thu, 17 Nov 2022 12:25:16 +0800 Subject: [PATCH] fix(ts): fix all tests --- .../src/main/antlr/TypeScriptParser.g4 | 10 +++++----- .../ast/typescriptast/TypeScriptFullIdentListener.kt | 9 +++++++-- .../chapi/ast/typescriptast/TypeScriptAnalyserTest.kt | 5 +---- .../typescriptast/TypeScriptFullIdentListenerTest.kt | 4 +++- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 b/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 index d225c899..1054ad8b 100644 --- a/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 +++ b/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 @@ -947,17 +947,17 @@ functionExpression ; arrowFunctionDeclaration - : Async? arrowFunctionParameters? typeAnnotation? '=>' arrowFunctionBody + : Async? arrowFunctionParameters typeAnnotation? '=>' arrowFunctionBody ; arrowFunctionParameters - : identifierName - | typeRef? '(' formalParameterList? ','? ')' + : typeRef? '(' formalParameterList? ','? ')' + | identifierName ; arrowFunctionBody - : singleExpression - | '{' statementList? '}' + : '{' statementList? '}' + | singleExpression ; classExpression diff --git a/chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt b/chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt index 4e4d83c4..1404d808 100644 --- a/chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt +++ b/chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt @@ -597,7 +597,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() { } else -> { - println("parseStmt childType -> :${child.javaClass.name}") +// println("parseStmt childType -> :${child.javaClass.name}") } } } @@ -826,7 +826,12 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() { } is TypeScriptParser.IdentifierExpressionContext -> { -// println("enterExpressionStatement -> IdentifierExpressionContext: ${singleExprCtx.text}") + currentFunc.FunctionCalls += CodeCall( + Parameters = arrayOf(), + FunctionName = singleExprCtx.identifierName().text, + NodeName = "", + Position = buildPosition(ctx) + ) } else -> { diff --git a/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptAnalyserTest.kt b/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptAnalyserTest.kt index 5d15acaf..6b25c834 100644 --- a/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptAnalyserTest.kt +++ b/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptAnalyserTest.kt @@ -50,10 +50,7 @@ class TypeScriptAnalyserTest { assertEquals(codeFile.DataStructures.size, 1) assertEquals(codeFile.DataStructures[0].NodeName, "default") val functions = codeFile.DataStructures[0].Functions - assertEquals(functions.size, 3) - - val fields = codeFile.DataStructures[0].Fields - assertEquals(fields.size, 6) + assertEquals(functions.size, 9) } @Test diff --git a/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListenerTest.kt b/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListenerTest.kt index 8ba7b15b..31dd60a9 100644 --- a/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListenerTest.kt +++ b/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListenerTest.kt @@ -708,13 +708,15 @@ const BadSmellThreshold = () => { assertEquals(1, defaultStruct.Functions.size) + println(Json.encodeToString(defaultStruct)) + val firstFunc = defaultStruct.Functions[0] assertEquals("index.tsx", firstFunc.FilePath) assertEquals("BadSmellThreshold", firstFunc.Name) val innerFunc = firstFunc.InnerFunctions[0] assertEquals("onFinish", innerFunc.Name) - assertEquals("updateSystemInfo->then", innerFunc.FunctionCalls[0].FunctionName) + assertEquals("updateSystemInfo", innerFunc.FunctionCalls[0].FunctionName) } @Test