From 1b3dd6dd772b1cb871c52347aac0376f7fa97dab Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Thu, 13 Jan 2022 17:58:18 -0500 Subject: [PATCH] Remove unused param and unnecessary baseline comments --- src/compiler/transformers/classFields.ts | 13 +++---------- .../derivedClassParameterProperties.errors.txt | 12 ++++++------ .../reference/derivedClassParameterProperties.js | 14 +++++++------- .../derivedClassParameterProperties.symbols | 12 ++++++------ .../derivedClassParameterProperties.types | 12 ++++++------ .../superCalls/derivedClassParameterProperties.ts | 12 ++++++------ 6 files changed, 34 insertions(+), 41 deletions(-) diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index 4ace9f236378b..0d4cb46a04c2c 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -1371,11 +1371,9 @@ namespace ts { * * @param properties An array of property declarations to transform. * @param receiver The receiver on which each property should be assigned. - * @param insertionIndex How far after a found property to splice the expression statement, if not the end of the array. */ - function addPropertyOrClassStaticBlockStatements(statements: Statement[], properties: readonly (PropertyDeclaration | ClassStaticBlockDeclaration)[], receiver: LeftHandSideExpression, insertionIndex?: number) { - for (let i = 0; i < properties.length; i += 1) { - const property = properties[i]; + function addPropertyOrClassStaticBlockStatements(statements: Statement[], properties: readonly (PropertyDeclaration | ClassStaticBlockDeclaration)[], receiver: LeftHandSideExpression) { + for (const property of properties) { const expression = isClassStaticBlockDeclaration(property) ? transformClassStaticBlockDeclaration(property) : transformProperty(property, receiver); @@ -1393,12 +1391,7 @@ namespace ts { setSyntheticLeadingComments(expression, undefined); setSyntheticTrailingComments(expression, undefined); - if (insertionIndex !== undefined) { - statements.splice(i + insertionIndex, 0, statement); - } - else { - statements.push(statement); - } + statements.push(statement); } } diff --git a/tests/baselines/reference/derivedClassParameterProperties.errors.txt b/tests/baselines/reference/derivedClassParameterProperties.errors.txt index 432ba60d96932..02d90402fefe0 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.errors.txt +++ b/tests/baselines/reference/derivedClassParameterProperties.errors.txt @@ -17,7 +17,7 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP class Derived extends Base { constructor(y: string) { var a = 1; - super(); // ok + super(); } } @@ -30,7 +30,7 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP class Derived3 extends Base { constructor(public y: string) { - super(); // ok + super(); var a = 1; } } @@ -46,7 +46,7 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP class Derived5 extends Base { a = 1; constructor(y: string) { - super(); // ok + super(); var b = 2; } } @@ -58,7 +58,7 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. var b = 2; - super(); // error: "super" has to be called before "this" accessing + super(); } } @@ -86,7 +86,7 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP a = 1; b: number; constructor(y: string) { - super(); // ok + super(); this.a = 3; this.b = 3; } @@ -119,7 +119,7 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP a = 1; b: number; constructor(y: string) { - super(); // ok + super(); this.a = 3; this.b = 3; } diff --git a/tests/baselines/reference/derivedClassParameterProperties.js b/tests/baselines/reference/derivedClassParameterProperties.js index 2002c042b56cb..6177865273809 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.js +++ b/tests/baselines/reference/derivedClassParameterProperties.js @@ -8,7 +8,7 @@ class Base { class Derived extends Base { constructor(y: string) { var a = 1; - super(); // ok + super(); } } @@ -21,7 +21,7 @@ class Derived2 extends Base { class Derived3 extends Base { constructor(public y: string) { - super(); // ok + super(); var a = 1; } } @@ -37,7 +37,7 @@ class Derived4 extends Base { class Derived5 extends Base { a = 1; constructor(y: string) { - super(); // ok + super(); var b = 2; } } @@ -47,7 +47,7 @@ class Derived6 extends Base { constructor(y: string) { this.a = 1; var b = 2; - super(); // error: "super" has to be called before "this" accessing + super(); } } @@ -65,7 +65,7 @@ class Derived8 extends Base { a = 1; b: number; constructor(y: string) { - super(); // ok + super(); this.a = 3; this.b = 3; } @@ -88,7 +88,7 @@ class Derived10 extends Base2 { a = 1; b: number; constructor(y: string) { - super(); // ok + super(); this.a = 3; this.b = 3; } @@ -172,7 +172,7 @@ var Derived6 = /** @class */ (function (_super) { var _this = this; _this.a = 1; var b = 2; - _this = _super.call(this) || this; // error: "super" has to be called before "this" accessing + _this = _super.call(this) || this; return _this; } return Derived6; diff --git a/tests/baselines/reference/derivedClassParameterProperties.symbols b/tests/baselines/reference/derivedClassParameterProperties.symbols index ad84699e6e2dc..5f34d8182abf1 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.symbols +++ b/tests/baselines/reference/derivedClassParameterProperties.symbols @@ -18,7 +18,7 @@ class Derived extends Base { var a = 1; >a : Symbol(a, Decl(derivedClassParameterProperties.ts, 8, 11)) - super(); // ok + super(); >super : Symbol(Base, Decl(derivedClassParameterProperties.ts, 0, 0)) } } @@ -45,7 +45,7 @@ class Derived3 extends Base { constructor(public y: string) { >y : Symbol(Derived3.y, Decl(derivedClassParameterProperties.ts, 21, 16)) - super(); // ok + super(); >super : Symbol(Base, Decl(derivedClassParameterProperties.ts, 0, 0)) var a = 1; @@ -81,7 +81,7 @@ class Derived5 extends Base { constructor(y: string) { >y : Symbol(y, Decl(derivedClassParameterProperties.ts, 37, 16)) - super(); // ok + super(); >super : Symbol(Base, Decl(derivedClassParameterProperties.ts, 0, 0)) var b = 2; @@ -107,7 +107,7 @@ class Derived6 extends Base { var b = 2; >b : Symbol(b, Decl(derivedClassParameterProperties.ts, 47, 11)) - super(); // error: "super" has to be called before "this" accessing + super(); >super : Symbol(Base, Decl(derivedClassParameterProperties.ts, 0, 0)) } } @@ -153,7 +153,7 @@ class Derived8 extends Base { constructor(y: string) { >y : Symbol(y, Decl(derivedClassParameterProperties.ts, 65, 16)) - super(); // ok + super(); >super : Symbol(Base, Decl(derivedClassParameterProperties.ts, 0, 0)) this.a = 3; @@ -220,7 +220,7 @@ class Derived10 extends Base2 { constructor(y: string) { >y : Symbol(y, Decl(derivedClassParameterProperties.ts, 88, 16)) - super(); // ok + super(); >super : Symbol(Base2, Decl(derivedClassParameterProperties.ts, 70, 1)) this.a = 3; diff --git a/tests/baselines/reference/derivedClassParameterProperties.types b/tests/baselines/reference/derivedClassParameterProperties.types index 2b8ace3610b05..1cb184bed34df 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.types +++ b/tests/baselines/reference/derivedClassParameterProperties.types @@ -19,7 +19,7 @@ class Derived extends Base { >a : number >1 : 1 - super(); // ok + super(); >super() : void >super : typeof Base } @@ -49,7 +49,7 @@ class Derived3 extends Base { constructor(public y: string) { >y : string - super(); // ok + super(); >super() : void >super : typeof Base @@ -91,7 +91,7 @@ class Derived5 extends Base { constructor(y: string) { >y : string - super(); // ok + super(); >super() : void >super : typeof Base @@ -122,7 +122,7 @@ class Derived6 extends Base { >b : number >2 : 2 - super(); // error: "super" has to be called before "this" accessing + super(); >super() : void >super : typeof Base } @@ -176,7 +176,7 @@ class Derived8 extends Base { constructor(y: string) { >y : string - super(); // ok + super(); >super() : void >super : typeof Base @@ -249,7 +249,7 @@ class Derived10 extends Base2 { constructor(y: string) { >y : string - super(); // ok + super(); >super() : void >super : typeof Base2 diff --git a/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts b/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts index b99bdb50bc740..6c6bfc63b9eb2 100644 --- a/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts +++ b/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts @@ -7,7 +7,7 @@ class Base { class Derived extends Base { constructor(y: string) { var a = 1; - super(); // ok + super(); } } @@ -20,7 +20,7 @@ class Derived2 extends Base { class Derived3 extends Base { constructor(public y: string) { - super(); // ok + super(); var a = 1; } } @@ -36,7 +36,7 @@ class Derived4 extends Base { class Derived5 extends Base { a = 1; constructor(y: string) { - super(); // ok + super(); var b = 2; } } @@ -46,7 +46,7 @@ class Derived6 extends Base { constructor(y: string) { this.a = 1; var b = 2; - super(); // error: "super" has to be called before "this" accessing + super(); } } @@ -64,7 +64,7 @@ class Derived8 extends Base { a = 1; b: number; constructor(y: string) { - super(); // ok + super(); this.a = 3; this.b = 3; } @@ -87,7 +87,7 @@ class Derived10 extends Base2 { a = 1; b: number; constructor(y: string) { - super(); // ok + super(); this.a = 3; this.b = 3; }