Skip to content

Commit

Permalink
fix(ts): add numberic support
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Nov 15, 2022
1 parent 8718727 commit 33a35b0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 284 deletions.
17 changes: 11 additions & 6 deletions chapi-ast-typescript/src/main/antlr/TypeScriptLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,22 @@ BooleanLiteral: 'true'

/// Numeric Literals

DecimalLiteral: DecimalIntegerLiteral '.' [0-9]* ExponentPart?
| '.' [0-9]+ ExponentPart?
DecimalLiteral: DecimalIntegerLiteral '.' [0-9] [0-9_]* ExponentPart?
| '.' [0-9] [0-9_]* ExponentPart?
| DecimalIntegerLiteral ExponentPart?
;

/// Numeric Literals

HexIntegerLiteral: '0' [xX] HexDigit+;
HexIntegerLiteral: '0' [xX] [0-9a-fA-F] HexDigit*;
OctalIntegerLiteral: '0' [0-7]+ {!this.IsStrictMode()}?;
OctalIntegerLiteral2: '0' [oO] [0-7]+;
BinaryIntegerLiteral: '0' [bB] [01]+;
OctalIntegerLiteral2: '0' [oO] [0-7] [_0-7]*;
BinaryIntegerLiteral: '0' [bB] [01] [_01]*;

BigHexIntegerLiteral: '0' [xX] [0-9a-fA-F] HexDigit* 'n';
BigOctalIntegerLiteral: '0' [oO] [0-7] [_0-7]* 'n';
BigBinaryIntegerLiteral: '0' [bB] [01] [_01]* 'n';
BigDecimalIntegerLiteral: DecimalIntegerLiteral 'n';

/// Keywords

Expand Down Expand Up @@ -376,7 +381,7 @@ fragment HexDigit
fragment DecimalIntegerLiteral
: '0'
| [1-9] [0-9]*
| [1-9] [0-9_]*
;
fragment ExponentPart
Expand Down
276 changes: 0 additions & 276 deletions chapi-ast-typescript/src/main/antlr/TypeScriptLexer.tokens

This file was deleted.

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 @@ -103,7 +103,25 @@ export class DemoComponent implements OnInit, ControlValueAccessor {
val code = """export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };"""
TypeScriptAnalyser().analysis(code, "index.tsx")

val code2 = """export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };"""
val code2 =
"""export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };"""
TypeScriptAnalyser().analysis(code2, "index.tsx")
}

@Test
fun numeric_separators() {
val code = """if (+value > 1_000_000_000) {
}"""

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

@Test
fun annotated_in_constructor() {
val code = """export class DemoComponent implements OnInit {
constructor(@Optional() @Inject(GROUP) private group: Component) {}
}"""

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

0 comments on commit 33a35b0

Please sign in to comment.