Skip to content

Commit 41e62e7

Browse files
committed
fix(ts): fix axios<Info>(){} call issue
1 parent d54c1f0 commit 41e62e7

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,8 @@ propertyAssignment
622622
| setAccessor # PropertySetter
623623
| generatorMethod # MethodProperty
624624
| restParameter # RestParameterInObject
625+
// for es6 { baseUrl , }
626+
| identifierName # PropertyShorthand
625627
;
626628

627629
propertyName
@@ -921,7 +923,7 @@ singleExpression
921923
| singleExpression As asExpression # CastAsExpression
922924

923925
// TODO: careful use those
924-
| singleExpression typeArguments? arguments # ArgumentsExpression
926+
| singleExpression typeArguments? '(' (argumentList ','?)? ')' # ArgumentsExpression
925927
| htmlElements # HtmlElementExpression
926928
;
927929

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
806806
when (singleExprCtx) {
807807
is TypeScriptParser.ArgumentsExpressionContext -> {
808808
currentFunc.FunctionCalls += CodeCall(
809-
Parameters = buildArguments(singleExprCtx.arguments()),
809+
Parameters = processArgumentList(singleExprCtx.argumentList()),
810810
FunctionName = buildFunctionName(singleExprCtx),
811811
NodeName = wrapTargetType(singleExprCtx),
812812
Position = buildPosition(ctx)
@@ -911,7 +911,12 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
911911
return arrayOf()
912912
}
913913

914-
return arguments?.argumentList()?.argument()?.map {
914+
val argumentList = arguments?.argumentList()
915+
return processArgumentList(argumentList)
916+
}
917+
918+
private fun processArgumentList(argumentList: TypeScriptParser.ArgumentListContext?) =
919+
argumentList?.argument()?.map {
915920
parseSingleExpression(it.singleExpression())
916921
val typeValue: String = when (val expr = it.singleExpression()) {
917922
is TypeScriptParser.LiteralExpressionContext -> {
@@ -921,14 +926,14 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
921926
it.text
922927
}
923928
}
929+
924930
else -> {
925931
it.text;
926932
}
927933
}
928934

929935
CodeProperty(TypeValue = typeValue, TypeType = "")
930936
}?.toTypedArray() ?: arrayOf()
931-
}
932937

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

0 commit comments

Comments
 (0)