Skip to content

Commit

Permalink
fix(ts): resolve all imports
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Nov 15, 2022
1 parent e57af30 commit fa9e70a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
7 changes: 5 additions & 2 deletions chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -782,10 +782,12 @@ singleExpression
| jsxArrowFunction # JsxArrowFunctionExpression
| Class Identifier? classTail # ClassExpression
// this.form.value?.id?.[0]
| singleExpression '?'? '!'? '.''[' expressionSequence ']' # MemberIndexExpression
| singleExpression '?'? '!'? '.'? '[' expressionSequence ']' # MemberIndexExpression
// for: `onHotUpdateSuccess?.();`
// onChange?.(userName || password || null)
| singleExpression '?'? '!'? '.' '#'? identifierName? nestedTypeGeneric? # MemberDotExpression
| singleExpression '?'? '!'? '.' '#'? identifierName? nestedTypeGeneric? # MemberDotExpression
// for: `onHotUpdateSuccess?.();`
| singleExpression '?'? '!'? '.' '#'? '(' identifierName? ')' # MemberDotExpression

// samples: `error?.response?.data?.message ?? error.message;`
| singleExpression '??' singleExpression # NullCoalesceExpression
Expand Down Expand Up @@ -835,6 +837,7 @@ singleExpression
| arrayLiteral # ArrayLiteralExpression
| objectLiteral # ObjectLiteralExpression
| '(' expressionSequence ')' # ParenthesizedExpression
| Of '(' expressionSequence ')' # OfParenthesizedExpression
| typeArguments expressionSequence? # GenericTypes
| singleExpression As asExpression # CastAsExpression
| htmlElements # HtmlElementExpression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {

}
else -> {
println("enterVariableStatement: ${it::class.java.simpleName} === ${it.text}")
// println("enterVariableStatement: ${it::class.java.simpleName} === ${it.text}")
}
}
}
Expand Down Expand Up @@ -116,7 +116,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
}
}
else -> {
println("variableToFields -> ${lastExpr.text} === ${lastExpr.javaClass.simpleName}")
// println("variableToFields -> ${lastExpr.text} === ${lastExpr.javaClass.simpleName}")
}
}

Expand Down Expand Up @@ -144,7 +144,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
field.Calls += CodeCall("", CallType.FIELD, "", identExpr.identifierName().text)
}
else -> {
println("todo -> var -> decl call: $name")
// println("todo -> var -> decl call: $name")
}
}
}
Expand Down Expand Up @@ -236,7 +236,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
currentNode.Functions += codeFunction
}
else -> {
println("handleClassBodyElements -> childElementType : $childElementType")
// println("handleClassBodyElements -> childElementType : $childElementType")
}
}
}
Expand Down Expand Up @@ -319,7 +319,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
currentNode.Functions += func
}
else -> {
println("enterInterfaceDeclaration -> buildInterfaceBody")
// println("enterInterfaceDeclaration -> buildInterfaceBody")
}
}
}
Expand Down Expand Up @@ -494,7 +494,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
}
else -> {
val text = statementParent.text
println("enterArrowFunctionDeclaration -> $parentName, $text")
// println("enterArrowFunctionDeclaration -> $parentName, $text")
}
}

Expand Down Expand Up @@ -589,7 +589,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
defaultNode.Functions += currentFunc
}
else -> {
println("enterFunctionExpressionDeclaration -> $parentName, ${statementParent.text} ")
// println("enterFunctionExpressionDeclaration -> $parentName, ${statementParent.text} ")
}
}
}
Expand Down Expand Up @@ -655,7 +655,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
currentFunc.FunctionCalls += CodeCall("", CallType.FUNCTION, "", currentExprIdent, parameters)
}
else -> {
println("todo -> need support type: ${ctx::class.java.simpleName} ==== ${ctx.text}")
// println("todo -> need support type: ${ctx::class.java.simpleName} ==== ${ctx.text}")
}
}
}
Expand Down Expand Up @@ -708,7 +708,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
currentExprIdent = ident.identifierName().text
}
else -> {
println("MemberDotExpressionContext: -> $subName")
// println("MemberDotExpressionContext: -> $subName")
}
}

Expand All @@ -722,7 +722,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {

}
else -> {
println("singleExpression -> ArgumentsExpressionContext -> $childName")
// println("singleExpression -> ArgumentsExpressionContext -> $childName")
}
}
}
Expand Down Expand Up @@ -762,7 +762,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
parameter = CodeProperty(TypeValue = singleExpToText(subSingle), TypeType = "string")
}
else -> {
println("todo -> ParenthesizedExpressionContext: $simpleName, text: ${subSingle.text}")
// println("todo -> ParenthesizedExpressionContext: $simpleName, text: ${subSingle.text}")
}
}

Expand Down Expand Up @@ -791,7 +791,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
root += prop
}
else -> {
println(propName)
// println(propName)
}
}
}
Expand Down Expand Up @@ -847,10 +847,10 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
currentFunc.FunctionCalls += codeCall
}
"IdentifierExpressionContext" -> {
println("enterExpressionStatement -> IdentifierExpressionContext: ${singleExprCtx.text}")
// println("enterExpressionStatement -> IdentifierExpressionContext: ${singleExprCtx.text}")
}
else -> {
println("enterExpressionStatement : $singleCtxType")
// println("enterExpressionStatement : $singleCtxType")
}
}

Expand Down Expand Up @@ -918,7 +918,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
parseSingleExpression(identExpr.singleExpression())
}
else -> {
println("IdentifierExpressionContext -> others variable decl: $identExprText ==== ${singleExprCtx.text}")
// println("IdentifierExpressionContext -> others variable decl: $identExprText ==== ${singleExprCtx.text}")
}
}
}
Expand All @@ -936,7 +936,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
parseParenthesizedExpression(singleExprCtx as ParenthesizedExpressionContext)
}
else -> {
println("enterVariableDeclaration : $singleCtxType === ${ctx.text}")
// println("enterVariableDeclaration : $singleCtxType === ${ctx.text}")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ if (node in graph) {
}
}
of(data)
"""

TypeScriptAnalyser().analysis(code, "index.tsx")
Expand Down Expand Up @@ -63,6 +65,15 @@ if (node in graph) {
TypeScriptAnalyser().analysis(code, "index.tsx")
}

@Test
fun array_in_for_loop() {
val code = """this.names.forEach((it, index) => {
multiSelect('', this.accessor[index])
})
"""
TypeScriptAnalyser().analysis(code, "index.tsx")
}

@Test
fun query_array_literal() {
val code = """
Expand Down

0 comments on commit fa9e70a

Please sign in to comment.