From 0eea7d270b5b5887319930e514b1e008fc3a32e6 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Thu, 17 Nov 2022 08:47:18 +0800 Subject: [PATCH] fix(ts): fix string as parameter issue --- chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 | 9 ++------- .../chapi/ast/typescriptast/TypeScriptAstListener.kt | 6 +++--- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 b/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 index f2e858c9..cc48c845 100644 --- a/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 +++ b/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 @@ -444,11 +444,6 @@ constructorDeclaration : accessibilityModifier? Constructor '(' formalParameterList? ')' block? ; -//propertyMemberDeclaration -// : abstractDeclaration -// | propertyMember -// ; - propertyMemberDeclaration : propertyMemberBase propertyName '!'? '?'? typeAnnotation? initializer? # PropertyDeclarationExpression | propertyMemberBase propertyName callSignature ( ('{' functionBody '}')) # MethodDeclarationExpression @@ -457,7 +452,7 @@ propertyMemberDeclaration ; abstractDeclaration - : Abstract (Identifier '?'? callSignature | variableStatement) + : Abstract (identifierName '?'? callSignature | variableStatement) ; //propertyMember @@ -495,7 +490,7 @@ formalParameterList ; formalParameterArg - : decoratorList? accessibilityModifier? ReadOnly? identifierOrKeyWord '?'? typeAnnotation? ('=' singleExpression)? // ECMAScript 6: Initialization + : decoratorList? accessibilityModifier? ReadOnly? identifierName '?'? typeAnnotation? ('=' singleExpression)? // ECMAScript 6: Initialization | lastFormalParameterArg // ([key, value]: [string, string[]]) // | arrayLiteral (':' formalParameterList)? // ECMAScript 6: Parameter Context Matching diff --git a/chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptAstListener.kt b/chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptAstListener.kt index 7fd3dae7..8ab5aaf2 100644 --- a/chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptAstListener.kt +++ b/chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptAstListener.kt @@ -15,11 +15,11 @@ open class TypeScriptAstListener : TypeScriptParserBaseListener() { for (argCtx in formalParameterListContext!!.formalParameterArg()) { val typeType = this.buildTypeAnnotation(argCtx.typeAnnotation()) var typeValue = argCtx.text - if (argCtx.identifierOrKeyWord() != null) { - typeValue = argCtx.identifierOrKeyWord().text + if (argCtx.identifierName() != null) { + typeValue = argCtx.identifierName().text } - val parameter = CodeProperty(TypeValue = typeValue, TypeType = typeType!!) + val parameter = CodeProperty(TypeValue = typeValue, TypeType = typeType) if (argCtx.accessibilityModifier() != null) { parameter.Modifiers += argCtx.accessibilityModifier().text