Skip to content

Commit 8050d4f

Browse files
committed
update parser error recovery tests to use ¬ not #
The intent of the tests seemed to be to regiment the behavior of the parser when a weird symbol is encountered. The `#` is now taken by private identifiers, so `¬` seems like a good new choice for keeping the diff small, since it also fits in 16 bits (wide emojis would be treated as multiple characters, since the scanner uses ++). Signed-off-by: Max Heiber <[email protected]>
1 parent 0f09ecb commit 8050d4f

32 files changed

+48
-42
lines changed

src/compiler/parser.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,7 +2242,7 @@ namespace ts {
22422242
break;
22432243
}
22442244
dotPos = scanner.getStartPos();
2245-
entity = createQualifiedName(entity, parseRightSideOfDot(allowReservedWords));
2245+
entity = createQualifiedName(entity, parseRightSideOfDot(allowReservedWords, /* allowPrivateNames */ false) as Identifier);
22462246
}
22472247
return entity;
22482248
}
@@ -2254,7 +2254,7 @@ namespace ts {
22542254
return finishNode(node);
22552255
}
22562256

2257-
function parseRightSideOfDot(allowIdentifierNames: boolean): Identifier {
2257+
function parseRightSideOfDot(allowIdentifierNames: boolean, allowPrivateNames: boolean): Identifier | PrivateName {
22582258
// Technically a keyword is valid here as all identifiers and keywords are identifier names.
22592259
// However, often we'll encounter this in error situations when the identifier or keyword
22602260
// is actually starting another valid construct.
@@ -2285,6 +2285,10 @@ namespace ts {
22852285
}
22862286
}
22872287

2288+
if (allowPrivateNames && token() === SyntaxKind.PrivateName) {
2289+
return parsePrivateName();
2290+
}
2291+
22882292
return allowIdentifierNames ? parseIdentifierName() : parseIdentifier();
22892293
}
22902294

@@ -4358,7 +4362,8 @@ namespace ts {
43584362
const node = <PropertyAccessExpression>createNode(SyntaxKind.PropertyAccessExpression, expression.pos);
43594363
node.expression = expression;
43604364
parseExpectedToken(SyntaxKind.DotToken, Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access);
4361-
node.name = parseRightSideOfDot(/*allowIdentifierNames*/ true);
4365+
// private names will never work with `super` (`super.#foo`), but that's a semantic error, not syntactic
4366+
node.name = parseRightSideOfDot(/*allowIdentifierNames*/ true, /*allowPrivateNames*/ true);
43624367
return finishNode(node);
43634368
}
43644369

@@ -4529,7 +4534,7 @@ namespace ts {
45294534
while (parseOptional(SyntaxKind.DotToken)) {
45304535
const propertyAccess: JsxTagNamePropertyAccess = <JsxTagNamePropertyAccess>createNode(SyntaxKind.PropertyAccessExpression, expression.pos);
45314536
propertyAccess.expression = expression;
4532-
propertyAccess.name = parseRightSideOfDot(/*allowIdentifierNames*/ true);
4537+
propertyAccess.name = parseRightSideOfDot(/*allowIdentifierNames*/ true, /*allowPrivateNames*/ true);
45334538
expression = finishNode(propertyAccess);
45344539
}
45354540
return expression;
@@ -4646,7 +4651,8 @@ namespace ts {
46464651
const propertyAccess = <PropertyAccessExpression>createNode(SyntaxKind.PropertyAccessExpression, expression.pos);
46474652
propertyAccess.expression = expression;
46484653
propertyAccess.questionDotToken = questionDotToken;
4649-
propertyAccess.name = parseRightSideOfDot(/*allowIdentifierNames*/ true);
4654+
propertyAccess.name = parseRightSideOfDot(/*allowIdentifierNames*/ true, /*allowPrivateNames*/ true);
4655+
46504656
if (questionDotToken || expression.flags & NodeFlags.OptionalChain) {
46514657
propertyAccess.flags |= NodeFlags.OptionalChain;
46524658
}

tests/baselines/reference/MemberFunctionDeclaration8_es6.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration
99
class C {
1010
foo() {
1111
// Make sure we don't think of *bar as the start of a generator method.
12-
if (a) # * bar;
12+
if (a) ¬ * bar;
1313
~
1414
!!! error TS2304: Cannot find name 'a'.
1515

tests/baselines/reference/MemberFunctionDeclaration8_es6.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
class C {
33
foo() {
44
// Make sure we don't think of *bar as the start of a generator method.
5-
if (a) # * bar;
5+
if (a) ¬ * bar;
66
return bar;
77
}
88
}

tests/baselines/reference/MemberFunctionDeclaration8_es6.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class C {
66
>foo : Symbol(C.foo, Decl(MemberFunctionDeclaration8_es6.ts, 0, 9))
77

88
// Make sure we don't think of *bar as the start of a generator method.
9-
if (a) # * bar;
9+
if (a) ¬ * bar;
1010
return bar;
1111
}
1212
}

tests/baselines/reference/MemberFunctionDeclaration8_es6.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class C {
66
>foo : () => any
77

88
// Make sure we don't think of *bar as the start of a generator method.
9-
if (a) # * bar;
9+
if (a) ¬ * bar;
1010
>a : any
1111
> : any
1212
>* bar : number

tests/baselines/reference/parseErrorInHeritageClause1.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ tests/cases/compiler/parseErrorInHeritageClause1.ts(1,19): error TS1127: Invalid
33

44

55
==== tests/cases/compiler/parseErrorInHeritageClause1.ts (2 errors) ====
6-
class C extends A # {
6+
class C extends A ¬ {
77
~
88
!!! error TS2304: Cannot find name 'A'.
99

tests/baselines/reference/parseErrorInHeritageClause1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//// [parseErrorInHeritageClause1.ts]
2-
class C extends A # {
2+
class C extends A ¬ {
33
}
44

55
//// [parseErrorInHeritageClause1.js]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
=== tests/cases/compiler/parseErrorInHeritageClause1.ts ===
2-
class C extends A # {
2+
class C extends A ¬ {
33
>C : Symbol(C, Decl(parseErrorInHeritageClause1.ts, 0, 0))
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
=== tests/cases/compiler/parseErrorInHeritageClause1.ts ===
2-
class C extends A # {
2+
class C extends A ¬ {
33
>C : C
44
>A : any
55
}

tests/baselines/reference/parserErrorRecovery_Block2.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecov
33

44
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts (1 errors) ====
55
function f() {
6-
#
6+
¬
77

88
!!! error TS1127: Invalid character.
99
return;

0 commit comments

Comments
 (0)