Skip to content

Commit 0eea7d2

Browse files
committed
fix(ts): fix string as parameter issue
1 parent 41e62e7 commit 0eea7d2

2 files changed

Lines changed: 5 additions & 10 deletions

File tree

chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,6 @@ constructorDeclaration
444444
: accessibilityModifier? Constructor '(' formalParameterList? ')' block?
445445
;
446446

447-
//propertyMemberDeclaration
448-
// : abstractDeclaration
449-
// | propertyMember
450-
// ;
451-
452447
propertyMemberDeclaration
453448
: propertyMemberBase propertyName '!'? '?'? typeAnnotation? initializer? # PropertyDeclarationExpression
454449
| propertyMemberBase propertyName callSignature ( ('{' functionBody '}')) # MethodDeclarationExpression
@@ -457,7 +452,7 @@ propertyMemberDeclaration
457452
;
458453

459454
abstractDeclaration
460-
: Abstract (Identifier '?'? callSignature | variableStatement)
455+
: Abstract (identifierName '?'? callSignature | variableStatement)
461456
;
462457

463458
//propertyMember
@@ -495,7 +490,7 @@ formalParameterList
495490
;
496491

497492
formalParameterArg
498-
: decoratorList? accessibilityModifier? ReadOnly? identifierOrKeyWord '?'? typeAnnotation? ('=' singleExpression)? // ECMAScript 6: Initialization
493+
: decoratorList? accessibilityModifier? ReadOnly? identifierName '?'? typeAnnotation? ('=' singleExpression)? // ECMAScript 6: Initialization
499494
| lastFormalParameterArg
500495
// ([key, value]: [string, string[]])
501496
// | arrayLiteral (':' formalParameterList)? // ECMAScript 6: Parameter Context Matching

chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptAstListener.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ open class TypeScriptAstListener : TypeScriptParserBaseListener() {
1515
for (argCtx in formalParameterListContext!!.formalParameterArg()) {
1616
val typeType = this.buildTypeAnnotation(argCtx.typeAnnotation())
1717
var typeValue = argCtx.text
18-
if (argCtx.identifierOrKeyWord() != null) {
19-
typeValue = argCtx.identifierOrKeyWord().text
18+
if (argCtx.identifierName() != null) {
19+
typeValue = argCtx.identifierName().text
2020
}
2121

22-
val parameter = CodeProperty(TypeValue = typeValue, TypeType = typeType!!)
22+
val parameter = CodeProperty(TypeValue = typeValue, TypeType = typeType)
2323

2424
if (argCtx.accessibilityModifier() != null) {
2525
parameter.Modifiers += argCtx.accessibilityModifier().text

0 commit comments

Comments
 (0)