From d704aae667fbb6bd6d00eb1612fb11ede1289df7 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Tue, 15 Nov 2022 21:54:37 +0800 Subject: [PATCH] fix(ts): fix type abstract ? issues --- chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 | 4 ++-- .../chapi/ast/typescriptast/TypeScriptRegressionTest.kt | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 b/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 index f4d38755..234059ed 100644 --- a/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 +++ b/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 @@ -211,7 +211,7 @@ typeAnnotation ; callSignature - : typeParameters? '(' parameterList? ','? ')' typeAnnotation? + : typeParameters? '(' parameterList? ','? ')' typeAnnotation? ';'? ; parameterList @@ -390,7 +390,7 @@ statementList ; abstractDeclaration - : Abstract (Identifier callSignature | variableStatement) eos + : Abstract (Identifier '?'? callSignature | variableStatement) eos ; importStatement 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 6081baa4..dd64de67 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 @@ -108,6 +108,15 @@ export class DemoComponent implements OnInit, ControlValueAccessor { TypeScriptAnalyser().analysis(code2, "index.tsx") } + @Test + fun type_in_interface() { + val code = """export abstract class ReactiveOptionProviderService { + abstract create?(name: string): Observable; +}""" + + TypeScriptAnalyser().analysis(code, "index.tsx") + } + @Test fun numeric_separators() { val code = """if (+value > 1_000_000_000) {