Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scanning issues related to Unicode escapes in identifiers #61042

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
339 changes: 164 additions & 175 deletions src/compiler/scanner.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/baselines/reference/TypeArgumentList1.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TypeArgumentList1.ts(1,14): error TS2695: Left side of comma operator is unused
!!! error TS2304: Cannot find name 'A'.
~
!!! error TS2304: Cannot find name 'B'.

~
!!! error TS1127: Invalid character.
~
!!! error TS2304: Cannot find name 'C'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ constructorWithIncompleteTypeAnnotation.ts(261,1): error TS1128: Declaration or
var undef = undefined;

var _\uD4A5\u7204\uC316\uE59F = local;

~
!!! error TS1127: Invalid character.
var мир = local;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
//// [extendedUnicodeEscapeSequenceIdentifiers.ts]
const \u{0061} = 12;
const a\u{0061} = 12;
const a\u{62}c\u{64}e = 12;

console.log(a + aa);
console.log(a + aa + abcde);


//// [extendedUnicodeEscapeSequenceIdentifiers.js]
const \u{0061} = 12;
const a\u{0061} = 12;
console.log(a + aa);
const a\u{62}c\u{64}e = 12;
console.log(a + aa + abcde);
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ const \u{0061} = 12;
const a\u{0061} = 12;
>a\u{0061} : Symbol(a\u{0061}, Decl(extendedUnicodeEscapeSequenceIdentifiers.ts, 1, 5))

console.log(a + aa);
const a\u{62}c\u{64}e = 12;
>a\u{62}c\u{64}e : Symbol(a\u{62}c\u{64}e, Decl(extendedUnicodeEscapeSequenceIdentifiers.ts, 2, 5))

console.log(a + aa + abcde);
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>a : Symbol(\u{0061}, Decl(extendedUnicodeEscapeSequenceIdentifiers.ts, 0, 5))
>aa : Symbol(a\u{0061}, Decl(extendedUnicodeEscapeSequenceIdentifiers.ts, 1, 5))
>abcde : Symbol(a\u{62}c\u{64}e, Decl(extendedUnicodeEscapeSequenceIdentifiers.ts, 2, 5))

Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,29 @@ const a\u{0061} = 12;
>12 : 12
> : ^^

console.log(a + aa);
>console.log(a + aa) : void
> : ^^^^
const a\u{62}c\u{64}e = 12;
>a\u{62}c\u{64}e : 12
> : ^^
>12 : 12
> : ^^

console.log(a + aa + abcde);
>console.log(a + aa + abcde) : void
> : ^^^^
>console.log : (...data: any[]) => void
> : ^^^^ ^^ ^^^^^
>console : Console
> : ^^^^^^^
>log : (...data: any[]) => void
> : ^^^^ ^^ ^^^^^
>a + aa + abcde : number
> : ^^^^^^
>a + aa : number
> : ^^^^^^
>a : 12
> : ^^
>aa : 12
> : ^^
>abcde : 12
> : ^^

Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ invalidUnicodeEscapeSequance.ts(1,8): error TS1127: Invalid character.

==== invalidUnicodeEscapeSequance.ts (1 errors) ====
var arg\u003

~
!!! error TS1127: Invalid character.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ invalidUnicodeEscapeSequance2.ts(1,8): error TS1127: Invalid character.

==== invalidUnicodeEscapeSequance2.ts (1 errors) ====
var arg\uxxxx

~
!!! error TS1127: Invalid character.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ invalidUnicodeEscapeSequance3.ts(1,3): error TS2304: Cannot find name 'u'.
a\u
~
!!! error TS2304: Cannot find name 'a'.

~
!!! error TS1127: Invalid character.
~
!!! error TS2304: Cannot find name 'u'.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ invalidUnicodeEscapeSequance4.ts(2,5): error TS1127: Invalid character.
==== invalidUnicodeEscapeSequance4.ts (1 errors) ====
var a\u0031; // a1 is a valid identifier
var \u0031a; // 1a is an invalid identifier

~
!!! error TS1127: Invalid character.
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@

1 const a =!@#!@$
   ~~
a.ts:1:13 - error TS1134: Variable declaration expected.
a.ts:1:14 - error TS1134: Variable declaration expected.

