typescript 4.6.0-dev.20220113 → 4.6.0-dev.20220114

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/tsserver.js CHANGED
@@ -100,7 +100,7 @@ var ts;
100
100
  // The following is baselined as a literal template type without intervention
101
101
  /** The version of the TypeScript compiler release */
102
102
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
103
- ts.version = ts.versionMajorMinor + ".0-dev.20220113";
103
+ ts.version = ts.versionMajorMinor + ".0-dev.20220114";
104
104
  /* @internal */
105
105
  var Comparison;
106
106
  (function (Comparison) {
@@ -8288,7 +8288,7 @@ var ts;
8288
8288
  Parameter_0_cannot_reference_identifier_1_declared_after_it: diag(2373, ts.DiagnosticCategory.Error, "Parameter_0_cannot_reference_identifier_1_declared_after_it_2373", "Parameter '{0}' cannot reference identifier '{1}' declared after it."),
8289
8289
  Duplicate_index_signature_for_type_0: diag(2374, ts.DiagnosticCategory.Error, "Duplicate_index_signature_for_type_0_2374", "Duplicate index signature for type '{0}'."),
8290
8290
  Type_0_is_not_assignable_to_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties: diag(2375, ts.DiagnosticCategory.Error, "Type_0_is_not_assignable_to_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefi_2375", "Type '{0}' is not assignable to type '{1}' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties."),
8291
- A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_parameter_properties_or_private_identifiers: diag(2376, ts.DiagnosticCategory.Error, "A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_proper_2376", "A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers."),
8291
+ 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: diag(2376, ts.DiagnosticCategory.Error, "A_super_call_must_be_the_first_statement_in_the_constructor_to_refer_to_super_or_this_when_a_derived_2376", "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."),
8292
8292
  Constructors_for_derived_classes_must_contain_a_super_call: diag(2377, ts.DiagnosticCategory.Error, "Constructors_for_derived_classes_must_contain_a_super_call_2377", "Constructors for derived classes must contain a 'super' call."),
8293
8293
  A_get_accessor_must_return_a_value: diag(2378, ts.DiagnosticCategory.Error, "A_get_accessor_must_return_a_value_2378", "A 'get' accessor must return a value."),
8294
8294
  Argument_of_type_0_is_not_assignable_to_parameter_of_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_types_of_the_target_s_properties: diag(2379, ts.DiagnosticCategory.Error, "Argument_of_type_0_is_not_assignable_to_parameter_of_type_1_with_exactOptionalPropertyTypes_Colon_tr_2379", "Argument of type '{0}' is not assignable to parameter of type '{1}' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties."),
@@ -8311,6 +8311,7 @@ var ts;
8311
8311
  constructor_cannot_be_used_as_a_parameter_property_name: diag(2398, ts.DiagnosticCategory.Error, "constructor_cannot_be_used_as_a_parameter_property_name_2398", "'constructor' cannot be used as a parameter property name."),
8312
8312
  Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference: diag(2399, ts.DiagnosticCategory.Error, "Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference_2399", "Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference."),
8313
8313
  Expression_resolves_to_variable_declaration_this_that_compiler_uses_to_capture_this_reference: diag(2400, ts.DiagnosticCategory.Error, "Expression_resolves_to_variable_declaration_this_that_compiler_uses_to_capture_this_reference_2400", "Expression resolves to variable declaration '_this' that compiler uses to capture 'this' reference."),
8314
+ 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: diag(2401, ts.DiagnosticCategory.Error, "A_super_call_must_be_a_root_level_statement_within_a_constructor_of_a_derived_class_that_contains_in_2401", "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."),
8314
8315
  Expression_resolves_to_super_that_compiler_uses_to_capture_base_class_reference: diag(2402, ts.DiagnosticCategory.Error, "Expression_resolves_to_super_that_compiler_uses_to_capture_base_class_reference_2402", "Expression resolves to '_super' that compiler uses to capture base class reference."),
8315
8316
  Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2: diag(2403, ts.DiagnosticCategory.Error, "Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_t_2403", "Subsequent variable declarations must have the same type. Variable '{0}' must be of type '{1}', but here has type '{2}'."),
8316
8317
  The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation: diag(2404, ts.DiagnosticCategory.Error, "The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation_2404", "The left-hand side of a 'for...in' statement cannot use a type annotation."),
@@ -15471,6 +15472,34 @@ var ts;
15471
15472
  }
15472
15473
  }
15473
15474
  ts.getThisContainer = getThisContainer;
