Skip to content

Commit 016d78b

Browse files
author
Orta Therox
authored
Allow for class static vars to be called static (#44813)
* Allow for class static vars to be called static - re: #41127 * Add the baselines
1 parent 95ef2a5 commit 016d78b

27 files changed

+196
-57
lines changed

src/compiler/parser.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1974,7 +1974,6 @@ namespace ts {
19741974
case SyntaxKind.DefaultKeyword:
19751975
return nextTokenCanFollowDefaultKeyword();
19761976
case SyntaxKind.StaticKeyword:
1977-
return nextTokenIsOnSameLineAndCanFollowModifier();
19781977
case SyntaxKind.GetKeyword:
19791978
case SyntaxKind.SetKeyword:
19801979
nextToken();
@@ -6870,7 +6869,7 @@ namespace ts {
68706869
return list && createNodeArray(list, pos);
68716870
}
68726871

6873-
function tryParseModifier(permitInvalidConstAsModifier?: boolean, stopOnStartOfClassStaticBlock?: boolean): Modifier | undefined {
6872+
function tryParseModifier(permitInvalidConstAsModifier?: boolean, stopOnStartOfClassStaticBlock?: boolean, hasSeenStaticModifier?: boolean): Modifier | undefined {
68746873
const pos = getNodePos();
68756874
const kind = token();
68766875

@@ -6884,6 +6883,9 @@ namespace ts {
68846883
else if (stopOnStartOfClassStaticBlock && token() === SyntaxKind.StaticKeyword && lookAhead(nextTokenIsOpenBrace)) {
68856884
return undefined;
68866885
}
6886+
else if (hasSeenStaticModifier && token() === SyntaxKind.StaticKeyword) {
6887+
return undefined;
6888+
}
68876889
else {
68886890
if (!parseAnyContextualModifier()) {
68896891
return undefined;
@@ -6902,8 +6904,9 @@ namespace ts {
69026904
*/
69036905
function parseModifiers(permitInvalidConstAsModifier?: boolean, stopOnStartOfClassStaticBlock?: boolean): NodeArray<Modifier> | undefined {
69046906
const pos = getNodePos();
6905-
let list, modifier;
6906-
while (modifier = tryParseModifier(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock)) {
6907+
let list, modifier, hasSeenStatic = false;
6908+
while (modifier = tryParseModifier(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock, hasSeenStatic)) {
6909+
if (modifier.kind === SyntaxKind.StaticKeyword) hasSeenStatic = true;
69076910
list = append(list, modifier);
69086911
}
69096912
return list && createNodeArray(list, pos);
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
1-
tests/cases/compiler/multipleClassPropertyModifiersErrors.ts(2,9): error TS1028: Accessibility modifier already seen.
2-
tests/cases/compiler/multipleClassPropertyModifiersErrors.ts(3,10): error TS1028: Accessibility modifier already seen.
3-
tests/cases/compiler/multipleClassPropertyModifiersErrors.ts(4,9): error TS1030: 'static' modifier already seen.
4-
tests/cases/compiler/multipleClassPropertyModifiersErrors.ts(5,9): error TS1028: Accessibility modifier already seen.
5-
tests/cases/compiler/multipleClassPropertyModifiersErrors.ts(6,10): error TS1028: Accessibility modifier already seen.
1+
tests/cases/compiler/multipleClassPropertyModifiersErrors.ts(4,16): error TS1005: ';' expected.
62

73

8-
==== tests/cases/compiler/multipleClassPropertyModifiersErrors.ts (5 errors) ====
4+
==== tests/cases/compiler/multipleClassPropertyModifiersErrors.ts (1 errors) ====
95
class C {
106
public public p1;
11-
~~~~~~
12-
!!! error TS1028: Accessibility modifier already seen.
137
private private p2;
14-
~~~~~~~
15-
!!! error TS1028: Accessibility modifier already seen.
168
static static p3;
17-
~~~~~~
18-
!!! error TS1030: 'static' modifier already seen.
9+
~~
10+
!!! error TS1005: ';' expected.
1911
public private p4;
20-
~~~~~~~
21-
!!! error TS1028: Accessibility modifier already seen.
2212
private public p5;
23-
~~~~~~
24-
!!! error TS1028: Accessibility modifier already seen.
2513
public static p6;
2614
private static p7;
2715
}

tests/baselines/reference/multipleClassPropertyModifiersErrors.symbols

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ class C {
99
>p2 : Symbol(C.p2, Decl(multipleClassPropertyModifiersErrors.ts, 1, 18))
1010

1111
static static p3;
12-
>p3 : Symbol(C.p3, Decl(multipleClassPropertyModifiersErrors.ts, 2, 20))
12+
>static : Symbol(C.static, Decl(multipleClassPropertyModifiersErrors.ts, 2, 20))
13+
>p3 : Symbol(C.p3, Decl(multipleClassPropertyModifiersErrors.ts, 3, 14))
1314

1415
public private p4;
1516
>p4 : Symbol(C.p4, Decl(multipleClassPropertyModifiersErrors.ts, 3, 18))

tests/baselines/reference/multipleClassPropertyModifiersErrors.types

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class C {
99
>p2 : any
1010

1111
static static p3;
12+
>static : any
1213
>p3 : any
1314

1415
public private p4;
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts(2,11): error TS1030: 'static' modifier already seen.
1+
tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts(2,18): error TS1005: ';' expected.
22

33

44
==== tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts (1 errors) ====
55
class C {
66
static static [x: string]: string;
7-
~~~~~~
8-
!!! error TS1030: 'static' modifier already seen.
7+
~
8+
!!! error TS1005: ';' expected.
99
}

tests/baselines/reference/parserIndexMemberDeclaration10.symbols

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ class C {
33
>C : Symbol(C, Decl(parserIndexMemberDeclaration10.ts, 0, 0))
44

55
static static [x: string]: string;
6+
>static : Symbol(C.static, Decl(parserIndexMemberDeclaration10.ts, 0, 9))
67
>x : Symbol(x, Decl(parserIndexMemberDeclaration10.ts, 1, 18))
78
}

tests/baselines/reference/parserIndexMemberDeclaration10.types

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ class C {
33
>C : C
44

55
static static [x: string]: string;
6+
>static : any
67
>x : string
78
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration8.ts(2,12): error TS1030: 'static' modifier already seen.
1+
tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration8.ts(2,19): error TS1005: ';' expected.
22
tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration8.ts(2,23): error TS2378: A 'get' accessor must return a value.
33

44

55
==== tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration8.ts (2 errors) ====
66
class C {
77
static static get Foo() { }
8-
~~~~~~
9-
!!! error TS1030: 'static' modifier already seen.
8+
~~~
9+
!!! error TS1005: ';' expected.
1010
~~~
1111
!!! error TS2378: A 'get' accessor must return a value.
1212
}

tests/baselines/reference/parserMemberAccessorDeclaration8.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class C {
77
var C = /** @class */ (function () {
88
function C() {
99
}
10-
Object.defineProperty(C, "Foo", {
10+
Object.defineProperty(C.prototype, "Foo", {
1111
get: function () { },
1212
enumerable: false,
1313
configurable: true

tests/baselines/reference/parserMemberAccessorDeclaration8.symbols

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ class C {
33
>C : Symbol(C, Decl(parserMemberAccessorDeclaration8.ts, 0, 0))
44

55
static static get Foo() { }
6-
>Foo : Symbol(C.Foo, Decl(parserMemberAccessorDeclaration8.ts, 0, 9))
6+
>static : Symbol(C.static, Decl(parserMemberAccessorDeclaration8.ts, 0, 9))
7+
>Foo : Symbol(C.Foo, Decl(parserMemberAccessorDeclaration8.ts, 1, 17))
78
}

tests/baselines/reference/parserMemberAccessorDeclaration8.types

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ class C {
33
>C : C
44

55
static static get Foo() { }
6+
>static : any
67
>Foo : void
78
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration2.ts(2,12): error TS1030: 'static' modifier already seen.
1+
tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration2.ts(2,19): error TS1005: ';' expected.
22

33

44
==== tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration2.ts (1 errors) ====
55
class C {
66
static static Foo() { }
7-
~~~~~~
8-
!!! error TS1030: 'static' modifier already seen.
7+
~~~
8+
!!! error TS1005: ';' expected.
99
}

tests/baselines/reference/parserMemberFunctionDeclaration2.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ class C {
77
var C = /** @class */ (function () {
88
function C() {
99
}
10-
C.Foo = function () { };
10+
C.prototype.Foo = function () { };
1111
return C;
1212
}());

tests/baselines/reference/parserMemberFunctionDeclaration2.symbols

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ class C {
33
>C : Symbol(C, Decl(parserMemberFunctionDeclaration2.ts, 0, 0))
44

55
static static Foo() { }
6-
>Foo : Symbol(C.Foo, Decl(parserMemberFunctionDeclaration2.ts, 0, 9))
6+
>static : Symbol(C.static, Decl(parserMemberFunctionDeclaration2.ts, 0, 9))
7+
>Foo : Symbol(C.Foo, Decl(parserMemberFunctionDeclaration2.ts, 1, 17))
78
}

tests/baselines/reference/parserMemberFunctionDeclaration2.types

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ class C {
33
>C : C
44

55
static static Foo() { }
6+
>static : any
67
>Foo : () => void
78
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
tests/cases/conformance/parser/ecmascript5/MemberVariableDeclarations/parserMemberVariableDeclaration2.ts(2,10): error TS1030: 'static' modifier already seen.
1+
tests/cases/conformance/parser/ecmascript5/MemberVariableDeclarations/parserMemberVariableDeclaration2.ts(2,17): error TS1005: ';' expected.
22

33

44
==== tests/cases/conformance/parser/ecmascript5/MemberVariableDeclarations/parserMemberVariableDeclaration2.ts (1 errors) ====
55
class C {
66
static static Foo;
7-
~~~~~~
8-
!!! error TS1030: 'static' modifier already seen.
7+
~~~
8+
!!! error TS1005: ';' expected.
99
}

tests/baselines/reference/parserMemberVariableDeclaration2.symbols

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ class C {
33
>C : Symbol(C, Decl(parserMemberVariableDeclaration2.ts, 0, 0))
44

55
static static Foo;
6-
>Foo : Symbol(C.Foo, Decl(parserMemberVariableDeclaration2.ts, 0, 9))
6+
>static : Symbol(C.static, Decl(parserMemberVariableDeclaration2.ts, 0, 9))
7+
>Foo : Symbol(C.Foo, Decl(parserMemberVariableDeclaration2.ts, 1, 15))
78
}

tests/baselines/reference/parserMemberVariableDeclaration2.types

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ class C {
33
>C : C
44

55
static static Foo;
6+
>static : any
67
>Foo : any
78
}

tests/baselines/reference/staticAsIdentifier.errors.txt

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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.
1+
tests/cases/compiler/staticAsIdentifier.ts(12,19): error TS1005: ';' expected.
2+
tests/cases/compiler/staticAsIdentifier.ts(16,19): error TS1005: ';' expected.
33

44

55
==== tests/cases/compiler/staticAsIdentifier.ts (2 errors) ====
@@ -15,13 +15,28 @@ tests/cases/compiler/staticAsIdentifier.ts(16,12): error TS1030: 'static' modifi
1515

1616
class C3 {
1717
static static p: string;
18-
~~~~~~
19-
!!! error TS1030: 'static' modifier already seen.
18+
~
19+
!!! error TS1005: ';' expected.
2020
}
2121

2222
class C4 {
2323
static static foo() {}
24-
~~~~~~
25-
!!! error TS1030: 'static' modifier already seen.
24+
~~~
25+
!!! error TS1005: ';' expected.
2626
}
27+
28+
class C5 {
29+
static static
30+
}
31+
32+
class C6 {
33+
static
34+
static
35+
}
36+
37+
class C7 extends C6 {
38+
static override static
39+
}
40+
41+
2742

tests/baselines/reference/staticAsIdentifier.js

+48-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,39 @@ class C3 {
1616
class C4 {
1717
static static foo() {}
1818
}
19+
20+
class C5 {
21+
static static
22+
}
23+
24+
class C6 {
25+
static
26+
static
27+
}
28+
29+
class C7 extends C6 {
30+
static override static
31+
}
32+
33+
1934

2035

2136
//// [staticAsIdentifier.js]
37+
var __extends = (this && this.__extends) || (function () {
38+
var extendStatics = function (d, b) {
39+
extendStatics = Object.setPrototypeOf ||
40+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
41+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
42+
return extendStatics(d, b);
43+
};
44+
return function (d, b) {
45+
if (typeof b !== "function" && b !== null)
46+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
47+
extendStatics(d, b);
48+
function __() { this.constructor = d; }
49+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
50+
};
51+
})();
2252
var C1 = /** @class */ (function () {
2353
function C1() {
2454
}
@@ -38,6 +68,23 @@ var C3 = /** @class */ (function () {
3868
var C4 = /** @class */ (function () {
3969
function C4() {
4070
}
41-
C4.foo = function () { };
71+
C4.prototype.foo = function () { };
4272
return C4;
4373
}());
74+
var C5 = /** @class */ (function () {
75+
function C5() {
76+
}
77+
return C5;
78+
}());
79+
var C6 = /** @class */ (function () {
80+
function C6() {
81+
}
82+
return C6;
83+
}());
84+
var C7 = /** @class */ (function (_super) {
85+
__extends(C7, _super);
86+
function C7() {
87+
return _super !== null && _super.apply(this, arguments) || this;
88+
}
89+
return C7;
90+
}(C6));

tests/baselines/reference/staticAsIdentifier.symbols

+29-2
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,40 @@ class C3 {
2323
>C3 : Symbol(C3, Decl(staticAsIdentifier.ts, 8, 1))
2424

2525
static static p: string;
26-
>p : Symbol(C3.p, Decl(staticAsIdentifier.ts, 10, 10))
26+
>static : Symbol(C3.static, Decl(staticAsIdentifier.ts, 10, 10))
27+
>p : Symbol(C3.p, Decl(staticAsIdentifier.ts, 11, 17))
2728
}
2829

2930
class C4 {
3031
>C4 : Symbol(C4, Decl(staticAsIdentifier.ts, 12, 1))
3132

3233
static static foo() {}
33-
>foo : Symbol(C4.foo, Decl(staticAsIdentifier.ts, 14, 10))
34+
>static : Symbol(C4.static, Decl(staticAsIdentifier.ts, 14, 10))
35+
>foo : Symbol(C4.foo, Decl(staticAsIdentifier.ts, 15, 17))
3436
}
3537

38+
class C5 {
39+
>C5 : Symbol(C5, Decl(staticAsIdentifier.ts, 16, 1))
40+
41+
static static
42+
>static : Symbol(C5.static, Decl(staticAsIdentifier.ts, 18, 10))
43+
}
44+
45+
class C6 {
46+
>C6 : Symbol(C6, Decl(staticAsIdentifier.ts, 20, 1))
47+
48+
static
49+
static
50+
>static : Symbol(C6.static, Decl(staticAsIdentifier.ts, 22, 10))
51+
}
52+
53+
class C7 extends C6 {
54+
>C7 : Symbol(C7, Decl(staticAsIdentifier.ts, 25, 1))
55+
>C6 : Symbol(C6, Decl(staticAsIdentifier.ts, 20, 1))
56+
57+
static override static
58+
>static : Symbol(C7.static, Decl(staticAsIdentifier.ts, 27, 21))
59+
}
60+
61+
62+

0 commit comments

Comments
 (0)