Skip to content

Commit 71cdf6a

Browse files
authored
Private identifiers use standard identifier scanning (#44184)
* Private identifiers use standard identifer scanning Previously they used an old copy of the identifier scanning code that didn't handle extended unicode yet. * gotta fix that const lint
1 parent 4ce12f9 commit 71cdf6a

File tree

5 files changed

+65
-36
lines changed

5 files changed

+65
-36
lines changed

src/compiler/scanner.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,7 +1610,7 @@ namespace ts {
16101610
if (pos >= end) {
16111611
return token = SyntaxKind.EndOfFileToken;
16121612
}
1613-
let ch = codePointAt(text, pos);
1613+
const ch = codePointAt(text, pos);
16141614

16151615
// Special handling for shebang
16161616
if (ch === CharacterCodes.hash && pos === 0 && isShebangTrivia(text, pos)) {
@@ -2044,18 +2044,7 @@ namespace ts {
20442044
return token = SyntaxKind.Unknown;
20452045
}
20462046
pos++;
2047-
if (isIdentifierStart(ch = text.charCodeAt(pos), languageVersion)) {
2048-
pos++;
2049-
while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos), languageVersion)) pos++;
2050-
tokenValue = text.substring(tokenPos, pos);
2051-
if (ch === CharacterCodes.backslash) {
2052-
tokenValue += scanIdentifierParts();
2053-
}
2054-
}
2055-
else {
2056-
tokenValue = "#";
2057-
error(Diagnostics.Invalid_character);
2058-
}
2047+
scanIdentifier(codePointAt(text, pos), languageVersion);
20592048
return token = SyntaxKind.PrivateIdentifier;
20602049
default:
20612050
const identifierKind = scanIdentifier(ch, languageVersion);

tests/baselines/reference/extendedUnicodePlaneIdentifiers.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ const 𝑚 = 4;
33
const 𝑀 = 5;
44
console.log(𝑀 + 𝑚); // 9
55

6+
class K {
7+
#𝑚 = 4;
8+
#𝑀 = 5;
9+
}
10+
611
// lower 8 bits look like 'a'
712
const = 6;
813
console.log( ** );
@@ -39,9 +44,17 @@ const 𝓮𡚭𓀺ⱱ = "ok";
3944

4045

4146
//// [extendedUnicodePlaneIdentifiers.js]
47+
var _K_𝑚, _K_𝑀;
4248
const 𝑚 = 4;
4349
const 𝑀 = 5;
4450
console.log(𝑀 + 𝑚); // 9
51+
class K {
52+
constructor() {
53+
_K_𝑚.set(this, 4);
54+
_K_𝑀.set(this, 5);
55+
}
56+
}
57+
_K_𝑚 = new WeakMap(), _K_𝑀 = new WeakMap();
4558
// lower 8 bits look like 'a'
4659
const = 6;
4760
console.log( ** );

tests/baselines/reference/extendedUnicodePlaneIdentifiers.symbols

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,80 +12,90 @@ console.log(𝑀 + 𝑚); // 9
1212
>𝑀 : Symbol(𝑀, Decl(extendedUnicodePlaneIdentifiers.ts, 1, 5))
1313
>𝑚 : Symbol(𝑚, Decl(extendedUnicodePlaneIdentifiers.ts, 0, 5))
1414

15+
class K {
16+
>K : Symbol(K, Decl(extendedUnicodePlaneIdentifiers.ts, 2, 21))
17+
18+
#𝑚 = 4;
19+
>#𝑚 : Symbol(K[#𝑚], Decl(extendedUnicodePlaneIdentifiers.ts, 4, 9))
20+
21+
#𝑀 = 5;
22+
>#𝑀 : Symbol(K[#𝑀], Decl(extendedUnicodePlaneIdentifiers.ts, 5, 12))
23+
}
24+
1525
// lower 8 bits look like 'a'
1626
const ၡ = 6;
17-
>ၡ : Symbol(ၡ, Decl(extendedUnicodePlaneIdentifiers.ts, 5, 5))
27+
>ၡ : Symbol(ၡ, Decl(extendedUnicodePlaneIdentifiers.ts, 10, 5))
1828

1929
console.log(ၡ ** ၡ);
2030
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
2131
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
2232
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
23-
>ၡ : Symbol(ၡ, Decl(extendedUnicodePlaneIdentifiers.ts, 5, 5))
24-
>ၡ : Symbol(ၡ, Decl(extendedUnicodePlaneIdentifiers.ts, 5, 5))
33+
>ၡ : Symbol(ၡ, Decl(extendedUnicodePlaneIdentifiers.ts, 10, 5))
34+
>ၡ : Symbol(ၡ, Decl(extendedUnicodePlaneIdentifiers.ts, 10, 5))
2535

