Skip to content

Commit 5894afd

Browse files
authored
Assign normalized decimal value representations to non-decimal number tokens (microsoft#583)
1 parent bf9d859 commit 5894afd

29 files changed

+179
-614
lines changed

internal/scanner/scanner.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,14 +1863,6 @@ func (s *Scanner) scanBigIntSuffix() ast.Kind {
18631863
// !!! Convert all bigint tokens to their normalized decimal representation
18641864
return ast.KindBigIntLiteral
18651865
}
1866-
// !!! Once core.StringToNumber supports parsing of non-decimal values we should also convert non-decimal
1867-
// tokens to their normalized decimal representation
1868-
if len(s.tokenValue) >= 2 {
1869-
firstTwo := s.tokenValue[:2]
1870-
if firstTwo == "0x" || firstTwo == "0o" || firstTwo == "0b" {
1871-
return ast.KindNumericLiteral
1872-
}
1873-
}
18741866
s.tokenValue = jsnum.FromString(s.tokenValue).String()
18751867
return ast.KindNumericLiteral
18761868
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
duplicateIdentifierDifferentSpelling.ts(2,3): error TS2300: Duplicate identifier '0b11'.
2+
duplicateIdentifierDifferentSpelling.ts(3,3): error TS2300: Duplicate identifier '0b11'.
3+
duplicateIdentifierDifferentSpelling.ts(6,21): error TS1117: An object literal cannot have multiple properties with the same name.
4+
5+
6+
==== duplicateIdentifierDifferentSpelling.ts (3 errors) ====
7+
class A {
8+
0b11 = '';
9+
~~~~
10+
!!! error TS2300: Duplicate identifier '0b11'.
11+
3 = '';
12+
~
13+
!!! error TS2300: Duplicate identifier '0b11'.
14+
}
15+
16+
var X = { 0b11: '', 3: '' };
17+
~
18+
!!! error TS1117: An object literal cannot have multiple properties with the same name.
19+
Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
--- old.duplicateIdentifierDifferentSpelling.errors.txt
22
+++ new.duplicateIdentifierDifferentSpelling.errors.txt
3-
@@= skipped -0, +-1 lines =@@
3+
@@= skipped -0, +0 lines =@@
44
-duplicateIdentifierDifferentSpelling.ts(3,3): error TS2300: Duplicate identifier '3'.
5-
-duplicateIdentifierDifferentSpelling.ts(6,21): error TS1117: An object literal cannot have multiple properties with the same name.
6-
-
7-
-
5+
+duplicateIdentifierDifferentSpelling.ts(2,3): error TS2300: Duplicate identifier '0b11'.
6+
+duplicateIdentifierDifferentSpelling.ts(3,3): error TS2300: Duplicate identifier '0b11'.
7+
duplicateIdentifierDifferentSpelling.ts(6,21): error TS1117: An object literal cannot have multiple properties with the same name.
8+
9+
810
-==== duplicateIdentifierDifferentSpelling.ts (2 errors) ====
9-
- class A {
10-
- 0b11 = '';
11-
- 3 = '';
12-
- ~
11+
+==== duplicateIdentifierDifferentSpelling.ts (3 errors) ====
12+
class A {
13+
0b11 = '';
14+
+ ~~~~
15+
+!!! error TS2300: Duplicate identifier '0b11'.
16+
3 = '';
17+
~
1318
-!!! error TS2300: Duplicate identifier '3'.
14-
- }
15-
-
16-
- var X = { 0b11: '', 3: '' };
17-
- ~
18-
-!!! error TS1117: An object literal cannot have multiple properties with the same name.
19-
-
20-
@@= skipped --1, +1 lines =@@
21-
+<no content>
19+
+!!! error TS2300: Duplicate identifier '0b11'.
20+
}
21+
22+
var X = { 0b11: '', 3: '' };

testdata/baselines/reference/submodule/compiler/duplicateIdentifierDifferentSpelling.symbols

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ class A {
55
>A : Symbol(A, Decl(duplicateIdentifierDifferentSpelling.ts, 0, 0))
66

77
0b11 = '';
8-
>0b11 : Symbol(0b11, Decl(duplicateIdentifierDifferentSpelling.ts, 0, 9))
8+
>0b11 : Symbol(0b11, Decl(duplicateIdentifierDifferentSpelling.ts, 0, 9), Decl(duplicateIdentifierDifferentSpelling.ts, 1, 12))
99

1010
3 = '';
11-
>3 : Symbol(3, Decl(duplicateIdentifierDifferentSpelling.ts, 1, 12))
11+
>3 : Symbol(0b11, Decl(duplicateIdentifierDifferentSpelling.ts, 0, 9), Decl(duplicateIdentifierDifferentSpelling.ts, 1, 12))
1212
}
1313

1414
var X = { 0b11: '', 3: '' };
1515
>X : Symbol(X, Decl(duplicateIdentifierDifferentSpelling.ts, 5, 3))
16-
>0b11 : Symbol(0b11, Decl(duplicateIdentifierDifferentSpelling.ts, 5, 9))
17-
>3 : Symbol(3, Decl(duplicateIdentifierDifferentSpelling.ts, 5, 19))
16+
>0b11 : Symbol(0b11, Decl(duplicateIdentifierDifferentSpelling.ts, 5, 9), Decl(duplicateIdentifierDifferentSpelling.ts, 5, 19))
17+
>3 : Symbol(0b11, Decl(duplicateIdentifierDifferentSpelling.ts, 5, 9), Decl(duplicateIdentifierDifferentSpelling.ts, 5, 19))
1818

testdata/baselines/reference/submodule/compiler/duplicateIdentifierDifferentSpelling.symbols.diff

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,11 @@
55

66
0b11 = '';
77
->0b11 : Symbol(A[0b11], Decl(duplicateIdentifierDifferentSpelling.ts, 0, 9), Decl(duplicateIdentifierDifferentSpelling.ts, 1, 12))
8-
+>0b11 : Symbol(0b11, Decl(duplicateIdentifierDifferentSpelling.ts, 0, 9))
8+
+>0b11 : Symbol(0b11, Decl(duplicateIdentifierDifferentSpelling.ts, 0, 9), Decl(duplicateIdentifierDifferentSpelling.ts, 1, 12))
99

1010
3 = '';
1111
->3 : Symbol(A[0b11], Decl(duplicateIdentifierDifferentSpelling.ts, 0, 9), Decl(duplicateIdentifierDifferentSpelling.ts, 1, 12))
12-
+>3 : Symbol(3, Decl(duplicateIdentifierDifferentSpelling.ts, 1, 12))
12+
+>3 : Symbol(0b11, Decl(duplicateIdentifierDifferentSpelling.ts, 0, 9), Decl(duplicateIdentifierDifferentSpelling.ts, 1, 12))
1313
}
1414

