Skip to content

Commit 69195a9

Browse files
Store the tokenValue instead of tokenText on PrivateIdentifiers, since the latter can contain escapes and lead to semantic discrepancies.
1 parent 3f8b934 commit 69195a9

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2281,7 +2281,7 @@ namespace ts {
22812281

22822282
function parsePrivateIdentifier(): PrivateIdentifier {
22832283
const pos = getNodePos();
2284-
const node = factory.createPrivateIdentifier(internPrivateIdentifier(scanner.getTokenText()));
2284+
const node = factory.createPrivateIdentifier(internPrivateIdentifier(scanner.getTokenValue()));
22852285
nextToken();
22862286
return finishNode(node, pos);
22872287
}

src/compiler/scanner.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,6 +2054,11 @@ namespace ts {
20542054

20552055
if (isIdentifierStart(codePointAt(text, pos + 1), languageVersion)) {
20562056
pos++;
2057+
// We're relying on scanIdentifier's behavior and adjusting the token kind after the fact.
2058+
// Notably absent from this block is the fact that calling a function named "scanIdentifier",
2059+
// but identifiers don't include '#', and that function doesn't deal with it at all.
2060+
// This works because 'scanIdentifier' tries to reuse source characters and builds up substrings;
2061+
// however, it starts at the 'tokenPos' which includes the '#', and will "accidentally" prepend the '#' for us.
20572062
scanIdentifier(codePointAt(text, pos), languageVersion);
20582063
}
20592064
else {

0 commit comments

Comments
 (0)