Skip to content

Commit

Permalink
fix(ts): fix nested error issues
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Nov 16, 2022
1 parent c218d81 commit 6df62c4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ nestedTypeGeneric
// TODO: Fix recursive
//
typeGeneric
: '<' typeArgumentList '>'
: '<' typeArgumentList typeGeneric? '>'
;

typeIncludeGeneric
:'<' typeArgumentList '<' typeArgumentList ('>' bindingPattern '>' | '>>')
:'<' typeArgumentList '<' typeArgumentList ('>' bindingPattern '>' | '>>' | '>>>' | '>'*)
;

typeName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import chapi.ast.antlr.TypeScriptParser.IdentifierExpressionContext
import chapi.ast.antlr.TypeScriptParser.ParenthesizedExpressionContext
import chapi.domain.core.*
import chapi.infra.Stack
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.antlr.v4.runtime.ParserRuleContext

class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() {
private var hasHtmlElement: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package chapi.ast.typescriptast

import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.junit.jupiter.api.Test

class TypeScriptRegressionTest {
Expand Down Expand Up @@ -108,13 +106,6 @@ export class DemoComponent implements OnInit, ControlValueAccessor {
val code2 =
"""export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };"""
TypeScriptAnalyser().analysis(code2, "index.tsx")

val code3 = """export type Maybe<T> = Maybe<Array<Maybe<(
{ __typename?: 'User' }
& Pick<User, 'name'>
)>>>"""

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

@Test
Expand All @@ -133,4 +124,14 @@ export class DemoComponent implements OnInit, ControlValueAccessor {

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

@Test
fun nested_type() {
val code = """export type Query = Array<Array<Maybe<Number>>>"""

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

val code2 = """export type Query = Array<Array<Array<Maybe<Number>>>>"""
TypeScriptAnalyser().analysis(code2, "index.tsx")
}
}

0 comments on commit 6df62c4

Please sign in to comment.