Skip to content

Commit

Permalink
fix(ts): fix element in query
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Nov 15, 2022
1 parent 04bf39b commit e87a90c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
2 changes: 2 additions & 0 deletions chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,8 @@ singleExpression
| singleExpression '?'? '!'? '.' '#'? identifierName nestedTypeGeneric? # MemberDotExpression
// for: `onHotUpdateSuccess?.();`
| singleExpression '?'? '!'? '.' '#'? '(' identifierName? ')' # MemberDotExpression
// onChange?.(userName || password || null)
| singleExpression '?'? '!'? '.' '#'? '(' singleExpression? ')' # MemberDotExpression
// samples: `error?.response?.data?.message ?? error.message;`
| singleExpression '??' singleExpression # NullCoalesceExpression
| singleExpression '!' # PropCheckExpression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
val memberDot = it as TypeScriptParser.MemberDotExpressionContext
when (val subName = memberDot.singleExpression()::class.java.simpleName) {
"ParenthesizedExpressionContext" -> {
params += parseParenthesizedExpression(memberDot.singleExpression())
params += parseParenthesizedExpression(memberDot.singleExpression().first())
}
"ArgumentsExpressionContext" -> {
// request.get('/api/v1/xxx?id=1').then(function(response){console.log(response)}).catch()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package chapi.ast.typescriptast
import chapi.domain.core.DataStructType
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.io.File

internal class TypeScriptAnalyserTest {
class TypeScriptAnalyserTest {
@Test
internal fun shouldAnalysisTypeScriptMultipleClass() {
val content = this::class.java.getResource("/grammar/Class.ts")!!.readText()
Expand Down Expand Up @@ -66,4 +67,18 @@ internal class TypeScriptAnalyserTest {
assertEquals(codeFile.PackageName, "@.grammar.AbstractClass")
assertEquals(codeFile.DataStructures[0].Package, "@.grammar.AbstractClass")
}

@Test
@Ignore
fun someBug() {
val dir = File("/Users/phodal/bug-ui-system")
dir.walkTopDown().forEach {
if (it.extension == "ts" || it.extension == "js") {
val content = it.readText()
println(it.absolutePath)
val codeFile = TypeScriptAnalyser().analysis(content, it.name)
println(codeFile)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,21 @@ exports.test = test;
}

@Test
fun backend_arrow_function2() {
fun of_keyword_lost() {
val code = """
import {EMPTY, Observable, of} from 'rxjs';
"""

TypeScriptAnalyser().analysis(code, "index.tsx")
}

@Test
fun member_dot_issue() {
val code = """export class DemoComponent implements OnInit, ControlValueAccessor {
ngOnInit(): void {
this.onChange?.(userName || password || null);
}
}"""
TypeScriptAnalyser().analysis(code, "index.tsx")
}
}

0 comments on commit e87a90c

Please sign in to comment.