Skip to content

Commit

Permalink
fix(ts): fix string as parameter issue
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Nov 17, 2022
1 parent 41e62e7 commit 0eea7d2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
9 changes: 2 additions & 7 deletions chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,6 @@ constructorDeclaration
: accessibilityModifier? Constructor '(' formalParameterList? ')' block?
;

//propertyMemberDeclaration
// : abstractDeclaration
// | propertyMember
// ;

propertyMemberDeclaration
: propertyMemberBase propertyName '!'? '?'? typeAnnotation? initializer? # PropertyDeclarationExpression
| propertyMemberBase propertyName callSignature ( ('{' functionBody '}')) # MethodDeclarationExpression
Expand All @@ -457,7 +452,7 @@ propertyMemberDeclaration
;

abstractDeclaration
: Abstract (Identifier '?'? callSignature | variableStatement)
: Abstract (identifierName '?'? callSignature | variableStatement)
;

//propertyMember
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0eea7d2

Please sign in to comment.