From ec6fafbd8a3a66db135e070fe00608c6436cadd6 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Sat, 9 Apr 2022 17:02:44 +0800 Subject: [PATCH] feat(typescript): add exports to name support --- .../ast/typescriptast/TypeScriptFullIdentListener.kt | 10 ++++++++++ .../chapi/ast/typescriptast/TypeScriptAnalyserTest.kt | 1 + 2 files changed, 11 insertions(+) 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 ff7ae891..a9795d5a 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 @@ -963,6 +963,16 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() { return args } + override fun enterExportDefaultDeclaration(ctx: TypeScriptParser.ExportDefaultDeclarationContext?) { + val singleExpr = ctx!!.singleExpression() + if (singleExpr != null) { + if (!singleExpr.text.contains("(")) { + currentNode.Exports += CodeExport(singleExpr.text) + defaultNode.Exports += CodeExport(singleExpr.text) + } + } + } + fun getNodeInfo(): CodeContainer { for (entry in nodeMap) { codeContainer.DataStructures += entry.value 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 ba75ae00..a38a2f6e 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 @@ -57,6 +57,7 @@ internal class TypeScriptAnalyserTest { val codeFile = TypeScriptAnalyser().analysis(content, "BadSmellThreshold.tsx") assertEquals(codeFile.DataStructures.size, 1) + assertEquals(codeFile.DataStructures[0].Exports[0].Name, "BadSmellThreshold") } @Test