mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
fix accessor parse with line terminator (#22893)
This commit is contained in:
parent
adf30dd694
commit
cb9f436b54
@ -1344,26 +1344,26 @@ namespace ts {
|
||||
}
|
||||
|
||||
function nextTokenCanFollowModifier() {
|
||||
if (token() === SyntaxKind.ConstKeyword) {
|
||||
// 'const' is only a modifier if followed by 'enum'.
|
||||
return nextToken() === SyntaxKind.EnumKeyword;
|
||||
switch (token()) {
|
||||
case SyntaxKind.ConstKeyword:
|
||||
// 'const' is only a modifier if followed by 'enum'.
|
||||
return nextToken() === SyntaxKind.EnumKeyword;
|
||||
case SyntaxKind.ExportKeyword:
|
||||
nextToken();
|
||||
if (token() === SyntaxKind.DefaultKeyword) {
|
||||
return lookAhead(nextTokenCanFollowDefaultKeyword);
|
||||
}
|
||||
return token() !== SyntaxKind.AsteriskToken && token() !== SyntaxKind.AsKeyword && token() !== SyntaxKind.OpenBraceToken && canFollowModifier();
|
||||
case SyntaxKind.DefaultKeyword:
|
||||
return nextTokenCanFollowDefaultKeyword();
|
||||
case SyntaxKind.StaticKeyword:
|
||||
case SyntaxKind.GetKeyword:
|
||||
case SyntaxKind.SetKeyword:
|
||||
nextToken();
|
||||
return canFollowModifier();
|
||||
default:
|
||||
return nextTokenIsOnSameLineAndCanFollowModifier();
|
||||
}
|
||||
if (token() === SyntaxKind.ExportKeyword) {
|
||||
nextToken();
|
||||
if (token() === SyntaxKind.DefaultKeyword) {
|
||||
return lookAhead(nextTokenCanFollowDefaultKeyword);
|
||||
}
|
||||
return token() !== SyntaxKind.AsteriskToken && token() !== SyntaxKind.AsKeyword && token() !== SyntaxKind.OpenBraceToken && canFollowModifier();
|
||||
}
|
||||
if (token() === SyntaxKind.DefaultKeyword) {
|
||||
return nextTokenCanFollowDefaultKeyword();
|
||||
}
|
||||
if (token() === SyntaxKind.StaticKeyword) {
|
||||
nextToken();
|
||||
return canFollowModifier();
|
||||
}
|
||||
|
||||
return nextTokenIsOnSameLineAndCanFollowModifier();
|
||||
}
|
||||
|
||||
function parseAnyContextualModifier(): boolean {
|
||||
|
||||
21
tests/baselines/reference/accessorWithLineTerminator.js
Normal file
21
tests/baselines/reference/accessorWithLineTerminator.js
Normal file
@ -0,0 +1,21 @@
|
||||
//// [accessorWithLineTerminator.ts]
|
||||
class C {
|
||||
get
|
||||
x() { return 1 }
|
||||
|
||||
set
|
||||
x(v) { }
|
||||
}
|
||||
|
||||
//// [accessorWithLineTerminator.js]
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
Object.defineProperty(C.prototype, "x", {
|
||||
get: function () { return 1; },
|
||||
set: function (v) { },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return C;
|
||||
}());
|
||||
13
tests/baselines/reference/accessorWithLineTerminator.symbols
Normal file
13
tests/baselines/reference/accessorWithLineTerminator.symbols
Normal file
@ -0,0 +1,13 @@
|
||||
=== tests/cases/compiler/accessorWithLineTerminator.ts ===
|
||||
class C {
|
||||
>C : Symbol(C, Decl(accessorWithLineTerminator.ts, 0, 0))
|
||||
|
||||
get
|
||||
x() { return 1 }
|
||||
>x : Symbol(C.x, Decl(accessorWithLineTerminator.ts, 0, 9), Decl(accessorWithLineTerminator.ts, 2, 20))
|
||||
|
||||
set
|
||||
x(v) { }
|
||||
>x : Symbol(C.x, Decl(accessorWithLineTerminator.ts, 0, 9), Decl(accessorWithLineTerminator.ts, 2, 20))
|
||||
>v : Symbol(v, Decl(accessorWithLineTerminator.ts, 5, 6))
|
||||
}
|
||||
14
tests/baselines/reference/accessorWithLineTerminator.types
Normal file
14
tests/baselines/reference/accessorWithLineTerminator.types
Normal file
@ -0,0 +1,14 @@
|
||||
=== tests/cases/compiler/accessorWithLineTerminator.ts ===
|
||||
class C {
|
||||
>C : C
|
||||
|
||||
get
|
||||
x() { return 1 }
|
||||
>x : number
|
||||
>1 : 1
|
||||
|
||||
set
|
||||
x(v) { }
|
||||
>x : number
|
||||
>v : number
|
||||
}
|
||||
9
tests/cases/compiler/accessorWithLineTerminator.ts
Normal file
9
tests/cases/compiler/accessorWithLineTerminator.ts
Normal file
@ -0,0 +1,9 @@
|
||||
// @target: es5
|
||||
|
||||
class C {
|
||||
get
|
||||
x() { return 1 }
|
||||
|
||||
set
|
||||
x(v) { }
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user