Skip to content

Commit 056d01a

Browse files
authored
fix(38283): fix incorrect parsing of static modifier (#41127)
1 parent 7db5f68 commit 056d01a

File tree

6 files changed

+133
-17
lines changed

6 files changed

+133
-17
lines changed

src/compiler/parser.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,7 @@ namespace ts {
17681768
case SyntaxKind.DefaultKeyword:
17691769
return nextTokenCanFollowDefaultKeyword();
17701770
case SyntaxKind.StaticKeyword:
1771+
return nextTokenIsOnSameLineAndCanFollowModifier();
17711772
case SyntaxKind.GetKeyword:
17721773
case SyntaxKind.SetKeyword:
17731774
nextToken();
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
1-
tests/cases/compiler/staticAsIdentifier.ts(2,5): error TS1071: 'static' modifier cannot appear on an index signature.
1+
tests/cases/compiler/staticAsIdentifier.ts(12,12): error TS1030: 'static' modifier already seen.
2+
tests/cases/compiler/staticAsIdentifier.ts(16,12): error TS1030: 'static' modifier already seen.
23

34

4-
==== tests/cases/compiler/staticAsIdentifier.ts (1 errors) ====
5-
class C {
5+
==== tests/cases/compiler/staticAsIdentifier.ts (2 errors) ====
6+
class C1 {
67
static static
7-
~~~~~~
8-
!!! error TS1071: 'static' modifier cannot appear on an index signature.
98
[x: string]: string;
10-
}
9+
}
10+
11+
class C2 {
12+
static static
13+
m() {}
14+
}
15+
16+
class C3 {
17+
static static p: string;
18+
~~~~~~
19+
!!! error TS1030: 'static' modifier already seen.
20+
}
21+
22+
class C4 {
23+
static static foo() {}
24+
~~~~~~
25+
!!! error TS1030: 'static' modifier already seen.
26+
}
27+
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,43 @@
11
//// [staticAsIdentifier.ts]
2-
class C {
2+
class C1 {
33
static static
44
[x: string]: string;
5-
}
5+
}
6+
7+
class C2 {
8+
static static
9+
m() {}
10+
}
11+
12+
class C3 {
13+
static static p: string;
14+
}
15+
16+
class C4 {
17+
static static foo() {}
18+
}
19+
620

721
//// [staticAsIdentifier.js]
8-
var C = /** @class */ (function () {
9-
function C() {
22+
var C1 = /** @class */ (function () {
23+
function C1() {
24+
}
25+
return C1;
26+
}());
27+
var C2 = /** @class */ (function () {
28+
function C2() {
29+
}
30+
C2.prototype.m = function () { };
31+
return C2;
32+
}());
33+
var C3 = /** @class */ (function () {
34+
function C3() {
35+
}
36+
return C3;
37+
}());
38+
var C4 = /** @class */ (function () {
39+
function C4() {
1040
}
11-
return C;
41+
C4.foo = function () { };
42+
return C4;
1243
}());
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
11
=== tests/cases/compiler/staticAsIdentifier.ts ===
2-
class C {
3-
>C : Symbol(C, Decl(staticAsIdentifier.ts, 0, 0))
2+
class C1 {
3+
>C1 : Symbol(C1, Decl(staticAsIdentifier.ts, 0, 0))
44

55
static static
6+
>static : Symbol(C1.static, Decl(staticAsIdentifier.ts, 0, 10))
7+
68
[x: string]: string;
79
>x : Symbol(x, Decl(staticAsIdentifier.ts, 2, 5))
810
}
11+
12+
class C2 {
13+
>C2 : Symbol(C2, Decl(staticAsIdentifier.ts, 3, 1))
14+
15+
static static
16+
>static : Symbol(C2.static, Decl(staticAsIdentifier.ts, 5, 10))
17+
18+
m() {}
19+
>m : Symbol(C2.m, Decl(staticAsIdentifier.ts, 6, 17))
20+
}
21+
22+
class C3 {
23+
>C3 : Symbol(C3, Decl(staticAsIdentifier.ts, 8, 1))
24+
25+
static static p: string;
26+
>p : Symbol(C3.p, Decl(staticAsIdentifier.ts, 10, 10))
27+
}
28+
29+
class C4 {
30+
>C4 : Symbol(C4, Decl(staticAsIdentifier.ts, 12, 1))
31+
32+
static static foo() {}
33+
>foo : Symbol(C4.foo, Decl(staticAsIdentifier.ts, 14, 10))
34+
}
35+
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
11
=== tests/cases/compiler/staticAsIdentifier.ts ===
2-
class C {
3-
>C : C
2+
class C1 {
3+
>C1 : C1
44

55
static static
6+
>static : any
7+
68
[x: string]: string;
79
>x : string
810
}
11+
12+
class C2 {
13+
>C2 : C2
14+
15+
static static
16+
>static : any
17+
18+
m() {}
19+
>m : () => void
20+
}
21+
22+
class C3 {
23+
>C3 : C3
24+
25+
static static p: string;
26+
>p : string
27+
}
28+
29+
class C4 {
30+
>C4 : C4
31+
32+
static static foo() {}
33+
>foo : () => void
34+
}
35+
+15-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1-
class C {
1+
class C1 {
22
static static
33
[x: string]: string;
4-
}
4+
}
5+
6+
class C2 {
7+
static static
8+
m() {}
9+
}
10+
11+
class C3 {
12+
static static p: string;
13+
}
14+
15+
class C4 {
16+
static static foo() {}
17+
}

0 commit comments

Comments
 (0)