From 37859aa4a58256a11cc71ed4621429a0e0c0ebaf Mon Sep 17 00:00:00 2001 From: Alexander T Date: Thu, 15 Oct 2020 18:06:10 +0300 Subject: [PATCH] fix(38283): fix incorrect parsing of static modifier --- src/compiler/parser.ts | 1 + .../reference/staticAsIdentifier.errors.txt | 29 ++++++++++--- .../baselines/reference/staticAsIdentifier.js | 41 ++++++++++++++++--- .../reference/staticAsIdentifier.symbols | 31 +++++++++++++- .../reference/staticAsIdentifier.types | 31 +++++++++++++- tests/cases/compiler/staticAsIdentifier.ts | 17 +++++++- 6 files changed, 133 insertions(+), 17 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a815a12db9a53..8850ad8511147 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1767,6 +1767,7 @@ namespace ts { case SyntaxKind.DefaultKeyword: return nextTokenCanFollowDefaultKeyword(); case SyntaxKind.StaticKeyword: + return nextTokenIsOnSameLineAndCanFollowModifier(); case SyntaxKind.GetKeyword: case SyntaxKind.SetKeyword: nextToken(); diff --git a/tests/baselines/reference/staticAsIdentifier.errors.txt b/tests/baselines/reference/staticAsIdentifier.errors.txt index 4173b0b14c5d3..105c649c7eafa 100644 --- a/tests/baselines/reference/staticAsIdentifier.errors.txt +++ b/tests/baselines/reference/staticAsIdentifier.errors.txt @@ -1,10 +1,27 @@ -tests/cases/compiler/staticAsIdentifier.ts(2,5): error TS1071: 'static' modifier cannot appear on an index signature. +tests/cases/compiler/staticAsIdentifier.ts(12,12): error TS1030: 'static' modifier already seen. +tests/cases/compiler/staticAsIdentifier.ts(16,12): error TS1030: 'static' modifier already seen. -==== tests/cases/compiler/staticAsIdentifier.ts (1 errors) ==== - class C { +==== tests/cases/compiler/staticAsIdentifier.ts (2 errors) ==== + class C1 { static static - ~~~~~~ -!!! error TS1071: 'static' modifier cannot appear on an index signature. [x: string]: string; - } \ No newline at end of file + } + + class C2 { + static static + m() {} + } + + class C3 { + static static p: string; + ~~~~~~ +!!! error TS1030: 'static' modifier already seen. + } + + class C4 { + static static foo() {} + ~~~~~~ +!!! error TS1030: 'static' modifier already seen. + } + \ No newline at end of file diff --git a/tests/baselines/reference/staticAsIdentifier.js b/tests/baselines/reference/staticAsIdentifier.js index d04fd375be5d0..bb20660aef212 100644 --- a/tests/baselines/reference/staticAsIdentifier.js +++ b/tests/baselines/reference/staticAsIdentifier.js @@ -1,12 +1,43 @@ //// [staticAsIdentifier.ts] -class C { +class C1 { static static [x: string]: string; -} +} + +class C2 { + static static + m() {} +} + +class C3 { + static static p: string; +} + +class C4 { + static static foo() {} +} + //// [staticAsIdentifier.js] -var C = /** @class */ (function () { - function C() { +var C1 = /** @class */ (function () { + function C1() { + } + return C1; +}()); +var C2 = /** @class */ (function () { + function C2() { + } + C2.prototype.m = function () { }; + return C2; +}()); +var C3 = /** @class */ (function () { + function C3() { + } + return C3; +}()); +var C4 = /** @class */ (function () { + function C4() { } - return C; + C4.foo = function () { }; + return C4; }()); diff --git a/tests/baselines/reference/staticAsIdentifier.symbols b/tests/baselines/reference/staticAsIdentifier.symbols index c5f37ddd1f80a..d84a644c71dce 100644 --- a/tests/baselines/reference/staticAsIdentifier.symbols +++ b/tests/baselines/reference/staticAsIdentifier.symbols @@ -1,8 +1,35 @@ === tests/cases/compiler/staticAsIdentifier.ts === -class C { ->C : Symbol(C, Decl(staticAsIdentifier.ts, 0, 0)) +class C1 { +>C1 : Symbol(C1, Decl(staticAsIdentifier.ts, 0, 0)) static static +>static : Symbol(C1.static, Decl(staticAsIdentifier.ts, 0, 10)) + [x: string]: string; >x : Symbol(x, Decl(staticAsIdentifier.ts, 2, 5)) } + +class C2 { +>C2 : Symbol(C2, Decl(staticAsIdentifier.ts, 3, 1)) + + static static +>static : Symbol(C2.static, Decl(staticAsIdentifier.ts, 5, 10)) + + m() {} +>m : Symbol(C2.m, Decl(staticAsIdentifier.ts, 6, 17)) +} + +class C3 { +>C3 : Symbol(C3, Decl(staticAsIdentifier.ts, 8, 1)) + + static static p: string; +>p : Symbol(C3.p, Decl(staticAsIdentifier.ts, 10, 10)) +} + +class C4 { +>C4 : Symbol(C4, Decl(staticAsIdentifier.ts, 12, 1)) + + static static foo() {} +>foo : Symbol(C4.foo, Decl(staticAsIdentifier.ts, 14, 10)) +} + diff --git a/tests/baselines/reference/staticAsIdentifier.types b/tests/baselines/reference/staticAsIdentifier.types index 05608dce146b1..d2d82c343b466 100644 --- a/tests/baselines/reference/staticAsIdentifier.types +++ b/tests/baselines/reference/staticAsIdentifier.types @@ -1,8 +1,35 @@ === tests/cases/compiler/staticAsIdentifier.ts === -class C { ->C : C +class C1 { +>C1 : C1 static static +>static : any + [x: string]: string; >x : string } + +class C2 { +>C2 : C2 + + static static +>static : any + + m() {} +>m : () => void +} + +class C3 { +>C3 : C3 + + static static p: string; +>p : string +} + +class C4 { +>C4 : C4 + + static static foo() {} +>foo : () => void +} + diff --git a/tests/cases/compiler/staticAsIdentifier.ts b/tests/cases/compiler/staticAsIdentifier.ts index 3cccca3bf8874..a6cfdf5413dfe 100644 --- a/tests/cases/compiler/staticAsIdentifier.ts +++ b/tests/cases/compiler/staticAsIdentifier.ts @@ -1,4 +1,17 @@ -class C { +class C1 { static static [x: string]: string; -} \ No newline at end of file +} + +class C2 { + static static + m() {} +} + +class C3 { + static static p: string; +} + +class C4 { + static static foo() {} +}