mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
arguments should not be allowed in class static block (#48172)
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
This commit is contained in:
co-authored by
Nathan Shively-Sanders
Jake Bailey
parent
11e7932759
commit
e37ca49c70
+11
-21
@@ -30738,8 +30738,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
// To avoid that we will give an error to users if they use arguments objects in arrow function so that they
|
||||
// can explicitly bound arguments objects
|
||||
if (symbol === argumentsSymbol) {
|
||||
if (isInPropertyInitializerOrClassStaticBlock(node)) {
|
||||
error(node, Diagnostics.arguments_cannot_be_referenced_in_property_initializers);
|
||||
if (isInPropertyInitializerOrClassStaticBlock(node, /*ignoreArrowFunctions*/ true)) {
|
||||
error(node, Diagnostics.arguments_cannot_be_referenced_in_property_initializers_or_class_static_initialization_blocks);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -34788,31 +34788,21 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
}
|
||||
}
|
||||
|
||||
function isInPropertyInitializerOrClassStaticBlock(node: Node): boolean {
|
||||
function isInPropertyInitializerOrClassStaticBlock(node: Node, ignoreArrowFunctions?: boolean): boolean {
|
||||
return !!findAncestor(node, node => {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.ClassStaticBlockDeclaration:
|
||||
return true;
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
case SyntaxKind.SpreadAssignment:
|
||||
case SyntaxKind.ComputedPropertyName:
|
||||
case SyntaxKind.TemplateSpan:
|
||||
case SyntaxKind.JsxExpression:
|
||||
case SyntaxKind.JsxAttribute:
|
||||
case SyntaxKind.JsxAttributes:
|
||||
case SyntaxKind.JsxSpreadAttribute:
|
||||
case SyntaxKind.JsxOpeningElement:
|
||||
case SyntaxKind.ExpressionWithTypeArguments:
|
||||
case SyntaxKind.HeritageClause:
|
||||
return false;
|
||||
case SyntaxKind.TypeQuery:
|
||||
case SyntaxKind.JsxClosingElement: // already reported in JsxOpeningElement
|
||||
return "quit";
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.ExpressionStatement:
|
||||
return isBlock(node.parent) && isClassStaticBlockDeclaration(node.parent.parent) ? true : "quit";
|
||||
return ignoreArrowFunctions ? false : "quit";
|
||||
case SyntaxKind.Block:
|
||||
return isFunctionLikeDeclaration(node.parent) && node.parent.kind !== SyntaxKind.ArrowFunction ? "quit" : false;
|
||||
default:
|
||||
return isExpressionNode(node) ? false : "quit";
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3767,7 +3767,7 @@
|
||||
"category": "Error",
|
||||
"code": 2814
|
||||
},
|
||||
"'arguments' cannot be referenced in property initializers.": {
|
||||
"'arguments' cannot be referenced in property initializers or class static initialization blocks.": {
|
||||
"category": "Error",
|
||||
"code": 2815
|
||||
},
|
||||
|
||||
+118
-10
@@ -1,15 +1,23 @@
|
||||
argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(3,10): error TS2815: 'arguments' cannot be referenced in property initializers.
|
||||
argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(9,10): error TS2815: 'arguments' cannot be referenced in property initializers.
|
||||
argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(15,15): error TS2815: 'arguments' cannot be referenced in property initializers.
|
||||
argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(21,15): error TS2815: 'arguments' cannot be referenced in property initializers.
|
||||
argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(3,10): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(9,10): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(15,15): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(21,15): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(33,16): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(40,7): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(42,16): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(66,6): error TS2585: 'Symbol' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the 'lib' compiler option to es2015 or later.
|
||||
argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(75,7): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(77,9): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(96,26): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(102,15): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
|
||||
|
||||
==== argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts (4 errors) ====
|
||||
==== argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts (12 errors) ====
|
||||
function A() {
|
||||
return class T {
|
||||
a = arguments
|
||||
~~~~~~~~~
|
||||
!!! error TS2815: 'arguments' cannot be referenced in property initializers.
|
||||
!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +25,7 @@ argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(21,15): error
|
||||
return new class T {
|
||||
a = arguments
|
||||
~~~~~~~~~
|
||||
!!! error TS2815: 'arguments' cannot be referenced in property initializers.
|
||||
!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +33,7 @@ argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(21,15): error
|
||||
return class T {
|
||||
a = { b: arguments }
|
||||
~~~~~~~~~
|
||||
!!! error TS2815: 'arguments' cannot be referenced in property initializers.
|
||||
!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +41,7 @@ argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(21,15): error
|
||||
return new class T {
|
||||
a = { b: arguments }
|
||||
~~~~~~~~~
|
||||
!!! error TS2815: 'arguments' cannot be referenced in property initializers.
|
||||
!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,4 +49,104 @@ argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(21,15): error
|
||||
return class T {
|
||||
a = function () { arguments }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function D() {
|
||||
return class T {
|
||||
a = () => arguments // should error
|
||||
~~~~~~~~~
|
||||
!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
}
|
||||
}
|
||||
|
||||
function D1() {
|
||||
return class T {
|
||||
a = () => {
|
||||
arguments; // should error
|
||||
~~~~~~~~~
|
||||
!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
const b = () => {
|
||||
return arguments; // should error
|
||||
~~~~~~~~~
|
||||
!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
}
|
||||
|
||||
function f() {
|
||||
return arguments; // ok
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function D2() {
|
||||
return class {
|
||||
constructor() {
|
||||
arguments; // ok
|
||||
}
|
||||
get foo() {
|
||||
return arguments; // ok
|
||||
}
|
||||
set foo(foo: any) {
|
||||
arguments; // ok
|
||||
}
|
||||
bar() {
|
||||
arguments; // ok
|
||||
}
|
||||
[Symbol.iterator]() {
|
||||
~~~~~~
|
||||
!!! error TS2585: 'Symbol' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the 'lib' compiler option to es2015 or later.
|
||||
arguments; // ok
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function D3() {
|
||||
return class T {
|
||||
static {
|
||||
arguments; // should error
|
||||
~~~~~~~~~
|
||||
!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
while(1) {
|
||||
arguments // should error
|
||||
~~~~~~~~~
|
||||
!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function D4() {
|
||||
return class T {
|
||||
static {
|
||||
function f() {
|
||||
arguments; // ok
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function D5() {
|
||||
return class T {
|
||||
a = (() => { return arguments; })() // should error
|
||||
~~~~~~~~~
|
||||
!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
}
|
||||
}
|
||||
|
||||
function D6() {
|
||||
return class T {
|
||||
a = (x = arguments) => {} // should error
|
||||
~~~~~~~~~
|
||||
!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
}
|
||||
}
|
||||
|
||||
function D7() {
|
||||
return class T {
|
||||
a(x = arguments){ // ok
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+190
-1
@@ -29,7 +29,91 @@ function C() {
|
||||
return class T {
|
||||
a = function () { arguments }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function D() {
|
||||
return class T {
|
||||
a = () => arguments // should error
|
||||
}
|
||||
}
|
||||
|
||||
function D1() {
|
||||
return class T {
|
||||
a = () => {
|
||||
arguments; // should error
|
||||
const b = () => {
|
||||
return arguments; // should error
|
||||
}
|
||||
|
||||
function f() {
|
||||
return arguments; // ok
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function D2() {
|
||||
return class {
|
||||
constructor() {
|
||||
arguments; // ok
|
||||
}
|
||||
get foo() {
|
||||
return arguments; // ok
|
||||
}
|
||||
set foo(foo: any) {
|
||||
arguments; // ok
|
||||
}
|
||||
bar() {
|
||||
arguments; // ok
|
||||
}
|
||||
[Symbol.iterator]() {
|
||||
arguments; // ok
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function D3() {
|
||||
return class T {
|
||||
static {
|
||||
arguments; // should error
|
||||
while(1) {
|
||||
arguments // should error
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function D4() {
|
||||
return class T {
|
||||
static {
|
||||
function f() {
|
||||
arguments; // ok
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function D5() {
|
||||
return class T {
|
||||
a = (() => { return arguments; })() // should error
|
||||
}
|
||||
}
|
||||
|
||||
function D6() {
|
||||
return class T {
|
||||
a = (x = arguments) => {} // should error
|
||||
}
|
||||
}
|
||||
|
||||
function D7() {
|
||||
return class T {
|
||||
a(x = arguments){ // ok
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.js]
|
||||
function A() {
|
||||
@@ -72,3 +156,108 @@ function C() {
|
||||
return T;
|
||||
}());
|
||||
}
|
||||
function D() {
|
||||
return /** @class */ (function () {
|
||||
function T() {
|
||||
this.a = function () { return arguments; }; // should error
|
||||
}
|
||||
return T;
|
||||
}());
|
||||
}
|
||||
function D1() {
|
||||
return /** @class */ (function () {
|
||||
function T() {
|
||||
this.a = function () {
|
||||
arguments; // should error
|
||||
var b = function () {
|
||||
return arguments; // should error
|
||||
};
|
||||
function f() {
|
||||
return arguments; // ok
|
||||
}
|
||||
};
|
||||
}
|
||||
return T;
|
||||
}());
|
||||
}
|
||||
function D2() {
|
||||
return /** @class */ (function () {
|
||||
function class_1() {
|
||||
arguments; // ok
|
||||
}
|
||||
Object.defineProperty(class_1.prototype, "foo", {
|
||||
get: function () {
|
||||
return arguments; // ok
|
||||
},
|
||||
set: function (foo) {
|
||||
arguments; // ok
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
class_1.prototype.bar = function () {
|
||||
arguments; // ok
|
||||
};
|
||||
class_1.prototype[Symbol.iterator] = function () {
|
||||
arguments; // ok
|
||||
};
|
||||
return class_1;
|
||||
}());
|
||||
}
|
||||
function D3() {
|
||||
var _a;
|
||||
return _a = /** @class */ (function () {
|
||||
function T() {
|
||||
}
|
||||
return T;
|
||||
}()),
|
||||
(function () {
|
||||
arguments; // should error
|
||||
while (1) {
|
||||
arguments; // should error
|
||||
}
|
||||
})(),
|
||||
_a;
|
||||
}
|
||||
function D4() {
|
||||
var _a;
|
||||
return _a = /** @class */ (function () {
|
||||
function T() {
|
||||
}
|
||||
return T;
|
||||
}()),
|
||||
(function () {
|
||||
function f() {
|
||||
arguments; // ok
|
||||
}
|
||||
})(),
|
||||
_a;
|
||||
}
|
||||
function D5() {
|
||||
return /** @class */ (function () {
|
||||
function T() {
|
||||
this.a = (function () { return arguments; })(); // should error
|
||||
}
|
||||
return T;
|
||||
}());
|
||||
}
|
||||
function D6() {
|
||||
return /** @class */ (function () {
|
||||
function T() {
|
||||
this.a = function (x) {
|
||||
if (x === void 0) { x = arguments; }
|
||||
}; // should error
|
||||
}
|
||||
return T;
|
||||
}());
|
||||
}
|
||||
function D7() {
|
||||
return /** @class */ (function () {
|
||||
function T() {
|
||||
}
|
||||
T.prototype.a = function (x) {
|
||||
if (x === void 0) { x = arguments; }
|
||||
};
|
||||
return T;
|
||||
}());
|
||||
}
|
||||
|
||||
+154
@@ -62,3 +62,157 @@ function C() {
|
||||
>arguments : Symbol(arguments)
|
||||
}
|
||||
}
|
||||
|
||||
function D() {
|
||||
>D : Symbol(D, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 28, 1))
|
||||
|
||||
return class T {
|
||||
>T : Symbol(T, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 31, 8))
|
||||
|
||||
a = () => arguments // should error
|
||||
>a : Symbol(T.a, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 31, 18))
|
||||
>arguments : Symbol(arguments)
|
||||
}
|
||||
}
|
||||
|
||||
function D1() {
|
||||
>D1 : Symbol(D1, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 34, 1))
|
||||
|
||||
return class T {
|
||||
>T : Symbol(T, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 37, 8))
|
||||
|
||||
a = () => {
|
||||
>a : Symbol(T.a, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 37, 18))
|
||||
|
||||
arguments; // should error
|
||||
>arguments : Symbol(arguments)
|
||||
|
||||
const b = () => {
|
||||
>b : Symbol(b, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 40, 11))
|
||||
|
||||
return arguments; // should error
|
||||
>arguments : Symbol(arguments)
|
||||
}
|
||||
|
||||
function f() {
|
||||
>f : Symbol(f, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 42, 7))
|
||||
|
||||
return arguments; // ok
|
||||
>arguments : Symbol(arguments)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function D2() {
|
||||
>D2 : Symbol(D2, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 49, 1))
|
||||
|
||||
return class {
|
||||
constructor() {
|
||||
arguments; // ok
|
||||
>arguments : Symbol(arguments)
|
||||
}
|
||||
get foo() {
|
||||
>foo : Symbol((Anonymous class).foo, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 55, 5), Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 58, 5))
|
||||
|
||||
return arguments; // ok
|
||||
>arguments : Symbol(arguments)
|
||||
}
|
||||
set foo(foo: any) {
|
||||
>foo : Symbol((Anonymous class).foo, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 55, 5), Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 58, 5))
|
||||
>foo : Symbol(foo, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 59, 12))
|
||||
|
||||
arguments; // ok
|
||||
>arguments : Symbol(arguments)
|
||||
}
|
||||
bar() {
|
||||
>bar : Symbol((Anonymous class).bar, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 61, 5))
|
||||
|
||||
arguments; // ok
|
||||
>arguments : Symbol(arguments)
|
||||
}
|
||||
[Symbol.iterator]() {
|
||||
>[Symbol.iterator] : Symbol((Anonymous class)[Symbol.iterator], Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 64, 5))
|
||||
|
||||
arguments; // ok
|
||||
>arguments : Symbol(arguments)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function D3() {
|
||||
>D3 : Symbol(D3, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 69, 1))
|
||||
|
||||
return class T {
|
||||
>T : Symbol(T, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 72, 8))
|
||||
|
||||
static {
|
||||
arguments; // should error
|
||||
>arguments : Symbol(arguments)
|
||||
|
||||
while(1) {
|
||||
arguments // should error
|
||||
>arguments : Symbol(arguments)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function D4() {
|
||||
>D4 : Symbol(D4, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 80, 1))
|
||||
|
||||
return class T {
|
||||
>T : Symbol(T, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 83, 8))
|
||||
|
||||
static {
|
||||
function f() {
|
||||
>f : Symbol(f, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 84, 12))
|
||||
|
||||
arguments; // ok
|
||||
>arguments : Symbol(arguments)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function D5() {
|
||||
>D5 : Symbol(D5, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 90, 1))
|
||||
|
||||
return class T {
|
||||
>T : Symbol(T, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 94, 8))
|
||||
|
||||
a = (() => { return arguments; })() // should error
|
||||
>a : Symbol(T.a, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 94, 18))
|
||||
>arguments : Symbol(arguments)
|
||||
}
|
||||
}
|
||||
|
||||
function D6() {
|
||||
>D6 : Symbol(D6, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 97, 1))
|
||||
|
||||
return class T {
|
||||
>T : Symbol(T, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 100, 8))
|
||||
|
||||
a = (x = arguments) => {} // should error
|
||||
>a : Symbol(T.a, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 100, 18))
|
||||
>x : Symbol(x, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 101, 10))
|
||||
>arguments : Symbol(arguments)
|
||||
}
|
||||
}
|
||||
|
||||
function D7() {
|
||||
>D7 : Symbol(D7, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 103, 1))
|
||||
|
||||
return class T {
|
||||
>T : Symbol(T, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 106, 8))
|
||||
|
||||
a(x = arguments){ // ok
|
||||
>a : Symbol(T.a, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 106, 18))
|
||||
>x : Symbol(x, Decl(argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts, 107, 7))
|
||||
>arguments : Symbol(arguments)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+239
@@ -104,3 +104,242 @@ function C() {
|
||||
> : ^^^^^^^^^^
|
||||
}
|
||||
}
|
||||
|
||||
function D() {
|
||||
>D : () => typeof T
|
||||
> : ^^^^^^^^^^^^^^
|
||||
|
||||
return class T {
|
||||
>class T { a = () => arguments // should error } : typeof T
|
||||
> : ^^^^^^^^
|
||||
>T : typeof T
|
||||
> : ^^^^^^^^
|
||||
|
||||
a = () => arguments // should error
|
||||
>a : () => IArguments
|
||||
> : ^^^^^^^^^^^^^^^^
|
||||
>() => arguments : () => IArguments
|
||||
> : ^^^^^^^^^^^^^^^^
|
||||
>arguments : IArguments
|
||||
> : ^^^^^^^^^^
|
||||
}
|
||||
}
|
||||
|
||||
function D1() {
|
||||
>D1 : () => typeof T
|
||||
> : ^^^^^^^^^^^^^^
|
||||
|
||||
return class T {
|
||||
>class T { a = () => { arguments; // should error const b = () => { return arguments; // should error } function f() { return arguments; // ok } } } : typeof T
|
||||
> : ^^^^^^^^
|
||||
>T : typeof T
|
||||
> : ^^^^^^^^
|
||||
|
||||
a = () => {
|
||||
>a : () => void
|
||||
> : ^^^^^^^^^^
|
||||
>() => { arguments; // should error const b = () => { return arguments; // should error } function f() { return arguments; // ok } } : () => void
|
||||
> : ^^^^^^^^^^
|
||||
|
||||
arguments; // should error
|
||||
>arguments : IArguments
|
||||
> : ^^^^^^^^^^
|
||||
|
||||
const b = () => {
|
||||
>b : () => IArguments
|
||||
> : ^^^^^^^^^^^^^^^^
|
||||
>() => { return arguments; // should error } : () => IArguments
|
||||
> : ^^^^^^^^^^^^^^^^
|
||||
|
||||
return arguments; // should error
|
||||
>arguments : IArguments
|
||||
> : ^^^^^^^^^^
|
||||
}
|
||||
|
||||
function f() {
|
||||
>f : () => IArguments
|
||||
> : ^^^^^^^^^^^^^^^^
|
||||
|
||||
return arguments; // ok
|
||||
>arguments : IArguments
|
||||
> : ^^^^^^^^^^
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function D2() {
|
||||
>D2 : () => typeof (Anonymous class)
|
||||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
return class {
|
||||
>class { constructor() { arguments; // ok } get foo() { return arguments; // ok } set foo(foo: any) { arguments; // ok } bar() { arguments; // ok } [Symbol.iterator]() { arguments; // ok } } : typeof (Anonymous class)
|
||||
> : ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
constructor() {
|
||||
arguments; // ok
|
||||
>arguments : IArguments
|
||||
> : ^^^^^^^^^^
|
||||
}
|
||||
get foo() {
|
||||
>foo : any
|
||||
> : ^^^
|
||||
|
||||
return arguments; // ok
|
||||
>arguments : IArguments
|
||||
> : ^^^^^^^^^^
|
||||
}
|
||||
set foo(foo: any) {
|
||||
>foo : any
|
||||
> : ^^^
|
||||
>foo : any
|
||||
> : ^^^
|
||||
|
||||
arguments; // ok
|
||||
>arguments : IArguments
|
||||
> : ^^^^^^^^^^
|
||||
}
|
||||
bar() {
|
||||
>bar : () => void
|
||||
> : ^^^^^^^^^^
|
||||
|
||||
arguments; // ok
|
||||
>arguments : IArguments
|
||||
> : ^^^^^^^^^^
|
||||
}
|
||||
[Symbol.iterator]() {
|
||||
>[Symbol.iterator] : () => void
|
||||
> : ^^^^^^^^^^
|
||||
>Symbol.iterator : any
|
||||
> : ^^^
|
||||
>Symbol : any
|
||||
> : ^^^
|
||||
>iterator : any
|
||||
> : ^^^
|
||||
|
||||
arguments; // ok
|
||||
>arguments : IArguments
|
||||
> : ^^^^^^^^^^
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function D3() {
|
||||
>D3 : () => typeof T
|
||||
> : ^^^^^^^^^^^^^^
|
||||
|
||||
return class T {
|
||||
>class T { static { arguments; // should error while(1) { arguments // should error } } } : typeof T
|
||||
> : ^^^^^^^^
|
||||
>T : typeof T
|
||||
> : ^^^^^^^^
|
||||
|
||||
static {
|
||||
arguments; // should error
|
||||
>arguments : any
|
||||
> : ^^^
|
||||
|
||||
while(1) {
|
||||
>1 : 1
|
||||
> : ^
|
||||
|
||||
arguments // should error
|
||||
>arguments : any
|
||||
> : ^^^
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function D4() {
|
||||
>D4 : () => typeof T
|
||||
> : ^^^^^^^^^^^^^^
|
||||
|
||||
return class T {
|
||||
>class T { static { function f() { arguments; // ok } } } : typeof T
|
||||
> : ^^^^^^^^
|
||||
>T : typeof T
|
||||
> : ^^^^^^^^
|
||||
|
||||
static {
|
||||
function f() {
|
||||
>f : () => void
|
||||
> : ^^^^^^^^^^
|
||||
|
||||
arguments; // ok
|
||||
>arguments : IArguments
|
||||
> : ^^^^^^^^^^
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function D5() {
|
||||
>D5 : () => typeof T
|
||||
> : ^^^^^^^^^^^^^^
|
||||
|
||||
return class T {
|
||||
>class T { a = (() => { return arguments; })() // should error } : typeof T
|
||||
> : ^^^^^^^^
|
||||
>T : typeof T
|
||||
> : ^^^^^^^^
|
||||
|
||||
a = (() => { return arguments; })() // should error
|
||||
>a : IArguments
|
||||
> : ^^^^^^^^^^
|
||||
>(() => { return arguments; })() : IArguments
|
||||
> : ^^^^^^^^^^
|
||||
>(() => { return arguments; }) : () => IArguments
|
||||
> : ^^^^^^^^^^^^^^^^
|
||||
>() => { return arguments; } : () => IArguments
|
||||
> : ^^^^^^^^^^^^^^^^
|
||||
>arguments : IArguments
|
||||
> : ^^^^^^^^^^
|
||||
}
|
||||
}
|
||||
|
||||
function D6() {
|
||||
>D6 : () => typeof T
|
||||
> : ^^^^^^^^^^^^^^
|
||||
|
||||
return class T {
|
||||
>class T { a = (x = arguments) => {} // should error } : typeof T
|
||||
> : ^^^^^^^^
|
||||
>T : typeof T
|
||||
> : ^^^^^^^^
|
||||
|
||||
a = (x = arguments) => {} // should error
|
||||
>a : (x?: IArguments) => void
|
||||
> : ^ ^^^^^^^^^^^^^^^^^^^^^^
|
||||
>(x = arguments) => {} : (x?: IArguments) => void
|
||||
> : ^ ^^^^^^^^^^^^^^^^^^^^^^
|
||||
>x : IArguments
|
||||
> : ^^^^^^^^^^
|
||||
>arguments : IArguments
|
||||
> : ^^^^^^^^^^
|
||||
}
|
||||
}
|
||||
|
||||
function D7() {
|
||||
>D7 : () => typeof T
|
||||
> : ^^^^^^^^^^^^^^
|
||||
|
||||
return class T {
|
||||
>class T { a(x = arguments){ // ok } } : typeof T
|
||||
> : ^^^^^^^^
|
||||
>T : typeof T
|
||||
> : ^^^^^^^^
|
||||
|
||||
a(x = arguments){ // ok
|
||||
>a : (x?: IArguments) => void
|
||||
> : ^ ^^^^^^^^^^^^^^^^^^^^^^
|
||||
>x : IArguments
|
||||
> : ^^^^^^^^^^
|
||||
>arguments : IArguments
|
||||
> : ^^^^^^^^^^
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,15 +7,17 @@ classStaticBlock6.ts(18,9): error TS18037: 'await' expression cannot be used ins
|
||||
classStaticBlock6.ts(18,14): error TS1109: Expression expected.
|
||||
classStaticBlock6.ts(19,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
|
||||
classStaticBlock6.ts(32,17): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
|
||||
classStaticBlock6.ts(41,13): error TS2815: 'arguments' cannot be referenced in property initializers.
|
||||
classStaticBlock6.ts(41,13): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
classStaticBlock6.ts(42,13): error TS18037: 'await' expression cannot be used inside a class static block.
|
||||
classStaticBlock6.ts(42,18): error TS1109: Expression expected.
|
||||
classStaticBlock6.ts(45,17): error TS2522: The 'arguments' object cannot be referenced in an async function or method in ES5. Consider using a standard function or method.
|
||||
classStaticBlock6.ts(46,22): error TS1109: Expression expected.
|
||||
classStaticBlock6.ts(55,13): error TS2815: 'arguments' cannot be referenced in property initializers.
|
||||
classStaticBlock6.ts(55,13): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
classStaticBlock6.ts(66,14): error TS2729: Property 'b' is used before its initialization.
|
||||
classStaticBlock6.ts(69,18): error TS2729: Property 'b' is used before its initialization.
|
||||
|
||||
|
||||
==== classStaticBlock6.ts (15 errors) ====
|
||||
==== classStaticBlock6.ts (17 errors) ====
|
||||
class B {
|
||||
static a = 1;
|
||||
}
|
||||
@@ -76,7 +78,7 @@ classStaticBlock6.ts(55,13): error TS2815: 'arguments' cannot be referenced in p
|
||||
static {
|
||||
arguments;
|
||||
~~~~~~~~~
|
||||
!!! error TS2815: 'arguments' cannot be referenced in property initializers.
|
||||
!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
await;
|
||||
~~~~~
|
||||
!!! error TS18037: 'await' expression cannot be used inside a class static block.
|
||||
@@ -100,7 +102,7 @@ classStaticBlock6.ts(55,13): error TS2815: 'arguments' cannot be referenced in p
|
||||
static {
|
||||
arguments;
|
||||
~~~~~~~~~
|
||||
!!! error TS2815: 'arguments' cannot be referenced in property initializers.
|
||||
!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks.
|
||||
|
||||
function ff () {
|
||||
arguments;
|
||||
@@ -108,4 +110,21 @@ classStaticBlock6.ts(55,13): error TS2815: 'arguments' cannot be referenced in p
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class foo2 {
|
||||
static {
|
||||
this.b // should error
|
||||
~
|
||||
!!! error TS2729: Property 'b' is used before its initialization.
|
||||
!!! related TS2728 classStaticBlock6.ts:73:12: 'b' is declared here.
|
||||
let b: typeof this.b; // ok
|
||||
if (1) {
|
||||
this.b; // should error
|
||||
~
|
||||
!!! error TS2729: Property 'b' is used before its initialization.
|
||||
!!! related TS2728 classStaticBlock6.ts:73:12: 'b' is declared here.
|
||||
}
|
||||
}
|
||||
|
||||
static b = 1;
|
||||
}
|
||||
@@ -63,7 +63,18 @@ function foo1 () {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class foo2 {
|
||||
static {
|
||||
this.b // should error
|
||||
let b: typeof this.b; // ok
|
||||
if (1) {
|
||||
this.b; // should error
|
||||
}
|
||||
}
|
||||
|
||||
static b = 1;
|
||||
}
|
||||
|
||||
//// [classStaticBlock6.js]
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
@@ -214,3 +225,18 @@ function foo1() {
|
||||
}
|
||||
})();
|
||||
}
|
||||
var foo2 = /** @class */ (function () {
|
||||
function foo2() {
|
||||
}
|
||||
var _a;
|
||||
_a = foo2;
|
||||
(function () {
|
||||
_a.b; // should error
|
||||
var b; // ok
|
||||
if (1) {
|
||||
_a.b; // should error
|
||||
}
|
||||
})();
|
||||
foo2.b = 1;
|
||||
return foo2;
|
||||
}());
|
||||
|
||||
@@ -104,3 +104,29 @@ function foo1 () {
|
||||
}
|
||||
}
|
||||
|
||||
class foo2 {
|
||||
>foo2 : Symbol(foo2, Decl(classStaticBlock6.ts, 61, 1))
|
||||
|
||||
static {
|
||||
this.b // should error
|
||||
>this.b : Symbol(foo2.b, Decl(classStaticBlock6.ts, 70, 5))
|
||||
>this : Symbol(foo2, Decl(classStaticBlock6.ts, 61, 1))
|
||||
>b : Symbol(foo2.b, Decl(classStaticBlock6.ts, 70, 5))
|
||||
|
||||
let b: typeof this.b; // ok
|
||||
>b : Symbol(b, Decl(classStaticBlock6.ts, 66, 11))
|
||||
>this.b : Symbol(foo2.b, Decl(classStaticBlock6.ts, 70, 5))
|
||||
>this : Symbol(foo2, Decl(classStaticBlock6.ts, 61, 1))
|
||||
>b : Symbol(foo2.b, Decl(classStaticBlock6.ts, 70, 5))
|
||||
|
||||
if (1) {
|
||||
this.b; // should error
|
||||
>this.b : Symbol(foo2.b, Decl(classStaticBlock6.ts, 70, 5))
|
||||
>this : Symbol(foo2, Decl(classStaticBlock6.ts, 61, 1))
|
||||
>b : Symbol(foo2.b, Decl(classStaticBlock6.ts, 70, 5))
|
||||
}
|
||||
}
|
||||
|
||||
static b = 1;
|
||||
>b : Symbol(foo2.b, Decl(classStaticBlock6.ts, 70, 5))
|
||||
}
|
||||
|
||||
@@ -169,3 +169,46 @@ function foo1 () {
|
||||
}
|
||||
}
|
||||
|
||||
class foo2 {
|
||||
>foo2 : foo2
|
||||
> : ^^^^
|
||||
|
||||
static {
|
||||
this.b // should error
|
||||
>this.b : number
|
||||
> : ^^^^^^
|
||||
>this : typeof foo2
|
||||
> : ^^^^^^^^^^^
|
||||
>b : number
|
||||
> : ^^^^^^
|
||||
|
||||
let b: typeof this.b; // ok
|
||||
>b : number
|
||||
> : ^^^^^^
|
||||
>this.b : number
|
||||
> : ^^^^^^
|
||||
>this : typeof foo2
|
||||
> : ^^^^^^^^^^^
|
||||
>b : number
|
||||
> : ^^^^^^
|
||||
|
||||
if (1) {
|
||||
>1 : 1
|
||||
> : ^
|
||||
|
||||
this.b; // should error
|
||||
>this.b : number
|
||||
> : ^^^^^^
|
||||
>this : typeof foo2
|
||||
> : ^^^^^^^^^^^
|
||||
>b : number
|
||||
> : ^^^^^^
|
||||
}
|
||||
}
|
||||
|
||||
static b = 1;
|
||||
>b : number
|
||||
> : ^^^^^^
|
||||
>1 : 1
|
||||
> : ^
|
||||
}
|
||||
|
||||
+84
-1
@@ -26,4 +26,87 @@ function C() {
|
||||
return class T {
|
||||
a = function () { arguments }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function D() {
|
||||
return class T {
|
||||
a = () => arguments // should error
|
||||
}
|
||||
}
|
||||
|
||||
function D1() {
|
||||
return class T {
|
||||
a = () => {
|
||||
arguments; // should error
|
||||
const b = () => {
|
||||
return arguments; // should error
|
||||
}
|
||||
|
||||
function f() {
|
||||
return arguments; // ok
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function D2() {
|
||||
return class {
|
||||
constructor() {
|
||||
arguments; // ok
|
||||
}
|
||||
get foo() {
|
||||
return arguments; // ok
|
||||
}
|
||||
set foo(foo: any) {
|
||||
arguments; // ok
|
||||
}
|
||||
bar() {
|
||||
arguments; // ok
|
||||
}
|
||||
[Symbol.iterator]() {
|
||||
arguments; // ok
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function D3() {
|
||||
return class T {
|
||||
static {
|
||||
arguments; // should error
|
||||
while(1) {
|
||||
arguments // should error
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function D4() {
|
||||
return class T {
|
||||
static {
|
||||
function f() {
|
||||
arguments; // ok
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function D5() {
|
||||
return class T {
|
||||
a = (() => { return arguments; })() // should error
|
||||
}
|
||||
}
|
||||
|
||||
function D6() {
|
||||
return class T {
|
||||
a = (x = arguments) => {} // should error
|
||||
}
|
||||
}
|
||||
|
||||
function D7() {
|
||||
return class T {
|
||||
a(x = arguments){ // ok
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,3 +60,15 @@ function foo1 () {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class foo2 {
|
||||
static {
|
||||
this.b // should error
|
||||
let b: typeof this.b; // ok
|
||||
if (1) {
|
||||
this.b; // should error
|
||||
}
|
||||
}
|
||||
|
||||
static b = 1;
|
||||
}
|
||||
Reference in New Issue
Block a user