Skip to content

Commit

Permalink
fix(ts): fix import of conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Nov 15, 2022
1 parent 6e1890b commit e57af30
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
11 changes: 6 additions & 5 deletions chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ importDefault

aliasName
: identifierName (As identifierName)?
// for import { of } from 'rxjs';
| Of
;

importNamespace
Expand Down Expand Up @@ -779,12 +781,12 @@ singleExpression
| arrowFunctionDeclaration # ArrowFunctionExpression // ECMAScript 6
| jsxArrowFunction # JsxArrowFunctionExpression
| Class Identifier? classTail # ClassExpression
| singleExpression '[' expressionSequence ']' # MemberIndexExpression
| singleExpression '?'? '!'? '.' '#'? identifierName nestedTypeGeneric? # MemberDotExpression
// this.form.value?.id?.[0]
| singleExpression '?'? '!'? '.''[' expressionSequence ']' # MemberIndexExpression
// for: `onHotUpdateSuccess?.();`
| singleExpression '?'? '!'? '.' '#'? '(' identifierName? ')' # MemberDotExpression
// onChange?.(userName || password || null)
| singleExpression '?'? '!'? '.' '#'? '('? singleExpression? ')'? # MemberDotExpression
| singleExpression '?'? '!'? '.' '#'? identifierName? nestedTypeGeneric? # MemberDotExpression

// samples: `error?.response?.data?.message ?? error.message;`
| singleExpression '??' singleExpression # NullCoalesceExpression
| singleExpression '!' # PropCheckExpression
Expand Down Expand Up @@ -986,7 +988,6 @@ keyword
| Namespace
| Number
| Boolean
| Of
;

getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,15 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {

if (ctx.moduleItems() != null) {
for (nameContext in ctx.moduleItems().aliasName()) {
codeImport.UsageName += nameContext.identifierName()[0].text
if (nameContext.As() != null) {
codeImport.AsName += nameContext.identifierName()[1].text
if (nameContext.identifierName().isNotEmpty()) {
codeImport.UsageName += nameContext.identifierName()[0].text
if (nameContext.As() != null) {
codeImport.AsName += nameContext.identifierName()[1].text
}
}
if (nameContext.Of() != null) {
codeImport.UsageName += nameContext.Of().text
codeImport.AsName += nameContext.Of().text
}
}
}
Expand Down Expand Up @@ -690,7 +696,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().first())
params += parseParenthesizedExpression(memberDot.singleExpression())
}
"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 @@ -70,7 +70,7 @@ class TypeScriptAnalyserTest {
}

@Test
// @Disabled
@Disabled
fun someBug() {
val dir = File("/Users/phodal/bug-ui-system")
dir.walkTopDown().forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ export class ELKLayout {
}

@Test
internal fun forOfStatement() {
fun forOfStatement() {
val code = """
function dfs() {
if (node in graph) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ exports.test = test;
fun of_keyword_lost() {
val code = """
import {EMPTY, Observable, of} from 'rxjs';
if (node in graph) {
for (const n of graph[node]) {
}
}
"""

TypeScriptAnalyser().analysis(code, "index.tsx")
Expand Down

0 comments on commit e57af30

Please sign in to comment.