From 6df62c494295e554ba212f3992a9017ee2b7ce16 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Wed, 16 Nov 2022 11:15:08 +0800 Subject: [PATCH] fix(ts): fix nested error issues --- .../src/main/antlr/TypeScriptParser.g4 | 4 ++-- .../TypeScriptFullIdentListener.kt | 3 +-- .../typescriptast/TypeScriptRegressionTest.kt | 19 ++++++++++--------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 b/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 index 7effef9a..14b79603 100644 --- a/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 +++ b/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 @@ -139,11 +139,11 @@ nestedTypeGeneric // TODO: Fix recursive // typeGeneric - : '<' typeArgumentList '>' + : '<' typeArgumentList typeGeneric? '>' ; typeIncludeGeneric - :'<' typeArgumentList '<' typeArgumentList ('>' bindingPattern '>' | '>>') + :'<' typeArgumentList '<' typeArgumentList ('>' bindingPattern '>' | '>>' | '>>>' | '>'*) ; typeName 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 c3bd46ad..d2d9b1b8 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 @@ -5,8 +5,7 @@ import chapi.ast.antlr.TypeScriptParser.IdentifierExpressionContext import chapi.ast.antlr.TypeScriptParser.ParenthesizedExpressionContext import chapi.domain.core.* import chapi.infra.Stack -import kotlinx.serialization.encodeToString -import kotlinx.serialization.json.Json +import org.antlr.v4.runtime.ParserRuleContext class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() { private var hasHtmlElement: Boolean = false diff --git a/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptRegressionTest.kt b/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptRegressionTest.kt index 31e183e0..b674ee03 100644 --- a/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptRegressionTest.kt +++ b/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptRegressionTest.kt @@ -1,7 +1,5 @@ package chapi.ast.typescriptast -import kotlinx.serialization.encodeToString -import kotlinx.serialization.json.Json import org.junit.jupiter.api.Test class TypeScriptRegressionTest { @@ -108,13 +106,6 @@ export class DemoComponent implements OnInit, ControlValueAccessor { val code2 = """export type MakeOptional = Omit & { [SubKey in K]?: Maybe };""" TypeScriptAnalyser().analysis(code2, "index.tsx") - - val code3 = """export type Maybe = Maybe - )>>>""" - - TypeScriptAnalyser().analysis(code3, "index.tsx") } @Test @@ -133,4 +124,14 @@ export class DemoComponent implements OnInit, ControlValueAccessor { TypeScriptAnalyser().analysis(code, "index.tsx") } + + @Test + fun nested_type() { + val code = """export type Query = Array>>""" + + TypeScriptAnalyser().analysis(code, "index.tsx") + + val code2 = """export type Query = Array>>>""" + TypeScriptAnalyser().analysis(code2, "index.tsx") + } }