Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(38283): Incorrect parse on static property followed by method #41127

Merged
merged 1 commit into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1767,6 +1767,7 @@ namespace ts {
case SyntaxKind.DefaultKeyword:
return nextTokenCanFollowDefaultKeyword();
case SyntaxKind.StaticKeyword:
return nextTokenIsOnSameLineAndCanFollowModifier();
case SyntaxKind.GetKeyword:
case SyntaxKind.SetKeyword:
nextToken();
Expand Down
29 changes: 23 additions & 6 deletions tests/baselines/reference/staticAsIdentifier.errors.txt
Original file line number Diff line number Diff line change
@@ -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;
}
}

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

41 changes: 36 additions & 5 deletions tests/baselines/reference/staticAsIdentifier.js
Original file line number Diff line number Diff line change
@@ -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;
}());
31 changes: 29 additions & 2 deletions tests/baselines/reference/staticAsIdentifier.symbols
Original file line number Diff line number Diff line change
@@ -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))
}

31 changes: 29 additions & 2 deletions tests/baselines/reference/staticAsIdentifier.types
Original file line number Diff line number Diff line change
@@ -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
}

17 changes: 15 additions & 2 deletions tests/cases/compiler/staticAsIdentifier.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
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() {}
}