Skip to content

Commit cb9f436

Browse files
Kingwlsandersn
authored andcommitted
fix accessor parse with line terminator (microsoft#22893)
1 parent adf30dd commit cb9f436

File tree

5 files changed

+76
-19
lines changed

5 files changed

+76
-19
lines changed

src/compiler/parser.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,26 +1344,26 @@ namespace ts {
13441344
}
13451345

13461346
function nextTokenCanFollowModifier() {
1347-
if (token() === SyntaxKind.ConstKeyword) {
1348-
// 'const' is only a modifier if followed by 'enum'.
1349-
return nextToken() === SyntaxKind.EnumKeyword;
1350-
}
1351-
if (token() === SyntaxKind.ExportKeyword) {
1352-
nextToken();
1353-
if (token() === SyntaxKind.DefaultKeyword) {
1354-
return lookAhead(nextTokenCanFollowDefaultKeyword);
1355-
}
1356-
return token() !== SyntaxKind.AsteriskToken && token() !== SyntaxKind.AsKeyword && token() !== SyntaxKind.OpenBraceToken && canFollowModifier();
1357-
}
1358-
if (token() === SyntaxKind.DefaultKeyword) {
1359-
return nextTokenCanFollowDefaultKeyword();
1360-
}
1361-
if (token() === SyntaxKind.StaticKeyword) {
1362-
nextToken();
1363-
return canFollowModifier();
1347+
switch (token()) {
1348+
case SyntaxKind.ConstKeyword:
1349+
// 'const' is only a modifier if followed by 'enum'.
1350+
return nextToken() === SyntaxKind.EnumKeyword;
1351+
case SyntaxKind.ExportKeyword:
1352+
nextToken();
1353+
if (token() === SyntaxKind.DefaultKeyword) {
1354+
return lookAhead(nextTokenCanFollowDefaultKeyword);
1355+
}
1356+
return token() !== SyntaxKind.AsteriskToken && token() !== SyntaxKind.AsKeyword && token() !== SyntaxKind.OpenBraceToken && canFollowModifier();
1357+
case SyntaxKind.DefaultKeyword:
1358+
return nextTokenCanFollowDefaultKeyword();
1359+
case SyntaxKind.StaticKeyword:
1360+
case SyntaxKind.GetKeyword:
1361+
case SyntaxKind.SetKeyword:
1362+
nextToken();
1363+
return canFollowModifier();
1364+
default:
1365+
return nextTokenIsOnSameLineAndCanFollowModifier();
13641366
}
1365-
1366-
return nextTokenIsOnSameLineAndCanFollowModifier();
13671367
}
13681368

13691369
function parseAnyContextualModifier(): boolean {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//// [accessorWithLineTerminator.ts]
2+
class C {
3+
get
4+
x() { return 1 }
5+
6+
set
7+
x(v) { }
8+
}
9+
10+
//// [accessorWithLineTerminator.js]
11+
var C = /** @class */ (function () {
12+
function C() {
13+
}
14+
Object.defineProperty(C.prototype, "x", {
15+
get: function () { return 1; },
16+
set: function (v) { },
17+
enumerable: true,
18+
configurable: true
19+
});
20+
return C;
21+
}());
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/accessorWithLineTerminator.ts ===
2+
class C {
3+
>C : Symbol(C, Decl(accessorWithLineTerminator.ts, 0, 0))
4+
5+
get
6+
x() { return 1 }
7+
>x : Symbol(C.x, Decl(accessorWithLineTerminator.ts, 0, 9), Decl(accessorWithLineTerminator.ts, 2, 20))
8+
9+
set
10+
x(v) { }
11+
>x : Symbol(C.x, Decl(accessorWithLineTerminator.ts, 0, 9), Decl(accessorWithLineTerminator.ts, 2, 20))
12+
>v : Symbol(v, Decl(accessorWithLineTerminator.ts, 5, 6))
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/accessorWithLineTerminator.ts ===
2+
class C {
3+
>C : C
4+
5+
get
6+
x() { return 1 }
7+
>x : number
8+
>1 : 1
9+
10+
set
11+
x(v) { }
12+
>x : number
13+
>v : number
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @target: es5
2+
3+
class C {
4+
get
5+
x() { return 1 }
6+
7+
set
8+
x(v) { }
9+
}

0 commit comments

Comments
 (0)