1515
var X = { 0b11: '', 3: '' };
16-
>X : Symbol(X, Decl(duplicateIdentifierDifferentSpelling.ts, 5, 3))
17-
->0b11 : Symbol(0b11, Decl(duplicateIdentifierDifferentSpelling.ts, 5, 9), Decl(duplicateIdentifierDifferentSpelling.ts, 5, 19))
18-
->3 : Symbol(0b11, Decl(duplicateIdentifierDifferentSpelling.ts, 5, 9), Decl(duplicateIdentifierDifferentSpelling.ts, 5, 19))
19-
+>0b11 : Symbol(0b11, Decl(duplicateIdentifierDifferentSpelling.ts, 5, 9))
20-
+>3 : Symbol(3, Decl(duplicateIdentifierDifferentSpelling.ts, 5, 19))
21-

testdata/baselines/reference/submodule/compiler/enumIdentifierLiterals.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
enumIdentifierLiterals.ts(2,5): error TS2452: An enum member cannot have a numeric name.
22
enumIdentifierLiterals.ts(3,5): error TS2452: An enum member cannot have a numeric name.
33
enumIdentifierLiterals.ts(4,5): error TS2452: An enum member cannot have a numeric name.
4+
enumIdentifierLiterals.ts(6,5): error TS2452: An enum member cannot have a numeric name.
45

56

6-
==== enumIdentifierLiterals.ts (3 errors) ====
7+
==== enumIdentifierLiterals.ts (4 errors) ====
78
enum Nums {
89
1.0,
910
~~~
@@ -16,4 +17,6 @@ enumIdentifierLiterals.ts(4,5): error TS2452: An enum member cannot have a numer
1617
!!! error TS2452: An enum member cannot have a numeric name.
1718
"13e-1",
1819
0xF00D
20+
~~~~~~
21+
!!! error TS2452: An enum member cannot have a numeric name.
1922
}

testdata/baselines/reference/submodule/compiler/enumIdentifierLiterals.errors.txt.diff

Lines changed: 0 additions & 21 deletions
This file was deleted.

testdata/baselines/reference/submodule/conformance/binaryIntegerLiteral.symbols

Lines changed: 8 additions & 2 deletions
Large diffs are not rendered by default.

testdata/baselines/reference/submodule/conformance/binaryIntegerLiteral.symbols.diff

Lines changed: 9 additions & 39 deletions
Large diffs are not rendered by default.

testdata/baselines/reference/submodule/conformance/binaryIntegerLiteralES6.symbols

Lines changed: 8 additions & 2 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)