15475
+ /**
15476
+ * @returns Whether the node creates a new 'this' scope for its children.
15477
+ */
15478
+ function isThisContainerOrFunctionBlock(node) {
15479
+ switch (node.kind) {
15480
+ // Arrow functions use the same scope, but may do so in a "delayed" manner
15481
+ // For example, `const getThis = () => this` may be before a super() call in a derived constructor
15482
+ case 213 /* ArrowFunction */:
15483
+ case 255 /* FunctionDeclaration */:
15484
+ case 212 /* FunctionExpression */:
15485
+ case 166 /* PropertyDeclaration */:
15486
+ return true;
15487
+ case 234 /* Block */:
15488
+ switch (node.parent.kind) {
15489
+ case 170 /* Constructor */:
15490
+ case 168 /* MethodDeclaration */:
15491
+ case 171 /* GetAccessor */:
15492
+ case 172 /* SetAccessor */:
15493
+ // Object properties can have computed names; only method-like bodies start a new scope
15494
+ return true;
15495
+ default:
15496
+ return false;
15497
+ }
15498
+ default:
15499
+ return false;
15500
+ }
15501
+ }
15502
+ ts.isThisContainerOrFunctionBlock = isThisContainerOrFunctionBlock;
15474
15503
  function isInTopLevelContext(node) {
15475
15504
  // The name of a class or function declaration is a BindingIdentifier in its surrounding scope.
15476
15505
  if (ts.isIdentifier(node) && (ts.isClassDeclaration(node.parent) || ts.isFunctionDeclaration(node.parent)) && node.parent.name === node) {
@@ -26057,7 +26086,7 @@ var ts;
26057
26086
  * @param visitor Optional callback used to visit any custom prologue directives.
26058
26087
  */
26059
26088
  function copyPrologue(source, target, ensureUseStrict, visitor) {
26060
- var offset = copyStandardPrologue(source, target, ensureUseStrict);
26089
+ var offset = copyStandardPrologue(source, target, 0, ensureUseStrict);
26061
26090
  return copyCustomPrologue(source, target, offset, visitor);
26062
26091
  }
26063
26092
  function isUseStrictPrologue(node) {
@@ -26070,12 +26099,14 @@ var ts;
26070
26099
  * Copies only the standard (string-expression) prologue-directives into the target statement-array.
26071
26100
  * @param source origin statements array
26072
26101
  * @param target result statements array
26102
+ * @param statementOffset The offset at which to begin the copy.
26073
26103
  * @param ensureUseStrict boolean determining whether the function need to add prologue-directives
26104
+ * @returns Count of how many directive statements were copied.
26074
26105
  */
26075
- function copyStandardPrologue(source, target, ensureUseStrict) {
26106
+ function copyStandardPrologue(source, target, statementOffset, ensureUseStrict) {
26107
+ if (statementOffset === void 0) { statementOffset = 0; }
26076
26108
  ts.Debug.assert(target.length === 0, "Prologue directives should be at the first statement in the target statements array");
26077
26109
  var foundUseStrict = false;
26078
- var statementOffset = 0;
26079
26110
  var numStatements = source.length;
26080
26111
  while (statementOffset < numStatements) {
26081
26112
  var statement = source[statementOffset];
@@ -27498,7 +27529,7 @@ var ts;
27498
27529
  importName: "__createBinding",
27499
27530
  scoped: false,
27500
27531
  priority: 1,
27501
- text: "\n var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\n }) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n }));"
27532
+ text: "\n var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n }) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n }));"
27502
27533
  };
27503
27534
  ts.setModuleDefaultHelper = {
27504
27535
  name: "typescript:commonjscreatevalue",
@@ -41133,7 +41164,7 @@ var ts;
41133
41164
  ? 1 /* Recursive */ : 0 /* None */
41134
41165
  };
41135
41166
  }
41136
- if (ts.isImplicitGlob(spec)) {
41167
+ if (ts.isImplicitGlob(spec.substring(spec.lastIndexOf(ts.directorySeparator) + 1))) {
41137
41168
  return {
41138
41169
  key: useCaseSensitiveFileNames ? spec : ts.toFileNameLowerCase(spec),
41139
41170
  flags: 1 /* Recursive */
@@ -78518,32 +78549,38 @@ var ts;
78518
78549
  if (classExtendsNull) {
78519
78550
  error(superCall, ts.Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null);
78520
78551
  }
78521
- // The first statement in the body of a constructor (excluding prologue directives) must be a super call
78522
- // if both of the following are true:
78552
+ // A super call must be root-level in a constructor if both of the following are true:
78523
78553
  // - The containing class is a derived class.
78524
78554
  // - The constructor declares parameter properties
78525
78555
  // or the containing class declares instance member variables with initializers.
78526
- var superCallShouldBeFirst = (ts.getEmitScriptTarget(compilerOptions) !== 99 /* ESNext */ || !useDefineForClassFields) &&
78556
+ var superCallShouldBeRootLevel = (ts.getEmitScriptTarget(compilerOptions) !== 99 /* ESNext */ || !useDefineForClassFields) &&
78527
78557
  (ts.some(node.parent.members, isInstancePropertyWithInitializerOrPrivateIdentifierProperty) ||
78528
78558
  ts.some(node.parameters, function (p) { return ts.hasSyntacticModifier(p, 16476 /* ParameterPropertyModifier */); }));
78529
- // Skip past any prologue directives to find the first statement
78530
- // to ensure that it was a super call.
78531
- if (superCallShouldBeFirst) {
78532
- var statements = node.body.statements;
78533
- var superCallStatement = void 0;
78534
- for (var _i = 0, statements_4 = statements; _i < statements_4.length; _i++) {
78535
- var statement = statements_4[_i];
78536
- if (statement.kind === 237 /* ExpressionStatement */ && ts.isSuperCall(statement.expression)) {
78537
- superCallStatement = statement;
78538
- break;
78559
+ if (superCallShouldBeRootLevel) {
78560
+ // Until we have better flow analysis, it is an error to place the super call within any kind of block or conditional
78561
+ // See GH #8277
78562
+ if (!superCallIsRootLevelInConstructor(superCall, node.body)) {
78563
+ error(superCall, ts.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);
78564
+ }
78565
+ // Skip past any prologue directives to check statements for referring to 'super' or 'this' before a super call
78566
+ else {
78567
+ var superCallStatement = void 0;
78568
+ for (var _i = 0, _a = node.body.statements; _i < _a.length; _i++) {
78569
+ var statement = _a[_i];
78570
+ if (ts.isExpressionStatement(statement) && ts.isSuperCall(ts.skipOuterExpressions(statement.expression))) {
78571
+ superCallStatement = statement;
78572
+ break;
78573
+ }
78574
+ if (!ts.isPrologueDirective(statement) && nodeImmediatelyReferencesSuperOrThis(statement)) {
78575
+ break;
78576
+ }
78539
78577
  }
78540
- if (!ts.isPrologueDirective(statement)) {
78541
- break;
78578
+ // Until we have better flow analysis, it is an error to place the super call within any kind of block or conditional
78579
+ // See GH #8277
78580
+ if (superCallStatement === undefined) {
78581
+ error(node, ts.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);
78542
78582
  }
78543
78583
  }
78544
- if (!superCallStatement) {
78545
- error(node, ts.Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_parameter_properties_or_private_identifiers);
78546
- }
78547
78584
  }
78548
78585
  }
78549
78586
  else if (!classExtendsNull) {
@@ -78551,6 +78588,19 @@ var ts;
78551
78588
  }
78552
78589
  }
78553
78590
  }
78591
+ function superCallIsRootLevelInConstructor(superCall, body) {
78592
+ var superCallParent = ts.walkUpParenthesizedExpressions(superCall.parent);
78593
+ return ts.isExpressionStatement(superCallParent) && superCallParent.parent === body;
78594
+ }
78595
+ function nodeImmediatelyReferencesSuperOrThis(node) {
78596
+ if (node.kind === 106 /* SuperKeyword */ || node.kind === 108 /* ThisKeyword */) {
78597
+ return true;
78598
+ }
78599
+ if (ts.isThisContainerOrFunctionBlock(node)) {
78600
+ return false;
78601
+ }
78602
+ return !!ts.forEachChild(node, nodeImmediatelyReferencesSuperOrThis);
78603
+ }
78554
78604
  function checkAccessorDeclaration(node) {
78555
78605
  if (produceDiagnostics) {
78556
78606
  // Grammar checking accessors
@@ -88673,34 +88723,31 @@ var ts;
88673
88723
  }
88674
88724
  ts.getNonAssignmentOperatorForCompoundAssignment = getNonAssignmentOperatorForCompoundAssignment;
88675
88725
  /**
88676
- * Adds super call and preceding prologue directives into the list of statements.
88677
- *
88678
- * @param ctor The constructor node.
88679
- * @param result The list of statements.
88680
- * @param visitor The visitor to apply to each node added to the result array.
88681
- * @returns index of the statement that follows super call
88726
+ * @returns Contained super() call from descending into the statement ignoring parentheses, if that call exists.
88727
+ */
88728
+ function getSuperCallFromStatement(statement) {
88729
+ if (!ts.isExpressionStatement(statement)) {
88730
+ return undefined;
88731
+ }
88732
+ var expression = ts.skipParentheses(statement.expression);
88733
+ return ts.isSuperCall(expression)
88734
+ ? expression
88735
+ : undefined;
88736
+ }
88737
+ ts.getSuperCallFromStatement = getSuperCallFromStatement;
88738
+ /**
88739
+ * @returns The index (after prologue statements) of a super call, or -1 if not found.
88682
88740
  */
88683
- function addPrologueDirectivesAndInitialSuperCall(factory, ctor, result, visitor) {
88684
- if (ctor.body) {
88685
- var statements = ctor.body.statements;
88686
- // add prologue directives to the list (if any)
88687
- var index = factory.copyPrologue(statements, result, /*ensureUseStrict*/ false, visitor);
88688
- if (index === statements.length) {
88689
- // list contains nothing but prologue directives (or empty) - exit
88690
- return index;
88691
- }
88692
- var superIndex = ts.findIndex(statements, function (s) { return ts.isExpressionStatement(s) && ts.isSuperCall(s.expression); }, index);
88693
- if (superIndex > -1) {
88694
- for (var i = index; i <= superIndex; i++) {
88695
- result.push(ts.visitNode(statements[i], visitor, ts.isStatement));
88696
- }
88697
- return superIndex + 1;
88741
+ function findSuperStatementIndex(statements, indexAfterLastPrologueStatement) {
88742
+ for (var i = indexAfterLastPrologueStatement; i < statements.length; i += 1) {
88743
+ var statement = statements[i];
88744
+ if (getSuperCallFromStatement(statement)) {
88745
+ return i;
88698
88746
  }
88699
- return index;
88700
88747
  }
88701
- return 0;
88748
+ return -1;
88702
88749
  }
88703
- ts.addPrologueDirectivesAndInitialSuperCall = addPrologueDirectivesAndInitialSuperCall;
88750
+ ts.findSuperStatementIndex = findSuperStatementIndex;
88704
88751
  function getProperties(node, requireInitializer, isStatic) {
88705
88752
  return ts.filter(node.members, function (m) { return isInitializedOrStaticProperty(m, requireInitializer, isStatic); });
88706
88753
  }
@@ -90938,10 +90985,14 @@ var ts;
90938
90985
  return ts.visitFunctionBody(body, visitor, context);
90939
90986
  }
90940
90987
  var statements = [];
90941
- var indexOfFirstStatement = 0;
90942
90988
  resumeLexicalEnvironment();
90943
- indexOfFirstStatement = ts.addPrologueDirectivesAndInitialSuperCall(factory, constructor, statements, visitor);
90944
- // Add parameters with property assignments. Transforms this:
90989
+ var indexAfterLastPrologueStatement = factory.copyPrologue(body.statements, statements, /*ensureUseStrict*/ false, visitor);
90990
+ var superStatementIndex = ts.findSuperStatementIndex(body.statements, indexAfterLastPrologueStatement);
90991
+ // If there was a super call, visit existing statements up to and including it
90992
+ if (superStatementIndex >= 0) {
90993
+ ts.addRange(statements, ts.visitNodes(body.statements, visitor, ts.isStatement, indexAfterLastPrologueStatement, superStatementIndex + 1 - indexAfterLastPrologueStatement));
90994
+ }
90995
+ // Transform parameters into property assignments. Transforms this:
90945
90996
  //
90946
90997
  // constructor (public x, public y) {
90947
90998
  // }
@@ -90953,9 +91004,17 @@ var ts;
90953
91004
  // this.y = y;
90954
91005
  // }
90955
91006
  //
90956
- ts.addRange(statements, ts.map(parametersWithPropertyAssignments, transformParameterWithPropertyAssignment));
90957
- // Add the existing statements, skipping the initial super call.
90958
- ts.addRange(statements, ts.visitNodes(body.statements, visitor, ts.isStatement, indexOfFirstStatement));
91007
+ var parameterPropertyAssignments = ts.mapDefined(parametersWithPropertyAssignments, transformParameterWithPropertyAssignment);
91008
+ // If there is a super() call, the parameter properties go immediately after it
91009
+ if (superStatementIndex >= 0) {
91010
+ ts.addRange(statements, parameterPropertyAssignments);
91011
+ }
91012
+ // Since there was no super() call, parameter properties are the first statements in the constructor
91013
+ else {
91014
+ statements = ts.addRange(parameterPropertyAssignments, statements);
91015
+ }
91016
+ // Add remaining statements from the body, skipping the super() call if it was found
91017
+ ts.addRange(statements, ts.visitNodes(body.statements, visitor, ts.isStatement, superStatementIndex + 1));
90959
91018
  // End the lexical environment.
90960
91019
  statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment());
90961
91020
  var block = factory.createBlock(ts.setTextRange(factory.createNodeArray(statements), body.statements), /*multiLine*/ true);
@@ -92853,6 +92912,7 @@ var ts;
92853
92912
  /*modifiers*/ undefined, parameters !== null && parameters !== void 0 ? parameters : [], body), constructor || node), constructor));
92854
92913
  }
92855
92914
  function transformConstructorBody(node, constructor, isDerivedClass) {
92915
+ var _a;
92856
92916
  var properties = ts.getProperties(node, /*requireInitializer*/ false, /*isStatic*/ false);
92857
92917
  if (!useDefineForClassFields) {
92858
92918
  properties = ts.filter(properties, function (property) { return !!property.initializer || ts.isPrivateIdentifier(property.name); });
@@ -92864,9 +92924,21 @@ var ts;
92864
92924
  return ts.visitFunctionBody(/*node*/ undefined, visitor, context);
92865
92925
  }
92866
92926
  resumeLexicalEnvironment();
92867
- var indexOfFirstStatement = 0;
92927
+ var needsSyntheticConstructor = !constructor && isDerivedClass;
92928
+ var indexOfFirstStatementAfterSuper = 0;
92929
+ var prologueStatementCount = 0;
92930
+ var superStatementIndex = -1;
92868
92931
  var statements = [];
92869
- if (!constructor && isDerivedClass) {
92932
+ if ((_a = constructor === null || constructor === void 0 ? void 0 : constructor.body) === null || _a === void 0 ? void 0 : _a.statements) {
92933
+ prologueStatementCount = factory.copyPrologue(constructor.body.statements, statements, /*ensureUseStrict*/ false, visitor);
92934
+ superStatementIndex = ts.findSuperStatementIndex(constructor.body.statements, prologueStatementCount);
92935
+ // If there was a super call, visit existing statements up to and including it
92936
+ if (superStatementIndex >= 0) {
92937
+ indexOfFirstStatementAfterSuper = superStatementIndex + 1;
92938
+ statements = __spreadArray(__spreadArray(__spreadArray([], statements.slice(0, prologueStatementCount), true), ts.visitNodes(constructor.body.statements, visitor, ts.isStatement, prologueStatementCount, indexOfFirstStatementAfterSuper - prologueStatementCount), true), statements.slice(prologueStatementCount), true);
92939
+ }
92940
+ }
92941
+ if (needsSyntheticConstructor) {
92870
92942
  // Add a synthetic `super` call:
92871
92943
  //
92872
92944
  // super(...arguments);
@@ -92874,9 +92946,6 @@ var ts;
92874
92946
  statements.push(factory.createExpressionStatement(factory.createCallExpression(factory.createSuper(),
92875
92947
  /*typeArguments*/ undefined, [factory.createSpreadElement(factory.createIdentifier("arguments"))])));
92876
92948
  }
92877
- if (constructor) {
92878
- indexOfFirstStatement = ts.addPrologueDirectivesAndInitialSuperCall(factory, constructor, statements, visitor);
92879
- }
92880
92949
  // Add the property initializers. Transforms this:
92881
92950
  //
92882
92951
  // public x = 1;
@@ -92887,31 +92956,59 @@ var ts;
92887
92956
  // this.x = 1;
92888
92957
  // }
92889
92958
  //
92959
+ // If we do useDefineForClassFields, they'll be converted elsewhere.
92960
+ // We instead *remove* them from the transformed output at this stage.
92961
+ var parameterPropertyDeclarationCount = 0;
92890
92962
  if (constructor === null || constructor === void 0 ? void 0 : constructor.body) {
92891
- var afterParameterProperties = ts.findIndex(constructor.body.statements, function (s) { return !ts.isParameterPropertyDeclaration(ts.getOriginalNode(s), constructor); }, indexOfFirstStatement);
92892
- if (afterParameterProperties === -1) {
92893
- afterParameterProperties = constructor.body.statements.length;
92963
+ if (useDefineForClassFields) {
92964
+ statements = statements.filter(function (statement) { return !ts.isParameterPropertyDeclaration(ts.getOriginalNode(statement), constructor); });
92894
92965
  }
92895
- if (afterParameterProperties > indexOfFirstStatement) {
92896
- if (!useDefineForClassFields) {
92897
- ts.addRange(statements, ts.visitNodes(constructor.body.statements, visitor, ts.isStatement, indexOfFirstStatement, afterParameterProperties - indexOfFirstStatement));
92966
+ else {
92967
+ for (var _i = 0, _b = constructor.body.statements; _i < _b.length; _i++) {
92968
+ var statement = _b[_i];
92969
+ if (ts.isParameterPropertyDeclaration(ts.getOriginalNode(statement), constructor)) {
92970
+ parameterPropertyDeclarationCount++;
92971
+ }
92972
+ }
92973
+ if (parameterPropertyDeclarationCount > 0) {
92974
+ var parameterProperties = ts.visitNodes(constructor.body.statements, visitor, ts.isStatement, indexOfFirstStatementAfterSuper, parameterPropertyDeclarationCount);
92975
+ // If there was a super() call found, add parameter properties immediately after it
92976
+ if (superStatementIndex >= 0) {
92977
+ ts.addRange(statements, parameterProperties);
92978
+ }
92979
+ // If a synthetic super() call was added, add them just after it
92980
+ else if (needsSyntheticConstructor) {
92981
+ statements = __spreadArray(__spreadArray([
92982
+ statements[0]
92983
+ ], parameterProperties, true), statements.slice(1), true);
92984
+ }
92985
+ // Since there wasn't a super() call, add them to the top of the constructor
92986
+ else {
92987
+ statements = __spreadArray(__spreadArray([], parameterProperties, true), statements, true);
92988
+ }
92989
+ indexOfFirstStatementAfterSuper += parameterPropertyDeclarationCount;
92898
92990
  }
92899
- indexOfFirstStatement = afterParameterProperties;
92900
92991
  }
92901
92992
  }
92902
92993
  var receiver = factory.createThis();
92903
92994
  // private methods can be called in property initializers, they should execute first.
92904
92995
  addMethodStatements(statements, privateMethodsAndAccessors, receiver);
92905
92996
  addPropertyOrClassStaticBlockStatements(statements, properties, receiver);
92906
- // Add existing statements, skipping the initial super call.
92997
+ // Add existing statements after the initial prologues and super call
92907
92998
  if (constructor) {
92908
- ts.addRange(statements, ts.visitNodes(constructor.body.statements, visitor, ts.isStatement, indexOfFirstStatement));
92999
+ ts.addRange(statements, ts.visitNodes(constructor.body.statements, visitBodyStatement, ts.isStatement, indexOfFirstStatementAfterSuper + prologueStatementCount));
92909
93000
  }
92910
93001
  statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment());
92911
93002
  return ts.setTextRange(factory.createBlock(ts.setTextRange(factory.createNodeArray(statements),
92912
93003
  /*location*/ constructor ? constructor.body.statements : node.members),
92913
93004
  /*multiLine*/ true),
92914
93005
  /*location*/ constructor ? constructor.body : undefined);
93006
+ function visitBodyStatement(statement) {
93007
+ if (useDefineForClassFields && ts.isParameterPropertyDeclaration(ts.getOriginalNode(statement), constructor)) {
93008
+ return undefined;
93009
+ }
93010
+ return visitor(statement);
93011
+ }
92915
93012
  }
92916
93013
  /**
92917
93014
  * Generates assignment statements for property initializers.
@@ -96703,37 +96800,39 @@ var ts;
96703
96800
  var prologue = [];
96704
96801
  var statements = [];
96705
96802
  resumeLexicalEnvironment();
96803
+ // In derived classes, there may be code before the necessary super() call
96804
+ // We'll remove pre-super statements to be tacked on after the rest of the body
96805
+ var existingPrologue = ts.takeWhile(constructor.body.statements, ts.isPrologueDirective);
96806
+ var _a = findSuperCallAndStatementIndex(constructor.body.statements, existingPrologue), superCall = _a.superCall, superStatementIndex = _a.superStatementIndex;
96807
+ var postSuperStatementsStart = superStatementIndex === -1 ? existingPrologue.length : superStatementIndex + 1;
96706
96808
  // If a super call has already been synthesized,
96707
96809
  // we're going to assume that we should just transform everything after that.
96708
96810
  // The assumption is that no prior step in the pipeline has added any prologue directives.
96709
- var statementOffset = 0;
96811
+ var statementOffset = postSuperStatementsStart;
96710
96812
  if (!hasSynthesizedSuper)
96711
- statementOffset = factory.copyStandardPrologue(constructor.body.statements, prologue, /*ensureUseStrict*/ false);
96712
- addDefaultValueAssignmentsIfNeeded(statements, constructor);
96713
- addRestParameterIfNeeded(statements, constructor, hasSynthesizedSuper);
96813
+ statementOffset = factory.copyStandardPrologue(constructor.body.statements, prologue, statementOffset, /*ensureUseStrict*/ false);
96714
96814
  if (!hasSynthesizedSuper)
96715
- statementOffset = factory.copyCustomPrologue(constructor.body.statements, statements, statementOffset, visitor);
96716
- // If the first statement is a call to `super()`, visit the statement directly
96815
+ statementOffset = factory.copyCustomPrologue(constructor.body.statements, statements, statementOffset, visitor, /*filter*/ undefined);
96816
+ // If there already exists a call to `super()`, visit the statement directly
96717
96817
  var superCallExpression;
96718
96818
  if (hasSynthesizedSuper) {
96719
96819
  superCallExpression = createDefaultSuperCallOrThis();
96720
96820
  }
96721
- else if (isDerivedClass && statementOffset < constructor.body.statements.length) {
96722
- var firstStatement = constructor.body.statements[statementOffset];
96723
- if (ts.isExpressionStatement(firstStatement) && ts.isSuperCall(firstStatement.expression)) {
96724
- superCallExpression = visitImmediateSuperCallInBody(firstStatement.expression);
96725
- }
96821
+ else if (superCall) {
96822
+ superCallExpression = visitSuperCallInBody(superCall);
96726
96823
  }
96727
96824
  if (superCallExpression) {
96728
96825
  hierarchyFacts |= 8192 /* ConstructorWithCapturedSuper */;
96729
- statementOffset++; // skip this statement, we will add it after visiting the rest of the body.
96730
96826
  }
96827
+ // Add parameter defaults at the beginning of the output, with prologue statements
96828
+ addDefaultValueAssignmentsIfNeeded(prologue, constructor);
96829
+ addRestParameterIfNeeded(prologue, constructor, hasSynthesizedSuper);
96731
96830
  // visit the remaining statements
96732
96831
  ts.addRange(statements, ts.visitNodes(constructor.body.statements, visitor, ts.isStatement, /*start*/ statementOffset));
96733
96832
  factory.mergeLexicalEnvironment(prologue, endLexicalEnvironment());
96734
96833
  insertCaptureNewTargetIfNeeded(prologue, constructor, /*copyOnWrite*/ false);
96735
- if (isDerivedClass) {
96736
- if (superCallExpression && statementOffset === constructor.body.statements.length && !(constructor.body.transformFlags & 8192 /* ContainsLexicalThis */)) {
96834
+ if (isDerivedClass || superCallExpression) {
96835
+ if (superCallExpression && postSuperStatementsStart === constructor.body.statements.length && !(constructor.body.transformFlags & 8192 /* ContainsLexicalThis */)) {
96737
96836
  // If the subclass constructor does *not* contain `this` and *ends* with a `super()` call, we will use the
96738
96837
  // following representation:
96739
96838
  //
@@ -96753,10 +96852,10 @@ var ts;
96753
96852
  // return C;
96754
96853
  // })(Base);
96755
96854
  // ```
96756
- var superCall = ts.cast(ts.cast(superCallExpression, ts.isBinaryExpression).left, ts.isCallExpression);
96855
+ var superCall_1 = ts.cast(ts.cast(superCallExpression, ts.isBinaryExpression).left, ts.isCallExpression);
96757
96856
  var returnStatement = factory.createReturnStatement(superCallExpression);
96758
- ts.setCommentRange(returnStatement, ts.getCommentRange(superCall));
96759
- ts.setEmitFlags(superCall, 1536 /* NoComments */);
96857
+ ts.setCommentRange(returnStatement, ts.getCommentRange(superCall_1));
96858
+ ts.setEmitFlags(superCall_1, 1536 /* NoComments */);
96760
96859
  statements.push(returnStatement);
96761
96860
  }
96762
96861
  else {
@@ -96781,9 +96880,19 @@ var ts;
96781
96880
  // return C;
96782
96881
  // })(Base);
96783
96882
  // ```
96784
- // Since the `super()` call was the first statement, we insert the `this` capturing call to
96785
- // `super()` at the top of the list of `statements` (after any pre-existing custom prologues).
96786
- insertCaptureThisForNode(statements, constructor, superCallExpression || createActualThis());
96883
+ // If the super() call is the first statement, we can directly create and assign its result to `_this`
96884
+ if (superStatementIndex <= existingPrologue.length) {
96885
+ insertCaptureThisForNode(statements, constructor, superCallExpression || createActualThis());
96886
+ }
96887
+ // Since the `super()` call isn't the first statement, it's split across 1-2 statements:
96888
+ // * A prologue `var _this = this;`, in case the constructor accesses this before super()
96889
+ // * If it exists, a reassignment to that `_this` of the super() call
96890
+ else {
96891
+ insertCaptureThisForNode(prologue, constructor, createActualThis());
96892
+ if (superCallExpression) {
96893
+ insertSuperThisCaptureThisForNode(statements, superCallExpression);
96894
+ }
96895
+ }
96787
96896
  if (!isSufficientlyCoveredByReturnStatements(constructor.body)) {
96788
96897
  statements.push(factory.createReturnStatement(factory.createUniqueName("_this", 16 /* Optimistic */ | 32 /* FileLevel */)));
96789
96898
  }
@@ -96806,11 +96915,27 @@ var ts;
96806
96915
  // ```
96807
96916
  insertCaptureThisForNodeIfNeeded(prologue, constructor);
96808
96917
  }
96809
- var block = factory.createBlock(ts.setTextRange(factory.createNodeArray(ts.concatenate(prologue, statements)),
96918
+ var body = factory.createBlock(ts.setTextRange(factory.createNodeArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], existingPrologue, true), prologue, true), (superStatementIndex <= existingPrologue.length ? ts.emptyArray : ts.visitNodes(constructor.body.statements, visitor, ts.isStatement, existingPrologue.length, superStatementIndex)), true), statements, true)),
96810
96919
  /*location*/ constructor.body.statements),
96811
96920
  /*multiLine*/ true);
96812
- ts.setTextRange(block, constructor.body);
96813
- return block;
96921
+ ts.setTextRange(body, constructor.body);
96922
+ return body;
96923
+ }
96924
+ function findSuperCallAndStatementIndex(originalBodyStatements, existingPrologue) {
96925
+ for (var i = existingPrologue.length; i < originalBodyStatements.length; i += 1) {
96926
+ var superCall = ts.getSuperCallFromStatement(originalBodyStatements[i]);
96927
+ if (superCall) {
96928
+ // With a super() call, split the statements into pre-super() and 'body' (post-super())
96929
+ return {
96930
+ superCall: superCall,
96931
+ superStatementIndex: i,
96932
+ };
96933
+ }
96934
+ }
96935
+ // Since there was no super() call found, consider all statements to be in the main 'body' (post-super())
96936
+ return {
96937
+ superStatementIndex: -1,
96938
+ };
96814
96939
  }
96815
96940
  /**
96816
96941
  * We want to try to avoid emitting a return statement in certain cases if a user already returned something.
@@ -97039,6 +97164,18 @@ var ts;
97039
97164
  }
97040
97165
  return false;
97041
97166
  }
97167
+ /**
97168
+ * Assigns the `this` in a constructor to the result of its `super()` call.
97169
+ *
97170
+ * @param statements Statements in the constructor body.
97171
+ * @param superExpression Existing `super()` call for the constructor.
97172
+ */
97173
+ function insertSuperThisCaptureThisForNode(statements, superExpression) {
97174
+ enableSubstitutionsForCapturedThis();
97175
+ var assignSuperExpression = factory.createExpressionStatement(factory.createBinaryExpression(factory.createThis(), 63 /* EqualsToken */, superExpression));
97176
+ ts.insertStatementAfterCustomPrologue(statements, assignSuperExpression);
97177
+ ts.setCommentRange(assignSuperExpression, ts.getOriginalNode(superExpression).parent);
97178
+ }
97042
97179
  function insertCaptureThisForNode(statements, node, initializer) {
97043
97180
  enableSubstitutionsForCapturedThis();
97044
97181
  var captureThisStatement = factory.createVariableStatement(
@@ -97348,7 +97485,7 @@ var ts;
97348
97485
  if (ts.isBlock(body)) {
97349
97486
  // ensureUseStrict is false because no new prologue-directive should be added.
97350
97487
  // addStandardPrologue will put already-existing directives at the beginning of the target statement-array
97351
- statementOffset = factory.copyStandardPrologue(body.statements, prologue, /*ensureUseStrict*/ false);
97488
+ statementOffset = factory.copyStandardPrologue(body.statements, prologue, 0, /*ensureUseStrict*/ false);
97352
97489
  statementOffset = factory.copyCustomPrologue(body.statements, statements, statementOffset, visitor, ts.isHoistedFunction);
97353
97490
  statementOffset = factory.copyCustomPrologue(body.statements, statements, statementOffset, visitor, ts.isHoistedVariableStatement);
97354
97491
  }
@@ -98719,7 +98856,7 @@ var ts;
98719
98856
  /*type*/ undefined, factory.updateBlock(func.body, statements))),
98720
98857
  /*typeArguments*/ undefined, call.arguments))));
98721
98858
  }
98722
- function visitImmediateSuperCallInBody(node) {
98859
+ function visitSuperCallInBody(node) {
98723
98860
  return visitCallExpressionWithPotentialCapturedThisAssignment(node, /*assignToCapturedThis*/ false);
98724
98861
  }
98725
98862
  function visitCallExpressionWithPotentialCapturedThisAssignment(node, assignToCapturedThis) {
@@ -146231,20 +146368,31 @@ var ts;
146231
146368
  codefix.registerCodeFix({
146232
146369
  errorCodes: errorCodes,
146233
146370
  getCodeActions: function getCodeActionsToAddConvertToUnknownForNonOverlappingTypes(context) {
146234
- var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return makeChange(t, context.sourceFile, context.span.start); });
146371
+ var assertion = getAssertion(context.sourceFile, context.span.start);
146372
+ if (assertion === undefined)
146373
+ return undefined;
146374
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return makeChange(t, context.sourceFile, assertion); });
146235
146375
  return [codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_unknown_conversion_for_non_overlapping_types, fixId, ts.Diagnostics.Add_unknown_to_all_conversions_of_non_overlapping_types)];
146236
146376
  },
