Skip to content

Commit

Permalink
fix(ts): fix class abstract error issue
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Nov 17, 2022
1 parent 4640f34 commit d54c1f0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
10 changes: 5 additions & 5 deletions chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ constructSignature
;

callSignature
: typeParameters? parameterBlock ( ':' typePredicateWithOperatorTypeRef | typeAnnotation)?
: typeParameters? parameterBlock (':' (typePredicateWithOperatorTypeRef | typeRef))?
;

indexSignature
Expand Down Expand Up @@ -437,7 +437,7 @@ classMemberList
classMember
: constructorDeclaration
| indexSignature
| decoratorList? propertyMemberDeclaration
| decoratorList? propertyMemberDeclaration eos
;

constructorDeclaration
Expand All @@ -450,14 +450,14 @@ constructorDeclaration
// ;

propertyMemberDeclaration
: propertyMemberBase propertyName '!'? '?'? typeAnnotation? initializer? SemiColon # PropertyDeclarationExpression
| propertyMemberBase propertyName callSignature ( ('{' functionBody '}') | SemiColon) # MethodDeclarationExpression
: propertyMemberBase propertyName '!'? '?'? typeAnnotation? initializer? # PropertyDeclarationExpression
| propertyMemberBase propertyName callSignature ( ('{' functionBody '}')) # MethodDeclarationExpression
| propertyMemberBase (getAccessor | setAccessor) # GetterSetterDeclarationExpression
| abstractDeclaration # AbstractMemberDeclaration
;

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

//propertyMember
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ open class TypeScriptAstListener : TypeScriptParserBaseListener() {
// }
// }

return processRef(type)
return processRef(typeContext)
}

fun processRef(type: TypeScriptParser.TypeRefContext): String {
return type.text
}

// private fun handleTypeAnnotationPrimary(typeContext: TypeScriptParser.PrimaryContext, typ: String?): String? {
Expand Down Expand Up @@ -154,8 +158,4 @@ open class TypeScriptAstListener : TypeScriptParserBaseListener() {
}
return annotation
}

private fun processRef(type: String): String {
return type
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import chapi.ast.antlr.TypeScriptParser.IdentifierExpressionContext
import chapi.ast.antlr.TypeScriptParser.ParenthesizedExpressionContext
import chapi.domain.core.*
import chapi.infra.Stack
import org.antlr.v4.runtime.ParserRuleContext
import org.antlr.v4.runtime.tree.TerminalNodeImpl

class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
Expand Down Expand Up @@ -226,8 +225,8 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
)
val callSignCtx = childCtx.callSignature()

if (callSignCtx.typeAnnotation() != null) {
codeFunction.ReturnType = buildTypeAnnotation(callSignCtx.typeAnnotation())!!
if (callSignCtx.typeRef() != null) {
codeFunction.ReturnType = processRef(callSignCtx.typeRef())
}

codeFunction.FilePath = filePath
Expand Down

0 comments on commit d54c1f0

Please sign in to comment.