Skip to content

Commit

Permalink
fix(ts): fix string as parameter issue
Browse files Browse the repository at this point in the history
phodal committed Nov 17, 2022

Verified

This commit was signed with the committer’s verified signature.
bcoe Benjamin E. Coe
1 parent 41e62e7 commit 0eea7d2
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
@@ -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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0eea7d2

Please sign in to comment.