2636
// lower 8 bits aren't a valid unicode character
2737
const ဒ = 7;
28-
>ဒ : Symbol(ဒ, Decl(extendedUnicodePlaneIdentifiers.ts, 9, 5))
38+
>ဒ : Symbol(ဒ, Decl(extendedUnicodePlaneIdentifiers.ts, 14, 5))
2939

3040
console.log(ဒ ** ဒ);
3141
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
3242
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
3343
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
34-
>ဒ : Symbol(ဒ, Decl(extendedUnicodePlaneIdentifiers.ts, 9, 5))
35-
>ဒ : Symbol(ဒ, Decl(extendedUnicodePlaneIdentifiers.ts, 9, 5))
44+
>ဒ : Symbol(ဒ, Decl(extendedUnicodePlaneIdentifiers.ts, 14, 5))
45+
>ဒ : Symbol(ဒ, Decl(extendedUnicodePlaneIdentifiers.ts, 14, 5))
3646

3747
// a mix, for good measure
3848
const ဒၡ𝑀 = 7;
39-
>ဒၡ𝑀 : Symbol(ဒၡ𝑀, Decl(extendedUnicodePlaneIdentifiers.ts, 13, 5))
49+
>ဒၡ𝑀 : Symbol(ဒၡ𝑀, Decl(extendedUnicodePlaneIdentifiers.ts, 18, 5))
4050

4151
console.log(ဒၡ𝑀 ** ဒၡ𝑀);
4252
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
4353
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
4454
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
45-
>ဒၡ𝑀 : Symbol(ဒၡ𝑀, Decl(extendedUnicodePlaneIdentifiers.ts, 13, 5))
46-
>ဒၡ𝑀 : Symbol(ဒၡ𝑀, Decl(extendedUnicodePlaneIdentifiers.ts, 13, 5))
55+
>ဒၡ𝑀 : Symbol(ဒၡ𝑀, Decl(extendedUnicodePlaneIdentifiers.ts, 18, 5))
56+
>ဒၡ𝑀 : Symbol(ဒၡ𝑀, Decl(extendedUnicodePlaneIdentifiers.ts, 18, 5))
4757

4858
const ၡ𝑀ဒ = 7;
49-
>ၡ𝑀ဒ : Symbol(ၡ𝑀ဒ, Decl(extendedUnicodePlaneIdentifiers.ts, 16, 5))
59+
>ၡ𝑀ဒ : Symbol(ၡ𝑀ဒ, Decl(extendedUnicodePlaneIdentifiers.ts, 21, 5))
5060

5161
console.log(ၡ𝑀ဒ ** ၡ𝑀ဒ);
5262
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
5363
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
5464
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
55-
>ၡ𝑀ဒ : Symbol(ၡ𝑀ဒ, Decl(extendedUnicodePlaneIdentifiers.ts, 16, 5))
56-
>ၡ𝑀ဒ : Symbol(ၡ𝑀ဒ, Decl(extendedUnicodePlaneIdentifiers.ts, 16, 5))
65+
>ၡ𝑀ဒ : Symbol(ၡ𝑀ဒ, Decl(extendedUnicodePlaneIdentifiers.ts, 21, 5))
66+
>ၡ𝑀ဒ : Symbol(ၡ𝑀ဒ, Decl(extendedUnicodePlaneIdentifiers.ts, 21, 5))
5767

5868
const 𝑀ဒၡ = 7;
59-
>𝑀ဒၡ : Symbol(𝑀ဒၡ, Decl(extendedUnicodePlaneIdentifiers.ts, 19, 5))
69+
>𝑀ဒၡ : Symbol(𝑀ဒၡ, Decl(extendedUnicodePlaneIdentifiers.ts, 24, 5))
6070

6171
console.log(𝑀ဒၡ ** 𝑀ဒၡ);
6272
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
6373
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
6474
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
65-
>𝑀ဒၡ : Symbol(𝑀ဒၡ, Decl(extendedUnicodePlaneIdentifiers.ts, 19, 5))
66-
>𝑀ဒၡ : Symbol(𝑀ဒၡ, Decl(extendedUnicodePlaneIdentifiers.ts, 19, 5))
75+
>𝑀ဒၡ : Symbol(𝑀ဒၡ, Decl(extendedUnicodePlaneIdentifiers.ts, 24, 5))
76+
>𝑀ဒၡ : Symbol(𝑀ဒၡ, Decl(extendedUnicodePlaneIdentifiers.ts, 24, 5))
6777

