From b548af9b20d90cbb8c9d07b307be1842ae136851 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Tue, 15 Nov 2022 19:39:06 +0800 Subject: [PATCH] feat(ts): add readonly issue --- .../src/main/antlr/TypeScriptParser.g4 | 2 +- .../ast/typescriptast/TypeScriptRegressionTest.kt | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 b/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 index 5f9c83b9..565015c0 100644 --- a/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 +++ b/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 @@ -686,7 +686,7 @@ formalParameterList ; formalParameterArg - : decorator? accessibilityModifier? identifierOrKeyWord '?'? typeAnnotation? ('=' singleExpression)? // ECMAScript 6: Initialization + : decorator? accessibilityModifier? ReadOnly? identifierOrKeyWord '?'? typeAnnotation? ('=' singleExpression)? // ECMAScript 6: Initialization | lastFormalParameterArg // ([key, value]: [string, string[]]) | arrayLiteral (':' formalParameterList)? // ECMAScript 6: Parameter Context Matching 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 de398461..83d26008 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 @@ -84,4 +84,17 @@ export class DemoComponent implements OnInit, ControlValueAccessor { }""" TypeScriptAnalyser().analysis(code, "index.tsx") } + + @Test + fun readonly_property() { + val code = """class DataSource extends Data { + readonly pageSize = 5; + + constructor(public readonly type: TaskEnum,) { + super(); + } +}""" + + TypeScriptAnalyser().analysis(code, "index.tsx") + } }