mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Allow for class static vars to be called static (#44813)
* Allow for class static vars to be called static - re: #41127 * Add the baselines
This commit is contained in:
@@ -1974,7 +1974,6 @@ namespace ts {
|
||||
case SyntaxKind.DefaultKeyword:
|
||||
return nextTokenCanFollowDefaultKeyword();
|
||||
case SyntaxKind.StaticKeyword:
|
||||
return nextTokenIsOnSameLineAndCanFollowModifier();
|
||||
case SyntaxKind.GetKeyword:
|
||||
case SyntaxKind.SetKeyword:
|
||||
nextToken();
|
||||
@@ -6870,7 +6869,7 @@ namespace ts {
|
||||
return list && createNodeArray(list, pos);
|
||||
}
|
||||
|
||||
function tryParseModifier(permitInvalidConstAsModifier?: boolean, stopOnStartOfClassStaticBlock?: boolean): Modifier | undefined {
|
||||
function tryParseModifier(permitInvalidConstAsModifier?: boolean, stopOnStartOfClassStaticBlock?: boolean, hasSeenStaticModifier?: boolean): Modifier | undefined {
|
||||
const pos = getNodePos();
|
||||
const kind = token();
|
||||
|
||||
@@ -6884,6 +6883,9 @@ namespace ts {
|
||||
else if (stopOnStartOfClassStaticBlock && token() === SyntaxKind.StaticKeyword && lookAhead(nextTokenIsOpenBrace)) {
|
||||
return undefined;
|
||||
}
|
||||
else if (hasSeenStaticModifier && token() === SyntaxKind.StaticKeyword) {
|
||||
return undefined;
|
||||
}
|
||||
else {
|
||||
if (!parseAnyContextualModifier()) {
|
||||
return undefined;
|
||||
@@ -6902,8 +6904,9 @@ namespace ts {
|
||||
*/
|
||||
function parseModifiers(permitInvalidConstAsModifier?: boolean, stopOnStartOfClassStaticBlock?: boolean): NodeArray<Modifier> | undefined {
|
||||
const pos = getNodePos();
|
||||
let list, modifier;
|
||||
while (modifier = tryParseModifier(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock)) {
|
||||
let list, modifier, hasSeenStatic = false;
|
||||
while (modifier = tryParseModifier(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock, hasSeenStatic)) {
|
||||
if (modifier.kind === SyntaxKind.StaticKeyword) hasSeenStatic = true;
|
||||
list = append(list, modifier);
|
||||
}
|
||||
return list && createNodeArray(list, pos);
|
||||
|
||||
@@ -1,27 +1,15 @@
|
||||
tests/cases/compiler/multipleClassPropertyModifiersErrors.ts(2,9): error TS1028: Accessibility modifier already seen.
|
||||
tests/cases/compiler/multipleClassPropertyModifiersErrors.ts(3,10): error TS1028: Accessibility modifier already seen.
|
||||
tests/cases/compiler/multipleClassPropertyModifiersErrors.ts(4,9): error TS1030: 'static' modifier already seen.
|
||||
tests/cases/compiler/multipleClassPropertyModifiersErrors.ts(5,9): error TS1028: Accessibility modifier already seen.
|
||||
tests/cases/compiler/multipleClassPropertyModifiersErrors.ts(6,10): error TS1028: Accessibility modifier already seen.
|
||||
tests/cases/compiler/multipleClassPropertyModifiersErrors.ts(4,16): error TS1005: ';' expected.
|
||||
|
||||
|
||||
==== tests/cases/compiler/multipleClassPropertyModifiersErrors.ts (5 errors) ====
|
||||
==== tests/cases/compiler/multipleClassPropertyModifiersErrors.ts (1 errors) ====
|
||||
class C {
|
||||
public public p1;
|
||||
~~~~~~
|
||||
!!! error TS1028: Accessibility modifier already seen.
|
||||
private private p2;
|
||||
~~~~~~~
|
||||
!!! error TS1028: Accessibility modifier already seen.
|
||||
static static p3;
|
||||
~~~~~~
|
||||
!!! error TS1030: 'static' modifier already seen.
|
||||
~~
|
||||
!!! error TS1005: ';' expected.
|
||||
public private p4;
|
||||
~~~~~~~
|
||||
!!! error TS1028: Accessibility modifier already seen.
|
||||
private public p5;
|
||||
~~~~~~
|
||||
!!! error TS1028: Accessibility modifier already seen.
|
||||
public static p6;
|
||||
private static p7;
|
||||
}
|
||||
@@ -9,7 +9,8 @@ class C {
|
||||
>p2 : Symbol(C.p2, Decl(multipleClassPropertyModifiersErrors.ts, 1, 18))
|
||||
|
||||
static static p3;
|
||||
>p3 : Symbol(C.p3, Decl(multipleClassPropertyModifiersErrors.ts, 2, 20))
|
||||
>static : Symbol(C.static, Decl(multipleClassPropertyModifiersErrors.ts, 2, 20))
|
||||
>p3 : Symbol(C.p3, Decl(multipleClassPropertyModifiersErrors.ts, 3, 14))
|
||||
|
||||
public private p4;
|
||||
>p4 : Symbol(C.p4, Decl(multipleClassPropertyModifiersErrors.ts, 3, 18))
|
||||
|
||||
@@ -9,6 +9,7 @@ class C {
|
||||
>p2 : any
|
||||
|
||||
static static p3;
|
||||
>static : any
|
||||
>p3 : any
|
||||
|
||||
public private p4;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts(2,11): error TS1030: 'static' modifier already seen.
|
||||
tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts(2,18): error TS1005: ';' expected.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts (1 errors) ====
|
||||
class C {
|
||||
static static [x: string]: string;
|
||||
~~~~~~
|
||||
!!! error TS1030: 'static' modifier already seen.
|
||||
~
|
||||
!!! error TS1005: ';' expected.
|
||||
}
|
||||
@@ -3,5 +3,6 @@ class C {
|
||||
>C : Symbol(C, Decl(parserIndexMemberDeclaration10.ts, 0, 0))
|
||||
|
||||
static static [x: string]: string;
|
||||
>static : Symbol(C.static, Decl(parserIndexMemberDeclaration10.ts, 0, 9))
|
||||
>x : Symbol(x, Decl(parserIndexMemberDeclaration10.ts, 1, 18))
|
||||
}
|
||||
|
||||
@@ -3,5 +3,6 @@ class C {
|
||||
>C : C
|
||||
|
||||
static static [x: string]: string;
|
||||
>static : any
|
||||
>x : string
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration8.ts(2,12): error TS1030: 'static' modifier already seen.
|
||||
tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration8.ts(2,19): error TS1005: ';' expected.
|
||||
tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration8.ts(2,23): error TS2378: A 'get' accessor must return a value.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration8.ts (2 errors) ====
|
||||
class C {
|
||||
static static get Foo() { }
|
||||
~~~~~~
|
||||
!!! error TS1030: 'static' modifier already seen.
|
||||
~~~
|
||||
!!! error TS1005: ';' expected.
|
||||
~~~
|
||||
!!! error TS2378: A 'get' accessor must return a value.
|
||||
}
|
||||
@@ -7,7 +7,7 @@ class C {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
Object.defineProperty(C, "Foo", {
|
||||
Object.defineProperty(C.prototype, "Foo", {
|
||||
get: function () { },
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
|
||||
@@ -3,5 +3,6 @@ class C {
|
||||
>C : Symbol(C, Decl(parserMemberAccessorDeclaration8.ts, 0, 0))
|
||||
|
||||
static static get Foo() { }
|
||||
>Foo : Symbol(C.Foo, Decl(parserMemberAccessorDeclaration8.ts, 0, 9))
|
||||
>static : Symbol(C.static, Decl(parserMemberAccessorDeclaration8.ts, 0, 9))
|
||||
>Foo : Symbol(C.Foo, Decl(parserMemberAccessorDeclaration8.ts, 1, 17))
|
||||
}
|
||||
|
||||
@@ -3,5 +3,6 @@ class C {
|
||||
>C : C
|
||||
|
||||
static static get Foo() { }
|
||||
>static : any
|
||||
>Foo : void
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration2.ts(2,12): error TS1030: 'static' modifier already seen.
|
||||
tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration2.ts(2,19): error TS1005: ';' expected.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration2.ts (1 errors) ====
|
||||
class C {
|
||||
static static Foo() { }
|
||||
~~~~~~
|
||||
!!! error TS1030: 'static' modifier already seen.
|
||||
~~~
|
||||
!!! error TS1005: ';' expected.
|
||||
}
|
||||
@@ -7,6 +7,6 @@ class C {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
C.Foo = function () { };
|
||||
C.prototype.Foo = function () { };
|
||||
return C;
|
||||
}());
|
||||
|
||||
@@ -3,5 +3,6 @@ class C {
|
||||
>C : Symbol(C, Decl(parserMemberFunctionDeclaration2.ts, 0, 0))
|
||||
|
||||
static static Foo() { }
|
||||
>Foo : Symbol(C.Foo, Decl(parserMemberFunctionDeclaration2.ts, 0, 9))
|
||||
>static : Symbol(C.static, Decl(parserMemberFunctionDeclaration2.ts, 0, 9))
|
||||
>Foo : Symbol(C.Foo, Decl(parserMemberFunctionDeclaration2.ts, 1, 17))
|
||||
}
|
||||
|
||||
@@ -3,5 +3,6 @@ class C {
|
||||
>C : C
|
||||
|
||||
static static Foo() { }
|
||||
>static : any
|
||||
>Foo : () => void
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
tests/cases/conformance/parser/ecmascript5/MemberVariableDeclarations/parserMemberVariableDeclaration2.ts(2,10): error TS1030: 'static' modifier already seen.
|
||||
tests/cases/conformance/parser/ecmascript5/MemberVariableDeclarations/parserMemberVariableDeclaration2.ts(2,17): error TS1005: ';' expected.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/MemberVariableDeclarations/parserMemberVariableDeclaration2.ts (1 errors) ====
|
||||
class C {
|
||||
static static Foo;
|
||||
~~~~~~
|
||||
!!! error TS1030: 'static' modifier already seen.
|
||||
~~~
|
||||
!!! error TS1005: ';' expected.
|
||||
}
|
||||
@@ -3,5 +3,6 @@ class C {
|
||||
>C : Symbol(C, Decl(parserMemberVariableDeclaration2.ts, 0, 0))
|
||||
|
||||
static static Foo;
|
||||
>Foo : Symbol(C.Foo, Decl(parserMemberVariableDeclaration2.ts, 0, 9))
|
||||
>static : Symbol(C.static, Decl(parserMemberVariableDeclaration2.ts, 0, 9))
|
||||
>Foo : Symbol(C.Foo, Decl(parserMemberVariableDeclaration2.ts, 1, 15))
|
||||
}
|
||||
|
||||
@@ -3,5 +3,6 @@ class C {
|
||||
>C : C
|
||||
|
||||
static static Foo;
|
||||
>static : any
|
||||
>Foo : any
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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(12,19): error TS1005: ';' expected.
|
||||
tests/cases/compiler/staticAsIdentifier.ts(16,19): error TS1005: ';' expected.
|
||||
|
||||
|
||||
==== tests/cases/compiler/staticAsIdentifier.ts (2 errors) ====
|
||||
@@ -15,13 +15,28 @@ tests/cases/compiler/staticAsIdentifier.ts(16,12): error TS1030: 'static' modifi
|
||||
|
||||
class C3 {
|
||||
static static p: string;
|
||||
~~~~~~
|
||||
!!! error TS1030: 'static' modifier already seen.
|
||||
~
|
||||
!!! error TS1005: ';' expected.
|
||||
}
|
||||
|
||||
class C4 {
|
||||
static static foo() {}
|
||||
~~~~~~
|
||||
!!! error TS1030: 'static' modifier already seen.
|
||||
~~~
|
||||
!!! error TS1005: ';' expected.
|
||||
}
|
||||
|
||||
class C5 {
|
||||
static static
|
||||
}
|
||||
|
||||
class C6 {
|
||||
static
|
||||
static
|
||||
}
|
||||
|
||||
class C7 extends C6 {
|
||||
static override static
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,9 +16,39 @@ class C3 {
|
||||
class C4 {
|
||||
static static foo() {}
|
||||
}
|
||||
|
||||
class C5 {
|
||||
static static
|
||||
}
|
||||
|
||||
class C6 {
|
||||
static
|
||||
static
|
||||
}
|
||||
|
||||
class C7 extends C6 {
|
||||
static override static
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//// [staticAsIdentifier.js]
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var C1 = /** @class */ (function () {
|
||||
function C1() {
|
||||
}
|
||||
@@ -38,6 +68,23 @@ var C3 = /** @class */ (function () {
|
||||
var C4 = /** @class */ (function () {
|
||||
function C4() {
|
||||
}
|
||||
C4.foo = function () { };
|
||||
C4.prototype.foo = function () { };
|
||||
return C4;
|
||||
}());
|
||||
var C5 = /** @class */ (function () {
|
||||
function C5() {
|
||||
}
|
||||
return C5;
|
||||
}());
|
||||
var C6 = /** @class */ (function () {
|
||||
function C6() {
|
||||
}
|
||||
return C6;
|
||||
}());
|
||||
var C7 = /** @class */ (function (_super) {
|
||||
__extends(C7, _super);
|
||||
function C7() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return C7;
|
||||
}(C6));
|
||||
|
||||
@@ -23,13 +23,40 @@ class C3 {
|
||||
>C3 : Symbol(C3, Decl(staticAsIdentifier.ts, 8, 1))
|
||||
|
||||
static static p: string;
|
||||
>p : Symbol(C3.p, Decl(staticAsIdentifier.ts, 10, 10))
|
||||
>static : Symbol(C3.static, Decl(staticAsIdentifier.ts, 10, 10))
|
||||
>p : Symbol(C3.p, Decl(staticAsIdentifier.ts, 11, 17))
|
||||
}
|
||||
|
||||
class C4 {
|
||||
>C4 : Symbol(C4, Decl(staticAsIdentifier.ts, 12, 1))
|
||||
|
||||
static static foo() {}
|
||||
>foo : Symbol(C4.foo, Decl(staticAsIdentifier.ts, 14, 10))
|
||||
>static : Symbol(C4.static, Decl(staticAsIdentifier.ts, 14, 10))
|
||||
>foo : Symbol(C4.foo, Decl(staticAsIdentifier.ts, 15, 17))
|
||||
}
|
||||
|
||||
class C5 {
|
||||
>C5 : Symbol(C5, Decl(staticAsIdentifier.ts, 16, 1))
|
||||
|
||||
static static
|
||||
>static : Symbol(C5.static, Decl(staticAsIdentifier.ts, 18, 10))
|
||||
}
|
||||
|
||||
class C6 {
|
||||
>C6 : Symbol(C6, Decl(staticAsIdentifier.ts, 20, 1))
|
||||
|
||||
static
|
||||
static
|
||||
>static : Symbol(C6.static, Decl(staticAsIdentifier.ts, 22, 10))
|
||||
}
|
||||
|
||||
class C7 extends C6 {
|
||||
>C7 : Symbol(C7, Decl(staticAsIdentifier.ts, 25, 1))
|
||||
>C6 : Symbol(C6, Decl(staticAsIdentifier.ts, 20, 1))
|
||||
|
||||
static override static
|
||||
>static : Symbol(C7.static, Decl(staticAsIdentifier.ts, 27, 21))
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ class C3 {
|
||||
>C3 : C3
|
||||
|
||||
static static p: string;
|
||||
>static : any
|
||||
>p : string
|
||||
}
|
||||
|
||||
@@ -30,6 +31,32 @@ class C4 {
|
||||
>C4 : C4
|
||||
|
||||
static static foo() {}
|
||||
>static : any
|
||||
>foo : () => void
|
||||
}
|
||||
|
||||
class C5 {
|
||||
>C5 : C5
|
||||
|
||||
static static
|
||||
>static : any
|
||||
}
|
||||
|
||||
class C6 {
|
||||
>C6 : C6
|
||||
|
||||
static
|
||||
static
|
||||
>static : any
|
||||
}
|
||||
|
||||
class C7 extends C6 {
|
||||
>C7 : C7
|
||||
>C6 : C6
|
||||
|
||||
static override static
|
||||
>static : any
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
tests/cases/compiler/staticModifierAlreadySeen.ts(2,12): error TS1030: 'static' modifier already seen.
|
||||
tests/cases/compiler/staticModifierAlreadySeen.ts(3,19): error TS1030: 'static' modifier already seen.
|
||||
tests/cases/compiler/staticModifierAlreadySeen.ts(2,19): error TS1005: ';' expected.
|
||||
tests/cases/compiler/staticModifierAlreadySeen.ts(3,19): error TS2300: Duplicate identifier 'static'.
|
||||
tests/cases/compiler/staticModifierAlreadySeen.ts(3,26): error TS1005: ';' expected.
|
||||
|
||||
|
||||
==== tests/cases/compiler/staticModifierAlreadySeen.ts (2 errors) ====
|
||||
==== tests/cases/compiler/staticModifierAlreadySeen.ts (3 errors) ====
|
||||
class C {
|
||||
static static foo = 1;
|
||||
~~~~~~
|
||||
!!! error TS1030: 'static' modifier already seen.
|
||||
~~~
|
||||
!!! error TS1005: ';' expected.
|
||||
public static static bar() { }
|
||||
~~~~~~
|
||||
!!! error TS1030: 'static' modifier already seen.
|
||||
!!! error TS2300: Duplicate identifier 'static'.
|
||||
~~~
|
||||
!!! error TS1005: ';' expected.
|
||||
}
|
||||
@@ -7,8 +7,8 @@ class C {
|
||||
//// [staticModifierAlreadySeen.js]
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
this.foo = 1;
|
||||
}
|
||||
C.bar = function () { };
|
||||
C.foo = 1;
|
||||
C.prototype.bar = function () { };
|
||||
return C;
|
||||
}());
|
||||
|
||||
@@ -3,8 +3,10 @@ class C {
|
||||
>C : Symbol(C, Decl(staticModifierAlreadySeen.ts, 0, 0))
|
||||
|
||||
static static foo = 1;
|
||||
>foo : Symbol(C.foo, Decl(staticModifierAlreadySeen.ts, 0, 9))
|
||||
>static : Symbol(C.static, Decl(staticModifierAlreadySeen.ts, 0, 9), Decl(staticModifierAlreadySeen.ts, 1, 26))
|
||||
>foo : Symbol(C.foo, Decl(staticModifierAlreadySeen.ts, 1, 17))
|
||||
|
||||
public static static bar() { }
|
||||
>bar : Symbol(C.bar, Decl(staticModifierAlreadySeen.ts, 1, 26))
|
||||
>static : Symbol(C.static, Decl(staticModifierAlreadySeen.ts, 0, 9), Decl(staticModifierAlreadySeen.ts, 1, 26))
|
||||
>bar : Symbol(C.bar, Decl(staticModifierAlreadySeen.ts, 2, 24))
|
||||
}
|
||||
|
||||
@@ -3,9 +3,11 @@ class C {
|
||||
>C : C
|
||||
|
||||
static static foo = 1;
|
||||
>static : any
|
||||
>foo : number
|
||||
>1 : 1
|
||||
|
||||
public static static bar() { }
|
||||
>static : any
|
||||
>bar : () => void
|
||||
}
|
||||
|
||||
@@ -15,3 +15,18 @@ class C3 {
|
||||
class C4 {
|
||||
static static foo() {}
|
||||
}
|
||||
|
||||
class C5 {
|
||||
static static
|
||||
}
|
||||
|
||||
class C6 {
|
||||
static
|
||||
static
|
||||
}
|
||||
|
||||
class C7 extends C6 {
|
||||
static override static
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user