diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 578313bc7993c..7ee22318fb20d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -34731,34 +34731,42 @@ namespace ts { error(superCall, Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null); } - // The first statement in the body of a constructor (excluding prologue directives) must be a super call - // if both of the following are true: + // A super call must be root-level in a constructor if both of the following are true: // - The containing class is a derived class. // - The constructor declares parameter properties // or the containing class declares instance member variables with initializers. - const superCallShouldBeFirst = + + const superCallShouldBeRootLevel = (getEmitScriptTarget(compilerOptions) !== ScriptTarget.ESNext || !useDefineForClassFields) && (some((node.parent as ClassDeclaration).members, isInstancePropertyWithInitializerOrPrivateIdentifierProperty) || some(node.parameters, p => hasSyntacticModifier(p, ModifierFlags.ParameterPropertyModifier))); - // Skip past any prologue directives to find the first statement - // to ensure that it was a super call. - if (superCallShouldBeFirst) { - const statements = node.body!.statements; - let superCallStatement: ExpressionStatement | undefined; + if (superCallShouldBeRootLevel) { + // Until we have better flow analysis, it is an error to place the super call within any kind of block or conditional + // See GH #8277 + if (!superCallIsRootLevelInConstructor(superCall, node.body!)) { + error(superCall, Diagnostics.A_super_call_must_be_a_root_level_statement_within_a_constructor_of_a_derived_class_that_contains_initialized_properties_parameter_properties_or_private_identifiers); + } + // Skip past any prologue directives to check statements for referring to 'super' or 'this' before a super call + else { + let superCallStatement: ExpressionStatement | undefined; - for (const statement of statements) { - if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCall((statement as ExpressionStatement).expression)) { - superCallStatement = statement as ExpressionStatement; - break; + for (const statement of node.body!.statements) { + if (isExpressionStatement(statement) && isSuperCall(skipOuterExpressions(statement.expression))) { + superCallStatement = statement; + break; + } + if (!isPrologueDirective(statement) && nodeImmediatelyReferencesSuperOrThis(statement)) { + break; + } } - if (!isPrologueDirective(statement)) { - break; + + // Until we have better flow analysis, it is an error to place the super call within any kind of block or conditional + // See GH #8277 + if (superCallStatement === undefined) { + error(node, Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_to_refer_to_super_or_this_when_a_derived_class_contains_initialized_properties_parameter_properties_or_private_identifiers); } } - if (!superCallStatement) { - error(node, Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_parameter_properties_or_private_identifiers); - } } } else if (!classExtendsNull) { @@ -34767,6 +34775,23 @@ namespace ts { } } + function superCallIsRootLevelInConstructor(superCall: Node, body: Block) { + const superCallParent = walkUpParenthesizedExpressions(superCall.parent); + return isExpressionStatement(superCallParent) && superCallParent.parent === body; + } + + function nodeImmediatelyReferencesSuperOrThis(node: Node): boolean { + if (node.kind === SyntaxKind.SuperKeyword || node.kind === SyntaxKind.ThisKeyword) { + return true; + } + + if (isThisContainerOrFunctionBlock(node)) { + return false; + } + + return !!forEachChild(node, nodeImmediatelyReferencesSuperOrThis); + } + function checkAccessorDeclaration(node: AccessorDeclaration) { if (produceDiagnostics) { // Grammar checking accessors diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 778a9304aa75e..dd2d7c800398e 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1747,7 +1747,7 @@ "category": "Error", "code": 2375 }, - "A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers.": { + "A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.": { "category": "Error", "code": 2376 }, @@ -1839,6 +1839,10 @@ "category": "Error", "code": 2400 }, + "A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers.": { + "category": "Error", + "code": 2401 + }, "Expression resolves to '_super' that compiler uses to capture base class reference.": { "category": "Error", "code": 2402 diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 77a3da2d3cceb..6a20f8069a7fc 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -5885,7 +5885,7 @@ namespace ts { * @param visitor Optional callback used to visit any custom prologue directives. */ function copyPrologue(source: readonly Statement[], target: Push, ensureUseStrict?: boolean, visitor?: (node: Node) => VisitResult): number { - const offset = copyStandardPrologue(source, target, ensureUseStrict); + const offset = copyStandardPrologue(source, target, 0, ensureUseStrict); return copyCustomPrologue(source, target, offset, visitor); } @@ -5901,12 +5901,13 @@ namespace ts { * Copies only the standard (string-expression) prologue-directives into the target statement-array. * @param source origin statements array * @param target result statements array + * @param statementOffset The offset at which to begin the copy. * @param ensureUseStrict boolean determining whether the function need to add prologue-directives + * @returns Count of how many directive statements were copied. */ - function copyStandardPrologue(source: readonly Statement[], target: Push, ensureUseStrict?: boolean): number { + function copyStandardPrologue(source: readonly Statement[], target: Push, statementOffset = 0, ensureUseStrict?: boolean): number { Debug.assert(target.length === 0, "Prologue directives should be at the first statement in the target statements array"); let foundUseStrict = false; - let statementOffset = 0; const numStatements = source.length; while (statementOffset < numStatements) { const statement = source[statementOffset]; diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index e898f9199f75a..0d4cb46a04c2c 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -1249,10 +1249,28 @@ namespace ts { resumeLexicalEnvironment(); - let indexOfFirstStatement = 0; + const needsSyntheticConstructor = !constructor && isDerivedClass; + let indexOfFirstStatementAfterSuper = 0; + let prologueStatementCount = 0; + let superStatementIndex = -1; let statements: Statement[] = []; - if (!constructor && isDerivedClass) { + if (constructor?.body?.statements) { + prologueStatementCount = factory.copyPrologue(constructor.body.statements, statements, /*ensureUseStrict*/ false, visitor); + superStatementIndex = findSuperStatementIndex(constructor.body.statements, prologueStatementCount); + + // If there was a super call, visit existing statements up to and including it + if (superStatementIndex >= 0) { + indexOfFirstStatementAfterSuper = superStatementIndex + 1; + statements = [ + ...statements.slice(0, prologueStatementCount), + ...visitNodes(constructor.body.statements, visitor, isStatement, prologueStatementCount, indexOfFirstStatementAfterSuper - prologueStatementCount), + ...statements.slice(prologueStatementCount), + ]; + } + } + + if (needsSyntheticConstructor) { // Add a synthetic `super` call: // // super(...arguments); @@ -1268,9 +1286,6 @@ namespace ts { ); } - if (constructor) { - indexOfFirstStatement = addPrologueDirectivesAndInitialSuperCall(factory, constructor, statements, visitor); - } // Add the property initializers. Transforms this: // // public x = 1; @@ -1281,26 +1296,52 @@ namespace ts { // this.x = 1; // } // + // If we do useDefineForClassFields, they'll be converted elsewhere. + // We instead *remove* them from the transformed output at this stage. + let parameterPropertyDeclarationCount = 0; if (constructor?.body) { - let afterParameterProperties = findIndex(constructor.body.statements, s => !isParameterPropertyDeclaration(getOriginalNode(s), constructor), indexOfFirstStatement); - if (afterParameterProperties === -1) { - afterParameterProperties = constructor.body.statements.length; + if (useDefineForClassFields) { + statements = statements.filter(statement => !isParameterPropertyDeclaration(getOriginalNode(statement), constructor)); } - if (afterParameterProperties > indexOfFirstStatement) { - if (!useDefineForClassFields) { - addRange(statements, visitNodes(constructor.body.statements, visitor, isStatement, indexOfFirstStatement, afterParameterProperties - indexOfFirstStatement)); + else { + for (const statement of constructor.body.statements) { + if (isParameterPropertyDeclaration(getOriginalNode(statement), constructor)) { + parameterPropertyDeclarationCount++; + } + } + if (parameterPropertyDeclarationCount > 0) { + const parameterProperties = visitNodes(constructor.body.statements, visitor, isStatement, indexOfFirstStatementAfterSuper, parameterPropertyDeclarationCount); + + // If there was a super() call found, add parameter properties immediately after it + if (superStatementIndex >= 0) { + addRange(statements, parameterProperties); + } + // If a synthetic super() call was added, add them just after it + else if (needsSyntheticConstructor) { + statements = [ + statements[0], + ...parameterProperties, + ...statements.slice(1), + ]; + } + // Since there wasn't a super() call, add them to the top of the constructor + else { + statements = [...parameterProperties, ...statements]; + } + + indexOfFirstStatementAfterSuper += parameterPropertyDeclarationCount; } - indexOfFirstStatement = afterParameterProperties; } } + const receiver = factory.createThis(); // private methods can be called in property initializers, they should execute first. addMethodStatements(statements, privateMethodsAndAccessors, receiver); addPropertyOrClassStaticBlockStatements(statements, properties, receiver); - // Add existing statements, skipping the initial super call. + // Add existing statements after the initial prologues and super call if (constructor) { - addRange(statements, visitNodes(constructor.body!.statements, visitor, isStatement, indexOfFirstStatement)); + addRange(statements, visitNodes(constructor.body!.statements, visitBodyStatement, isStatement, indexOfFirstStatementAfterSuper + prologueStatementCount)); } statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment()); @@ -1315,6 +1356,14 @@ namespace ts { ), /*location*/ constructor ? constructor.body : undefined ); + + function visitBodyStatement(statement: Node) { + if (useDefineForClassFields && isParameterPropertyDeclaration(getOriginalNode(statement), constructor!)) { + return undefined; + } + + return visitor(statement); + } } /** @@ -1335,11 +1384,13 @@ namespace ts { setSourceMapRange(statement, moveRangePastModifiers(property)); setCommentRange(statement, property); setOriginalNode(statement, property); + // `setOriginalNode` *copies* the `emitNode` from `property`, so now both // `statement` and `expression` have a copy of the synthesized comments. // Drop the comments from expression to avoid printing them twice. setSyntheticLeadingComments(expression, undefined); setSyntheticTrailingComments(expression, undefined); + statements.push(statement); } } diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index 3ad6ce006b034..c37fda499533c 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -1017,40 +1017,44 @@ namespace ts { const statements: Statement[] = []; resumeLexicalEnvironment(); + // In derived classes, there may be code before the necessary super() call + // We'll remove pre-super statements to be tacked on after the rest of the body + const existingPrologue = takeWhile(constructor.body.statements, isPrologueDirective); + const { superCall, superStatementIndex } = findSuperCallAndStatementIndex(constructor.body.statements, existingPrologue); + const postSuperStatementsStart = superStatementIndex === -1 ? existingPrologue.length : superStatementIndex + 1; + // If a super call has already been synthesized, // we're going to assume that we should just transform everything after that. // The assumption is that no prior step in the pipeline has added any prologue directives. - let statementOffset = 0; - if (!hasSynthesizedSuper) statementOffset = factory.copyStandardPrologue(constructor.body.statements, prologue, /*ensureUseStrict*/ false); - addDefaultValueAssignmentsIfNeeded(statements, constructor); - addRestParameterIfNeeded(statements, constructor, hasSynthesizedSuper); - if (!hasSynthesizedSuper) statementOffset = factory.copyCustomPrologue(constructor.body.statements, statements, statementOffset, visitor); + let statementOffset = postSuperStatementsStart; + if (!hasSynthesizedSuper) statementOffset = factory.copyStandardPrologue(constructor.body.statements, prologue, statementOffset, /*ensureUseStrict*/ false); + if (!hasSynthesizedSuper) statementOffset = factory.copyCustomPrologue(constructor.body.statements, statements, statementOffset, visitor, /*filter*/ undefined); - // If the first statement is a call to `super()`, visit the statement directly + // If there already exists a call to `super()`, visit the statement directly let superCallExpression: Expression | undefined; if (hasSynthesizedSuper) { superCallExpression = createDefaultSuperCallOrThis(); } - else if (isDerivedClass && statementOffset < constructor.body.statements.length) { - const firstStatement = constructor.body.statements[statementOffset]; - if (isExpressionStatement(firstStatement) && isSuperCall(firstStatement.expression)) { - superCallExpression = visitImmediateSuperCallInBody(firstStatement.expression); - } + else if (superCall) { + superCallExpression = visitSuperCallInBody(superCall); } if (superCallExpression) { hierarchyFacts |= HierarchyFacts.ConstructorWithCapturedSuper; - statementOffset++; // skip this statement, we will add it after visiting the rest of the body. } + // Add parameter defaults at the beginning of the output, with prologue statements + addDefaultValueAssignmentsIfNeeded(prologue, constructor); + addRestParameterIfNeeded(prologue, constructor, hasSynthesizedSuper); + // visit the remaining statements addRange(statements, visitNodes(constructor.body.statements, visitor, isStatement, /*start*/ statementOffset)); factory.mergeLexicalEnvironment(prologue, endLexicalEnvironment()); insertCaptureNewTargetIfNeeded(prologue, constructor, /*copyOnWrite*/ false); - if (isDerivedClass) { - if (superCallExpression && statementOffset === constructor.body.statements.length && !(constructor.body.transformFlags & TransformFlags.ContainsLexicalThis)) { + if (isDerivedClass || superCallExpression) { + if (superCallExpression && postSuperStatementsStart === constructor.body.statements.length && !(constructor.body.transformFlags & TransformFlags.ContainsLexicalThis)) { // If the subclass constructor does *not* contain `this` and *ends* with a `super()` call, we will use the // following representation: // @@ -1099,9 +1103,19 @@ namespace ts { // })(Base); // ``` - // Since the `super()` call was the first statement, we insert the `this` capturing call to - // `super()` at the top of the list of `statements` (after any pre-existing custom prologues). - insertCaptureThisForNode(statements, constructor, superCallExpression || createActualThis()); + // If the super() call is the first statement, we can directly create and assign its result to `_this` + if (superStatementIndex <= existingPrologue.length) { + insertCaptureThisForNode(statements, constructor, superCallExpression || createActualThis()); + } + // Since the `super()` call isn't the first statement, it's split across 1-2 statements: + // * A prologue `var _this = this;`, in case the constructor accesses this before super() + // * If it exists, a reassignment to that `_this` of the super() call + else { + insertCaptureThisForNode(prologue, constructor, createActualThis()); + if (superCallExpression) { + insertSuperThisCaptureThisForNode(statements, superCallExpression); + } + } if (!isSufficientlyCoveredByReturnStatements(constructor.body)) { statements.push(factory.createReturnStatement(factory.createUniqueName("_this", GeneratedIdentifierFlags.Optimistic | GeneratedIdentifierFlags.FileLevel))); @@ -1126,19 +1140,41 @@ namespace ts { insertCaptureThisForNodeIfNeeded(prologue, constructor); } - const block = factory.createBlock( + const body = factory.createBlock( setTextRange( factory.createNodeArray( - concatenate(prologue, statements) + [ + ...existingPrologue, + ...prologue, + ...(superStatementIndex <= existingPrologue.length ? emptyArray : visitNodes(constructor.body.statements, visitor, isStatement, existingPrologue.length, superStatementIndex)), + ...statements + ] ), /*location*/ constructor.body.statements ), /*multiLine*/ true ); - setTextRange(block, constructor.body); + setTextRange(body, constructor.body); + return body; + } - return block; + function findSuperCallAndStatementIndex(originalBodyStatements: NodeArray, existingPrologue: Statement[]) { + for (let i = existingPrologue.length; i < originalBodyStatements.length; i += 1) { + const superCall = getSuperCallFromStatement(originalBodyStatements[i]); + if (superCall) { + // With a super() call, split the statements into pre-super() and 'body' (post-super()) + return { + superCall, + superStatementIndex: i, + }; + } + } + + // Since there was no super() call found, consider all statements to be in the main 'body' (post-super()) + return { + superStatementIndex: -1, + }; } /** @@ -1511,6 +1547,25 @@ namespace ts { return false; } + /** + * Assigns the `this` in a constructor to the result of its `super()` call. + * + * @param statements Statements in the constructor body. + * @param superExpression Existing `super()` call for the constructor. + */ + function insertSuperThisCaptureThisForNode(statements: Statement[], superExpression: Expression): void { + enableSubstitutionsForCapturedThis(); + const assignSuperExpression = factory.createExpressionStatement( + factory.createBinaryExpression( + factory.createThis(), + SyntaxKind.EqualsToken, + superExpression + ) + ); + insertStatementAfterCustomPrologue(statements, assignSuperExpression); + setCommentRange(assignSuperExpression, getOriginalNode(superExpression).parent); + } + function insertCaptureThisForNode(statements: Statement[], node: Node, initializer: Expression | undefined): void { enableSubstitutionsForCapturedThis(); const captureThisStatement = factory.createVariableStatement( @@ -1919,7 +1974,7 @@ namespace ts { if (isBlock(body)) { // ensureUseStrict is false because no new prologue-directive should be added. // addStandardPrologue will put already-existing directives at the beginning of the target statement-array - statementOffset = factory.copyStandardPrologue(body.statements, prologue, /*ensureUseStrict*/ false); + statementOffset = factory.copyStandardPrologue(body.statements, prologue, 0, /*ensureUseStrict*/ false); statementOffset = factory.copyCustomPrologue(body.statements, statements, statementOffset, visitor, isHoistedFunction); statementOffset = factory.copyCustomPrologue(body.statements, statements, statementOffset, visitor, isHoistedVariableStatement); } @@ -3822,7 +3877,7 @@ namespace ts { ); } - function visitImmediateSuperCallInBody(node: CallExpression) { + function visitSuperCallInBody(node: CallExpression) { return visitCallExpressionWithPotentialCapturedThisAssignment(node, /*assignToCapturedThis*/ false); } diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 86dedd9d6d2c3..3f38d34c16e51 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -1932,13 +1932,21 @@ namespace ts { } let statements: Statement[] = []; - let indexOfFirstStatement = 0; resumeLexicalEnvironment(); - indexOfFirstStatement = addPrologueDirectivesAndInitialSuperCall(factory, constructor, statements, visitor); + const indexAfterLastPrologueStatement = factory.copyPrologue(body.statements, statements, /*ensureUseStrict*/ false, visitor); + const superStatementIndex = findSuperStatementIndex(body.statements, indexAfterLastPrologueStatement); - // Add parameters with property assignments. Transforms this: + // If there was a super call, visit existing statements up to and including it + if (superStatementIndex >= 0) { + addRange( + statements, + visitNodes(body.statements, visitor, isStatement, indexAfterLastPrologueStatement, superStatementIndex + 1 - indexAfterLastPrologueStatement), + ); + } + + // Transform parameters into property assignments. Transforms this: // // constructor (public x, public y) { // } @@ -1950,10 +1958,19 @@ namespace ts { // this.y = y; // } // - addRange(statements, map(parametersWithPropertyAssignments, transformParameterWithPropertyAssignment)); + const parameterPropertyAssignments = mapDefined(parametersWithPropertyAssignments, transformParameterWithPropertyAssignment); + + // If there is a super() call, the parameter properties go immediately after it + if (superStatementIndex >= 0) { + addRange(statements, parameterPropertyAssignments); + } + // Since there was no super() call, parameter properties are the first statements in the constructor + else { + statements = addRange(parameterPropertyAssignments, statements); + } - // Add the existing statements, skipping the initial super call. - addRange(statements, visitNodes(body.statements, visitor, isStatement, indexOfFirstStatement)); + // Add remaining statements from the body, skipping the super() call if it was found + addRange(statements, visitNodes(body.statements, visitor, isStatement, superStatementIndex + 1)); // End the lexical environment. statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment()); diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index 276d034c7b92c..7a714befd8291 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -299,35 +299,32 @@ namespace ts { } /** - * Adds super call and preceding prologue directives into the list of statements. - * - * @param ctor The constructor node. - * @param result The list of statements. - * @param visitor The visitor to apply to each node added to the result array. - * @returns index of the statement that follows super call + * @returns Contained super() call from descending into the statement ignoring parentheses, if that call exists. */ - export function addPrologueDirectivesAndInitialSuperCall(factory: NodeFactory, ctor: ConstructorDeclaration, result: Statement[], visitor: Visitor): number { - if (ctor.body) { - const statements = ctor.body.statements; - // add prologue directives to the list (if any) - const index = factory.copyPrologue(statements, result, /*ensureUseStrict*/ false, visitor); - if (index === statements.length) { - // list contains nothing but prologue directives (or empty) - exit - return index; - } + export function getSuperCallFromStatement(statement: Statement) { + if (!isExpressionStatement(statement)) { + return undefined; + } - const superIndex = findIndex(statements, s => isExpressionStatement(s) && isSuperCall(s.expression), index); - if (superIndex > -1) { - for (let i = index; i <= superIndex; i++) { - result.push(visitNode(statements[i], visitor, isStatement)); - } - return superIndex + 1; - } + const expression = skipParentheses(statement.expression); + return isSuperCall(expression) + ? expression + : undefined; + } - return index; + /** + * @returns The index (after prologue statements) of a super call, or -1 if not found. + */ + export function findSuperStatementIndex(statements: NodeArray, indexAfterLastPrologueStatement: number) { + for (let i = indexAfterLastPrologueStatement; i < statements.length; i += 1) { + const statement = statements[i]; + + if (getSuperCallFromStatement(statement)) { + return i; + } } - return 0; + return -1; } /** diff --git a/src/compiler/types.ts b/src/compiler/types.ts index dcea2e7e38526..389cf73c88225 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -7813,9 +7813,10 @@ namespace ts { * Copies only the standard (string-expression) prologue-directives into the target statement-array. * @param source origin statements array * @param target result statements array + * @param statementOffset The offset at which to begin the copy. * @param ensureUseStrict boolean determining whether the function need to add prologue-directives */ - /* @internal */ copyStandardPrologue(source: readonly Statement[], target: Push, ensureUseStrict?: boolean): number; + /* @internal */ copyStandardPrologue(source: readonly Statement[], target: Push, statementOffset: number | undefined, ensureUseStrict?: boolean): number; /** * Copies only the custom prologue-directives into target statement-array. * @param source origin statements array diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 98d89d4612824..aa518d99bab7f 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1669,6 +1669,34 @@ namespace ts { } } + /** + * @returns Whether the node creates a new 'this' scope for its children. + */ + export function isThisContainerOrFunctionBlock(node: Node): boolean { + switch (node.kind) { + // Arrow functions use the same scope, but may do so in a "delayed" manner + // For example, `const getThis = () => this` may be before a super() call in a derived constructor + case SyntaxKind.ArrowFunction: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.FunctionExpression: + case SyntaxKind.PropertyDeclaration: + return true; + case SyntaxKind.Block: + switch (node.parent.kind) { + case SyntaxKind.Constructor: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + // Object properties can have computed names; only method-like bodies start a new scope + return true; + default: + return false; + } + default: + return false; + } + } + export function isInTopLevelContext(node: Node) { // The name of a class or function declaration is a BindingIdentifier in its surrounding scope. if (isIdentifier(node) && (isClassDeclaration(node.parent) || isFunctionDeclaration(node.parent)) && node.parent.name === node) { diff --git a/tests/baselines/reference/classExtendsNull.js b/tests/baselines/reference/classExtendsNull.js index 29143e609de96..0a90a0aa3c7ae 100644 --- a/tests/baselines/reference/classExtendsNull.js +++ b/tests/baselines/reference/classExtendsNull.js @@ -31,7 +31,7 @@ var __extends = (this && this.__extends) || (function () { var C = /** @class */ (function (_super) { __extends(C, _super); function C() { - _this = _super.call(this) || this; + var _this = _super.call(this) || this; return Object.create(null); } return C; diff --git a/tests/baselines/reference/classUpdateTests.errors.txt b/tests/baselines/reference/classUpdateTests.errors.txt index 4a10022982838..7609acf8e2374 100644 --- a/tests/baselines/reference/classUpdateTests.errors.txt +++ b/tests/baselines/reference/classUpdateTests.errors.txt @@ -1,11 +1,9 @@ tests/cases/compiler/classUpdateTests.ts(34,2): error TS2377: Constructors for derived classes must contain a 'super' call. tests/cases/compiler/classUpdateTests.ts(43,18): error TS2335: 'super' can only be referenced in a derived class. -tests/cases/compiler/classUpdateTests.ts(57,2): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers. tests/cases/compiler/classUpdateTests.ts(63,7): error TS2415: Class 'L' incorrectly extends base class 'G'. Property 'p1' is private in type 'L' but not in type 'G'. tests/cases/compiler/classUpdateTests.ts(69,7): error TS2415: Class 'M' incorrectly extends base class 'G'. Property 'p1' is private in type 'M' but not in type 'G'. -tests/cases/compiler/classUpdateTests.ts(70,2): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers. tests/cases/compiler/classUpdateTests.ts(93,3): error TS1128: Declaration or statement expected. tests/cases/compiler/classUpdateTests.ts(95,1): error TS1128: Declaration or statement expected. tests/cases/compiler/classUpdateTests.ts(99,3): error TS1128: Declaration or statement expected. @@ -20,7 +18,7 @@ tests/cases/compiler/classUpdateTests.ts(111,15): error TS1068: Unexpected token tests/cases/compiler/classUpdateTests.ts(113,1): error TS1128: Declaration or statement expected. -==== tests/cases/compiler/classUpdateTests.ts (18 errors) ==== +==== tests/cases/compiler/classUpdateTests.ts (16 errors) ==== // // test codegen for instance properties // @@ -82,14 +80,9 @@ tests/cases/compiler/classUpdateTests.ts(113,1): error TS1128: Declaration or st class K extends G { constructor(public p1:number) { // ERROR - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var i = 0; - ~~~~~~~~~~~~ super(); - ~~~~~~~~~~ } - ~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers. } class L extends G { @@ -106,14 +99,9 @@ tests/cases/compiler/classUpdateTests.ts(113,1): error TS1128: Declaration or st !!! error TS2415: Class 'M' incorrectly extends base class 'G'. !!! error TS2415: Property 'p1' is private in type 'M' but not in type 'G'. constructor(private p1:number) { // ERROR - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var i = 0; - ~~~~~~~~~~~~ super(); - ~~~~~~~~~~ } - ~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers. } // diff --git a/tests/baselines/reference/classUpdateTests.js b/tests/baselines/reference/classUpdateTests.js index 325f4ef87f166..cc641c1eaf047 100644 --- a/tests/baselines/reference/classUpdateTests.js +++ b/tests/baselines/reference/classUpdateTests.js @@ -192,7 +192,7 @@ var G = /** @class */ (function (_super) { }(D)); var H = /** @class */ (function () { function H() { - _this = _super.call(this) || this; + return _super.call(this) || this; } // ERROR - no super call allowed return H; }()); diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.js b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.js index 8cc2cbeb53656..73fca72a9b2e6 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.js +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.js @@ -150,8 +150,9 @@ _a = Math.pow(['', ''], value), '' = _a[0], '' = _a[1]; var Derived = /** @class */ (function (_super) { __extends(Derived, _super); function Derived() { + var _this = this; var _a; - var _this = _super.call(this) || this; + _this = _super.call(this) || this; (_a = _super.prototype). = Math.pow(_a., value); return _this; } diff --git a/tests/baselines/reference/derivedClassParameterProperties.errors.txt b/tests/baselines/reference/derivedClassParameterProperties.errors.txt index a29632acafa90..02d90402fefe0 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.errors.txt +++ b/tests/baselines/reference/derivedClassParameterProperties.errors.txt @@ -1,15 +1,13 @@ -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(15,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers. -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(30,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(47,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(56,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(56,5): error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(57,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(58,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(79,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(79,5): error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(80,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(81,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts (9 errors) ==== +==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts (7 errors) ==== // ordering of super calls in derived constructors matters depending on other class contents class Base { @@ -19,25 +17,20 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP class Derived extends Base { constructor(y: string) { var a = 1; - super(); // ok + super(); } } class Derived2 extends Base { constructor(public y: string) { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var a = 1; - ~~~~~~~~~~~~~~~~~~ - super(); // error - ~~~~~~~~~~~~~~~~~~~~~~~~~ + super(); } - ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers. } class Derived3 extends Base { constructor(public y: string) { - super(); // ok + super(); var a = 1; } } @@ -45,20 +38,15 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP class Derived4 extends Base { a = 1; constructor(y: string) { - ~~~~~~~~~~~~~~~~~~~~~~~~ var b = 2; - ~~~~~~~~~~~~~~~~~~ - super(); // error - ~~~~~~~~~~~~~~~~~~~~~~~~~ + super(); } - ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers. } class Derived5 extends Base { a = 1; constructor(y: string) { - super(); // ok + super(); var b = 2; } } @@ -70,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(); } } @@ -87,18 +75,18 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP ~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. - super(); // error - ~~~~~~~~~~~~~~~~~~~~~~~~~ + super(); + ~~~~~~~~~~~~~~~~ } ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers. +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. } class Derived8 extends Base { a = 1; b: number; constructor(y: string) { - super(); // ok + super(); this.a = 3; this.b = 3; } @@ -120,18 +108,18 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP ~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. - super(); // error - ~~~~~~~~~~~~~~~~~~~~~~~~~ + super(); + ~~~~~~~~~~~~~~~~ } ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers. +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. } class Derived10 extends Base2 { 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 9003b828f0923..6177865273809 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.js +++ b/tests/baselines/reference/derivedClassParameterProperties.js @@ -8,20 +8,20 @@ class Base { class Derived extends Base { constructor(y: string) { var a = 1; - super(); // ok + super(); } } class Derived2 extends Base { constructor(public y: string) { var a = 1; - super(); // error + super(); } } class Derived3 extends Base { constructor(public y: string) { - super(); // ok + super(); var a = 1; } } @@ -30,14 +30,14 @@ class Derived4 extends Base { a = 1; constructor(y: string) { var b = 2; - super(); // error + super(); } } 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(); } } @@ -57,7 +57,7 @@ class Derived7 extends Base { constructor(y: string) { this.a = 3; this.b = 3; - super(); // error + 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; } @@ -80,7 +80,7 @@ class Derived9 extends Base2 { constructor(y: string) { this.a = 3; this.b = 3; - super(); // error + super(); } } @@ -88,7 +88,7 @@ class Derived10 extends Base2 { a = 1; b: number; constructor(y: string) { - super(); // ok + super(); this.a = 3; this.b = 3; } @@ -119,10 +119,8 @@ var Base = /** @class */ (function () { var Derived = /** @class */ (function (_super) { __extends(Derived, _super); function Derived(y) { - var _this = this; var a = 1; - _this = _super.call(this) || this; // ok - return _this; + return _super.call(this) || this; } return Derived; }(Base)); @@ -131,7 +129,7 @@ var Derived2 = /** @class */ (function (_super) { function Derived2(y) { var _this = this; var a = 1; - _this = _super.call(this) || this; // error + _this = _super.call(this) || this; _this.y = y; return _this; } @@ -152,7 +150,7 @@ var Derived4 = /** @class */ (function (_super) { function Derived4(y) { var _this = this; var b = 2; - _this = _super.call(this) || this; // error + _this = _super.call(this) || this; _this.a = 1; return _this; } @@ -174,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; @@ -185,7 +183,7 @@ var Derived7 = /** @class */ (function (_super) { var _this = this; _this.a = 3; _this.b = 3; - _this = _super.call(this) || this; // error + _this = _super.call(this) || this; _this.a = 1; return _this; } @@ -214,7 +212,7 @@ var Derived9 = /** @class */ (function (_super) { var _this = this; _this.a = 3; _this.b = 3; - _this = _super.call(this) || this; // error + _this = _super.call(this) || this; _this.a = 1; return _this; } diff --git a/tests/baselines/reference/derivedClassParameterProperties.symbols b/tests/baselines/reference/derivedClassParameterProperties.symbols index 691385d592b1b..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)) } } @@ -33,7 +33,7 @@ class Derived2 extends Base { var a = 1; >a : Symbol(a, Decl(derivedClassParameterProperties.ts, 15, 11)) - super(); // error + 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; @@ -66,7 +66,7 @@ class Derived4 extends Base { var b = 2; >b : Symbol(b, Decl(derivedClassParameterProperties.ts, 30, 11)) - super(); // error + super(); >super : Symbol(Base, Decl(derivedClassParameterProperties.ts, 0, 0)) } } @@ -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)) } } @@ -135,7 +135,7 @@ class Derived7 extends Base { >this : Symbol(Derived7, Decl(derivedClassParameterProperties.ts, 50, 1)) >b : Symbol(Derived7.b, Decl(derivedClassParameterProperties.ts, 53, 10)) - super(); // error + 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; @@ -200,7 +200,7 @@ class Derived9 extends Base2 { >this : Symbol(Derived9, Decl(derivedClassParameterProperties.ts, 73, 24)) >b : Symbol(Derived9.b, Decl(derivedClassParameterProperties.ts, 76, 10)) - super(); // error + super(); >super : Symbol(Base2, Decl(derivedClassParameterProperties.ts, 70, 1)) } } @@ -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 ea4f5b94fa502..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 } @@ -36,7 +36,7 @@ class Derived2 extends Base { >a : number >1 : 1 - super(); // error + 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 @@ -74,7 +74,7 @@ class Derived4 extends Base { >b : number >2 : 2 - super(); // error + 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 } @@ -156,7 +156,7 @@ class Derived7 extends Base { >b : number >3 : 3 - super(); // error + 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 @@ -229,7 +229,7 @@ class Derived9 extends Base2 { >b : number >3 : 3 - super(); // error + super(); >super() : void >super : typeof Base2 } @@ -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/baselines/reference/derivedClassSuperProperties.errors.txt b/tests/baselines/reference/derivedClassSuperProperties.errors.txt new file mode 100644 index 0000000000000..9834157050ff8 --- /dev/null +++ b/tests/baselines/reference/derivedClassSuperProperties.errors.txt @@ -0,0 +1,606 @@ +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(11,5): error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(12,9): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(19,5): error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(20,9): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(20,32): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(27,5): error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(28,9): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(29,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(35,5): error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(36,9): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(36,32): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(37,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(52,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(68,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(91,5): error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(92,19): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(101,5): error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(103,23): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(115,23): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(162,5): error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(163,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(195,5): error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(196,34): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(230,5): error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(231,35): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(281,5): error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(284,18): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(287,18): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(313,5): error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(315,19): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(323,5): error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(325,14): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(349,17): error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(355,20): error TS1345: An expression of type 'void' cannot be tested for truthiness. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(355,20): error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(361,23): error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(367,21): error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(373,29): error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(373,29): error TS2495: Type 'void' is not an array type or a string type. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(379,20): error TS1345: An expression of type 'void' cannot be tested for truthiness. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(379,20): error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(385,26): error TS1345: An expression of type 'void' cannot be tested for truthiness. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(385,26): error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(391,17): error TS1345: An expression of type 'void' cannot be tested for truthiness. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(391,17): error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. + + +==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts (46 errors) ==== + declare const decorate: any; + + class Base { + constructor(a?) { } + + receivesAnything(param?) { } + } + + class Derived1 extends Base { + prop = true; + constructor() { + ~~~~~~~~~~~~~~~ + super.receivesAnything(); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~ +!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. + super(); + ~~~~~~~~~~~~~~~~ + } + ~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. + } + + class Derived2 extends Base { + prop = true; + constructor() { + ~~~~~~~~~~~~~~~ + super.receivesAnything(this); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~ +!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + super(); + ~~~~~~~~~~~~~~~~ + } + ~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. + } + + class Derived3 extends Base { + prop = true; + constructor() { + ~~~~~~~~~~~~~~~ + super.receivesAnything(); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~ +!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. + super(this); + ~~~~~~~~~~~~~~~~~~~~ + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + } + ~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. + } + + class Derived4 extends Base { + prop = true; + constructor() { + ~~~~~~~~~~~~~~~ + super.receivesAnything(this); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~ +!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + super(this); + ~~~~~~~~~~~~~~~~~~~~ + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + } + ~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. + } + + class Derived5 extends Base { + prop = true; + constructor() { + super(); + super.receivesAnything(); + } + } + + class Derived6 extends Base { + prop = true; + constructor() { + super(this); + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + super.receivesAnything(); + } + } + + class Derived7 extends Base { + prop = true; + constructor() { + super(); + super.receivesAnything(this); + } + } + + class Derived8 extends Base { + prop = true; + constructor() { + super(this); + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + super.receivesAnything(this); + } + } + + class DerivedWithArrowFunction extends Base { + prop = true; + constructor() { + (() => this)(); + super(); + } + } + + class DerivedWithArrowFunctionParameter extends Base { + prop = true; + constructor() { + const lambda = (param = this) => {}; + super(); + } + } + + class DerivedWithDecoratorOnClass extends Base { + prop = true; + constructor() { + ~~~~~~~~~~~~~~~ + @decorate(this) + ~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + class InnerClass { } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + + super(); + ~~~~~~~~~~~~~~~~ + } + ~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. + } + + class DerivedWithDecoratorOnClassMethod extends Base { + prop = true; + constructor() { + ~~~~~~~~~~~~~~~ + class InnerClass { + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + @decorate(this) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + innerMethod() { } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~ + + + super(); + ~~~~~~~~~~~~~~~~ + } + ~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. + } + + class DerivedWithDecoratorOnClassProperty extends Base { + prop = true; + constructor() { + class InnerClass { + @decorate(this) + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + innerProp = true; + } + + super(); + } + } + + class DerivedWithFunctionDeclaration extends Base { + prop = true; + constructor() { + function declaration() { + return this; + } + super(); + } + } + + class DerivedWithFunctionDeclarationAndThisParam extends Base { + prop = true; + constructor() { + function declaration(param = this) { + return param; + } + super(); + } + } + + class DerivedWithFunctionExpression extends Base { + prop = true; + constructor() { + (function () { + return this; + })(); + super(); + } + } + + class DerivedWithParenthesis extends Base { + prop = true; + constructor() { + (super()); + } + } + + class DerivedWithParenthesisAfterStatement extends Base { + prop = true; + constructor() { + ~~~~~~~~~~~~~~~ + this.prop; + ~~~~~~~~~~~~~~~~~~ + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + (super()); + ~~~~~~~~~~~~~~~~~~ + } + ~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. + } + + class DerivedWithParenthesisBeforeStatement extends Base { + prop = true; + constructor() { + (super()); + this.prop; + } + } + + class DerivedWithClassDeclaration extends Base { + prop = true; + constructor() { + class InnerClass { + private method() { + return this; + } + private property = 7; + constructor() { + this.property; + this.method(); + } + } + super(); + } + } + + class DerivedWithClassDeclarationExtendingMember extends Base { + memberClass = class { }; + constructor() { + ~~~~~~~~~~~~~~~ + class InnerClass extends this.memberClass { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + private method() { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + return this; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + private property = 7; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + constructor() { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + super(); + ~~~~~~~~~~~~~~~~~~~~~~~~ + this.property; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + this.method(); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + } + ~~~~~~~~~ + super(); + ~~~~~~~~~~~~~~~~ + } + ~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. + } + + class DerivedWithClassExpression extends Base { + prop = true; + constructor() { + console.log(class { + private method() { + return this; + } + private property = 7; + constructor() { + this.property; + this.method(); + } + }); + super(); + } + } + + class DerivedWithClassExpressionExtendingMember extends Base { + memberClass = class { }; + constructor() { + ~~~~~~~~~~~~~~~ + console.log(class extends this.memberClass { }); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + super(); + ~~~~~~~~~~~~~~~~ + } + ~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. + } + + class DerivedWithDerivedClassExpression extends Base { + prop = true; + constructor() { + console.log(class extends Base { + constructor() { + super(); + } + public foo() { + return this; + } + public bar = () => this; + }); + super(); + } + } + + class DerivedWithNewDerivedClassExpression extends Base { + prop = true; + constructor() { + console.log(new class extends Base { + constructor() { + super(); + } + }()); + super(); + } + } + + class DerivedWithObjectAccessors extends Base { + prop = true; + constructor() { + const obj = { + get prop() { + return true; + }, + set prop(param) { + this._prop = param; + } + }; + super(); + } + } + + class DerivedWithObjectAccessorsUsingThisInKeys extends Base { + propName = "prop"; + constructor() { + ~~~~~~~~~~~~~~~ + const obj = { + ~~~~~~~~~~~~~~~~~~~~~ + _prop: "prop", + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + get [this.propName]() { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + return true; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + }, + ~~~~~~~~~~~~~~ + set [this.propName](param) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + this._prop = param; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + }; + ~~~~~~~~~~ + super(); + ~~~~~~~~~~~~~~~~ + } + ~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. + } + + class DerivedWithObjectAccessorsUsingThisInBodies extends Base { + propName = "prop"; + constructor() { + const obj = { + _prop: "prop", + get prop() { + return this._prop; + }, + set prop(param) { + this._prop = param; + } + }; + super(); + } + } + + class DerivedWithObjectComputedPropertyBody extends Base { + propName = "prop"; + constructor() { + ~~~~~~~~~~~~~~~ + const obj = { + ~~~~~~~~~~~~~~~~~~~~~ + prop: this.propName, + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + }; + ~~~~~~~~~~ + super(); + ~~~~~~~~~~~~~~~~ + } + ~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. + } + + class DerivedWithObjectComputedPropertyName extends Base { + propName = "prop"; + constructor() { + ~~~~~~~~~~~~~~~ + const obj = { + ~~~~~~~~~~~~~~~~~~~~~ + [this.propName]: true, + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + }; + ~~~~~~~~~~ + super(); + ~~~~~~~~~~~~~~~~ + } + ~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. + } + + class DerivedWithObjectMethod extends Base { + prop = true; + constructor() { + const obj = { + getProp() { + return this; + }, + }; + super(); + } + } + + let a, b; + + const DerivedWithLoops = [ + class extends Base { + prop = true; + constructor() { + for(super();;) {} + ~~~~~~~ +!!! error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. + } + }, + class extends Base { + prop = true; + constructor() { + for(a; super();) {} + ~~~~~~~ +!!! error TS1345: An expression of type 'void' cannot be tested for truthiness. + ~~~~~~~ +!!! error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. + } + }, + class extends Base { + prop = true; + constructor() { + for(a; b; super()) {} + ~~~~~~~ +!!! error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. + } + }, + class extends Base { + prop = true; + constructor() { + for(; ; super()) { break; } + ~~~~~~~ +!!! error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. + } + }, + class extends Base { + prop = true; + constructor() { + for (const x of super()) {} + ~~~~~~~ +!!! error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. + ~~~~~~~ +!!! error TS2495: Type 'void' is not an array type or a string type. + } + }, + class extends Base { + prop = true; + constructor() { + while (super()) {} + ~~~~~~~ +!!! error TS1345: An expression of type 'void' cannot be tested for truthiness. + ~~~~~~~ +!!! error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. + } + }, + class extends Base { + prop = true; + constructor() { + do {} while (super()); + ~~~~~~~ +!!! error TS1345: An expression of type 'void' cannot be tested for truthiness. + ~~~~~~~ +!!! error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. + } + }, + class extends Base { + prop = true; + constructor() { + if (super()) {} + ~~~~~~~ +!!! error TS1345: An expression of type 'void' cannot be tested for truthiness. + ~~~~~~~ +!!! error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. + } + }, + class extends Base { + prop = true; + constructor() { + switch (super()) {} + ~~~~~~~ +!!! error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. + } + }, + ] + \ No newline at end of file diff --git a/tests/baselines/reference/derivedClassSuperProperties.js b/tests/baselines/reference/derivedClassSuperProperties.js new file mode 100644 index 0000000000000..9dfd73cd39f20 --- /dev/null +++ b/tests/baselines/reference/derivedClassSuperProperties.js @@ -0,0 +1,1001 @@ +//// [derivedClassSuperProperties.ts] +declare const decorate: any; + +class Base { + constructor(a?) { } + + receivesAnything(param?) { } +} + +class Derived1 extends Base { + prop = true; + constructor() { + super.receivesAnything(); + super(); + } +} + +class Derived2 extends Base { + prop = true; + constructor() { + super.receivesAnything(this); + super(); + } +} + +class Derived3 extends Base { + prop = true; + constructor() { + super.receivesAnything(); + super(this); + } +} + +class Derived4 extends Base { + prop = true; + constructor() { + super.receivesAnything(this); + super(this); + } +} + +class Derived5 extends Base { + prop = true; + constructor() { + super(); + super.receivesAnything(); + } +} + +class Derived6 extends Base { + prop = true; + constructor() { + super(this); + super.receivesAnything(); + } +} + +class Derived7 extends Base { + prop = true; + constructor() { + super(); + super.receivesAnything(this); + } +} + +class Derived8 extends Base { + prop = true; + constructor() { + super(this); + super.receivesAnything(this); + } +} + +class DerivedWithArrowFunction extends Base { + prop = true; + constructor() { + (() => this)(); + super(); + } +} + +class DerivedWithArrowFunctionParameter extends Base { + prop = true; + constructor() { + const lambda = (param = this) => {}; + super(); + } +} + +class DerivedWithDecoratorOnClass extends Base { + prop = true; + constructor() { + @decorate(this) + class InnerClass { } + + super(); + } +} + +class DerivedWithDecoratorOnClassMethod extends Base { + prop = true; + constructor() { + class InnerClass { + @decorate(this) + innerMethod() { } + } + + super(); + } +} + +class DerivedWithDecoratorOnClassProperty extends Base { + prop = true; + constructor() { + class InnerClass { + @decorate(this) + innerProp = true; + } + + super(); + } +} + +class DerivedWithFunctionDeclaration extends Base { + prop = true; + constructor() { + function declaration() { + return this; + } + super(); + } +} + +class DerivedWithFunctionDeclarationAndThisParam extends Base { + prop = true; + constructor() { + function declaration(param = this) { + return param; + } + super(); + } +} + +class DerivedWithFunctionExpression extends Base { + prop = true; + constructor() { + (function () { + return this; + })(); + super(); + } +} + +class DerivedWithParenthesis extends Base { + prop = true; + constructor() { + (super()); + } +} + +class DerivedWithParenthesisAfterStatement extends Base { + prop = true; + constructor() { + this.prop; + (super()); + } +} + +class DerivedWithParenthesisBeforeStatement extends Base { + prop = true; + constructor() { + (super()); + this.prop; + } +} + +class DerivedWithClassDeclaration extends Base { + prop = true; + constructor() { + class InnerClass { + private method() { + return this; + } + private property = 7; + constructor() { + this.property; + this.method(); + } + } + super(); + } +} + +class DerivedWithClassDeclarationExtendingMember extends Base { + memberClass = class { }; + constructor() { + class InnerClass extends this.memberClass { + private method() { + return this; + } + private property = 7; + constructor() { + super(); + this.property; + this.method(); + } + } + super(); + } +} + +class DerivedWithClassExpression extends Base { + prop = true; + constructor() { + console.log(class { + private method() { + return this; + } + private property = 7; + constructor() { + this.property; + this.method(); + } + }); + super(); + } +} + +class DerivedWithClassExpressionExtendingMember extends Base { + memberClass = class { }; + constructor() { + console.log(class extends this.memberClass { }); + super(); + } +} + +class DerivedWithDerivedClassExpression extends Base { + prop = true; + constructor() { + console.log(class extends Base { + constructor() { + super(); + } + public foo() { + return this; + } + public bar = () => this; + }); + super(); + } +} + +class DerivedWithNewDerivedClassExpression extends Base { + prop = true; + constructor() { + console.log(new class extends Base { + constructor() { + super(); + } + }()); + super(); + } +} + +class DerivedWithObjectAccessors extends Base { + prop = true; + constructor() { + const obj = { + get prop() { + return true; + }, + set prop(param) { + this._prop = param; + } + }; + super(); + } +} + +class DerivedWithObjectAccessorsUsingThisInKeys extends Base { + propName = "prop"; + constructor() { + const obj = { + _prop: "prop", + get [this.propName]() { + return true; + }, + set [this.propName](param) { + this._prop = param; + } + }; + super(); + } +} + +class DerivedWithObjectAccessorsUsingThisInBodies extends Base { + propName = "prop"; + constructor() { + const obj = { + _prop: "prop", + get prop() { + return this._prop; + }, + set prop(param) { + this._prop = param; + } + }; + super(); + } +} + +class DerivedWithObjectComputedPropertyBody extends Base { + propName = "prop"; + constructor() { + const obj = { + prop: this.propName, + }; + super(); + } +} + +class DerivedWithObjectComputedPropertyName extends Base { + propName = "prop"; + constructor() { + const obj = { + [this.propName]: true, + }; + super(); + } +} + +class DerivedWithObjectMethod extends Base { + prop = true; + constructor() { + const obj = { + getProp() { + return this; + }, + }; + super(); + } +} + +let a, b; + +const DerivedWithLoops = [ + class extends Base { + prop = true; + constructor() { + for(super();;) {} + } + }, + class extends Base { + prop = true; + constructor() { + for(a; super();) {} + } + }, + class extends Base { + prop = true; + constructor() { + for(a; b; super()) {} + } + }, + class extends Base { + prop = true; + constructor() { + for(; ; super()) { break; } + } + }, + class extends Base { + prop = true; + constructor() { + for (const x of super()) {} + } + }, + class extends Base { + prop = true; + constructor() { + while (super()) {} + } + }, + class extends Base { + prop = true; + constructor() { + do {} while (super()); + } + }, + class extends Base { + prop = true; + constructor() { + if (super()) {} + } + }, + class extends Base { + prop = true; + constructor() { + switch (super()) {} + } + }, +] + + +//// [derivedClassSuperProperties.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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var Base = /** @class */ (function () { + function Base(a) { + } + Base.prototype.receivesAnything = function (param) { }; + return Base; +}()); +var Derived1 = /** @class */ (function (_super) { + __extends(Derived1, _super); + function Derived1() { + var _this = this; + _super.prototype.receivesAnything.call(_this); + _this = _super.call(this) || this; + _this.prop = true; + return _this; + } + return Derived1; +}(Base)); +var Derived2 = /** @class */ (function (_super) { + __extends(Derived2, _super); + function Derived2() { + var _this = this; + _super.prototype.receivesAnything.call(_this, _this); + _this = _super.call(this) || this; + _this.prop = true; + return _this; + } + return Derived2; +}(Base)); +var Derived3 = /** @class */ (function (_super) { + __extends(Derived3, _super); + function Derived3() { + var _this = this; + _super.prototype.receivesAnything.call(_this); + _this = _super.call(this, _this) || this; + _this.prop = true; + return _this; + } + return Derived3; +}(Base)); +var Derived4 = /** @class */ (function (_super) { + __extends(Derived4, _super); + function Derived4() { + var _this = this; + _super.prototype.receivesAnything.call(_this, _this); + _this = _super.call(this, _this) || this; + _this.prop = true; + return _this; + } + return Derived4; +}(Base)); +var Derived5 = /** @class */ (function (_super) { + __extends(Derived5, _super); + function Derived5() { + var _this = _super.call(this) || this; + _this.prop = true; + _super.prototype.receivesAnything.call(_this); + return _this; + } + return Derived5; +}(Base)); +var Derived6 = /** @class */ (function (_super) { + __extends(Derived6, _super); + function Derived6() { + var _this = _super.call(this, _this) || this; + _this.prop = true; + _super.prototype.receivesAnything.call(_this); + return _this; + } + return Derived6; +}(Base)); +var Derived7 = /** @class */ (function (_super) { + __extends(Derived7, _super); + function Derived7() { + var _this = _super.call(this) || this; + _this.prop = true; + _super.prototype.receivesAnything.call(_this, _this); + return _this; + } + return Derived7; +}(Base)); +var Derived8 = /** @class */ (function (_super) { + __extends(Derived8, _super); + function Derived8() { + var _this = _super.call(this, _this) || this; + _this.prop = true; + _super.prototype.receivesAnything.call(_this, _this); + return _this; + } + return Derived8; +}(Base)); +var DerivedWithArrowFunction = /** @class */ (function (_super) { + __extends(DerivedWithArrowFunction, _super); + function DerivedWithArrowFunction() { + var _this = this; + (function () { return _this; })(); + _this = _super.call(this) || this; + _this.prop = true; + return _this; + } + return DerivedWithArrowFunction; +}(Base)); +var DerivedWithArrowFunctionParameter = /** @class */ (function (_super) { + __extends(DerivedWithArrowFunctionParameter, _super); + function DerivedWithArrowFunctionParameter() { + var _this = this; + var lambda = function (param) { + if (param === void 0) { param = _this; } + }; + _this = _super.call(this) || this; + _this.prop = true; + return _this; + } + return DerivedWithArrowFunctionParameter; +}(Base)); +var DerivedWithDecoratorOnClass = /** @class */ (function (_super) { + __extends(DerivedWithDecoratorOnClass, _super); + function DerivedWithDecoratorOnClass() { + var _this = this; + var InnerClass = /** @class */ (function () { + function InnerClass() { + } + InnerClass = __decorate([ + decorate(this) + ], InnerClass); + return InnerClass; + }()); + _this = _super.call(this) || this; + _this.prop = true; + return _this; + } + return DerivedWithDecoratorOnClass; +}(Base)); +var DerivedWithDecoratorOnClassMethod = /** @class */ (function (_super) { + __extends(DerivedWithDecoratorOnClassMethod, _super); + function DerivedWithDecoratorOnClassMethod() { + var _this = this; + var InnerClass = /** @class */ (function () { + function InnerClass() { + } + InnerClass.prototype.innerMethod = function () { }; + __decorate([ + decorate(this) + ], InnerClass.prototype, "innerMethod", null); + return InnerClass; + }()); + _this = _super.call(this) || this; + _this.prop = true; + return _this; + } + return DerivedWithDecoratorOnClassMethod; +}(Base)); +var DerivedWithDecoratorOnClassProperty = /** @class */ (function (_super) { + __extends(DerivedWithDecoratorOnClassProperty, _super); + function DerivedWithDecoratorOnClassProperty() { + var _this = this; + var InnerClass = /** @class */ (function () { + function InnerClass() { + this.innerProp = true; + } + __decorate([ + decorate(this) + ], InnerClass.prototype, "innerProp", void 0); + return InnerClass; + }()); + _this = _super.call(this) || this; + _this.prop = true; + return _this; + } + return DerivedWithDecoratorOnClassProperty; +}(Base)); +var DerivedWithFunctionDeclaration = /** @class */ (function (_super) { + __extends(DerivedWithFunctionDeclaration, _super); + function DerivedWithFunctionDeclaration() { + var _this = this; + function declaration() { + return this; + } + _this = _super.call(this) || this; + _this.prop = true; + return _this; + } + return DerivedWithFunctionDeclaration; +}(Base)); +var DerivedWithFunctionDeclarationAndThisParam = /** @class */ (function (_super) { + __extends(DerivedWithFunctionDeclarationAndThisParam, _super); + function DerivedWithFunctionDeclarationAndThisParam() { + var _this = this; + function declaration(param) { + if (param === void 0) { param = this; } + return param; + } + _this = _super.call(this) || this; + _this.prop = true; + return _this; + } + return DerivedWithFunctionDeclarationAndThisParam; +}(Base)); +var DerivedWithFunctionExpression = /** @class */ (function (_super) { + __extends(DerivedWithFunctionExpression, _super); + function DerivedWithFunctionExpression() { + var _this = this; + (function () { + return this; + })(); + _this = _super.call(this) || this; + _this.prop = true; + return _this; + } + return DerivedWithFunctionExpression; +}(Base)); +var DerivedWithParenthesis = /** @class */ (function (_super) { + __extends(DerivedWithParenthesis, _super); + function DerivedWithParenthesis() { + var _this = _super.call(this) || this; + _this.prop = true; + return _this; + } + return DerivedWithParenthesis; +}(Base)); +var DerivedWithParenthesisAfterStatement = /** @class */ (function (_super) { + __extends(DerivedWithParenthesisAfterStatement, _super); + function DerivedWithParenthesisAfterStatement() { + var _this = this; + _this.prop; + _this = _super.call(this) || this; + _this.prop = true; + return _this; + } + return DerivedWithParenthesisAfterStatement; +}(Base)); +var DerivedWithParenthesisBeforeStatement = /** @class */ (function (_super) { + __extends(DerivedWithParenthesisBeforeStatement, _super); + function DerivedWithParenthesisBeforeStatement() { + var _this = _super.call(this) || this; + _this.prop = true; + _this.prop; + return _this; + } + return DerivedWithParenthesisBeforeStatement; +}(Base)); +var DerivedWithClassDeclaration = /** @class */ (function (_super) { + __extends(DerivedWithClassDeclaration, _super); + function DerivedWithClassDeclaration() { + var _this = this; + var InnerClass = /** @class */ (function () { + function InnerClass() { + this.property = 7; + this.property; + this.method(); + } + InnerClass.prototype.method = function () { + return this; + }; + return InnerClass; + }()); + _this = _super.call(this) || this; + _this.prop = true; + return _this; + } + return DerivedWithClassDeclaration; +}(Base)); +var DerivedWithClassDeclarationExtendingMember = /** @class */ (function (_super) { + __extends(DerivedWithClassDeclarationExtendingMember, _super); + function DerivedWithClassDeclarationExtendingMember() { + var _this = this; + var InnerClass = /** @class */ (function (_super) { + __extends(InnerClass, _super); + function InnerClass() { + var _this = _super.call(this) || this; + _this.property = 7; + _this.property; + _this.method(); + return _this; + } + InnerClass.prototype.method = function () { + return this; + }; + return InnerClass; + }(_this.memberClass)); + _this = _super.call(this) || this; + _this.memberClass = /** @class */ (function () { + function class_1() { + } + return class_1; + }()); + return _this; + } + return DerivedWithClassDeclarationExtendingMember; +}(Base)); +var DerivedWithClassExpression = /** @class */ (function (_super) { + __extends(DerivedWithClassExpression, _super); + function DerivedWithClassExpression() { + var _this = this; + console.log(/** @class */ (function () { + function class_2() { + this.property = 7; + this.property; + this.method(); + } + class_2.prototype.method = function () { + return this; + }; + return class_2; + }())); + _this = _super.call(this) || this; + _this.prop = true; + return _this; + } + return DerivedWithClassExpression; +}(Base)); +var DerivedWithClassExpressionExtendingMember = /** @class */ (function (_super) { + __extends(DerivedWithClassExpressionExtendingMember, _super); + function DerivedWithClassExpressionExtendingMember() { + var _this = this; + console.log(/** @class */ (function (_super) { + __extends(class_3, _super); + function class_3() { + return _super !== null && _super.apply(this, arguments) || this; + } + return class_3; + }(_this.memberClass))); + _this = _super.call(this) || this; + _this.memberClass = /** @class */ (function () { + function class_4() { + } + return class_4; + }()); + return _this; + } + return DerivedWithClassExpressionExtendingMember; +}(Base)); +var DerivedWithDerivedClassExpression = /** @class */ (function (_super) { + __extends(DerivedWithDerivedClassExpression, _super); + function DerivedWithDerivedClassExpression() { + var _this = this; + console.log(/** @class */ (function (_super) { + __extends(class_5, _super); + function class_5() { + var _this = _super.call(this) || this; + _this.bar = function () { return _this; }; + return _this; + } + class_5.prototype.foo = function () { + return this; + }; + return class_5; + }(Base))); + _this = _super.call(this) || this; + _this.prop = true; + return _this; + } + return DerivedWithDerivedClassExpression; +}(Base)); +var DerivedWithNewDerivedClassExpression = /** @class */ (function (_super) { + __extends(DerivedWithNewDerivedClassExpression, _super); + function DerivedWithNewDerivedClassExpression() { + var _this = this; + console.log(new /** @class */ (function (_super) { + __extends(class_6, _super); + function class_6() { + return _super.call(this) || this; + } + return class_6; + }(Base))()); + _this = _super.call(this) || this; + _this.prop = true; + return _this; + } + return DerivedWithNewDerivedClassExpression; +}(Base)); +var DerivedWithObjectAccessors = /** @class */ (function (_super) { + __extends(DerivedWithObjectAccessors, _super); + function DerivedWithObjectAccessors() { + var _this = this; + var obj = { + get prop() { + return true; + }, + set prop(param) { + this._prop = param; + } + }; + _this = _super.call(this) || this; + _this.prop = true; + return _this; + } + return DerivedWithObjectAccessors; +}(Base)); +var DerivedWithObjectAccessorsUsingThisInKeys = /** @class */ (function (_super) { + var _a; + __extends(DerivedWithObjectAccessorsUsingThisInKeys, _super); + function DerivedWithObjectAccessorsUsingThisInKeys() { + var _this = this; + var obj = (_a = { + _prop: "prop" + }, + Object.defineProperty(_a, _this.propName, { + get: function () { + return true; + }, + enumerable: false, + configurable: true + }), + Object.defineProperty(_a, _this.propName, { + set: function (param) { + this._prop = param; + }, + enumerable: false, + configurable: true + }), + _a); + _this = _super.call(this) || this; + _this.propName = "prop"; + return _this; + } + return DerivedWithObjectAccessorsUsingThisInKeys; +}(Base)); +var DerivedWithObjectAccessorsUsingThisInBodies = /** @class */ (function (_super) { + __extends(DerivedWithObjectAccessorsUsingThisInBodies, _super); + function DerivedWithObjectAccessorsUsingThisInBodies() { + var _this = this; + var obj = { + _prop: "prop", + get prop() { + return this._prop; + }, + set prop(param) { + this._prop = param; + } + }; + _this = _super.call(this) || this; + _this.propName = "prop"; + return _this; + } + return DerivedWithObjectAccessorsUsingThisInBodies; +}(Base)); +var DerivedWithObjectComputedPropertyBody = /** @class */ (function (_super) { + __extends(DerivedWithObjectComputedPropertyBody, _super); + function DerivedWithObjectComputedPropertyBody() { + var _this = this; + var obj = { + prop: _this.propName, + }; + _this = _super.call(this) || this; + _this.propName = "prop"; + return _this; + } + return DerivedWithObjectComputedPropertyBody; +}(Base)); +var DerivedWithObjectComputedPropertyName = /** @class */ (function (_super) { + var _b; + __extends(DerivedWithObjectComputedPropertyName, _super); + function DerivedWithObjectComputedPropertyName() { + var _this = this; + var obj = (_b = {}, + _b[_this.propName] = true, + _b); + _this = _super.call(this) || this; + _this.propName = "prop"; + return _this; + } + return DerivedWithObjectComputedPropertyName; +}(Base)); +var DerivedWithObjectMethod = /** @class */ (function (_super) { + __extends(DerivedWithObjectMethod, _super); + function DerivedWithObjectMethod() { + var _this = this; + var obj = { + getProp: function () { + return this; + }, + }; + _this = _super.call(this) || this; + _this.prop = true; + return _this; + } + return DerivedWithObjectMethod; +}(Base)); +var a, b; +var DerivedWithLoops = [ + /** @class */ (function (_super) { + __extends(class_7, _super); + function class_7() { + var _this = this; + _this.prop = true; + for (_this = _super.call(this) || this;;) { } + return _this; + } + return class_7; + }(Base)), + /** @class */ (function (_super) { + __extends(class_8, _super); + function class_8() { + var _this = this; + _this.prop = true; + for (a; _this = _super.call(this) || this;) { } + return _this; + } + return class_8; + }(Base)), + /** @class */ (function (_super) { + __extends(class_9, _super); + function class_9() { + var _this = this; + _this.prop = true; + for (a; b; _this = _super.call(this) || this) { } + return _this; + } + return class_9; + }(Base)), + /** @class */ (function (_super) { + __extends(class_10, _super); + function class_10() { + var _this = this; + _this.prop = true; + for (;; _this = _super.call(this) || this) { + break; + } + return _this; + } + return class_10; + }(Base)), + /** @class */ (function (_super) { + __extends(class_11, _super); + function class_11() { + var _this = this; + _this.prop = true; + for (var _i = 0, _a = _this = _super.call(this) || this; _i < _a.length; _i++) { + var x = _a[_i]; + } + return _this; + } + return class_11; + }(Base)), + /** @class */ (function (_super) { + __extends(class_12, _super); + function class_12() { + var _this = this; + _this.prop = true; + while (_this = _super.call(this) || this) { } + return _this; + } + return class_12; + }(Base)), + /** @class */ (function (_super) { + __extends(class_13, _super); + function class_13() { + var _this = this; + _this.prop = true; + do { } while (_this = _super.call(this) || this); + return _this; + } + return class_13; + }(Base)), + /** @class */ (function (_super) { + __extends(class_14, _super); + function class_14() { + var _this = this; + _this.prop = true; + if (_this = _super.call(this) || this) { } + return _this; + } + return class_14; + }(Base)), + /** @class */ (function (_super) { + __extends(class_15, _super); + function class_15() { + var _this = this; + _this.prop = true; + switch (_this = _super.call(this) || this) { + } + return _this; + } + return class_15; + }(Base)), +]; diff --git a/tests/baselines/reference/derivedClassSuperProperties.symbols b/tests/baselines/reference/derivedClassSuperProperties.symbols new file mode 100644 index 0000000000000..67d18567ad90f --- /dev/null +++ b/tests/baselines/reference/derivedClassSuperProperties.symbols @@ -0,0 +1,849 @@ +=== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts === +declare const decorate: any; +>decorate : Symbol(decorate, Decl(derivedClassSuperProperties.ts, 0, 13)) + +class Base { +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + constructor(a?) { } +>a : Symbol(a, Decl(derivedClassSuperProperties.ts, 3, 16)) + + receivesAnything(param?) { } +>receivesAnything : Symbol(Base.receivesAnything, Decl(derivedClassSuperProperties.ts, 3, 23)) +>param : Symbol(param, Decl(derivedClassSuperProperties.ts, 5, 21)) +} + +class Derived1 extends Base { +>Derived1 : Symbol(Derived1, Decl(derivedClassSuperProperties.ts, 6, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(Derived1.prop, Decl(derivedClassSuperProperties.ts, 8, 29)) + + constructor() { + super.receivesAnything(); +>super.receivesAnything : Symbol(Base.receivesAnything, Decl(derivedClassSuperProperties.ts, 3, 23)) +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) +>receivesAnything : Symbol(Base.receivesAnything, Decl(derivedClassSuperProperties.ts, 3, 23)) + + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class Derived2 extends Base { +>Derived2 : Symbol(Derived2, Decl(derivedClassSuperProperties.ts, 14, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(Derived2.prop, Decl(derivedClassSuperProperties.ts, 16, 29)) + + constructor() { + super.receivesAnything(this); +>super.receivesAnything : Symbol(Base.receivesAnything, Decl(derivedClassSuperProperties.ts, 3, 23)) +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) +>receivesAnything : Symbol(Base.receivesAnything, Decl(derivedClassSuperProperties.ts, 3, 23)) +>this : Symbol(Derived2, Decl(derivedClassSuperProperties.ts, 14, 1)) + + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class Derived3 extends Base { +>Derived3 : Symbol(Derived3, Decl(derivedClassSuperProperties.ts, 22, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(Derived3.prop, Decl(derivedClassSuperProperties.ts, 24, 29)) + + constructor() { + super.receivesAnything(); +>super.receivesAnything : Symbol(Base.receivesAnything, Decl(derivedClassSuperProperties.ts, 3, 23)) +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) +>receivesAnything : Symbol(Base.receivesAnything, Decl(derivedClassSuperProperties.ts, 3, 23)) + + super(this); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) +>this : Symbol(Derived3, Decl(derivedClassSuperProperties.ts, 22, 1)) + } +} + +class Derived4 extends Base { +>Derived4 : Symbol(Derived4, Decl(derivedClassSuperProperties.ts, 30, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(Derived4.prop, Decl(derivedClassSuperProperties.ts, 32, 29)) + + constructor() { + super.receivesAnything(this); +>super.receivesAnything : Symbol(Base.receivesAnything, Decl(derivedClassSuperProperties.ts, 3, 23)) +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) +>receivesAnything : Symbol(Base.receivesAnything, Decl(derivedClassSuperProperties.ts, 3, 23)) +>this : Symbol(Derived4, Decl(derivedClassSuperProperties.ts, 30, 1)) + + super(this); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) +>this : Symbol(Derived4, Decl(derivedClassSuperProperties.ts, 30, 1)) + } +} + +class Derived5 extends Base { +>Derived5 : Symbol(Derived5, Decl(derivedClassSuperProperties.ts, 38, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(Derived5.prop, Decl(derivedClassSuperProperties.ts, 40, 29)) + + constructor() { + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + super.receivesAnything(); +>super.receivesAnything : Symbol(Base.receivesAnything, Decl(derivedClassSuperProperties.ts, 3, 23)) +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) +>receivesAnything : Symbol(Base.receivesAnything, Decl(derivedClassSuperProperties.ts, 3, 23)) + } +} + +class Derived6 extends Base { +>Derived6 : Symbol(Derived6, Decl(derivedClassSuperProperties.ts, 46, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(Derived6.prop, Decl(derivedClassSuperProperties.ts, 48, 29)) + + constructor() { + super(this); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) +>this : Symbol(Derived6, Decl(derivedClassSuperProperties.ts, 46, 1)) + + super.receivesAnything(); +>super.receivesAnything : Symbol(Base.receivesAnything, Decl(derivedClassSuperProperties.ts, 3, 23)) +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) +>receivesAnything : Symbol(Base.receivesAnything, Decl(derivedClassSuperProperties.ts, 3, 23)) + } +} + +class Derived7 extends Base { +>Derived7 : Symbol(Derived7, Decl(derivedClassSuperProperties.ts, 54, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(Derived7.prop, Decl(derivedClassSuperProperties.ts, 56, 29)) + + constructor() { + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + super.receivesAnything(this); +>super.receivesAnything : Symbol(Base.receivesAnything, Decl(derivedClassSuperProperties.ts, 3, 23)) +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) +>receivesAnything : Symbol(Base.receivesAnything, Decl(derivedClassSuperProperties.ts, 3, 23)) +>this : Symbol(Derived7, Decl(derivedClassSuperProperties.ts, 54, 1)) + } +} + +class Derived8 extends Base { +>Derived8 : Symbol(Derived8, Decl(derivedClassSuperProperties.ts, 62, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(Derived8.prop, Decl(derivedClassSuperProperties.ts, 64, 29)) + + constructor() { + super(this); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) +>this : Symbol(Derived8, Decl(derivedClassSuperProperties.ts, 62, 1)) + + super.receivesAnything(this); +>super.receivesAnything : Symbol(Base.receivesAnything, Decl(derivedClassSuperProperties.ts, 3, 23)) +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) +>receivesAnything : Symbol(Base.receivesAnything, Decl(derivedClassSuperProperties.ts, 3, 23)) +>this : Symbol(Derived8, Decl(derivedClassSuperProperties.ts, 62, 1)) + } +} + +class DerivedWithArrowFunction extends Base { +>DerivedWithArrowFunction : Symbol(DerivedWithArrowFunction, Decl(derivedClassSuperProperties.ts, 70, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(DerivedWithArrowFunction.prop, Decl(derivedClassSuperProperties.ts, 72, 45)) + + constructor() { + (() => this)(); +>this : Symbol(DerivedWithArrowFunction, Decl(derivedClassSuperProperties.ts, 70, 1)) + + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class DerivedWithArrowFunctionParameter extends Base { +>DerivedWithArrowFunctionParameter : Symbol(DerivedWithArrowFunctionParameter, Decl(derivedClassSuperProperties.ts, 78, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(DerivedWithArrowFunctionParameter.prop, Decl(derivedClassSuperProperties.ts, 80, 54)) + + constructor() { + const lambda = (param = this) => {}; +>lambda : Symbol(lambda, Decl(derivedClassSuperProperties.ts, 83, 13)) +>param : Symbol(param, Decl(derivedClassSuperProperties.ts, 83, 24)) +>this : Symbol(DerivedWithArrowFunctionParameter, Decl(derivedClassSuperProperties.ts, 78, 1)) + + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class DerivedWithDecoratorOnClass extends Base { +>DerivedWithDecoratorOnClass : Symbol(DerivedWithDecoratorOnClass, Decl(derivedClassSuperProperties.ts, 86, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(DerivedWithDecoratorOnClass.prop, Decl(derivedClassSuperProperties.ts, 88, 48)) + + constructor() { + @decorate(this) +>decorate : Symbol(decorate, Decl(derivedClassSuperProperties.ts, 0, 13)) +>this : Symbol(DerivedWithDecoratorOnClass, Decl(derivedClassSuperProperties.ts, 86, 1)) + + class InnerClass { } +>InnerClass : Symbol(InnerClass, Decl(derivedClassSuperProperties.ts, 90, 19)) + + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class DerivedWithDecoratorOnClassMethod extends Base { +>DerivedWithDecoratorOnClassMethod : Symbol(DerivedWithDecoratorOnClassMethod, Decl(derivedClassSuperProperties.ts, 96, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(DerivedWithDecoratorOnClassMethod.prop, Decl(derivedClassSuperProperties.ts, 98, 54)) + + constructor() { + class InnerClass { +>InnerClass : Symbol(InnerClass, Decl(derivedClassSuperProperties.ts, 100, 19)) + + @decorate(this) +>decorate : Symbol(decorate, Decl(derivedClassSuperProperties.ts, 0, 13)) +>this : Symbol(DerivedWithDecoratorOnClassMethod, Decl(derivedClassSuperProperties.ts, 96, 1)) + + innerMethod() { } +>innerMethod : Symbol(InnerClass.innerMethod, Decl(derivedClassSuperProperties.ts, 101, 26)) + } + + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class DerivedWithDecoratorOnClassProperty extends Base { +>DerivedWithDecoratorOnClassProperty : Symbol(DerivedWithDecoratorOnClassProperty, Decl(derivedClassSuperProperties.ts, 108, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(DerivedWithDecoratorOnClassProperty.prop, Decl(derivedClassSuperProperties.ts, 110, 56)) + + constructor() { + class InnerClass { +>InnerClass : Symbol(InnerClass, Decl(derivedClassSuperProperties.ts, 112, 19)) + + @decorate(this) +>decorate : Symbol(decorate, Decl(derivedClassSuperProperties.ts, 0, 13)) +>this : Symbol(DerivedWithDecoratorOnClassProperty, Decl(derivedClassSuperProperties.ts, 108, 1)) + + innerProp = true; +>innerProp : Symbol(InnerClass.innerProp, Decl(derivedClassSuperProperties.ts, 113, 26)) + } + + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class DerivedWithFunctionDeclaration extends Base { +>DerivedWithFunctionDeclaration : Symbol(DerivedWithFunctionDeclaration, Decl(derivedClassSuperProperties.ts, 120, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(DerivedWithFunctionDeclaration.prop, Decl(derivedClassSuperProperties.ts, 122, 51)) + + constructor() { + function declaration() { +>declaration : Symbol(declaration, Decl(derivedClassSuperProperties.ts, 124, 19)) + + return this; + } + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class DerivedWithFunctionDeclarationAndThisParam extends Base { +>DerivedWithFunctionDeclarationAndThisParam : Symbol(DerivedWithFunctionDeclarationAndThisParam, Decl(derivedClassSuperProperties.ts, 130, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(DerivedWithFunctionDeclarationAndThisParam.prop, Decl(derivedClassSuperProperties.ts, 132, 63)) + + constructor() { + function declaration(param = this) { +>declaration : Symbol(declaration, Decl(derivedClassSuperProperties.ts, 134, 19)) +>param : Symbol(param, Decl(derivedClassSuperProperties.ts, 135, 29)) + + return param; +>param : Symbol(param, Decl(derivedClassSuperProperties.ts, 135, 29)) + } + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class DerivedWithFunctionExpression extends Base { +>DerivedWithFunctionExpression : Symbol(DerivedWithFunctionExpression, Decl(derivedClassSuperProperties.ts, 140, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(DerivedWithFunctionExpression.prop, Decl(derivedClassSuperProperties.ts, 142, 50)) + + constructor() { + (function () { + return this; + })(); + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class DerivedWithParenthesis extends Base { +>DerivedWithParenthesis : Symbol(DerivedWithParenthesis, Decl(derivedClassSuperProperties.ts, 150, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(DerivedWithParenthesis.prop, Decl(derivedClassSuperProperties.ts, 152, 43)) + + constructor() { + (super()); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class DerivedWithParenthesisAfterStatement extends Base { +>DerivedWithParenthesisAfterStatement : Symbol(DerivedWithParenthesisAfterStatement, Decl(derivedClassSuperProperties.ts, 157, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(DerivedWithParenthesisAfterStatement.prop, Decl(derivedClassSuperProperties.ts, 159, 57)) + + constructor() { + this.prop; +>this.prop : Symbol(DerivedWithParenthesisAfterStatement.prop, Decl(derivedClassSuperProperties.ts, 159, 57)) +>this : Symbol(DerivedWithParenthesisAfterStatement, Decl(derivedClassSuperProperties.ts, 157, 1)) +>prop : Symbol(DerivedWithParenthesisAfterStatement.prop, Decl(derivedClassSuperProperties.ts, 159, 57)) + + (super()); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class DerivedWithParenthesisBeforeStatement extends Base { +>DerivedWithParenthesisBeforeStatement : Symbol(DerivedWithParenthesisBeforeStatement, Decl(derivedClassSuperProperties.ts, 165, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(DerivedWithParenthesisBeforeStatement.prop, Decl(derivedClassSuperProperties.ts, 167, 58)) + + constructor() { + (super()); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + this.prop; +>this.prop : Symbol(DerivedWithParenthesisBeforeStatement.prop, Decl(derivedClassSuperProperties.ts, 167, 58)) +>this : Symbol(DerivedWithParenthesisBeforeStatement, Decl(derivedClassSuperProperties.ts, 165, 1)) +>prop : Symbol(DerivedWithParenthesisBeforeStatement.prop, Decl(derivedClassSuperProperties.ts, 167, 58)) + } +} + +class DerivedWithClassDeclaration extends Base { +>DerivedWithClassDeclaration : Symbol(DerivedWithClassDeclaration, Decl(derivedClassSuperProperties.ts, 173, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(DerivedWithClassDeclaration.prop, Decl(derivedClassSuperProperties.ts, 175, 48)) + + constructor() { + class InnerClass { +>InnerClass : Symbol(InnerClass, Decl(derivedClassSuperProperties.ts, 177, 19)) + + private method() { +>method : Symbol(InnerClass.method, Decl(derivedClassSuperProperties.ts, 178, 26)) + + return this; +>this : Symbol(InnerClass, Decl(derivedClassSuperProperties.ts, 177, 19)) + } + private property = 7; +>property : Symbol(InnerClass.property, Decl(derivedClassSuperProperties.ts, 181, 13)) + + constructor() { + this.property; +>this.property : Symbol(InnerClass.property, Decl(derivedClassSuperProperties.ts, 181, 13)) +>this : Symbol(InnerClass, Decl(derivedClassSuperProperties.ts, 177, 19)) +>property : Symbol(InnerClass.property, Decl(derivedClassSuperProperties.ts, 181, 13)) + + this.method(); +>this.method : Symbol(InnerClass.method, Decl(derivedClassSuperProperties.ts, 178, 26)) +>this : Symbol(InnerClass, Decl(derivedClassSuperProperties.ts, 177, 19)) +>method : Symbol(InnerClass.method, Decl(derivedClassSuperProperties.ts, 178, 26)) + } + } + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class DerivedWithClassDeclarationExtendingMember extends Base { +>DerivedWithClassDeclarationExtendingMember : Symbol(DerivedWithClassDeclarationExtendingMember, Decl(derivedClassSuperProperties.ts, 190, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + memberClass = class { }; +>memberClass : Symbol(DerivedWithClassDeclarationExtendingMember.memberClass, Decl(derivedClassSuperProperties.ts, 192, 63)) + + constructor() { + class InnerClass extends this.memberClass { +>InnerClass : Symbol(InnerClass, Decl(derivedClassSuperProperties.ts, 194, 19)) +>this.memberClass : Symbol(DerivedWithClassDeclarationExtendingMember.memberClass, Decl(derivedClassSuperProperties.ts, 192, 63)) +>this : Symbol(DerivedWithClassDeclarationExtendingMember, Decl(derivedClassSuperProperties.ts, 190, 1)) +>memberClass : Symbol(DerivedWithClassDeclarationExtendingMember.memberClass, Decl(derivedClassSuperProperties.ts, 192, 63)) + + private method() { +>method : Symbol(InnerClass.method, Decl(derivedClassSuperProperties.ts, 195, 51)) + + return this; +>this : Symbol(InnerClass, Decl(derivedClassSuperProperties.ts, 194, 19)) + } + private property = 7; +>property : Symbol(InnerClass.property, Decl(derivedClassSuperProperties.ts, 198, 13)) + + constructor() { + super(); +>super : Symbol((Anonymous class), Decl(derivedClassSuperProperties.ts, 193, 17)) + + this.property; +>this.property : Symbol(InnerClass.property, Decl(derivedClassSuperProperties.ts, 198, 13)) +>this : Symbol(InnerClass, Decl(derivedClassSuperProperties.ts, 194, 19)) +>property : Symbol(InnerClass.property, Decl(derivedClassSuperProperties.ts, 198, 13)) + + this.method(); +>this.method : Symbol(InnerClass.method, Decl(derivedClassSuperProperties.ts, 195, 51)) +>this : Symbol(InnerClass, Decl(derivedClassSuperProperties.ts, 194, 19)) +>method : Symbol(InnerClass.method, Decl(derivedClassSuperProperties.ts, 195, 51)) + } + } + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class DerivedWithClassExpression extends Base { +>DerivedWithClassExpression : Symbol(DerivedWithClassExpression, Decl(derivedClassSuperProperties.ts, 208, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(DerivedWithClassExpression.prop, Decl(derivedClassSuperProperties.ts, 210, 47)) + + constructor() { + console.log(class { +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) + + private method() { +>method : Symbol((Anonymous class).method, Decl(derivedClassSuperProperties.ts, 213, 27)) + + return this; +>this : Symbol((Anonymous class), Decl(derivedClassSuperProperties.ts, 213, 20)) + } + private property = 7; +>property : Symbol((Anonymous class).property, Decl(derivedClassSuperProperties.ts, 216, 13)) + + constructor() { + this.property; +>this.property : Symbol((Anonymous class).property, Decl(derivedClassSuperProperties.ts, 216, 13)) +>this : Symbol((Anonymous class), Decl(derivedClassSuperProperties.ts, 213, 20)) +>property : Symbol((Anonymous class).property, Decl(derivedClassSuperProperties.ts, 216, 13)) + + this.method(); +>this.method : Symbol((Anonymous class).method, Decl(derivedClassSuperProperties.ts, 213, 27)) +>this : Symbol((Anonymous class), Decl(derivedClassSuperProperties.ts, 213, 20)) +>method : Symbol((Anonymous class).method, Decl(derivedClassSuperProperties.ts, 213, 27)) + } + }); + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class DerivedWithClassExpressionExtendingMember extends Base { +>DerivedWithClassExpressionExtendingMember : Symbol(DerivedWithClassExpressionExtendingMember, Decl(derivedClassSuperProperties.ts, 225, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + memberClass = class { }; +>memberClass : Symbol(DerivedWithClassExpressionExtendingMember.memberClass, Decl(derivedClassSuperProperties.ts, 227, 62)) + + constructor() { + console.log(class extends this.memberClass { }); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this.memberClass : Symbol(DerivedWithClassExpressionExtendingMember.memberClass, Decl(derivedClassSuperProperties.ts, 227, 62)) +>this : Symbol(DerivedWithClassExpressionExtendingMember, Decl(derivedClassSuperProperties.ts, 225, 1)) +>memberClass : Symbol(DerivedWithClassExpressionExtendingMember.memberClass, Decl(derivedClassSuperProperties.ts, 227, 62)) + + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class DerivedWithDerivedClassExpression extends Base { +>DerivedWithDerivedClassExpression : Symbol(DerivedWithDerivedClassExpression, Decl(derivedClassSuperProperties.ts, 233, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(DerivedWithDerivedClassExpression.prop, Decl(derivedClassSuperProperties.ts, 235, 54)) + + constructor() { + console.log(class extends Base { +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + constructor() { + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } + public foo() { +>foo : Symbol((Anonymous class).foo, Decl(derivedClassSuperProperties.ts, 241, 13)) + + return this; +>this : Symbol((Anonymous class), Decl(derivedClassSuperProperties.ts, 238, 20)) + } + public bar = () => this; +>bar : Symbol((Anonymous class).bar, Decl(derivedClassSuperProperties.ts, 244, 13)) +>this : Symbol((Anonymous class), Decl(derivedClassSuperProperties.ts, 238, 20)) + + }); + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class DerivedWithNewDerivedClassExpression extends Base { +>DerivedWithNewDerivedClassExpression : Symbol(DerivedWithNewDerivedClassExpression, Decl(derivedClassSuperProperties.ts, 249, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(DerivedWithNewDerivedClassExpression.prop, Decl(derivedClassSuperProperties.ts, 251, 57)) + + constructor() { + console.log(new class extends Base { +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + constructor() { + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } + }()); + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class DerivedWithObjectAccessors extends Base { +>DerivedWithObjectAccessors : Symbol(DerivedWithObjectAccessors, Decl(derivedClassSuperProperties.ts, 261, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(DerivedWithObjectAccessors.prop, Decl(derivedClassSuperProperties.ts, 263, 47)) + + constructor() { + const obj = { +>obj : Symbol(obj, Decl(derivedClassSuperProperties.ts, 266, 13)) + + get prop() { +>prop : Symbol(prop, Decl(derivedClassSuperProperties.ts, 266, 21), Decl(derivedClassSuperProperties.ts, 269, 14)) + + return true; + }, + set prop(param) { +>prop : Symbol(prop, Decl(derivedClassSuperProperties.ts, 266, 21), Decl(derivedClassSuperProperties.ts, 269, 14)) +>param : Symbol(param, Decl(derivedClassSuperProperties.ts, 270, 21)) + + this._prop = param; +>param : Symbol(param, Decl(derivedClassSuperProperties.ts, 270, 21)) + } + }; + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class DerivedWithObjectAccessorsUsingThisInKeys extends Base { +>DerivedWithObjectAccessorsUsingThisInKeys : Symbol(DerivedWithObjectAccessorsUsingThisInKeys, Decl(derivedClassSuperProperties.ts, 276, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + propName = "prop"; +>propName : Symbol(DerivedWithObjectAccessorsUsingThisInKeys.propName, Decl(derivedClassSuperProperties.ts, 278, 62)) + + constructor() { + const obj = { +>obj : Symbol(obj, Decl(derivedClassSuperProperties.ts, 281, 13)) + + _prop: "prop", +>_prop : Symbol(_prop, Decl(derivedClassSuperProperties.ts, 281, 21)) + + get [this.propName]() { +>[this.propName] : Symbol([this.propName], Decl(derivedClassSuperProperties.ts, 282, 26)) +>this.propName : Symbol(DerivedWithObjectAccessorsUsingThisInKeys.propName, Decl(derivedClassSuperProperties.ts, 278, 62)) +>this : Symbol(DerivedWithObjectAccessorsUsingThisInKeys, Decl(derivedClassSuperProperties.ts, 276, 1)) +>propName : Symbol(DerivedWithObjectAccessorsUsingThisInKeys.propName, Decl(derivedClassSuperProperties.ts, 278, 62)) + + return true; + }, + set [this.propName](param) { +>[this.propName] : Symbol([this.propName], Decl(derivedClassSuperProperties.ts, 285, 14)) +>this.propName : Symbol(DerivedWithObjectAccessorsUsingThisInKeys.propName, Decl(derivedClassSuperProperties.ts, 278, 62)) +>this : Symbol(DerivedWithObjectAccessorsUsingThisInKeys, Decl(derivedClassSuperProperties.ts, 276, 1)) +>propName : Symbol(DerivedWithObjectAccessorsUsingThisInKeys.propName, Decl(derivedClassSuperProperties.ts, 278, 62)) +>param : Symbol(param, Decl(derivedClassSuperProperties.ts, 286, 32)) + + this._prop = param; +>param : Symbol(param, Decl(derivedClassSuperProperties.ts, 286, 32)) + } + }; + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class DerivedWithObjectAccessorsUsingThisInBodies extends Base { +>DerivedWithObjectAccessorsUsingThisInBodies : Symbol(DerivedWithObjectAccessorsUsingThisInBodies, Decl(derivedClassSuperProperties.ts, 292, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + propName = "prop"; +>propName : Symbol(DerivedWithObjectAccessorsUsingThisInBodies.propName, Decl(derivedClassSuperProperties.ts, 294, 64)) + + constructor() { + const obj = { +>obj : Symbol(obj, Decl(derivedClassSuperProperties.ts, 297, 13)) + + _prop: "prop", +>_prop : Symbol(_prop, Decl(derivedClassSuperProperties.ts, 297, 21)) + + get prop() { +>prop : Symbol(prop, Decl(derivedClassSuperProperties.ts, 298, 26), Decl(derivedClassSuperProperties.ts, 301, 14)) + + return this._prop; + }, + set prop(param) { +>prop : Symbol(prop, Decl(derivedClassSuperProperties.ts, 298, 26), Decl(derivedClassSuperProperties.ts, 301, 14)) +>param : Symbol(param, Decl(derivedClassSuperProperties.ts, 302, 21)) + + this._prop = param; +>param : Symbol(param, Decl(derivedClassSuperProperties.ts, 302, 21)) + } + }; + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class DerivedWithObjectComputedPropertyBody extends Base { +>DerivedWithObjectComputedPropertyBody : Symbol(DerivedWithObjectComputedPropertyBody, Decl(derivedClassSuperProperties.ts, 308, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + propName = "prop"; +>propName : Symbol(DerivedWithObjectComputedPropertyBody.propName, Decl(derivedClassSuperProperties.ts, 310, 58)) + + constructor() { + const obj = { +>obj : Symbol(obj, Decl(derivedClassSuperProperties.ts, 313, 13)) + + prop: this.propName, +>prop : Symbol(prop, Decl(derivedClassSuperProperties.ts, 313, 21)) +>this.propName : Symbol(DerivedWithObjectComputedPropertyBody.propName, Decl(derivedClassSuperProperties.ts, 310, 58)) +>this : Symbol(DerivedWithObjectComputedPropertyBody, Decl(derivedClassSuperProperties.ts, 308, 1)) +>propName : Symbol(DerivedWithObjectComputedPropertyBody.propName, Decl(derivedClassSuperProperties.ts, 310, 58)) + + }; + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class DerivedWithObjectComputedPropertyName extends Base { +>DerivedWithObjectComputedPropertyName : Symbol(DerivedWithObjectComputedPropertyName, Decl(derivedClassSuperProperties.ts, 318, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + propName = "prop"; +>propName : Symbol(DerivedWithObjectComputedPropertyName.propName, Decl(derivedClassSuperProperties.ts, 320, 58)) + + constructor() { + const obj = { +>obj : Symbol(obj, Decl(derivedClassSuperProperties.ts, 323, 13)) + + [this.propName]: true, +>[this.propName] : Symbol([this.propName], Decl(derivedClassSuperProperties.ts, 323, 21)) +>this.propName : Symbol(DerivedWithObjectComputedPropertyName.propName, Decl(derivedClassSuperProperties.ts, 320, 58)) +>this : Symbol(DerivedWithObjectComputedPropertyName, Decl(derivedClassSuperProperties.ts, 318, 1)) +>propName : Symbol(DerivedWithObjectComputedPropertyName.propName, Decl(derivedClassSuperProperties.ts, 320, 58)) + + }; + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +class DerivedWithObjectMethod extends Base { +>DerivedWithObjectMethod : Symbol(DerivedWithObjectMethod, Decl(derivedClassSuperProperties.ts, 328, 1)) +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol(DerivedWithObjectMethod.prop, Decl(derivedClassSuperProperties.ts, 330, 44)) + + constructor() { + const obj = { +>obj : Symbol(obj, Decl(derivedClassSuperProperties.ts, 333, 13)) + + getProp() { +>getProp : Symbol(getProp, Decl(derivedClassSuperProperties.ts, 333, 21)) + + return this; + }, + }; + super(); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } +} + +let a, b; +>a : Symbol(a, Decl(derivedClassSuperProperties.ts, 342, 3)) +>b : Symbol(b, Decl(derivedClassSuperProperties.ts, 342, 6)) + +const DerivedWithLoops = [ +>DerivedWithLoops : Symbol(DerivedWithLoops, Decl(derivedClassSuperProperties.ts, 344, 5)) + + class extends Base { +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol((Anonymous class).prop, Decl(derivedClassSuperProperties.ts, 345, 24)) + + constructor() { + for(super();;) {} +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } + }, + class extends Base { +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol((Anonymous class).prop, Decl(derivedClassSuperProperties.ts, 351, 24)) + + constructor() { + for(a; super();) {} +>a : Symbol(a, Decl(derivedClassSuperProperties.ts, 342, 3)) +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } + }, + class extends Base { +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol((Anonymous class).prop, Decl(derivedClassSuperProperties.ts, 357, 24)) + + constructor() { + for(a; b; super()) {} +>a : Symbol(a, Decl(derivedClassSuperProperties.ts, 342, 3)) +>b : Symbol(b, Decl(derivedClassSuperProperties.ts, 342, 6)) +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } + }, + class extends Base { +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol((Anonymous class).prop, Decl(derivedClassSuperProperties.ts, 363, 24)) + + constructor() { + for(; ; super()) { break; } +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } + }, + class extends Base { +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol((Anonymous class).prop, Decl(derivedClassSuperProperties.ts, 369, 24)) + + constructor() { + for (const x of super()) {} +>x : Symbol(x, Decl(derivedClassSuperProperties.ts, 372, 22)) +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } + }, + class extends Base { +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol((Anonymous class).prop, Decl(derivedClassSuperProperties.ts, 375, 24)) + + constructor() { + while (super()) {} +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } + }, + class extends Base { +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol((Anonymous class).prop, Decl(derivedClassSuperProperties.ts, 381, 24)) + + constructor() { + do {} while (super()); +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } + }, + class extends Base { +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol((Anonymous class).prop, Decl(derivedClassSuperProperties.ts, 387, 24)) + + constructor() { + if (super()) {} +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } + }, + class extends Base { +>Base : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + + prop = true; +>prop : Symbol((Anonymous class).prop, Decl(derivedClassSuperProperties.ts, 393, 24)) + + constructor() { + switch (super()) {} +>super : Symbol(Base, Decl(derivedClassSuperProperties.ts, 0, 28)) + } + }, +] + diff --git a/tests/baselines/reference/derivedClassSuperProperties.types b/tests/baselines/reference/derivedClassSuperProperties.types new file mode 100644 index 0000000000000..c52f578ce7ecd --- /dev/null +++ b/tests/baselines/reference/derivedClassSuperProperties.types @@ -0,0 +1,1016 @@ +=== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts === +declare const decorate: any; +>decorate : any + +class Base { +>Base : Base + + constructor(a?) { } +>a : any + + receivesAnything(param?) { } +>receivesAnything : (param?: any) => void +>param : any +} + +class Derived1 extends Base { +>Derived1 : Derived1 +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + super.receivesAnything(); +>super.receivesAnything() : void +>super.receivesAnything : (param?: any) => void +>super : Base +>receivesAnything : (param?: any) => void + + super(); +>super() : void +>super : typeof Base + } +} + +class Derived2 extends Base { +>Derived2 : Derived2 +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + super.receivesAnything(this); +>super.receivesAnything(this) : void +>super.receivesAnything : (param?: any) => void +>super : Base +>receivesAnything : (param?: any) => void +>this : this + + super(); +>super() : void +>super : typeof Base + } +} + +class Derived3 extends Base { +>Derived3 : Derived3 +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + super.receivesAnything(); +>super.receivesAnything() : void +>super.receivesAnything : (param?: any) => void +>super : Base +>receivesAnything : (param?: any) => void + + super(this); +>super(this) : void +>super : typeof Base +>this : this + } +} + +class Derived4 extends Base { +>Derived4 : Derived4 +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + super.receivesAnything(this); +>super.receivesAnything(this) : void +>super.receivesAnything : (param?: any) => void +>super : Base +>receivesAnything : (param?: any) => void +>this : this + + super(this); +>super(this) : void +>super : typeof Base +>this : this + } +} + +class Derived5 extends Base { +>Derived5 : Derived5 +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + super(); +>super() : void +>super : typeof Base + + super.receivesAnything(); +>super.receivesAnything() : void +>super.receivesAnything : (param?: any) => void +>super : Base +>receivesAnything : (param?: any) => void + } +} + +class Derived6 extends Base { +>Derived6 : Derived6 +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + super(this); +>super(this) : void +>super : typeof Base +>this : this + + super.receivesAnything(); +>super.receivesAnything() : void +>super.receivesAnything : (param?: any) => void +>super : Base +>receivesAnything : (param?: any) => void + } +} + +class Derived7 extends Base { +>Derived7 : Derived7 +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + super(); +>super() : void +>super : typeof Base + + super.receivesAnything(this); +>super.receivesAnything(this) : void +>super.receivesAnything : (param?: any) => void +>super : Base +>receivesAnything : (param?: any) => void +>this : this + } +} + +class Derived8 extends Base { +>Derived8 : Derived8 +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + super(this); +>super(this) : void +>super : typeof Base +>this : this + + super.receivesAnything(this); +>super.receivesAnything(this) : void +>super.receivesAnything : (param?: any) => void +>super : Base +>receivesAnything : (param?: any) => void +>this : this + } +} + +class DerivedWithArrowFunction extends Base { +>DerivedWithArrowFunction : DerivedWithArrowFunction +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + (() => this)(); +>(() => this)() : this +>(() => this) : () => this +>() => this : () => this +>this : this + + super(); +>super() : void +>super : typeof Base + } +} + +class DerivedWithArrowFunctionParameter extends Base { +>DerivedWithArrowFunctionParameter : DerivedWithArrowFunctionParameter +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + const lambda = (param = this) => {}; +>lambda : (param?: this) => void +>(param = this) => {} : (param?: this) => void +>param : this +>this : this + + super(); +>super() : void +>super : typeof Base + } +} + +class DerivedWithDecoratorOnClass extends Base { +>DerivedWithDecoratorOnClass : DerivedWithDecoratorOnClass +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + @decorate(this) +>decorate(this) : any +>decorate : any +>this : this + + class InnerClass { } +>InnerClass : InnerClass + + super(); +>super() : void +>super : typeof Base + } +} + +class DerivedWithDecoratorOnClassMethod extends Base { +>DerivedWithDecoratorOnClassMethod : DerivedWithDecoratorOnClassMethod +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + class InnerClass { +>InnerClass : InnerClass + + @decorate(this) +>decorate(this) : any +>decorate : any +>this : this + + innerMethod() { } +>innerMethod : () => void + } + + super(); +>super() : void +>super : typeof Base + } +} + +class DerivedWithDecoratorOnClassProperty extends Base { +>DerivedWithDecoratorOnClassProperty : DerivedWithDecoratorOnClassProperty +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + class InnerClass { +>InnerClass : InnerClass + + @decorate(this) +>decorate(this) : any +>decorate : any +>this : this + + innerProp = true; +>innerProp : boolean +>true : true + } + + super(); +>super() : void +>super : typeof Base + } +} + +class DerivedWithFunctionDeclaration extends Base { +>DerivedWithFunctionDeclaration : DerivedWithFunctionDeclaration +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + function declaration() { +>declaration : () => any + + return this; +>this : any + } + super(); +>super() : void +>super : typeof Base + } +} + +class DerivedWithFunctionDeclarationAndThisParam extends Base { +>DerivedWithFunctionDeclarationAndThisParam : DerivedWithFunctionDeclarationAndThisParam +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + function declaration(param = this) { +>declaration : (param?: any) => any +>param : any +>this : any + + return param; +>param : any + } + super(); +>super() : void +>super : typeof Base + } +} + +class DerivedWithFunctionExpression extends Base { +>DerivedWithFunctionExpression : DerivedWithFunctionExpression +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + (function () { +>(function () { return this; })() : any +>(function () { return this; }) : () => any +>function () { return this; } : () => any + + return this; +>this : any + + })(); + super(); +>super() : void +>super : typeof Base + } +} + +class DerivedWithParenthesis extends Base { +>DerivedWithParenthesis : DerivedWithParenthesis +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + (super()); +>(super()) : void +>super() : void +>super : typeof Base + } +} + +class DerivedWithParenthesisAfterStatement extends Base { +>DerivedWithParenthesisAfterStatement : DerivedWithParenthesisAfterStatement +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + this.prop; +>this.prop : boolean +>this : this +>prop : boolean + + (super()); +>(super()) : void +>super() : void +>super : typeof Base + } +} + +class DerivedWithParenthesisBeforeStatement extends Base { +>DerivedWithParenthesisBeforeStatement : DerivedWithParenthesisBeforeStatement +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + (super()); +>(super()) : void +>super() : void +>super : typeof Base + + this.prop; +>this.prop : boolean +>this : this +>prop : boolean + } +} + +class DerivedWithClassDeclaration extends Base { +>DerivedWithClassDeclaration : DerivedWithClassDeclaration +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + class InnerClass { +>InnerClass : InnerClass + + private method() { +>method : () => this + + return this; +>this : this + } + private property = 7; +>property : number +>7 : 7 + + constructor() { + this.property; +>this.property : number +>this : this +>property : number + + this.method(); +>this.method() : this +>this.method : () => this +>this : this +>method : () => this + } + } + super(); +>super() : void +>super : typeof Base + } +} + +class DerivedWithClassDeclarationExtendingMember extends Base { +>DerivedWithClassDeclarationExtendingMember : DerivedWithClassDeclarationExtendingMember +>Base : Base + + memberClass = class { }; +>memberClass : typeof (Anonymous class) +>class { } : typeof (Anonymous class) + + constructor() { + class InnerClass extends this.memberClass { +>InnerClass : InnerClass +>this.memberClass : (Anonymous class) +>this : this +>memberClass : typeof (Anonymous class) + + private method() { +>method : () => this + + return this; +>this : this + } + private property = 7; +>property : number +>7 : 7 + + constructor() { + super(); +>super() : void +>super : typeof (Anonymous class) + + this.property; +>this.property : number +>this : this +>property : number + + this.method(); +>this.method() : this +>this.method : () => this +>this : this +>method : () => this + } + } + super(); +>super() : void +>super : typeof Base + } +} + +class DerivedWithClassExpression extends Base { +>DerivedWithClassExpression : DerivedWithClassExpression +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + console.log(class { +>console.log(class { private method() { return this; } private property = 7; constructor() { this.property; this.method(); } }) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>class { private method() { return this; } private property = 7; constructor() { this.property; this.method(); } } : typeof (Anonymous class) + + private method() { +>method : () => this + + return this; +>this : this + } + private property = 7; +>property : number +>7 : 7 + + constructor() { + this.property; +>this.property : number +>this : this +>property : number + + this.method(); +>this.method() : this +>this.method : () => this +>this : this +>method : () => this + } + }); + super(); +>super() : void +>super : typeof Base + } +} + +class DerivedWithClassExpressionExtendingMember extends Base { +>DerivedWithClassExpressionExtendingMember : DerivedWithClassExpressionExtendingMember +>Base : Base + + memberClass = class { }; +>memberClass : typeof (Anonymous class) +>class { } : typeof (Anonymous class) + + constructor() { + console.log(class extends this.memberClass { }); +>console.log(class extends this.memberClass { }) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>class extends this.memberClass { } : typeof (Anonymous class) +>this.memberClass : (Anonymous class) +>this : this +>memberClass : typeof (Anonymous class) + + super(); +>super() : void +>super : typeof Base + } +} + +class DerivedWithDerivedClassExpression extends Base { +>DerivedWithDerivedClassExpression : DerivedWithDerivedClassExpression +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + console.log(class extends Base { +>console.log(class extends Base { constructor() { super(); } public foo() { return this; } public bar = () => this; }) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>class extends Base { constructor() { super(); } public foo() { return this; } public bar = () => this; } : typeof (Anonymous class) +>Base : Base + + constructor() { + super(); +>super() : void +>super : typeof Base + } + public foo() { +>foo : () => this + + return this; +>this : this + } + public bar = () => this; +>bar : () => this +>() => this : () => this +>this : this + + }); + super(); +>super() : void +>super : typeof Base + } +} + +class DerivedWithNewDerivedClassExpression extends Base { +>DerivedWithNewDerivedClassExpression : DerivedWithNewDerivedClassExpression +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + console.log(new class extends Base { +>console.log(new class extends Base { constructor() { super(); } }()) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>new class extends Base { constructor() { super(); } }() : (Anonymous class) +>class extends Base { constructor() { super(); } } : typeof (Anonymous class) +>Base : Base + + constructor() { + super(); +>super() : void +>super : typeof Base + } + }()); + super(); +>super() : void +>super : typeof Base + } +} + +class DerivedWithObjectAccessors extends Base { +>DerivedWithObjectAccessors : DerivedWithObjectAccessors +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + const obj = { +>obj : { prop: boolean; } +>{ get prop() { return true; }, set prop(param) { this._prop = param; } } : { prop: boolean; } + + get prop() { +>prop : boolean + + return true; +>true : true + + }, + set prop(param) { +>prop : boolean +>param : boolean + + this._prop = param; +>this._prop = param : boolean +>this._prop : any +>this : any +>_prop : any +>param : boolean + } + }; + super(); +>super() : void +>super : typeof Base + } +} + +class DerivedWithObjectAccessorsUsingThisInKeys extends Base { +>DerivedWithObjectAccessorsUsingThisInKeys : DerivedWithObjectAccessorsUsingThisInKeys +>Base : Base + + propName = "prop"; +>propName : string +>"prop" : "prop" + + constructor() { + const obj = { +>obj : { [x: string]: any; _prop: string; } +>{ _prop: "prop", get [this.propName]() { return true; }, set [this.propName](param) { this._prop = param; } } : { [x: string]: any; _prop: string; } + + _prop: "prop", +>_prop : string +>"prop" : "prop" + + get [this.propName]() { +>[this.propName] : boolean +>this.propName : string +>this : this +>propName : string + + return true; +>true : true + + }, + set [this.propName](param) { +>[this.propName] : any +>this.propName : string +>this : this +>propName : string +>param : any + + this._prop = param; +>this._prop = param : any +>this._prop : any +>this : any +>_prop : any +>param : any + } + }; + super(); +>super() : void +>super : typeof Base + } +} + +class DerivedWithObjectAccessorsUsingThisInBodies extends Base { +>DerivedWithObjectAccessorsUsingThisInBodies : DerivedWithObjectAccessorsUsingThisInBodies +>Base : Base + + propName = "prop"; +>propName : string +>"prop" : "prop" + + constructor() { + const obj = { +>obj : { _prop: string; prop: any; } +>{ _prop: "prop", get prop() { return this._prop; }, set prop(param) { this._prop = param; } } : { _prop: string; prop: any; } + + _prop: "prop", +>_prop : string +>"prop" : "prop" + + get prop() { +>prop : any + + return this._prop; +>this._prop : any +>this : any +>_prop : any + + }, + set prop(param) { +>prop : any +>param : any + + this._prop = param; +>this._prop = param : any +>this._prop : any +>this : any +>_prop : any +>param : any + } + }; + super(); +>super() : void +>super : typeof Base + } +} + +class DerivedWithObjectComputedPropertyBody extends Base { +>DerivedWithObjectComputedPropertyBody : DerivedWithObjectComputedPropertyBody +>Base : Base + + propName = "prop"; +>propName : string +>"prop" : "prop" + + constructor() { + const obj = { +>obj : { prop: string; } +>{ prop: this.propName, } : { prop: string; } + + prop: this.propName, +>prop : string +>this.propName : string +>this : this +>propName : string + + }; + super(); +>super() : void +>super : typeof Base + } +} + +class DerivedWithObjectComputedPropertyName extends Base { +>DerivedWithObjectComputedPropertyName : DerivedWithObjectComputedPropertyName +>Base : Base + + propName = "prop"; +>propName : string +>"prop" : "prop" + + constructor() { + const obj = { +>obj : { [x: string]: boolean; } +>{ [this.propName]: true, } : { [x: string]: boolean; } + + [this.propName]: true, +>[this.propName] : boolean +>this.propName : string +>this : this +>propName : string +>true : true + + }; + super(); +>super() : void +>super : typeof Base + } +} + +class DerivedWithObjectMethod extends Base { +>DerivedWithObjectMethod : DerivedWithObjectMethod +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + const obj = { +>obj : { getProp(): any; } +>{ getProp() { return this; }, } : { getProp(): any; } + + getProp() { +>getProp : () => any + + return this; +>this : any + + }, + }; + super(); +>super() : void +>super : typeof Base + } +} + +let a, b; +>a : any +>b : any + +const DerivedWithLoops = [ +>DerivedWithLoops : (typeof (Anonymous class))[] +>[ class extends Base { prop = true; constructor() { for(super();;) {} } }, class extends Base { prop = true; constructor() { for(a; super();) {} } }, class extends Base { prop = true; constructor() { for(a; b; super()) {} } }, class extends Base { prop = true; constructor() { for(; ; super()) { break; } } }, class extends Base { prop = true; constructor() { for (const x of super()) {} } }, class extends Base { prop = true; constructor() { while (super()) {} } }, class extends Base { prop = true; constructor() { do {} while (super()); } }, class extends Base { prop = true; constructor() { if (super()) {} } }, class extends Base { prop = true; constructor() { switch (super()) {} } },] : (typeof (Anonymous class))[] + + class extends Base { +>class extends Base { prop = true; constructor() { for(super();;) {} } } : typeof (Anonymous class) +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + for(super();;) {} +>super() : void +>super : typeof Base + } + }, + class extends Base { +>class extends Base { prop = true; constructor() { for(a; super();) {} } } : typeof (Anonymous class) +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + for(a; super();) {} +>a : any +>super() : void +>super : typeof Base + } + }, + class extends Base { +>class extends Base { prop = true; constructor() { for(a; b; super()) {} } } : typeof (Anonymous class) +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + for(a; b; super()) {} +>a : any +>b : any +>super() : void +>super : typeof Base + } + }, + class extends Base { +>class extends Base { prop = true; constructor() { for(; ; super()) { break; } } } : typeof (Anonymous class) +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + for(; ; super()) { break; } +>super() : void +>super : typeof Base + } + }, + class extends Base { +>class extends Base { prop = true; constructor() { for (const x of super()) {} } } : typeof (Anonymous class) +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + for (const x of super()) {} +>x : any +>super() : void +>super : typeof Base + } + }, + class extends Base { +>class extends Base { prop = true; constructor() { while (super()) {} } } : typeof (Anonymous class) +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + while (super()) {} +>super() : void +>super : typeof Base + } + }, + class extends Base { +>class extends Base { prop = true; constructor() { do {} while (super()); } } : typeof (Anonymous class) +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + do {} while (super()); +>super() : void +>super : typeof Base + } + }, + class extends Base { +>class extends Base { prop = true; constructor() { if (super()) {} } } : typeof (Anonymous class) +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + if (super()) {} +>super() : void +>super : typeof Base + } + }, + class extends Base { +>class extends Base { prop = true; constructor() { switch (super()) {} } } : typeof (Anonymous class) +>Base : Base + + prop = true; +>prop : boolean +>true : true + + constructor() { + switch (super()) {} +>super() : void +>super : typeof Base + } + }, +] + diff --git a/tests/baselines/reference/derivedClassSuperStatementPosition.errors.txt b/tests/baselines/reference/derivedClassSuperStatementPosition.errors.txt new file mode 100644 index 0000000000000..4a9df073646fa --- /dev/null +++ b/tests/baselines/reference/derivedClassSuperStatementPosition.errors.txt @@ -0,0 +1,120 @@ +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperStatementPosition.ts(12,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperStatementPosition.ts(22,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperStatementPosition.ts(45,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperStatementPosition.ts(60,15): error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperStatementPosition.ts(69,13): error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperStatementPosition.ts(81,13): error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperStatementPosition.ts(90,13): error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. + + +==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperStatementPosition.ts (7 errors) ==== + class DerivedBasic extends Object { + prop = 1; + constructor() { + super(); + } + } + + class DerivedAfterParameterDefault extends Object { + x1: boolean; + x2: boolean; + constructor(x = false) { + this.x1 = x; + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + super(x); + this.x2 = x; + } + } + + class DerivedAfterRestParameter extends Object { + x1: boolean[]; + x2: boolean[]; + constructor(...x: boolean[]) { + this.x1 = x; + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + super(x); + this.x2 = x; + } + } + + class DerivedComments extends Object { + x: any; + constructor() { + // c1 + console.log(); // c2 + // c3 + super(); // c4 + // c5 + this.x = null; // c6 + // c7 + } + } + + class DerivedCommentsInvalidThis extends Object { + x: any; + constructor() { + // c0 + this; + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + // c1 + console.log(); // c2 + // c3 + super(); // c4 + // c5 + this.x = null; // c6 + // c7 + } + } + + class DerivedInConditional extends Object { + prop = 1; + constructor() { + Math.random() + ? super(1) + ~~~~~~~~ +!!! error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. + : super(0); + } + } + + class DerivedInIf extends Object { + prop = 1; + constructor() { + if (Math.random()) { + super(1); + ~~~~~~~~ +!!! error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. + } + else { + super(0); + } + } + } + + class DerivedInBlockWithProperties extends Object { + prop = 1; + constructor(private paramProp = 2) { + { + super(); + ~~~~~~~ +!!! error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. + } + } + } + + class DerivedInConditionalWithProperties extends Object { + prop = 1; + constructor(private paramProp = 2) { + if (Math.random()) { + super(1); + ~~~~~~~~ +!!! error TS2401: A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers. + } else { + super(0); + } + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/derivedClassSuperStatementPosition.js b/tests/baselines/reference/derivedClassSuperStatementPosition.js new file mode 100644 index 0000000000000..45209f9319564 --- /dev/null +++ b/tests/baselines/reference/derivedClassSuperStatementPosition.js @@ -0,0 +1,239 @@ +//// [derivedClassSuperStatementPosition.ts] +class DerivedBasic extends Object { + prop = 1; + constructor() { + super(); + } +} + +class DerivedAfterParameterDefault extends Object { + x1: boolean; + x2: boolean; + constructor(x = false) { + this.x1 = x; + super(x); + this.x2 = x; + } +} + +class DerivedAfterRestParameter extends Object { + x1: boolean[]; + x2: boolean[]; + constructor(...x: boolean[]) { + this.x1 = x; + super(x); + this.x2 = x; + } +} + +class DerivedComments extends Object { + x: any; + constructor() { + // c1 + console.log(); // c2 + // c3 + super(); // c4 + // c5 + this.x = null; // c6 + // c7 + } +} + +class DerivedCommentsInvalidThis extends Object { + x: any; + constructor() { + // c0 + this; + // c1 + console.log(); // c2 + // c3 + super(); // c4 + // c5 + this.x = null; // c6 + // c7 + } +} + +class DerivedInConditional extends Object { + prop = 1; + constructor() { + Math.random() + ? super(1) + : super(0); + } +} + +class DerivedInIf extends Object { + prop = 1; + constructor() { + if (Math.random()) { + super(1); + } + else { + super(0); + } + } +} + +class DerivedInBlockWithProperties extends Object { + prop = 1; + constructor(private paramProp = 2) { + { + super(); + } + } +} + +class DerivedInConditionalWithProperties extends Object { + prop = 1; + constructor(private paramProp = 2) { + if (Math.random()) { + super(1); + } else { + super(0); + } + } +} + + +//// [derivedClassSuperStatementPosition.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 DerivedBasic = /** @class */ (function (_super) { + __extends(DerivedBasic, _super); + function DerivedBasic() { + var _this = _super.call(this) || this; + _this.prop = 1; + return _this; + } + return DerivedBasic; +}(Object)); +var DerivedAfterParameterDefault = /** @class */ (function (_super) { + __extends(DerivedAfterParameterDefault, _super); + function DerivedAfterParameterDefault(x) { + if (x === void 0) { x = false; } + var _this = this; + _this.x1 = x; + _this = _super.call(this, x) || this; + _this.x2 = x; + return _this; + } + return DerivedAfterParameterDefault; +}(Object)); +var DerivedAfterRestParameter = /** @class */ (function (_super) { + __extends(DerivedAfterRestParameter, _super); + function DerivedAfterRestParameter() { + var x = []; + for (var _i = 0; _i < arguments.length; _i++) { + x[_i] = arguments[_i]; + } + var _this = this; + _this.x1 = x; + _this = _super.call(this, x) || this; + _this.x2 = x; + return _this; + } + return DerivedAfterRestParameter; +}(Object)); +var DerivedComments = /** @class */ (function (_super) { + __extends(DerivedComments, _super); + function DerivedComments() { + var _this = this; + // c1 + console.log(); // c2 + // c3 + _this = _super.call(this) || this; // c4 + // c5 + _this.x = null; // c6 + return _this; + // c7 + } + return DerivedComments; +}(Object)); +var DerivedCommentsInvalidThis = /** @class */ (function (_super) { + __extends(DerivedCommentsInvalidThis, _super); + function DerivedCommentsInvalidThis() { + var _this = this; + // c0 + _this; + // c1 + console.log(); // c2 + // c3 + _this = _super.call(this) || this; // c4 + // c5 + _this.x = null; // c6 + return _this; + // c7 + } + return DerivedCommentsInvalidThis; +}(Object)); +var DerivedInConditional = /** @class */ (function (_super) { + __extends(DerivedInConditional, _super); + function DerivedInConditional() { + var _this = this; + _this.prop = 1; + Math.random() + ? _this = _super.call(this, 1) || this : _this = _super.call(this, 0) || this; + return _this; + } + return DerivedInConditional; +}(Object)); +var DerivedInIf = /** @class */ (function (_super) { + __extends(DerivedInIf, _super); + function DerivedInIf() { + var _this = this; + _this.prop = 1; + if (Math.random()) { + _this = _super.call(this, 1) || this; + } + else { + _this = _super.call(this, 0) || this; + } + return _this; + } + return DerivedInIf; +}(Object)); +var DerivedInBlockWithProperties = /** @class */ (function (_super) { + __extends(DerivedInBlockWithProperties, _super); + function DerivedInBlockWithProperties(paramProp) { + if (paramProp === void 0) { paramProp = 2; } + var _this = this; + _this.paramProp = paramProp; + _this.prop = 1; + { + _this = _super.call(this) || this; + } + return _this; + } + return DerivedInBlockWithProperties; +}(Object)); +var DerivedInConditionalWithProperties = /** @class */ (function (_super) { + __extends(DerivedInConditionalWithProperties, _super); + function DerivedInConditionalWithProperties(paramProp) { + if (paramProp === void 0) { paramProp = 2; } + var _this = this; + _this.paramProp = paramProp; + _this.prop = 1; + if (Math.random()) { + _this = _super.call(this, 1) || this; + } + else { + _this = _super.call(this, 0) || this; + } + return _this; + } + return DerivedInConditionalWithProperties; +}(Object)); diff --git a/tests/baselines/reference/derivedClassSuperStatementPosition.symbols b/tests/baselines/reference/derivedClassSuperStatementPosition.symbols new file mode 100644 index 0000000000000..025889caea633 --- /dev/null +++ b/tests/baselines/reference/derivedClassSuperStatementPosition.symbols @@ -0,0 +1,221 @@ +=== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperStatementPosition.ts === +class DerivedBasic extends Object { +>DerivedBasic : Symbol(DerivedBasic, Decl(derivedClassSuperStatementPosition.ts, 0, 0)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + + prop = 1; +>prop : Symbol(DerivedBasic.prop, Decl(derivedClassSuperStatementPosition.ts, 0, 35)) + + constructor() { + super(); +>super : Symbol(ObjectConstructor, Decl(lib.es5.d.ts, --, --)) + } +} + +class DerivedAfterParameterDefault extends Object { +>DerivedAfterParameterDefault : Symbol(DerivedAfterParameterDefault, Decl(derivedClassSuperStatementPosition.ts, 5, 1)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + + x1: boolean; +>x1 : Symbol(DerivedAfterParameterDefault.x1, Decl(derivedClassSuperStatementPosition.ts, 7, 51)) + + x2: boolean; +>x2 : Symbol(DerivedAfterParameterDefault.x2, Decl(derivedClassSuperStatementPosition.ts, 8, 16)) + + constructor(x = false) { +>x : Symbol(x, Decl(derivedClassSuperStatementPosition.ts, 10, 16)) + + this.x1 = x; +>this.x1 : Symbol(DerivedAfterParameterDefault.x1, Decl(derivedClassSuperStatementPosition.ts, 7, 51)) +>this : Symbol(DerivedAfterParameterDefault, Decl(derivedClassSuperStatementPosition.ts, 5, 1)) +>x1 : Symbol(DerivedAfterParameterDefault.x1, Decl(derivedClassSuperStatementPosition.ts, 7, 51)) +>x : Symbol(x, Decl(derivedClassSuperStatementPosition.ts, 10, 16)) + + super(x); +>super : Symbol(ObjectConstructor, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(derivedClassSuperStatementPosition.ts, 10, 16)) + + this.x2 = x; +>this.x2 : Symbol(DerivedAfterParameterDefault.x2, Decl(derivedClassSuperStatementPosition.ts, 8, 16)) +>this : Symbol(DerivedAfterParameterDefault, Decl(derivedClassSuperStatementPosition.ts, 5, 1)) +>x2 : Symbol(DerivedAfterParameterDefault.x2, Decl(derivedClassSuperStatementPosition.ts, 8, 16)) +>x : Symbol(x, Decl(derivedClassSuperStatementPosition.ts, 10, 16)) + } +} + +class DerivedAfterRestParameter extends Object { +>DerivedAfterRestParameter : Symbol(DerivedAfterRestParameter, Decl(derivedClassSuperStatementPosition.ts, 15, 1)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + + x1: boolean[]; +>x1 : Symbol(DerivedAfterRestParameter.x1, Decl(derivedClassSuperStatementPosition.ts, 17, 48)) + + x2: boolean[]; +>x2 : Symbol(DerivedAfterRestParameter.x2, Decl(derivedClassSuperStatementPosition.ts, 18, 18)) + + constructor(...x: boolean[]) { +>x : Symbol(x, Decl(derivedClassSuperStatementPosition.ts, 20, 16)) + + this.x1 = x; +>this.x1 : Symbol(DerivedAfterRestParameter.x1, Decl(derivedClassSuperStatementPosition.ts, 17, 48)) +>this : Symbol(DerivedAfterRestParameter, Decl(derivedClassSuperStatementPosition.ts, 15, 1)) +>x1 : Symbol(DerivedAfterRestParameter.x1, Decl(derivedClassSuperStatementPosition.ts, 17, 48)) +>x : Symbol(x, Decl(derivedClassSuperStatementPosition.ts, 20, 16)) + + super(x); +>super : Symbol(ObjectConstructor, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(derivedClassSuperStatementPosition.ts, 20, 16)) + + this.x2 = x; +>this.x2 : Symbol(DerivedAfterRestParameter.x2, Decl(derivedClassSuperStatementPosition.ts, 18, 18)) +>this : Symbol(DerivedAfterRestParameter, Decl(derivedClassSuperStatementPosition.ts, 15, 1)) +>x2 : Symbol(DerivedAfterRestParameter.x2, Decl(derivedClassSuperStatementPosition.ts, 18, 18)) +>x : Symbol(x, Decl(derivedClassSuperStatementPosition.ts, 20, 16)) + } +} + +class DerivedComments extends Object { +>DerivedComments : Symbol(DerivedComments, Decl(derivedClassSuperStatementPosition.ts, 25, 1)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + + x: any; +>x : Symbol(DerivedComments.x, Decl(derivedClassSuperStatementPosition.ts, 27, 38)) + + constructor() { + // c1 + console.log(); // c2 +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) + + // c3 + super(); // c4 +>super : Symbol(ObjectConstructor, Decl(lib.es5.d.ts, --, --)) + + // c5 + this.x = null; // c6 +>this.x : Symbol(DerivedComments.x, Decl(derivedClassSuperStatementPosition.ts, 27, 38)) +>this : Symbol(DerivedComments, Decl(derivedClassSuperStatementPosition.ts, 25, 1)) +>x : Symbol(DerivedComments.x, Decl(derivedClassSuperStatementPosition.ts, 27, 38)) + + // c7 + } +} + +class DerivedCommentsInvalidThis extends Object { +>DerivedCommentsInvalidThis : Symbol(DerivedCommentsInvalidThis, Decl(derivedClassSuperStatementPosition.ts, 38, 1)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + + x: any; +>x : Symbol(DerivedCommentsInvalidThis.x, Decl(derivedClassSuperStatementPosition.ts, 40, 49)) + + constructor() { + // c0 + this; +>this : Symbol(DerivedCommentsInvalidThis, Decl(derivedClassSuperStatementPosition.ts, 38, 1)) + + // c1 + console.log(); // c2 +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) + + // c3 + super(); // c4 +>super : Symbol(ObjectConstructor, Decl(lib.es5.d.ts, --, --)) + + // c5 + this.x = null; // c6 +>this.x : Symbol(DerivedCommentsInvalidThis.x, Decl(derivedClassSuperStatementPosition.ts, 40, 49)) +>this : Symbol(DerivedCommentsInvalidThis, Decl(derivedClassSuperStatementPosition.ts, 38, 1)) +>x : Symbol(DerivedCommentsInvalidThis.x, Decl(derivedClassSuperStatementPosition.ts, 40, 49)) + + // c7 + } +} + +class DerivedInConditional extends Object { +>DerivedInConditional : Symbol(DerivedInConditional, Decl(derivedClassSuperStatementPosition.ts, 53, 1)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + + prop = 1; +>prop : Symbol(DerivedInConditional.prop, Decl(derivedClassSuperStatementPosition.ts, 55, 43)) + + constructor() { + Math.random() +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) + + ? super(1) +>super : Symbol(ObjectConstructor, Decl(lib.es5.d.ts, --, --)) + + : super(0); +>super : Symbol(ObjectConstructor, Decl(lib.es5.d.ts, --, --)) + } +} + +class DerivedInIf extends Object { +>DerivedInIf : Symbol(DerivedInIf, Decl(derivedClassSuperStatementPosition.ts, 62, 1)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + + prop = 1; +>prop : Symbol(DerivedInIf.prop, Decl(derivedClassSuperStatementPosition.ts, 64, 34)) + + constructor() { + if (Math.random()) { +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) + + super(1); +>super : Symbol(ObjectConstructor, Decl(lib.es5.d.ts, --, --)) + } + else { + super(0); +>super : Symbol(ObjectConstructor, Decl(lib.es5.d.ts, --, --)) + } + } +} + +class DerivedInBlockWithProperties extends Object { +>DerivedInBlockWithProperties : Symbol(DerivedInBlockWithProperties, Decl(derivedClassSuperStatementPosition.ts, 74, 1)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + + prop = 1; +>prop : Symbol(DerivedInBlockWithProperties.prop, Decl(derivedClassSuperStatementPosition.ts, 76, 51)) + + constructor(private paramProp = 2) { +>paramProp : Symbol(DerivedInBlockWithProperties.paramProp, Decl(derivedClassSuperStatementPosition.ts, 78, 16)) + { + super(); +>super : Symbol(ObjectConstructor, Decl(lib.es5.d.ts, --, --)) + } + } +} + +class DerivedInConditionalWithProperties extends Object { +>DerivedInConditionalWithProperties : Symbol(DerivedInConditionalWithProperties, Decl(derivedClassSuperStatementPosition.ts, 83, 1)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + + prop = 1; +>prop : Symbol(DerivedInConditionalWithProperties.prop, Decl(derivedClassSuperStatementPosition.ts, 85, 57)) + + constructor(private paramProp = 2) { +>paramProp : Symbol(DerivedInConditionalWithProperties.paramProp, Decl(derivedClassSuperStatementPosition.ts, 87, 16)) + + if (Math.random()) { +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) + + super(1); +>super : Symbol(ObjectConstructor, Decl(lib.es5.d.ts, --, --)) + + } else { + super(0); +>super : Symbol(ObjectConstructor, Decl(lib.es5.d.ts, --, --)) + } + } +} + diff --git a/tests/baselines/reference/derivedClassSuperStatementPosition.types b/tests/baselines/reference/derivedClassSuperStatementPosition.types new file mode 100644 index 0000000000000..ce3afe895e826 --- /dev/null +++ b/tests/baselines/reference/derivedClassSuperStatementPosition.types @@ -0,0 +1,261 @@ +=== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperStatementPosition.ts === +class DerivedBasic extends Object { +>DerivedBasic : DerivedBasic +>Object : Object + + prop = 1; +>prop : number +>1 : 1 + + constructor() { + super(); +>super() : void +>super : ObjectConstructor + } +} + +class DerivedAfterParameterDefault extends Object { +>DerivedAfterParameterDefault : DerivedAfterParameterDefault +>Object : Object + + x1: boolean; +>x1 : boolean + + x2: boolean; +>x2 : boolean + + constructor(x = false) { +>x : boolean +>false : false + + this.x1 = x; +>this.x1 = x : boolean +>this.x1 : boolean +>this : this +>x1 : boolean +>x : boolean + + super(x); +>super(x) : void +>super : ObjectConstructor +>x : boolean + + this.x2 = x; +>this.x2 = x : boolean +>this.x2 : boolean +>this : this +>x2 : boolean +>x : boolean + } +} + +class DerivedAfterRestParameter extends Object { +>DerivedAfterRestParameter : DerivedAfterRestParameter +>Object : Object + + x1: boolean[]; +>x1 : boolean[] + + x2: boolean[]; +>x2 : boolean[] + + constructor(...x: boolean[]) { +>x : boolean[] + + this.x1 = x; +>this.x1 = x : boolean[] +>this.x1 : boolean[] +>this : this +>x1 : boolean[] +>x : boolean[] + + super(x); +>super(x) : void +>super : ObjectConstructor +>x : boolean[] + + this.x2 = x; +>this.x2 = x : boolean[] +>this.x2 : boolean[] +>this : this +>x2 : boolean[] +>x : boolean[] + } +} + +class DerivedComments extends Object { +>DerivedComments : DerivedComments +>Object : Object + + x: any; +>x : any + + constructor() { + // c1 + console.log(); // c2 +>console.log() : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void + + // c3 + super(); // c4 +>super() : void +>super : ObjectConstructor + + // c5 + this.x = null; // c6 +>this.x = null : null +>this.x : any +>this : this +>x : any +>null : null + + // c7 + } +} + +class DerivedCommentsInvalidThis extends Object { +>DerivedCommentsInvalidThis : DerivedCommentsInvalidThis +>Object : Object + + x: any; +>x : any + + constructor() { + // c0 + this; +>this : this + + // c1 + console.log(); // c2 +>console.log() : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void + + // c3 + super(); // c4 +>super() : void +>super : ObjectConstructor + + // c5 + this.x = null; // c6 +>this.x = null : null +>this.x : any +>this : this +>x : any +>null : null + + // c7 + } +} + +class DerivedInConditional extends Object { +>DerivedInConditional : DerivedInConditional +>Object : Object + + prop = 1; +>prop : number +>1 : 1 + + constructor() { + Math.random() +>Math.random() ? super(1) : super(0) : void +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number + + ? super(1) +>super(1) : void +>super : ObjectConstructor +>1 : 1 + + : super(0); +>super(0) : void +>super : ObjectConstructor +>0 : 0 + } +} + +class DerivedInIf extends Object { +>DerivedInIf : DerivedInIf +>Object : Object + + prop = 1; +>prop : number +>1 : 1 + + constructor() { + if (Math.random()) { +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number + + super(1); +>super(1) : void +>super : ObjectConstructor +>1 : 1 + } + else { + super(0); +>super(0) : void +>super : ObjectConstructor +>0 : 0 + } + } +} + +class DerivedInBlockWithProperties extends Object { +>DerivedInBlockWithProperties : DerivedInBlockWithProperties +>Object : Object + + prop = 1; +>prop : number +>1 : 1 + + constructor(private paramProp = 2) { +>paramProp : number +>2 : 2 + { + super(); +>super() : void +>super : ObjectConstructor + } + } +} + +class DerivedInConditionalWithProperties extends Object { +>DerivedInConditionalWithProperties : DerivedInConditionalWithProperties +>Object : Object + + prop = 1; +>prop : number +>1 : 1 + + constructor(private paramProp = 2) { +>paramProp : number +>2 : 2 + + if (Math.random()) { +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number + + super(1); +>super(1) : void +>super : ObjectConstructor +>1 : 1 + + } else { + super(0); +>super(0) : void +>super : ObjectConstructor +>0 : 0 + } + } +} + diff --git a/tests/baselines/reference/errorSuperCalls.js b/tests/baselines/reference/errorSuperCalls.js index f479d4f5bbedd..53fd58d9e6656 100644 --- a/tests/baselines/reference/errorSuperCalls.js +++ b/tests/baselines/reference/errorSuperCalls.js @@ -93,9 +93,10 @@ var __extends = (this && this.__extends) || (function () { //super call in class constructor with no base type var NoBase = /** @class */ (function () { function NoBase() { - _this = _super.call(this) || this; + var _this = _super.call(this) || this; //super call in class member initializer with no base type this.p = _this = _super.call(this) || this; + return _this; } //super call in class member function with no base type NoBase.prototype.fn = function () { diff --git a/tests/baselines/reference/keyofAndIndexedAccess.js b/tests/baselines/reference/keyofAndIndexedAccess.js index d9445d47a2c6e..f7c34bdb3329f 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.js +++ b/tests/baselines/reference/keyofAndIndexedAccess.js @@ -1040,10 +1040,8 @@ var SampleClass = /** @class */ (function () { var AnotherSampleClass = /** @class */ (function (_super) { __extends(AnotherSampleClass, _super); function AnotherSampleClass(props) { - var _this = this; var foo = { foo: "bar" }; - _this = _super.call(this, merge(props, foo)) || this; - return _this; + return _super.call(this, merge(props, foo)) || this; } AnotherSampleClass.prototype.brokenMethod = function () { this.props.foo.concat; diff --git a/tests/baselines/reference/privateNameBadSuper.errors.txt b/tests/baselines/reference/privateNameBadSuper.errors.txt index ece66a5e95cd2..cf635191e285b 100644 --- a/tests/baselines/reference/privateNameBadSuper.errors.txt +++ b/tests/baselines/reference/privateNameBadSuper.errors.txt @@ -1,17 +1,20 @@ -tests/cases/conformance/classes/members/privateNames/privateNameBadSuper.ts(4,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/members/privateNames/privateNameBadSuper.ts(4,3): error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/members/privateNames/privateNameBadSuper.ts(5,5): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/conformance/classes/members/privateNames/privateNameBadSuper.ts (1 errors) ==== +==== tests/cases/conformance/classes/members/privateNames/privateNameBadSuper.ts (2 errors) ==== class B {}; class A extends B { - #x; - constructor() { - ~~~~~~~~~~~~~~~ - void 0; // Error: 'super' call must come first - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - super(); - ~~~~~~~~~~~~~~~~ - } - ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers. + #x; + constructor() { + ~~~~~~~~~~~~~~~ + this; + ~~~~~~~~~ + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + super(); + ~~~~~~~~~~~~ + } + ~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. } \ No newline at end of file diff --git a/tests/baselines/reference/privateNameBadSuper.js b/tests/baselines/reference/privateNameBadSuper.js index ac4a4a80695f1..839f95527cef8 100644 --- a/tests/baselines/reference/privateNameBadSuper.js +++ b/tests/baselines/reference/privateNameBadSuper.js @@ -1,11 +1,11 @@ //// [privateNameBadSuper.ts] class B {}; class A extends B { - #x; - constructor() { - void 0; // Error: 'super' call must come first - super(); - } + #x; + constructor() { + this; + super(); + } } //// [privateNameBadSuper.js] @@ -15,7 +15,7 @@ class B { ; class A extends B { constructor() { - void 0; // Error: 'super' call must come first + this; super(); _A_x.set(this, void 0); } diff --git a/tests/baselines/reference/privateNameBadSuper.symbols b/tests/baselines/reference/privateNameBadSuper.symbols index 4af1f8feb9c29..ad724d9fc5389 100644 --- a/tests/baselines/reference/privateNameBadSuper.symbols +++ b/tests/baselines/reference/privateNameBadSuper.symbols @@ -6,12 +6,14 @@ class A extends B { >A : Symbol(A, Decl(privateNameBadSuper.ts, 0, 11)) >B : Symbol(B, Decl(privateNameBadSuper.ts, 0, 0)) - #x; + #x; >#x : Symbol(A.#x, Decl(privateNameBadSuper.ts, 1, 19)) - constructor() { - void 0; // Error: 'super' call must come first - super(); + constructor() { + this; +>this : Symbol(A, Decl(privateNameBadSuper.ts, 0, 11)) + + super(); >super : Symbol(B, Decl(privateNameBadSuper.ts, 0, 0)) - } + } } diff --git a/tests/baselines/reference/privateNameBadSuper.types b/tests/baselines/reference/privateNameBadSuper.types index 5029155262fab..30dd9e43c7bfc 100644 --- a/tests/baselines/reference/privateNameBadSuper.types +++ b/tests/baselines/reference/privateNameBadSuper.types @@ -6,16 +6,15 @@ class A extends B { >A : A >B : B - #x; + #x; >#x : any - constructor() { - void 0; // Error: 'super' call must come first ->void 0 : undefined ->0 : 0 + constructor() { + this; +>this : this - super(); + super(); >super() : void >super : typeof B - } + } } diff --git a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=es2022).errors.txt b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=es2022).errors.txt index 976e71e8d06cf..ab2f65cb53d7f 100644 --- a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=es2022).errors.txt +++ b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=es2022).errors.txt @@ -1,18 +1,21 @@ -tests/cases/conformance/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields.ts(4,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields.ts(4,3): error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. +tests/cases/conformance/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields.ts(5,5): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/conformance/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields.ts (1 errors) ==== +==== tests/cases/conformance/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields.ts (2 errors) ==== class B {}; class A extends B { - #x; - constructor() { - ~~~~~~~~~~~~~~~ - void 0; // Error: 'super' call must come first - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - super(); - ~~~~~~~~~~~~~~~~ - } - ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers. + #x; + constructor() { + ~~~~~~~~~~~~~~~ + this; + ~~~~~~~~~ + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + super(); + ~~~~~~~~~~~~ + } + ~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. } \ No newline at end of file diff --git a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=es2022).js b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=es2022).js index 018c1eaaecedb..cae8d9c65c8a6 100644 --- a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=es2022).js +++ b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=es2022).js @@ -1,11 +1,11 @@ //// [privateNameBadSuperUseDefineForClassFields.ts] class B {}; class A extends B { - #x; - constructor() { - void 0; // Error: 'super' call must come first - super(); - } + #x; + constructor() { + this; + super(); + } } @@ -16,7 +16,7 @@ class B { class A extends B { #x; constructor() { - void 0; // Error: 'super' call must come first + this; super(); } } diff --git a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=es2022).symbols b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=es2022).symbols index 5e5115d741790..1faec18f829cf 100644 --- a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=es2022).symbols +++ b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=es2022).symbols @@ -6,13 +6,15 @@ class A extends B { >A : Symbol(A, Decl(privateNameBadSuperUseDefineForClassFields.ts, 0, 11)) >B : Symbol(B, Decl(privateNameBadSuperUseDefineForClassFields.ts, 0, 0)) - #x; + #x; >#x : Symbol(A.#x, Decl(privateNameBadSuperUseDefineForClassFields.ts, 1, 19)) - constructor() { - void 0; // Error: 'super' call must come first - super(); + constructor() { + this; +>this : Symbol(A, Decl(privateNameBadSuperUseDefineForClassFields.ts, 0, 11)) + + super(); >super : Symbol(B, Decl(privateNameBadSuperUseDefineForClassFields.ts, 0, 0)) - } + } } diff --git a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=es2022).types b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=es2022).types index 55432691aece8..410e752c22c1d 100644 --- a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=es2022).types +++ b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=es2022).types @@ -6,17 +6,16 @@ class A extends B { >A : A >B : B - #x; + #x; >#x : any - constructor() { - void 0; // Error: 'super' call must come first ->void 0 : undefined ->0 : 0 + constructor() { + this; +>this : this - super(); + super(); >super() : void >super : typeof B - } + } } diff --git a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=esnext).errors.txt b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=esnext).errors.txt new file mode 100644 index 0000000000000..8ff7da1b4b9d9 --- /dev/null +++ b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=esnext).errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields.ts(5,5): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields.ts (1 errors) ==== + class B {}; + class A extends B { + #x; + constructor() { + this; + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + super(); + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=esnext).js b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=esnext).js index 018c1eaaecedb..cae8d9c65c8a6 100644 --- a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=esnext).js +++ b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=esnext).js @@ -1,11 +1,11 @@ //// [privateNameBadSuperUseDefineForClassFields.ts] class B {}; class A extends B { - #x; - constructor() { - void 0; // Error: 'super' call must come first - super(); - } + #x; + constructor() { + this; + super(); + } } @@ -16,7 +16,7 @@ class B { class A extends B { #x; constructor() { - void 0; // Error: 'super' call must come first + this; super(); } } diff --git a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=esnext).symbols b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=esnext).symbols index 5e5115d741790..1faec18f829cf 100644 --- a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=esnext).symbols +++ b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=esnext).symbols @@ -6,13 +6,15 @@ class A extends B { >A : Symbol(A, Decl(privateNameBadSuperUseDefineForClassFields.ts, 0, 11)) >B : Symbol(B, Decl(privateNameBadSuperUseDefineForClassFields.ts, 0, 0)) - #x; + #x; >#x : Symbol(A.#x, Decl(privateNameBadSuperUseDefineForClassFields.ts, 1, 19)) - constructor() { - void 0; // Error: 'super' call must come first - super(); + constructor() { + this; +>this : Symbol(A, Decl(privateNameBadSuperUseDefineForClassFields.ts, 0, 11)) + + super(); >super : Symbol(B, Decl(privateNameBadSuperUseDefineForClassFields.ts, 0, 0)) - } + } } diff --git a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=esnext).types b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=esnext).types index 55432691aece8..410e752c22c1d 100644 --- a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=esnext).types +++ b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=esnext).types @@ -6,17 +6,16 @@ class A extends B { >A : A >B : B - #x; + #x; >#x : any - constructor() { - void 0; // Error: 'super' call must come first ->void 0 : undefined ->0 : 0 + constructor() { + this; +>this : this - super(); + super(); >super() : void >super : typeof B - } + } } diff --git a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields.js b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields.js index 018c1eaaecedb..7caa9fd353c2e 100644 --- a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields.js +++ b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields.js @@ -1,12 +1,12 @@ //// [privateNameBadSuperUseDefineForClassFields.ts] -class B {}; -class A extends B { - #x; - constructor() { - void 0; // Error: 'super' call must come first - super(); - } -} +class B {}; +class A extends B { + #x; + constructor() { + void 0; + super(); + } +} //// [privateNameBadSuperUseDefineForClassFields.js] @@ -16,7 +16,7 @@ class B { class A extends B { #x; constructor() { - void 0; // Error: 'super' call must come first + void 0; super(); } } diff --git a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields.symbols b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields.symbols index 5e5115d741790..69e98a20656fb 100644 --- a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields.symbols +++ b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields.symbols @@ -10,7 +10,7 @@ class A extends B { >#x : Symbol(A.#x, Decl(privateNameBadSuperUseDefineForClassFields.ts, 1, 19)) constructor() { - void 0; // Error: 'super' call must come first + void 0; super(); >super : Symbol(B, Decl(privateNameBadSuperUseDefineForClassFields.ts, 0, 0)) } diff --git a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields.types b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields.types index 55432691aece8..f4cc919839b20 100644 --- a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields.types +++ b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields.types @@ -10,7 +10,7 @@ class A extends B { >#x : any constructor() { - void 0; // Error: 'super' call must come first + void 0; >void 0 : undefined >0 : 0 diff --git a/tests/baselines/reference/privateNameLateSuper.js b/tests/baselines/reference/privateNameLateSuper.js new file mode 100644 index 0000000000000..ff8e33745552e --- /dev/null +++ b/tests/baselines/reference/privateNameLateSuper.js @@ -0,0 +1,23 @@ +//// [privateNameLateSuper.ts] +class B {} +class A extends B { + #x; + constructor() { + void 0; + super(); + } +} + + +//// [privateNameLateSuper.js] +var _A_x; +class B { +} +class A extends B { + constructor() { + void 0; + super(); + _A_x.set(this, void 0); + } +} +_A_x = new WeakMap(); diff --git a/tests/baselines/reference/privateNameLateSuper.symbols b/tests/baselines/reference/privateNameLateSuper.symbols new file mode 100644 index 0000000000000..918f853647452 --- /dev/null +++ b/tests/baselines/reference/privateNameLateSuper.symbols @@ -0,0 +1,18 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameLateSuper.ts === +class B {} +>B : Symbol(B, Decl(privateNameLateSuper.ts, 0, 0)) + +class A extends B { +>A : Symbol(A, Decl(privateNameLateSuper.ts, 0, 10)) +>B : Symbol(B, Decl(privateNameLateSuper.ts, 0, 0)) + + #x; +>#x : Symbol(A.#x, Decl(privateNameLateSuper.ts, 1, 19)) + + constructor() { + void 0; + super(); +>super : Symbol(B, Decl(privateNameLateSuper.ts, 0, 0)) + } +} + diff --git a/tests/baselines/reference/privateNameLateSuper.types b/tests/baselines/reference/privateNameLateSuper.types new file mode 100644 index 0000000000000..1a1dcbb026145 --- /dev/null +++ b/tests/baselines/reference/privateNameLateSuper.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameLateSuper.ts === +class B {} +>B : B + +class A extends B { +>A : A +>B : B + + #x; +>#x : any + + constructor() { + void 0; +>void 0 : undefined +>0 : 0 + + super(); +>super() : void +>super : typeof B + } +} + diff --git a/tests/baselines/reference/privateNameLateSuperUseDefineForClassFields(target=es2022).js b/tests/baselines/reference/privateNameLateSuperUseDefineForClassFields(target=es2022).js new file mode 100644 index 0000000000000..1e298b5e52627 --- /dev/null +++ b/tests/baselines/reference/privateNameLateSuperUseDefineForClassFields(target=es2022).js @@ -0,0 +1,21 @@ +//// [privateNameLateSuperUseDefineForClassFields.ts] +class B {} +class A extends B { + #x; + constructor() { + void 0; + super(); + } +} + + +//// [privateNameLateSuperUseDefineForClassFields.js] +class B { +} +class A extends B { + #x; + constructor() { + void 0; + super(); + } +} diff --git a/tests/baselines/reference/privateNameLateSuperUseDefineForClassFields(target=es2022).symbols b/tests/baselines/reference/privateNameLateSuperUseDefineForClassFields(target=es2022).symbols new file mode 100644 index 0000000000000..d366575804423 --- /dev/null +++ b/tests/baselines/reference/privateNameLateSuperUseDefineForClassFields(target=es2022).symbols @@ -0,0 +1,18 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameLateSuperUseDefineForClassFields.ts === +class B {} +>B : Symbol(B, Decl(privateNameLateSuperUseDefineForClassFields.ts, 0, 0)) + +class A extends B { +>A : Symbol(A, Decl(privateNameLateSuperUseDefineForClassFields.ts, 0, 10)) +>B : Symbol(B, Decl(privateNameLateSuperUseDefineForClassFields.ts, 0, 0)) + + #x; +>#x : Symbol(A.#x, Decl(privateNameLateSuperUseDefineForClassFields.ts, 1, 19)) + + constructor() { + void 0; + super(); +>super : Symbol(B, Decl(privateNameLateSuperUseDefineForClassFields.ts, 0, 0)) + } +} + diff --git a/tests/baselines/reference/privateNameLateSuperUseDefineForClassFields(target=es2022).types b/tests/baselines/reference/privateNameLateSuperUseDefineForClassFields(target=es2022).types new file mode 100644 index 0000000000000..3616c3327854b --- /dev/null +++ b/tests/baselines/reference/privateNameLateSuperUseDefineForClassFields(target=es2022).types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameLateSuperUseDefineForClassFields.ts === +class B {} +>B : B + +class A extends B { +>A : A +>B : B + + #x; +>#x : any + + constructor() { + void 0; +>void 0 : undefined +>0 : 0 + + super(); +>super() : void +>super : typeof B + } +} + diff --git a/tests/baselines/reference/privateNameLateSuperUseDefineForClassFields(target=esnext).js b/tests/baselines/reference/privateNameLateSuperUseDefineForClassFields(target=esnext).js new file mode 100644 index 0000000000000..1e298b5e52627 --- /dev/null +++ b/tests/baselines/reference/privateNameLateSuperUseDefineForClassFields(target=esnext).js @@ -0,0 +1,21 @@ +//// [privateNameLateSuperUseDefineForClassFields.ts] +class B {} +class A extends B { + #x; + constructor() { + void 0; + super(); + } +} + + +//// [privateNameLateSuperUseDefineForClassFields.js] +class B { +} +class A extends B { + #x; + constructor() { + void 0; + super(); + } +} diff --git a/tests/baselines/reference/privateNameLateSuperUseDefineForClassFields(target=esnext).symbols b/tests/baselines/reference/privateNameLateSuperUseDefineForClassFields(target=esnext).symbols new file mode 100644 index 0000000000000..d366575804423 --- /dev/null +++ b/tests/baselines/reference/privateNameLateSuperUseDefineForClassFields(target=esnext).symbols @@ -0,0 +1,18 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameLateSuperUseDefineForClassFields.ts === +class B {} +>B : Symbol(B, Decl(privateNameLateSuperUseDefineForClassFields.ts, 0, 0)) + +class A extends B { +>A : Symbol(A, Decl(privateNameLateSuperUseDefineForClassFields.ts, 0, 10)) +>B : Symbol(B, Decl(privateNameLateSuperUseDefineForClassFields.ts, 0, 0)) + + #x; +>#x : Symbol(A.#x, Decl(privateNameLateSuperUseDefineForClassFields.ts, 1, 19)) + + constructor() { + void 0; + super(); +>super : Symbol(B, Decl(privateNameLateSuperUseDefineForClassFields.ts, 0, 0)) + } +} + diff --git a/tests/baselines/reference/privateNameLateSuperUseDefineForClassFields(target=esnext).types b/tests/baselines/reference/privateNameLateSuperUseDefineForClassFields(target=esnext).types new file mode 100644 index 0000000000000..3616c3327854b --- /dev/null +++ b/tests/baselines/reference/privateNameLateSuperUseDefineForClassFields(target=esnext).types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameLateSuperUseDefineForClassFields.ts === +class B {} +>B : B + +class A extends B { +>A : A +>B : B + + #x; +>#x : any + + constructor() { + void 0; +>void 0 : undefined +>0 : 0 + + super(); +>super() : void +>super : typeof B + } +} + diff --git a/tests/baselines/reference/staticPropSuper.js b/tests/baselines/reference/staticPropSuper.js index 170879d4b647e..bba69c878b530 100644 --- a/tests/baselines/reference/staticPropSuper.js +++ b/tests/baselines/reference/staticPropSuper.js @@ -59,10 +59,8 @@ var A = /** @class */ (function () { var B = /** @class */ (function (_super) { __extends(B, _super); function B() { - var _this = this; var x = 1; // should not error - _this = _super.call(this) || this; - return _this; + return _super.call(this) || this; } B.s = 9; return B; diff --git a/tests/baselines/reference/strictModeInConstructor.errors.txt b/tests/baselines/reference/strictModeInConstructor.errors.txt index bce4fb1d7b747..f9ed26bf33c42 100644 --- a/tests/baselines/reference/strictModeInConstructor.errors.txt +++ b/tests/baselines/reference/strictModeInConstructor.errors.txt @@ -1,7 +1,8 @@ -tests/cases/compiler/strictModeInConstructor.ts(27,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers. +tests/cases/compiler/strictModeInConstructor.ts(27,5): error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. +tests/cases/compiler/strictModeInConstructor.ts(29,17): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/strictModeInConstructor.ts (1 errors) ==== +==== tests/cases/compiler/strictModeInConstructor.ts (2 errors) ==== class A { } @@ -30,15 +31,19 @@ tests/cases/compiler/strictModeInConstructor.ts(27,5): error TS2376: A 'super' c constructor () { ~~~~~~~~~~~~~~~~ - var x = 1; // Error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + var x = 1; // No error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + var y = this.s; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. super(); ~~~~~~~~~~~~~~~~ "use strict"; ~~~~~~~~~~~~~~~~~~~~~ } ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers. +!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. } class Bs extends A { diff --git a/tests/baselines/reference/strictModeInConstructor.js b/tests/baselines/reference/strictModeInConstructor.js index 85d5d3eecbfd5..680c065b41b8b 100644 --- a/tests/baselines/reference/strictModeInConstructor.js +++ b/tests/baselines/reference/strictModeInConstructor.js @@ -26,7 +26,8 @@ class D extends A { public s: number = 9; constructor () { - var x = 1; // Error + var x = 1; // No error + var y = this.s; // Error super(); "use strict"; } @@ -105,7 +106,8 @@ var D = /** @class */ (function (_super) { __extends(D, _super); function D() { var _this = this; - var x = 1; // Error + var x = 1; // No error + var y = _this.s; // Error _this = _super.call(this) || this; _this.s = 9; "use strict"; @@ -135,10 +137,10 @@ var Cs = /** @class */ (function (_super) { var Ds = /** @class */ (function (_super) { __extends(Ds, _super); function Ds() { + "use strict"; var _this = this; var x = 1; // no Error _this = _super.call(this) || this; - "use strict"; return _this; } Ds.s = 9; diff --git a/tests/baselines/reference/strictModeInConstructor.symbols b/tests/baselines/reference/strictModeInConstructor.symbols index 622dbb500e043..7c628a351ba44 100644 --- a/tests/baselines/reference/strictModeInConstructor.symbols +++ b/tests/baselines/reference/strictModeInConstructor.symbols @@ -42,9 +42,15 @@ class D extends A { >s : Symbol(D.s, Decl(strictModeInConstructor.ts, 23, 19)) constructor () { - var x = 1; // Error + var x = 1; // No error >x : Symbol(x, Decl(strictModeInConstructor.ts, 27, 11)) + var y = this.s; // Error +>y : Symbol(y, Decl(strictModeInConstructor.ts, 28, 11)) +>this.s : Symbol(D.s, Decl(strictModeInConstructor.ts, 23, 19)) +>this : Symbol(D, Decl(strictModeInConstructor.ts, 21, 1)) +>s : Symbol(D.s, Decl(strictModeInConstructor.ts, 23, 19)) + super(); >super : Symbol(A, Decl(strictModeInConstructor.ts, 0, 0)) @@ -53,11 +59,11 @@ class D extends A { } class Bs extends A { ->Bs : Symbol(Bs, Decl(strictModeInConstructor.ts, 31, 1)) +>Bs : Symbol(Bs, Decl(strictModeInConstructor.ts, 32, 1)) >A : Symbol(A, Decl(strictModeInConstructor.ts, 0, 0)) public static s: number = 9; ->s : Symbol(Bs.s, Decl(strictModeInConstructor.ts, 33, 20)) +>s : Symbol(Bs.s, Decl(strictModeInConstructor.ts, 34, 20)) constructor () { "use strict"; // No error @@ -67,11 +73,11 @@ class Bs extends A { } class Cs extends A { ->Cs : Symbol(Cs, Decl(strictModeInConstructor.ts, 40, 1)) +>Cs : Symbol(Cs, Decl(strictModeInConstructor.ts, 41, 1)) >A : Symbol(A, Decl(strictModeInConstructor.ts, 0, 0)) public static s: number = 9; ->s : Symbol(Cs.s, Decl(strictModeInConstructor.ts, 42, 20)) +>s : Symbol(Cs.s, Decl(strictModeInConstructor.ts, 43, 20)) constructor () { super(); // No error @@ -82,15 +88,15 @@ class Cs extends A { } class Ds extends A { ->Ds : Symbol(Ds, Decl(strictModeInConstructor.ts, 49, 1)) +>Ds : Symbol(Ds, Decl(strictModeInConstructor.ts, 50, 1)) >A : Symbol(A, Decl(strictModeInConstructor.ts, 0, 0)) public static s: number = 9; ->s : Symbol(Ds.s, Decl(strictModeInConstructor.ts, 51, 20)) +>s : Symbol(Ds.s, Decl(strictModeInConstructor.ts, 52, 20)) constructor () { var x = 1; // no Error ->x : Symbol(x, Decl(strictModeInConstructor.ts, 55, 11)) +>x : Symbol(x, Decl(strictModeInConstructor.ts, 56, 11)) super(); >super : Symbol(A, Decl(strictModeInConstructor.ts, 0, 0)) diff --git a/tests/baselines/reference/strictModeInConstructor.types b/tests/baselines/reference/strictModeInConstructor.types index 4a07696fc881a..e06ef20c9a912 100644 --- a/tests/baselines/reference/strictModeInConstructor.types +++ b/tests/baselines/reference/strictModeInConstructor.types @@ -50,10 +50,16 @@ class D extends A { >9 : 9 constructor () { - var x = 1; // Error + var x = 1; // No error >x : number >1 : 1 + var y = this.s; // Error +>y : number +>this.s : number +>this : this +>s : number + super(); >super() : void >super : typeof A diff --git a/tests/baselines/reference/superCallBeforeThisAccessing4.js b/tests/baselines/reference/superCallBeforeThisAccessing4.js index 4315fddc99393..d8ec242d89c37 100644 --- a/tests/baselines/reference/superCallBeforeThisAccessing4.js +++ b/tests/baselines/reference/superCallBeforeThisAccessing4.js @@ -34,16 +34,19 @@ var __extends = (this && this.__extends) || (function () { var D = /** @class */ (function (_super) { __extends(D, _super); function D() { - this._t; + var _this = this; + _this._t; _this = _super.call(this) || this; + return _this; } return D; }(null)); var E = /** @class */ (function (_super) { __extends(E, _super); function E() { - _this = _super.call(this) || this; - this._t; + var _this = _super.call(this) || this; + _this._t; + return _this; } return E; }(null)); diff --git a/tests/baselines/reference/superCallFromClassThatHasNoBaseType1.js b/tests/baselines/reference/superCallFromClassThatHasNoBaseType1.js index 1e01e4ad5ea5b..ddccaf9546f6c 100644 --- a/tests/baselines/reference/superCallFromClassThatHasNoBaseType1.js +++ b/tests/baselines/reference/superCallFromClassThatHasNoBaseType1.js @@ -18,7 +18,7 @@ var A = /** @class */ (function () { }()); var B = /** @class */ (function () { function B() { - _this = _super.call(this, function (value) { return String(value); }) || this; + return _super.call(this, function (value) { return String(value); }) || this; } return B; }()); diff --git a/tests/baselines/reference/superCallFromClassThatHasNoBaseTypeButWithSameSymbolInterface.js b/tests/baselines/reference/superCallFromClassThatHasNoBaseTypeButWithSameSymbolInterface.js index e933ec9daa2c9..eab3b78bebdb1 100644 --- a/tests/baselines/reference/superCallFromClassThatHasNoBaseTypeButWithSameSymbolInterface.js +++ b/tests/baselines/reference/superCallFromClassThatHasNoBaseTypeButWithSameSymbolInterface.js @@ -11,7 +11,7 @@ class Foo { //// [superCallFromClassThatHasNoBaseTypeButWithSameSymbolInterface.js] var Foo = /** @class */ (function () { function Foo() { - _this = _super.call(this) || this; // error + return _super.call(this) || this; } return Foo; }()); diff --git a/tests/baselines/reference/superCallInConstructorWithNoBaseType.js b/tests/baselines/reference/superCallInConstructorWithNoBaseType.js index 1550a0c6ad9f5..9983d1f5f1aff 100644 --- a/tests/baselines/reference/superCallInConstructorWithNoBaseType.js +++ b/tests/baselines/reference/superCallInConstructorWithNoBaseType.js @@ -14,14 +14,15 @@ class D { //// [superCallInConstructorWithNoBaseType.js] var C = /** @class */ (function () { function C() { - _this = _super.call(this) || this; // error + return _super.call(this) || this; } return C; }()); var D = /** @class */ (function () { function D(x) { - _this = _super.call(this) || this; // error + var _this = _super.call(this) || this; this.x = x; + return _this; } return D; }()); diff --git a/tests/baselines/reference/superCalls.js b/tests/baselines/reference/superCalls.js index 489cc54d2ee87..0517598aa2026 100644 --- a/tests/baselines/reference/superCalls.js +++ b/tests/baselines/reference/superCalls.js @@ -74,10 +74,8 @@ var OtherBase = /** @class */ (function () { var OtherDerived = /** @class */ (function (_super) { __extends(OtherDerived, _super); function OtherDerived() { - var _this = this; var p = ''; - _this = _super.call(this) || this; - return _this; + return _super.call(this) || this; } return OtherDerived; }(OtherBase)); diff --git a/tests/baselines/reference/thisInConstructorParameter2.js b/tests/baselines/reference/thisInConstructorParameter2.js index 3af8ee1d8d884..57a19d8338613 100644 --- a/tests/baselines/reference/thisInConstructorParameter2.js +++ b/tests/baselines/reference/thisInConstructorParameter2.js @@ -14,13 +14,13 @@ class P { //// [thisInConstructorParameter2.js] var P = /** @class */ (function () { function P(z, zz, zzz) { - var _this = this; if (z === void 0) { z = this; } if (zz === void 0) { zz = this; } if (zzz === void 0) { zzz = function (p) { if (p === void 0) { p = _this; } return _this; }; } + var _this = this; this.z = z; this.x = this; zzz = function (p) { diff --git a/tests/baselines/reference/underscoreThisInDerivedClass01.js b/tests/baselines/reference/underscoreThisInDerivedClass01.js index 372eb902cb07a..17878be39731e 100644 --- a/tests/baselines/reference/underscoreThisInDerivedClass01.js +++ b/tests/baselines/reference/underscoreThisInDerivedClass01.js @@ -19,7 +19,9 @@ class C { class D extends C { constructor() { var _this = "uh-oh?"; + console.log("ruh-roh..."); super(); + console.log("d'oh!"); } } @@ -59,7 +61,9 @@ var D = /** @class */ (function (_super) { function D() { var _this_1 = this; var _this = "uh-oh?"; + console.log("ruh-roh..."); _this_1 = _super.call(this) || this; + console.log("d'oh!"); return _this_1; } return D; diff --git a/tests/baselines/reference/underscoreThisInDerivedClass01.symbols b/tests/baselines/reference/underscoreThisInDerivedClass01.symbols index c05cd4f6fc327..5ff800893d5aa 100644 --- a/tests/baselines/reference/underscoreThisInDerivedClass01.symbols +++ b/tests/baselines/reference/underscoreThisInDerivedClass01.symbols @@ -26,7 +26,17 @@ class D extends C { var _this = "uh-oh?"; >_this : Symbol(_this, Decl(underscoreThisInDerivedClass01.ts, 19, 11)) + console.log("ruh-roh..."); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) + super(); >super : Symbol(C, Decl(underscoreThisInDerivedClass01.ts, 0, 0)) + + console.log("d'oh!"); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) } } diff --git a/tests/baselines/reference/underscoreThisInDerivedClass01.types b/tests/baselines/reference/underscoreThisInDerivedClass01.types index 66d19c03da939..b7c701f90005f 100644 --- a/tests/baselines/reference/underscoreThisInDerivedClass01.types +++ b/tests/baselines/reference/underscoreThisInDerivedClass01.types @@ -28,8 +28,22 @@ class D extends C { >_this : string >"uh-oh?" : "uh-oh?" + console.log("ruh-roh..."); +>console.log("ruh-roh...") : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>"ruh-roh..." : "ruh-roh..." + super(); >super() : void >super : typeof C + + console.log("d'oh!"); +>console.log("d'oh!") : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>"d'oh!" : "d'oh!" } } diff --git a/tests/cases/compiler/strictModeInConstructor.ts b/tests/cases/compiler/strictModeInConstructor.ts index eb9c633ace1b5..8de66ca354524 100644 --- a/tests/cases/compiler/strictModeInConstructor.ts +++ b/tests/cases/compiler/strictModeInConstructor.ts @@ -25,7 +25,8 @@ class D extends A { public s: number = 9; constructor () { - var x = 1; // Error + var x = 1; // No error + var y = this.s; // Error super(); "use strict"; } diff --git a/tests/cases/compiler/underscoreThisInDerivedClass01.ts b/tests/cases/compiler/underscoreThisInDerivedClass01.ts index 0d3f5849cb157..bdb14061f8533 100644 --- a/tests/cases/compiler/underscoreThisInDerivedClass01.ts +++ b/tests/cases/compiler/underscoreThisInDerivedClass01.ts @@ -18,6 +18,8 @@ class C { class D extends C { constructor() { var _this = "uh-oh?"; + console.log("ruh-roh..."); super(); + console.log("d'oh!"); } } \ No newline at end of file diff --git a/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts b/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts index a054ed0f6831b..6c6bfc63b9eb2 100644 --- a/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts +++ b/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts @@ -7,20 +7,20 @@ class Base { class Derived extends Base { constructor(y: string) { var a = 1; - super(); // ok + super(); } } class Derived2 extends Base { constructor(public y: string) { var a = 1; - super(); // error + super(); } } class Derived3 extends Base { constructor(public y: string) { - super(); // ok + super(); var a = 1; } } @@ -29,14 +29,14 @@ class Derived4 extends Base { a = 1; constructor(y: string) { var b = 2; - super(); // error + super(); } } 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(); } } @@ -56,7 +56,7 @@ class Derived7 extends Base { constructor(y: string) { this.a = 3; this.b = 3; - super(); // error + 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; } @@ -79,7 +79,7 @@ class Derived9 extends Base2 { constructor(y: string) { this.a = 3; this.b = 3; - super(); // error + super(); } } @@ -87,7 +87,7 @@ class Derived10 extends Base2 { a = 1; b: number; constructor(y: string) { - super(); // ok + super(); this.a = 3; this.b = 3; } diff --git a/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts b/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts new file mode 100644 index 0000000000000..ab580777d8e5b --- /dev/null +++ b/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperProperties.ts @@ -0,0 +1,403 @@ +// @experimentaldecorators: true +// @target: ES5 + +declare const decorate: any; + +class Base { + constructor(a?) { } + + receivesAnything(param?) { } +} + +class Derived1 extends Base { + prop = true; + constructor() { + super.receivesAnything(); + super(); + } +} + +class Derived2 extends Base { + prop = true; + constructor() { + super.receivesAnything(this); + super(); + } +} + +class Derived3 extends Base { + prop = true; + constructor() { + super.receivesAnything(); + super(this); + } +} + +class Derived4 extends Base { + prop = true; + constructor() { + super.receivesAnything(this); + super(this); + } +} + +class Derived5 extends Base { + prop = true; + constructor() { + super(); + super.receivesAnything(); + } +} + +class Derived6 extends Base { + prop = true; + constructor() { + super(this); + super.receivesAnything(); + } +} + +class Derived7 extends Base { + prop = true; + constructor() { + super(); + super.receivesAnything(this); + } +} + +class Derived8 extends Base { + prop = true; + constructor() { + super(this); + super.receivesAnything(this); + } +} + +class DerivedWithArrowFunction extends Base { + prop = true; + constructor() { + (() => this)(); + super(); + } +} + +class DerivedWithArrowFunctionParameter extends Base { + prop = true; + constructor() { + const lambda = (param = this) => {}; + super(); + } +} + +class DerivedWithDecoratorOnClass extends Base { + prop = true; + constructor() { + @decorate(this) + class InnerClass { } + + super(); + } +} + +class DerivedWithDecoratorOnClassMethod extends Base { + prop = true; + constructor() { + class InnerClass { + @decorate(this) + innerMethod() { } + } + + super(); + } +} + +class DerivedWithDecoratorOnClassProperty extends Base { + prop = true; + constructor() { + class InnerClass { + @decorate(this) + innerProp = true; + } + + super(); + } +} + +class DerivedWithFunctionDeclaration extends Base { + prop = true; + constructor() { + function declaration() { + return this; + } + super(); + } +} + +class DerivedWithFunctionDeclarationAndThisParam extends Base { + prop = true; + constructor() { + function declaration(param = this) { + return param; + } + super(); + } +} + +class DerivedWithFunctionExpression extends Base { + prop = true; + constructor() { + (function () { + return this; + })(); + super(); + } +} + +class DerivedWithParenthesis extends Base { + prop = true; + constructor() { + (super()); + } +} + +class DerivedWithParenthesisAfterStatement extends Base { + prop = true; + constructor() { + this.prop; + (super()); + } +} + +class DerivedWithParenthesisBeforeStatement extends Base { + prop = true; + constructor() { + (super()); + this.prop; + } +} + +class DerivedWithClassDeclaration extends Base { + prop = true; + constructor() { + class InnerClass { + private method() { + return this; + } + private property = 7; + constructor() { + this.property; + this.method(); + } + } + super(); + } +} + +class DerivedWithClassDeclarationExtendingMember extends Base { + memberClass = class { }; + constructor() { + class InnerClass extends this.memberClass { + private method() { + return this; + } + private property = 7; + constructor() { + super(); + this.property; + this.method(); + } + } + super(); + } +} + +class DerivedWithClassExpression extends Base { + prop = true; + constructor() { + console.log(class { + private method() { + return this; + } + private property = 7; + constructor() { + this.property; + this.method(); + } + }); + super(); + } +} + +class DerivedWithClassExpressionExtendingMember extends Base { + memberClass = class { }; + constructor() { + console.log(class extends this.memberClass { }); + super(); + } +} + +class DerivedWithDerivedClassExpression extends Base { + prop = true; + constructor() { + console.log(class extends Base { + constructor() { + super(); + } + public foo() { + return this; + } + public bar = () => this; + }); + super(); + } +} + +class DerivedWithNewDerivedClassExpression extends Base { + prop = true; + constructor() { + console.log(new class extends Base { + constructor() { + super(); + } + }()); + super(); + } +} + +class DerivedWithObjectAccessors extends Base { + prop = true; + constructor() { + const obj = { + get prop() { + return true; + }, + set prop(param) { + this._prop = param; + } + }; + super(); + } +} + +class DerivedWithObjectAccessorsUsingThisInKeys extends Base { + propName = "prop"; + constructor() { + const obj = { + _prop: "prop", + get [this.propName]() { + return true; + }, + set [this.propName](param) { + this._prop = param; + } + }; + super(); + } +} + +class DerivedWithObjectAccessorsUsingThisInBodies extends Base { + propName = "prop"; + constructor() { + const obj = { + _prop: "prop", + get prop() { + return this._prop; + }, + set prop(param) { + this._prop = param; + } + }; + super(); + } +} + +class DerivedWithObjectComputedPropertyBody extends Base { + propName = "prop"; + constructor() { + const obj = { + prop: this.propName, + }; + super(); + } +} + +class DerivedWithObjectComputedPropertyName extends Base { + propName = "prop"; + constructor() { + const obj = { + [this.propName]: true, + }; + super(); + } +} + +class DerivedWithObjectMethod extends Base { + prop = true; + constructor() { + const obj = { + getProp() { + return this; + }, + }; + super(); + } +} + +let a, b; + +const DerivedWithLoops = [ + class extends Base { + prop = true; + constructor() { + for(super();;) {} + } + }, + class extends Base { + prop = true; + constructor() { + for(a; super();) {} + } + }, + class extends Base { + prop = true; + constructor() { + for(a; b; super()) {} + } + }, + class extends Base { + prop = true; + constructor() { + for(; ; super()) { break; } + } + }, + class extends Base { + prop = true; + constructor() { + for (const x of super()) {} + } + }, + class extends Base { + prop = true; + constructor() { + while (super()) {} + } + }, + class extends Base { + prop = true; + constructor() { + do {} while (super()); + } + }, + class extends Base { + prop = true; + constructor() { + if (super()) {} + } + }, + class extends Base { + prop = true; + constructor() { + switch (super()) {} + } + }, +] diff --git a/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperStatementPosition.ts b/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperStatementPosition.ts new file mode 100644 index 0000000000000..b58c6c1574080 --- /dev/null +++ b/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperStatementPosition.ts @@ -0,0 +1,97 @@ +// @target: ES5 + +class DerivedBasic extends Object { + prop = 1; + constructor() { + super(); + } +} + +class DerivedAfterParameterDefault extends Object { + x1: boolean; + x2: boolean; + constructor(x = false) { + this.x1 = x; + super(x); + this.x2 = x; + } +} + +class DerivedAfterRestParameter extends Object { + x1: boolean[]; + x2: boolean[]; + constructor(...x: boolean[]) { + this.x1 = x; + super(x); + this.x2 = x; + } +} + +class DerivedComments extends Object { + x: any; + constructor() { + // c1 + console.log(); // c2 + // c3 + super(); // c4 + // c5 + this.x = null; // c6 + // c7 + } +} + +class DerivedCommentsInvalidThis extends Object { + x: any; + constructor() { + // c0 + this; + // c1 + console.log(); // c2 + // c3 + super(); // c4 + // c5 + this.x = null; // c6 + // c7 + } +} + +class DerivedInConditional extends Object { + prop = 1; + constructor() { + Math.random() + ? super(1) + : super(0); + } +} + +class DerivedInIf extends Object { + prop = 1; + constructor() { + if (Math.random()) { + super(1); + } + else { + super(0); + } + } +} + +class DerivedInBlockWithProperties extends Object { + prop = 1; + constructor(private paramProp = 2) { + { + super(); + } + } +} + +class DerivedInConditionalWithProperties extends Object { + prop = 1; + constructor(private paramProp = 2) { + if (Math.random()) { + super(1); + } else { + super(0); + } + } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameBadSuper.ts b/tests/cases/conformance/classes/members/privateNames/privateNameBadSuper.ts index 5e31c50599e31..b3930010db77b 100644 --- a/tests/cases/conformance/classes/members/privateNames/privateNameBadSuper.ts +++ b/tests/cases/conformance/classes/members/privateNames/privateNameBadSuper.ts @@ -1,9 +1,9 @@ // @target: es2015 class B {}; class A extends B { - #x; - constructor() { - void 0; // Error: 'super' call must come first - super(); - } + #x; + constructor() { + this; + super(); + } } \ No newline at end of file diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields.ts b/tests/cases/conformance/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields.ts index c9e67990f3d0b..bb110342444b3 100644 --- a/tests/cases/conformance/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields.ts +++ b/tests/cases/conformance/classes/members/privateNames/privateNameBadSuperUseDefineForClassFields.ts @@ -2,9 +2,9 @@ // @useDefineForClassFields: true class B {}; class A extends B { - #x; - constructor() { - void 0; // Error: 'super' call must come first - super(); - } + #x; + constructor() { + this; + super(); + } } diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameLateSuper.ts b/tests/cases/conformance/classes/members/privateNames/privateNameLateSuper.ts new file mode 100644 index 0000000000000..5bc814b9ff87d --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameLateSuper.ts @@ -0,0 +1,9 @@ +// @target: es2015 +class B {} +class A extends B { + #x; + constructor() { + void 0; + super(); + } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameLateSuperUseDefineForClassFields.ts b/tests/cases/conformance/classes/members/privateNames/privateNameLateSuperUseDefineForClassFields.ts new file mode 100644 index 0000000000000..7cee8f089c632 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameLateSuperUseDefineForClassFields.ts @@ -0,0 +1,10 @@ +// @target: esnext, es2022 +// @useDefineForClassFields: true +class B {} +class A extends B { + #x; + constructor() { + void 0; + super(); + } +}