Skip to content

Commit ec26282

Browse files
committed
fix(ts): fix function decl error issues
1 parent db90510 commit ec26282

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ constructSignature
356356
;
357357

358358
callSignature
359-
: typeParameters? '(' parameterList? ','? ')' (':' (typePredicateWithOperatorTypeRef | typeRef))?
359+
: typeParameters? '(' parameterList? ','? ')' (':' (typePredicateWithOperatorTypeRef | typeRef))? eos?
360360
;
361361

362362
indexSignature
@@ -401,7 +401,7 @@ enumMember
401401
// Function Declaration
402402

403403
functionDeclaration
404-
: propertyMemberBase? Function '*'? identifierName callSignature functionBody? SemiColon?
404+
: propertyMemberBase? Function '*'? identifierName callSignature '{' functionBody '}' eos?
405405
;
406406

407407
functionBody
@@ -831,7 +831,7 @@ breakStatement
831831

832832

833833
returnStatement
834-
: Return ({this.notLineTerminator()}? expressionSequence)? eos
834+
: Return ({this.notLineTerminator()}? expressionSequence)? eos?
835835
// | Return '(' htmlElements ')' eos
836836
;
837837

@@ -857,7 +857,7 @@ debuggerStatement
857857

858858

859859
expressionStatement
860-
: {this.notOpenBraceAndNotFunction()}? expressionSequence eos
860+
: {this.notOpenBraceAndNotFunction()}? expressionSequence eos?
861861
;
862862

863863

@@ -923,6 +923,7 @@ singleExpression
923923
| yieldStatement # YieldExpression // ECMAScript 6
924924
| Await singleExpression # AwaitExpression
925925
| typeArguments? identifierName singleExpression? # IdentifierExpression
926+
926927
| typeArguments expressionSequence? # GenericTypes
927928
| literal # LiteralExpression
928929
| arrayLiteral # ArrayLiteralExpression
@@ -981,7 +982,7 @@ unaryOperator
981982

982983

983984
generatorFunctionDeclaration
984-
: Function '*' Identifier? '(' formalParameterList? ')' '{' functionBody '}'
985+
: Function '*' Identifier? '(' formalParameterList? ')' '{' functionBody? '}'
985986
;
986987

987988
generatorBlock

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,12 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
754754
return objectLiteral.propertyAssignment().mapNotNull { property ->
755755
when (property) {
756756
is TypeScriptParser.PropertyExpressionAssignmentContext -> {
757-
val text = singleExpToText(property.singleExpression())
757+
val text = if(property.singleExpression() != null) {
758+
property.singleExpression().text
759+
} else {
760+
property.text
761+
}
762+
758763
val value = CodeProperty(TypeType = "value", TypeValue = text)
759764
val propText = property.propertyName().text
760765

chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListenerTest.kt

+2
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,8 @@ export function querySystemInfo() {
605605
val dataStruct = codeFile.DataStructures[0]
606606
val calls = dataStruct.Functions[0].FunctionCalls
607607

608+
println(Json.encodeToString(calls))
609+
608610
assertEquals(1, calls.size)
609611
assertEquals(1, dataStruct.Fields.size);
610612
assertEquals("systemInfoApi", dataStruct.Fields[0].TypeKey);

0 commit comments

Comments
 (0)