From ad68a8a9b00e9d88e32c70f0641ec4b0f71a67e8 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Sat, 12 Mar 2022 16:36:30 +0800 Subject: [PATCH] fix(grammar-ts): fix any in objectLiteral type issue --- .../src/main/antlr/TypeScriptParser.g4 | 5 +++-- .../TypeScriptFullIdentListenerTest.kt | 20 ++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 b/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 index ead0a9ec..42d0f53e 100644 --- a/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 +++ b/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 @@ -82,6 +82,7 @@ typeArgument type_ : (Keyof | Typeof)* unionOrIntersectionOrPrimaryType + | unionOrIntersectionOrPrimaryType | functionType | constructorType | typeGeneric @@ -168,7 +169,6 @@ typeMember | methodSignature ('=>' type_)? | enumSignature | '[' typeReference In typeReference ']' typeAnnotation -// | objectSignature ; arrayType @@ -909,7 +909,7 @@ identifierOrKeyWord | Module | Default | Lodash Lodash? - | Dollar Dollar? + | Any ; reservedWord @@ -972,6 +972,7 @@ keyword | TypeAlias | String | Undefined + | Any ; getter 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 e44c146f..d3163ede 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 @@ -1265,8 +1265,26 @@ const docs = { @Test internal fun keyofTypeOf() { val code = """ -const getClazzColumnsBy = (type: keyof typeof columnCount) => { +const getClazzColumnsBy = (type: keyof typeof columnCount) => {} +""" + val codeFile = TypeScriptAnalyser().analysis(code, "index.tsx") + assertEquals(1, codeFile.DataStructures.size) + } + @Test + internal fun someIssue() { + val code = """ +export function getChartsOption(data?: number[]): EChartOption { + return { + series: !data ? defaultSeriesMarkLineOpt : + [...defaultSeriesMarkLineOpt, { + data: [data], + tooltip: { + formatter: ({ value }: any) => {} + } + }, + ] + } } """ val codeFile = TypeScriptAnalyser().analysis(code, "index.tsx")