6878
const 𝓱𝓮𝓵𝓵𝓸 = "𝔀𝓸𝓻𝓵𝓭";
69-
>𝓱𝓮𝓵𝓵𝓸 : Symbol(𝓱𝓮𝓵𝓵𝓸, Decl(extendedUnicodePlaneIdentifiers.ts, 22, 5))
79+
>𝓱𝓮𝓵𝓵𝓸 : Symbol(𝓱𝓮𝓵𝓵𝓸, Decl(extendedUnicodePlaneIdentifiers.ts, 27, 5))
7080

7181
const Ɐⱱ = "ok"; // BMP
72-
>Ɐⱱ : Symbol(Ɐⱱ, Decl(extendedUnicodePlaneIdentifiers.ts, 24, 5))
82+
>Ɐⱱ : Symbol(Ɐⱱ, Decl(extendedUnicodePlaneIdentifiers.ts, 29, 5))
7383

7484
const 𓀸𓀹𓀺 = "ok"; // SMP
75-
>𓀸𓀹𓀺 : Symbol(𓀸𓀹𓀺, Decl(extendedUnicodePlaneIdentifiers.ts, 26, 5))
85+
>𓀸𓀹𓀺 : Symbol(𓀸𓀹𓀺, Decl(extendedUnicodePlaneIdentifiers.ts, 31, 5))
7686

7787
const 𡚭𡚮𡚯 = "ok"; // SIP
78-
>𡚭𡚮𡚯 : Symbol(𡚭𡚮𡚯, Decl(extendedUnicodePlaneIdentifiers.ts, 28, 5))
88+
>𡚭𡚮𡚯 : Symbol(𡚭𡚮𡚯, Decl(extendedUnicodePlaneIdentifiers.ts, 33, 5))
7989

8090
const 𡚭𓀺ⱱ𝓮 = "ok";
81-
>𡚭𓀺ⱱ𝓮 : Symbol(𡚭𓀺ⱱ𝓮, Decl(extendedUnicodePlaneIdentifiers.ts, 30, 5))
91+
>𡚭𓀺ⱱ𝓮 : Symbol(𡚭𓀺ⱱ𝓮, Decl(extendedUnicodePlaneIdentifiers.ts, 35, 5))
8292

8393
const 𓀺ⱱ𝓮𡚭 = "ok";
84-
>𓀺ⱱ𝓮𡚭 : Symbol(𓀺ⱱ𝓮𡚭, Decl(extendedUnicodePlaneIdentifiers.ts, 32, 5))
94+
>𓀺ⱱ𝓮𡚭 : Symbol(𓀺ⱱ𝓮𡚭, Decl(extendedUnicodePlaneIdentifiers.ts, 37, 5))
8595

8696
const ⱱ𝓮𡚭𓀺 = "ok";
87-
>ⱱ𝓮𡚭𓀺 : Symbol(ⱱ𝓮𡚭𓀺, Decl(extendedUnicodePlaneIdentifiers.ts, 34, 5))
97+
>ⱱ𝓮𡚭𓀺 : Symbol(ⱱ𝓮𡚭𓀺, Decl(extendedUnicodePlaneIdentifiers.ts, 39, 5))
8898

8999
const 𝓮𡚭𓀺ⱱ = "ok";
90-
>𝓮𡚭𓀺ⱱ : Symbol(𝓮𡚭𓀺ⱱ, Decl(extendedUnicodePlaneIdentifiers.ts, 36, 5))
100+
>𝓮𡚭𓀺ⱱ : Symbol(𝓮𡚭𓀺ⱱ, Decl(extendedUnicodePlaneIdentifiers.ts, 41, 5))
91101

tests/baselines/reference/extendedUnicodePlaneIdentifiers.types

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ console.log(𝑀 + 𝑚); // 9
1616
>𝑀 : 5
1717
>𝑚 : 4
1818

19+
class K {
20+
>K : K
21+
22+
#𝑚 = 4;
23+
>#𝑚 : number
24+
>4 : 4
25+
26+
#𝑀 = 5;
27+
>#𝑀 : number
28+
>5 : 5
29+
}
30+
1931
// lower 8 bits look like 'a'
2032
const ၡ = 6;
2133
>ၡ : 6

tests/cases/compiler/extendedUnicodePlaneIdentifiers.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ const 𝑚 = 4;
33
const 𝑀 = 5;
44
console.log(𝑀 + 𝑚); // 9
55

6+
class K {
7+
#𝑚 = 4;
8+
#𝑀 = 5;
9+
}
10+
611
// lower 8 bits look like 'a'
712
const = 6;
813
console.log( ** );

0 commit comments

Comments
 (0)