Skip to content

Commit

Permalink
fix(ts): fix axios<Info>(){} call issue
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Nov 17, 2022
1 parent d54c1f0 commit 41e62e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,8 @@ propertyAssignment
| setAccessor # PropertySetter
| generatorMethod # MethodProperty
| restParameter # RestParameterInObject
// for es6 { baseUrl , }
| identifierName # PropertyShorthand
;

propertyName
Expand Down Expand Up @@ -921,7 +923,7 @@ singleExpression
| singleExpression As asExpression # CastAsExpression

// TODO: careful use those
| singleExpression typeArguments? arguments # ArgumentsExpression
| singleExpression typeArguments? '(' (argumentList ','?)? ')' # ArgumentsExpression
| htmlElements # HtmlElementExpression
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
when (singleExprCtx) {
is TypeScriptParser.ArgumentsExpressionContext -> {
currentFunc.FunctionCalls += CodeCall(
Parameters = buildArguments(singleExprCtx.arguments()),
Parameters = processArgumentList(singleExprCtx.argumentList()),
FunctionName = buildFunctionName(singleExprCtx),
NodeName = wrapTargetType(singleExprCtx),
Position = buildPosition(ctx)
Expand Down Expand Up @@ -911,7 +911,12 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
return arrayOf()
}

return arguments?.argumentList()?.argument()?.map {
val argumentList = arguments?.argumentList()
return processArgumentList(argumentList)
}

private fun processArgumentList(argumentList: TypeScriptParser.ArgumentListContext?) =
argumentList?.argument()?.map {
parseSingleExpression(it.singleExpression())
val typeValue: String = when (val expr = it.singleExpression()) {
is TypeScriptParser.LiteralExpressionContext -> {
Expand All @@ -921,14 +926,14 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
it.text
}
}

else -> {
it.text;
}
}

CodeProperty(TypeValue = typeValue, TypeType = "")
}?.toTypedArray() ?: arrayOf()
}

// override fun enterExportDefaultDeclaration(ctx: TypeScriptParser.ExportDefaultDeclarationContext?) {
// val singleExpr = ctx!!.singleExpression()
Expand Down

0 comments on commit 41e62e7

Please sign in to comment.