146237
146377
  fixIds: [fixId],
146238
- getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) { return makeChange(changes, diag.file, diag.start); }); },
146378
+ getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
146379
+ var assertion = getAssertion(diag.file, diag.start);
146380
+ if (assertion) {
146381
+ makeChange(changes, diag.file, assertion);
146382
+ }
146383
+ }); },
146239
146384
  });
146240
- function makeChange(changeTracker, sourceFile, pos) {
146241
- var token = ts.getTokenAtPosition(sourceFile, pos);
146242
- var assertion = ts.Debug.checkDefined(ts.findAncestor(token, function (n) { return ts.isAsExpression(n) || ts.isTypeAssertionExpression(n); }), "Expected to find an assertion expression");
146385
+ function makeChange(changeTracker, sourceFile, assertion) {
146243
146386
  var replacement = ts.isAsExpression(assertion)
146244
146387
  ? ts.factory.createAsExpression(assertion.expression, ts.factory.createKeywordTypeNode(154 /* UnknownKeyword */))
146245
146388
  : ts.factory.createTypeAssertion(ts.factory.createKeywordTypeNode(154 /* UnknownKeyword */), assertion.expression);
146246
146389
  changeTracker.replaceNode(sourceFile, assertion.expression, replacement);
146247
146390
  }
146391
+ function getAssertion(sourceFile, pos) {
146392
+ if (ts.isInJSFile(sourceFile))
146393
+ return undefined;
146394
+ return ts.findAncestor(ts.getTokenAtPosition(sourceFile, pos), function (n) { return ts.isAsExpression(n) || ts.isTypeAssertionExpression(n); });
146395
+ }
146248
146396
  })(codefix = ts.codefix || (ts.codefix = {}));
146249
146397
  })(ts || (ts = {}));
146250
146398
  /* @internal */