fix accessor parse with line terminator (#22893)

This commit is contained in:
Wenlu Wang 2018-03-29 01:59:09 +08:00 committed by Nathan Shively-Sanders
parent adf30dd694
commit cb9f436b54
5 changed files with 76 additions and 19 deletions

View File

@ -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 {

View 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;
}());

View 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))
}

View 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
}

View File

@ -0,0 +1,9 @@
// @target: es5
class C {
get
x() { return 1 }
set
x(v) { }
}