1 const a =!@#!@$
   ~
a.ts:1:16 - error TS1109: Expression expected.

1 const a =!@#!@$
   
   ~
a.ts:2:13 - error TS18026: '#!' can only be used at the start of a file.

2 const b = !@#!@#!@#!
   ~~
a.ts:2:14 - error TS1134: Variable declaration expected.
a.ts:2:15 - error TS1134: Variable declaration expected.

2 const b = !@#!@#!@#!
   ~
   ~
a.ts:2:16 - error TS18026: '#!' can only be used at the start of a file.

2 const b = !@#!@#!@#!
Expand Down Expand Up @@ -76,18 +72,16 @@
  ~~~~~


==== a.ts (16 errors) ====
==== a.ts (15 errors) ====
const a =!@#!@$
~~
!!! error TS18026: '#!' can only be used at the start of a file.
~
~
!!! error TS1134: Variable declaration expected.

!!! error TS1109: Expression expected.
const b = !@#!@#!@#!
~~
!!! error TS18026: '#!' can only be used at the start of a file.
~
~
!!! error TS1134: Variable declaration expected.
~~
!!! error TS18026: '#!' can only be used at the start of a file.
Expand Down Expand Up @@ -125,8 +119,8 @@
limit
~~~~~
!!! error TS2304: Cannot find name 'limit'.
Found 19 errors in 2 files.
Found 18 errors in 2 files.

Errors Files
16 a.ts:1
15 a.ts:1
3 b.ts:1
5 changes: 1 addition & 4 deletions tests/baselines/reference/manyCompilerErrorsInTheTwoFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ limit

//// [a.js]
var a = !;
!;
var b = !;
!;
!;
!OK;
OK;
HERE;
's A shouty thing;
GOTTA;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const a =!@#!@$
> : ^^^^^^^
> : any
> : ^^^
>!@$ : boolean
> : ^^^^^^^
>$ : any
> : ^^^

Expand All @@ -20,16 +18,10 @@ const b = !@#!@#!@#!
> : ^^^^^^^
> : any
> : ^^^
>!@ : boolean
> : ^^^^^^^
> : any
> : ^^^
>!@ : boolean
> : ^^^^^^^
> : any
> : ^^^
>!OK! : boolean
> : ^^^^^^^

OK!
>OK! : any
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/parserSkippedTokens1.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ parserSkippedTokens1.ts(1,1): error TS1127: Invalid character.

==== parserSkippedTokens1.ts (1 errors) ====
\

~
!!! error TS1127: Invalid character.
4 changes: 2 additions & 2 deletions tests/baselines/reference/parserSkippedTokens10.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ parserSkippedTokens10.ts(2,1): error TS1127: Invalid character.

==== parserSkippedTokens10.ts (2 errors) ====
\

~
!!! error TS1127: Invalid character.
\

~
!!! error TS1127: Invalid character.
/*existing trivia*/ ;

6 changes: 3 additions & 3 deletions tests/baselines/reference/parserSkippedTokens11.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ parserSkippedTokens11.ts(1,7): error TS1127: Invalid character.

==== parserSkippedTokens11.ts (3 errors) ====
; \ \ \

~
!!! error TS1127: Invalid character.

~
!!! error TS1127: Invalid character.

~
!!! error TS1127: Invalid character.
6 changes: 3 additions & 3 deletions tests/baselines/reference/parserSkippedTokens12.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ parserSkippedTokens12.ts(1,5): error TS1127: Invalid character.

==== parserSkippedTokens12.ts (3 errors) ====
\ \ \

~
!!! error TS1127: Invalid character.

~
!!! error TS1127: Invalid character.

~
!!! error TS1127: Invalid character.
2 changes: 1 addition & 1 deletion tests/baselines/reference/parserSkippedTokens13.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ parserSkippedTokens13.ts(1,10): error TS1127: Invalid character.

==== parserSkippedTokens13.ts (1 errors) ====
/regexp/ \ ;

~
!!! error TS1127: Invalid character.
4 changes: 2 additions & 2 deletions tests/baselines/reference/parserSkippedTokens14.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ parserSkippedTokens14.ts(3,1): error TS1127: Invalid character.

==== parserSkippedTokens14.ts (2 errors) ====
\

