Skip to content

Commit

Permalink
fix(ts): fix function decl error issues
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Nov 17, 2022
1 parent db90510 commit ec26282
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
11 changes: 6 additions & 5 deletions chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ constructSignature
;

callSignature
: typeParameters? '(' parameterList? ','? ')' (':' (typePredicateWithOperatorTypeRef | typeRef))?
: typeParameters? '(' parameterList? ','? ')' (':' (typePredicateWithOperatorTypeRef | typeRef))? eos?
;

indexSignature
Expand Down Expand Up @@ -401,7 +401,7 @@ enumMember
// Function Declaration

functionDeclaration
: propertyMemberBase? Function '*'? identifierName callSignature functionBody? SemiColon?
: propertyMemberBase? Function '*'? identifierName callSignature '{' functionBody '}' eos?
;

functionBody
Expand Down Expand Up @@ -831,7 +831,7 @@ breakStatement


returnStatement
: Return ({this.notLineTerminator()}? expressionSequence)? eos
: Return ({this.notLineTerminator()}? expressionSequence)? eos?
// | Return '(' htmlElements ')' eos
;

Expand All @@ -857,7 +857,7 @@ debuggerStatement


expressionStatement
: {this.notOpenBraceAndNotFunction()}? expressionSequence eos
: {this.notOpenBraceAndNotFunction()}? expressionSequence eos?
;


Expand Down Expand Up @@ -923,6 +923,7 @@ singleExpression
| yieldStatement # YieldExpression // ECMAScript 6
| Await singleExpression # AwaitExpression
| typeArguments? identifierName singleExpression? # IdentifierExpression

| typeArguments expressionSequence? # GenericTypes
| literal # LiteralExpression
| arrayLiteral # ArrayLiteralExpression
Expand Down Expand Up @@ -981,7 +982,7 @@ unaryOperator


generatorFunctionDeclaration
: Function '*' Identifier? '(' formalParameterList? ')' '{' functionBody '}'
: Function '*' Identifier? '(' formalParameterList? ')' '{' functionBody? '}'
;

generatorBlock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,12 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
return objectLiteral.propertyAssignment().mapNotNull { property ->
when (property) {
is TypeScriptParser.PropertyExpressionAssignmentContext -> {
val text = singleExpToText(property.singleExpression())
val text = if(property.singleExpression() != null) {
property.singleExpression().text
} else {
property.text
}

val value = CodeProperty(TypeType = "value", TypeValue = text)
val propText = property.propertyName().text

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,8 @@ export function querySystemInfo() {
val dataStruct = codeFile.DataStructures[0]
val calls = dataStruct.Functions[0].FunctionCalls

println(Json.encodeToString(calls))

assertEquals(1, calls.size)
assertEquals(1, dataStruct.Fields.size);
assertEquals("systemInfoApi", dataStruct.Fields[0].TypeKey);
Expand Down

0 comments on commit ec26282

Please sign in to comment.