~
!!! error TS1127: Invalid character.
/*existing trivia*/
\

~
!!! error TS1127: Invalid character.
;

4 changes: 2 additions & 2 deletions tests/baselines/reference/parserSkippedTokens15.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ parserSkippedTokens15.ts(3,1): error TS1127: Invalid character.
==== parserSkippedTokens15.ts (2 errors) ====
/*existing trivia*/
\

~
!!! error TS1127: Invalid character.
\

~
!!! error TS1127: Invalid character.
;
2 changes: 1 addition & 1 deletion tests/baselines/reference/parserSkippedTokens17.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ parserSkippedTokens17.ts(1,9): error TS1005: ')' expected.
!!! error TS2304: Cannot find name 'foo'.
~
!!! error TS2304: Cannot find name 'a'.

~
!!! error TS1127: Invalid character.

!!! error TS1005: ')' expected.
2 changes: 1 addition & 1 deletion tests/baselines/reference/parserSkippedTokens18.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ parserSkippedTokens18.ts(1,8): error TS1005: ')' expected.
!!! error TS2304: Cannot find name 'foo'.
~
!!! error TS2304: Cannot find name 'a'.

~
!!! error TS1127: Invalid character.

!!! error TS1005: ')' expected.
2 changes: 1 addition & 1 deletion tests/baselines/reference/parserSkippedTokens19.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ parserSkippedTokens19.ts(1,1): error TS1127: Invalid character.

==== parserSkippedTokens19.ts (1 errors) ====
\ declare var v;

~
!!! error TS1127: Invalid character.
4 changes: 2 additions & 2 deletions tests/baselines/reference/parserSkippedTokens2.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ parserSkippedTokens2.ts(1,2): error TS1127: Invalid character.

==== parserSkippedTokens2.ts (2 errors) ====
\\

~
!!! error TS1127: Invalid character.

~
!!! error TS1127: Invalid character.
2 changes: 1 addition & 1 deletion tests/baselines/reference/parserSkippedTokens20.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ parserSkippedTokens20.ts(1,12): error TS1127: Invalid character.
!!! error TS2304: Cannot find name 'X'.
~
!!! error TS2304: Cannot find name 'T'.

~
!!! error TS1127: Invalid character.
4 changes: 2 additions & 2 deletions tests/baselines/reference/parserSkippedTokens3.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ parserSkippedTokens3.ts(1,5): error TS1127: Invalid character.

==== parserSkippedTokens3.ts (2 errors) ====
\ ; \

~
!!! error TS1127: Invalid character.

~
!!! error TS1127: Invalid character.
2 changes: 1 addition & 1 deletion tests/baselines/reference/parserSkippedTokens4.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ parserSkippedTokens4.ts(1,1): error TS1127: Invalid character.

==== parserSkippedTokens4.ts (1 errors) ====
\ /regexp/;

~
!!! error TS1127: Invalid character.
2 changes: 1 addition & 1 deletion tests/baselines/reference/parserSkippedTokens5.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ parserSkippedTokens5.ts(1,1): error TS1127: Invalid character.

==== parserSkippedTokens5.ts (1 errors) ====
\ /*foo*/ ;

~
!!! error TS1127: Invalid character.
2 changes: 1 addition & 1 deletion tests/baselines/reference/parserSkippedTokens6.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ parserSkippedTokens6.ts(1,9): error TS1127: Invalid character.

==== parserSkippedTokens6.ts (1 errors) ====
/*foo*/ \

~
!!! error TS1127: Invalid character.
2 changes: 1 addition & 1 deletion tests/baselines/reference/parserSkippedTokens7.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ parserSkippedTokens7.ts(1,9): error TS1127: Invalid character.

==== parserSkippedTokens7.ts (1 errors) ====
/*foo*/ \ /*bar*/

~
!!! error TS1127: Invalid character.
2 changes: 1 addition & 1 deletion tests/baselines/reference/parserSkippedTokens8.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ parserSkippedTokens8.ts(2,9): error TS1127: Invalid character.
==== parserSkippedTokens8.ts (1 errors) ====
;
/*foo*/ \ /*bar*/

~
!!! error TS1127: Invalid character.
Loading
Loading