typescript 4.6.0-dev.20220113 → 4.6.0-dev.20220117

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.
@@ -294,7 +294,7 @@ var ts;
294
294
  // The following is baselined as a literal template type without intervention
295
295
  /** The version of the TypeScript compiler release */
296
296
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
297
- ts.version = ts.versionMajorMinor + ".0-dev.20220113";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220117";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -8482,7 +8482,7 @@ var ts;
8482
8482
  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."),
8483
8483
  Duplicate_index_signature_for_type_0: diag(2374, ts.DiagnosticCategory.Error, "Duplicate_index_signature_for_type_0_2374", "Duplicate index signature for type '{0}'."),
8484
8484
  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."),
8485
- 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."),
8485
+ 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."),
8486
8486
  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."),
8487
8487
  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."),
8488
8488
  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."),
@@ -8505,6 +8505,7 @@ var ts;
8505
8505
  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."),
8506
8506
  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."),
8507
8507
  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."),
8508
+ 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."),
8508
8509
  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."),
8509
8510
  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}'."),
8510
8511
  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."),
@@ -15665,6 +15666,34 @@ var ts;
15665
15666
  }
15666
15667
  }
15667
15668
  ts.getThisContainer = getThisContainer;
15669
+ /**
15670
+ * @returns Whether the node creates a new 'this' scope for its children.
15671
+ */
15672
+ function isThisContainerOrFunctionBlock(node) {
15673
+ switch (node.kind) {
15674
+ // Arrow functions use the same scope, but may do so in a "delayed" manner
15675
+ // For example, `const getThis = () => this` may be before a super() call in a derived constructor
15676
+ case 213 /* ArrowFunction */:
15677
+ case 255 /* FunctionDeclaration */:
15678
+ case 212 /* FunctionExpression */:
15679
+ case 166 /* PropertyDeclaration */:
15680
+ return true;
15681
+ case 234 /* Block */:
15682
+ switch (node.parent.kind) {
15683
+ case 170 /* Constructor */:
15684
+ case 168 /* MethodDeclaration */:
15685
+ case 171 /* GetAccessor */:
15686
+ case 172 /* SetAccessor */:
15687
+ // Object properties can have computed names; only method-like bodies start a new scope
15688
+ return true;
15689
+ default:
15690
+ return false;
15691
+ }
15692
+ default:
15693
+ return false;
15694
+ }
15695
+ }
15696
+ ts.isThisContainerOrFunctionBlock = isThisContainerOrFunctionBlock;
15668
15697
  function isInTopLevelContext(node) {
15669
15698
  // The name of a class or function declaration is a BindingIdentifier in its surrounding scope.
15670
15699
  if (ts.isIdentifier(node) && (ts.isClassDeclaration(node.parent) || ts.isFunctionDeclaration(node.parent)) && node.parent.name === node) {
@@ -26251,7 +26280,7 @@ var ts;
26251
26280
  * @param visitor Optional callback used to visit any custom prologue directives.
26252
26281
  */
26253
26282
  function copyPrologue(source, target, ensureUseStrict, visitor) {
26254
- var offset = copyStandardPrologue(source, target, ensureUseStrict);
26283
+ var offset = copyStandardPrologue(source, target, 0, ensureUseStrict);
26255
26284
  return copyCustomPrologue(source, target, offset, visitor);
26256
26285
  }
26257
26286
  function isUseStrictPrologue(node) {
@@ -26264,12 +26293,14 @@ var ts;
26264
26293
  * Copies only the standard (string-expression) prologue-directives into the target statement-array.
26265
26294
  * @param source origin statements array
26266
26295
  * @param target result statements array
26296
+ * @param statementOffset The offset at which to begin the copy.
26267
26297
  * @param ensureUseStrict boolean determining whether the function need to add prologue-directives
26298
+ * @returns Count of how many directive statements were copied.
26268
26299
  */
26269
- function copyStandardPrologue(source, target, ensureUseStrict) {
26300
+ function copyStandardPrologue(source, target, statementOffset, ensureUseStrict) {
26301
+ if (statementOffset === void 0) { statementOffset = 0; }
26270
26302
  ts.Debug.assert(target.length === 0, "Prologue directives should be at the first statement in the target statements array");
26271
26303
  var foundUseStrict = false;
26272
- var statementOffset = 0;
26273
26304
  var numStatements = source.length;
26274
26305
  while (statementOffset < numStatements) {
26275
26306
  var statement = source[statementOffset];
@@ -27692,7 +27723,7 @@ var ts;
27692
27723
  importName: "__createBinding",
27693
27724
  scoped: false,
27694
27725
  priority: 1,
27695
- 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 }));"
27726
+ 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 }));"
27696
27727
  };
27697
27728
  ts.setModuleDefaultHelper = {
27698
27729
  name: "typescript:commonjscreatevalue",
@@ -41327,7 +41358,7 @@ var ts;
41327
41358
  ? 1 /* Recursive */ : 0 /* None */
41328
41359
  };
41329
41360
  }
41330
- if (ts.isImplicitGlob(spec)) {
41361
+ if (ts.isImplicitGlob(spec.substring(spec.lastIndexOf(ts.directorySeparator) + 1))) {
41331
41362
  return {
41332
41363
  key: useCaseSensitiveFileNames ? spec : ts.toFileNameLowerCase(spec),
41333
41364
  flags: 1 /* Recursive */
@@ -78712,32 +78743,38 @@ var ts;
78712
78743
  if (classExtendsNull) {
78713
78744
  error(superCall, ts.Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null);
78714
78745
  }
78715
- // The first statement in the body of a constructor (excluding prologue directives) must be a super call
78716
- // if both of the following are true:
78746
+ // A super call must be root-level in a constructor if both of the following are true:
78717
78747
  // - The containing class is a derived class.
78718
78748
  // - The constructor declares parameter properties
78719
78749
  // or the containing class declares instance member variables with initializers.
78720
- var superCallShouldBeFirst = (ts.getEmitScriptTarget(compilerOptions) !== 99 /* ESNext */ || !useDefineForClassFields) &&
78750
+ var superCallShouldBeRootLevel = (ts.getEmitScriptTarget(compilerOptions) !== 99 /* ESNext */ || !useDefineForClassFields) &&
78721
78751
  (ts.some(node.parent.members, isInstancePropertyWithInitializerOrPrivateIdentifierProperty) ||
78722
78752
  ts.some(node.parameters, function (p) { return ts.hasSyntacticModifier(p, 16476 /* ParameterPropertyModifier */); }));
78723
- // Skip past any prologue directives to find the first statement
78724
- // to ensure that it was a super call.
78725
- if (superCallShouldBeFirst) {
78726
- var statements = node.body.statements;
78727
- var superCallStatement = void 0;
78728
- for (var _i = 0, statements_4 = statements; _i < statements_4.length; _i++) {
78729
- var statement = statements_4[_i];
78730
- if (statement.kind === 237 /* ExpressionStatement */ && ts.isSuperCall(statement.expression)) {
78731
- superCallStatement = statement;
78732
- break;
78753
+ if (superCallShouldBeRootLevel) {
78754
+ // Until we have better flow analysis, it is an error to place the super call within any kind of block or conditional
78755
+ // See GH #8277
78756
+ if (!superCallIsRootLevelInConstructor(superCall, node.body)) {
78757
+ 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);
78758
+ }
78759
+ // Skip past any prologue directives to check statements for referring to 'super' or 'this' before a super call
78760
+ else {
78761
+ var superCallStatement = void 0;
78762
+ for (var _i = 0, _a = node.body.statements; _i < _a.length; _i++) {
78763
+ var statement = _a[_i];
78764
+ if (ts.isExpressionStatement(statement) && ts.isSuperCall(ts.skipOuterExpressions(statement.expression))) {
78765
+ superCallStatement = statement;
78766
+ break;
78767
+ }
78768
+ if (!ts.isPrologueDirective(statement) && nodeImmediatelyReferencesSuperOrThis(statement)) {
78769
+ break;
78770
+ }
78733
78771
  }
78734
- if (!ts.isPrologueDirective(statement)) {
78735
- break;
78772
+ // Until we have better flow analysis, it is an error to place the super call within any kind of block or conditional
78773
+ // See GH #8277
78774
+ if (superCallStatement === undefined) {
78775
+ 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);
78736
78776
  }
78737
78777
  }
78738
- if (!superCallStatement) {
78739
- 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);
78740
- }
78741
78778
  }
78742
78779
  }
78743
78780
  else if (!classExtendsNull) {
@@ -78745,6 +78782,19 @@ var ts;
78745
78782
  }
78746
78783
  }
78747
78784
  }
78785
+ function superCallIsRootLevelInConstructor(superCall, body) {
78786
+ var superCallParent = ts.walkUpParenthesizedExpressions(superCall.parent);
78787
+ return ts.isExpressionStatement(superCallParent) && superCallParent.parent === body;
78788
+ }
78789
+ function nodeImmediatelyReferencesSuperOrThis(node) {
78790
+ if (node.kind === 106 /* SuperKeyword */ || node.kind === 108 /* ThisKeyword */) {
78791
+ return true;
78792
+ }
78793
+ if (ts.isThisContainerOrFunctionBlock(node)) {
78794
+ return false;
78795
+ }
78796
+ return !!ts.forEachChild(node, nodeImmediatelyReferencesSuperOrThis);
78797
+ }
78748
78798
  function checkAccessorDeclaration(node) {
78749
78799
  if (produceDiagnostics) {
78750
78800
  // Grammar checking accessors
@@ -88867,34 +88917,31 @@ var ts;
88867
88917
  }
88868
88918
  ts.getNonAssignmentOperatorForCompoundAssignment = getNonAssignmentOperatorForCompoundAssignment;
88869
88919
  /**
88870
- * Adds super call and preceding prologue directives into the list of statements.
88871
- *
88872
- * @param ctor The constructor node.
88873
- * @param result The list of statements.
88874
- * @param visitor The visitor to apply to each node added to the result array.
88875
- * @returns index of the statement that follows super call
88920
+ * @returns Contained super() call from descending into the statement ignoring parentheses, if that call exists.
88921
+ */
88922
+ function getSuperCallFromStatement(statement) {
88923
+ if (!ts.isExpressionStatement(statement)) {
88924
+ return undefined;
88925
+ }
88926
+ var expression = ts.skipParentheses(statement.expression);
88927
+ return ts.isSuperCall(expression)
88928
+ ? expression
88929
+ : undefined;
88930
+ }
88931
+ ts.getSuperCallFromStatement = getSuperCallFromStatement;
88932
+ /**
88933
+ * @returns The index (after prologue statements) of a super call, or -1 if not found.
88876
88934
  */
88877
- function addPrologueDirectivesAndInitialSuperCall(factory, ctor, result, visitor) {
88878
- if (ctor.body) {
88879
- var statements = ctor.body.statements;
88880
- // add prologue directives to the list (if any)
88881
- var index = factory.copyPrologue(statements, result, /*ensureUseStrict*/ false, visitor);
88882
- if (index === statements.length) {
88883
- // list contains nothing but prologue directives (or empty) - exit
88884
- return index;
88885
- }
88886
- var superIndex = ts.findIndex(statements, function (s) { return ts.isExpressionStatement(s) && ts.isSuperCall(s.expression); }, index);
88887
- if (superIndex > -1) {
88888
- for (var i = index; i <= superIndex; i++) {
88889
- result.push(ts.visitNode(statements[i], visitor, ts.isStatement));
88890
- }
88891
- return superIndex + 1;
88935
+ function findSuperStatementIndex(statements, indexAfterLastPrologueStatement) {
88936
+ for (var i = indexAfterLastPrologueStatement; i < statements.length; i += 1) {
88937
+ var statement = statements[i];
88938
+ if (getSuperCallFromStatement(statement)) {
88939
+ return i;
88892
88940
  }
88893
- return index;
88894
88941
  }
88895
- return 0;
88942
+ return -1;
88896
88943
  }
88897
- ts.addPrologueDirectivesAndInitialSuperCall = addPrologueDirectivesAndInitialSuperCall;
88944
+ ts.findSuperStatementIndex = findSuperStatementIndex;
88898
88945
  function getProperties(node, requireInitializer, isStatic) {
88899
88946
  return ts.filter(node.members, function (m) { return isInitializedOrStaticProperty(m, requireInitializer, isStatic); });
88900
88947
  }
@@ -91132,10 +91179,14 @@ var ts;
91132
91179
  return ts.visitFunctionBody(body, visitor, context);
91133
91180
  }
91134
91181
  var statements = [];
91135
- var indexOfFirstStatement = 0;
91136
91182
  resumeLexicalEnvironment();
91137
- indexOfFirstStatement = ts.addPrologueDirectivesAndInitialSuperCall(factory, constructor, statements, visitor);
91138
- // Add parameters with property assignments. Transforms this:
91183
+ var indexAfterLastPrologueStatement = factory.copyPrologue(body.statements, statements, /*ensureUseStrict*/ false, visitor);
91184
+ var superStatementIndex = ts.findSuperStatementIndex(body.statements, indexAfterLastPrologueStatement);
91185
+ // If there was a super call, visit existing statements up to and including it
91186
+ if (superStatementIndex >= 0) {
91187
+ ts.addRange(statements, ts.visitNodes(body.statements, visitor, ts.isStatement, indexAfterLastPrologueStatement, superStatementIndex + 1 - indexAfterLastPrologueStatement));
91188
+ }
91189
+ // Transform parameters into property assignments. Transforms this:
91139
91190
  //
91140
91191
  // constructor (public x, public y) {
91141
91192
  // }
@@ -91147,9 +91198,17 @@ var ts;
91147
91198
  // this.y = y;
91148
91199
  // }
91149
91200
  //
91150
- ts.addRange(statements, ts.map(parametersWithPropertyAssignments, transformParameterWithPropertyAssignment));
91151
- // Add the existing statements, skipping the initial super call.
91152
- ts.addRange(statements, ts.visitNodes(body.statements, visitor, ts.isStatement, indexOfFirstStatement));
91201
+ var parameterPropertyAssignments = ts.mapDefined(parametersWithPropertyAssignments, transformParameterWithPropertyAssignment);
91202
+ // If there is a super() call, the parameter properties go immediately after it
91203
+ if (superStatementIndex >= 0) {
91204
+ ts.addRange(statements, parameterPropertyAssignments);
91205
+ }
91206
+ // Since there was no super() call, parameter properties are the first statements in the constructor
91207
+ else {
91208
+ statements = ts.addRange(parameterPropertyAssignments, statements);
91209
+ }
91210
+ // Add remaining statements from the body, skipping the super() call if it was found
91211
+ ts.addRange(statements, ts.visitNodes(body.statements, visitor, ts.isStatement, superStatementIndex + 1));
91153
91212
  // End the lexical environment.
91154
91213
  statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment());
91155
91214
  var block = factory.createBlock(ts.setTextRange(factory.createNodeArray(statements), body.statements), /*multiLine*/ true);
@@ -93047,6 +93106,7 @@ var ts;
93047
93106
  /*modifiers*/ undefined, parameters !== null && parameters !== void 0 ? parameters : [], body), constructor || node), constructor));
93048
93107
  }
93049
93108
  function transformConstructorBody(node, constructor, isDerivedClass) {
93109
+ var _a;
93050
93110
  var properties = ts.getProperties(node, /*requireInitializer*/ false, /*isStatic*/ false);
93051
93111
  if (!useDefineForClassFields) {
93052
93112
  properties = ts.filter(properties, function (property) { return !!property.initializer || ts.isPrivateIdentifier(property.name); });
@@ -93058,9 +93118,21 @@ var ts;
93058
93118
  return ts.visitFunctionBody(/*node*/ undefined, visitor, context);
93059
93119
  }
93060
93120
  resumeLexicalEnvironment();
93061
- var indexOfFirstStatement = 0;
93121
+ var needsSyntheticConstructor = !constructor && isDerivedClass;
93122
+ var indexOfFirstStatementAfterSuper = 0;
93123
+ var prologueStatementCount = 0;
93124
+ var superStatementIndex = -1;
93062
93125
  var statements = [];
93063
- if (!constructor && isDerivedClass) {
93126
+ if ((_a = constructor === null || constructor === void 0 ? void 0 : constructor.body) === null || _a === void 0 ? void 0 : _a.statements) {
93127
+ prologueStatementCount = factory.copyPrologue(constructor.body.statements, statements, /*ensureUseStrict*/ false, visitor);
93128
+ superStatementIndex = ts.findSuperStatementIndex(constructor.body.statements, prologueStatementCount);
93129
+ // If there was a super call, visit existing statements up to and including it
93130
+ if (superStatementIndex >= 0) {
93131
+ indexOfFirstStatementAfterSuper = superStatementIndex + 1;
93132
+ 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);
93133
+ }
93134
+ }
93135
+ if (needsSyntheticConstructor) {
93064
93136
  // Add a synthetic `super` call:
93065
93137
  //
93066
93138
  // super(...arguments);
@@ -93068,9 +93140,6 @@ var ts;
93068
93140
  statements.push(factory.createExpressionStatement(factory.createCallExpression(factory.createSuper(),
93069
93141
  /*typeArguments*/ undefined, [factory.createSpreadElement(factory.createIdentifier("arguments"))])));
93070
93142
  }
93071
- if (constructor) {
93072
- indexOfFirstStatement = ts.addPrologueDirectivesAndInitialSuperCall(factory, constructor, statements, visitor);
93073
- }
93074
93143
  // Add the property initializers. Transforms this:
93075
93144
  //
93076
93145
  // public x = 1;
@@ -93081,31 +93150,59 @@ var ts;
93081
93150
  // this.x = 1;
93082
93151
  // }
93083
93152
  //
93153
+ // If we do useDefineForClassFields, they'll be converted elsewhere.
93154
+ // We instead *remove* them from the transformed output at this stage.
93155
+ var parameterPropertyDeclarationCount = 0;
93084
93156
  if (constructor === null || constructor === void 0 ? void 0 : constructor.body) {
93085
- var afterParameterProperties = ts.findIndex(constructor.body.statements, function (s) { return !ts.isParameterPropertyDeclaration(ts.getOriginalNode(s), constructor); }, indexOfFirstStatement);
93086
- if (afterParameterProperties === -1) {
93087
- afterParameterProperties = constructor.body.statements.length;
93157
+ if (useDefineForClassFields) {
93158
+ statements = statements.filter(function (statement) { return !ts.isParameterPropertyDeclaration(ts.getOriginalNode(statement), constructor); });
93088
93159
  }
93089
- if (afterParameterProperties > indexOfFirstStatement) {
93090
- if (!useDefineForClassFields) {
93091
- ts.addRange(statements, ts.visitNodes(constructor.body.statements, visitor, ts.isStatement, indexOfFirstStatement, afterParameterProperties - indexOfFirstStatement));
93160
+ else {
93161
+ for (var _i = 0, _b = constructor.body.statements; _i < _b.length; _i++) {
93162
+ var statement = _b[_i];
93163
+ if (ts.isParameterPropertyDeclaration(ts.getOriginalNode(statement), constructor)) {
93164
+ parameterPropertyDeclarationCount++;
93165
+ }
93166
+ }
93167
+ if (parameterPropertyDeclarationCount > 0) {
93168
+ var parameterProperties = ts.visitNodes(constructor.body.statements, visitor, ts.isStatement, indexOfFirstStatementAfterSuper, parameterPropertyDeclarationCount);
93169
+ // If there was a super() call found, add parameter properties immediately after it
93170
+ if (superStatementIndex >= 0) {
93171
+ ts.addRange(statements, parameterProperties);
93172
+ }
93173
+ // If a synthetic super() call was added, add them just after it
93174
+ else if (needsSyntheticConstructor) {
93175
+ statements = __spreadArray(__spreadArray([
93176
+ statements[0]
93177
+ ], parameterProperties, true), statements.slice(1), true);
93178
+ }
93179
+ // Since there wasn't a super() call, add them to the top of the constructor
93180
+ else {
93181
+ statements = __spreadArray(__spreadArray([], parameterProperties, true), statements, true);
93182
+ }
93183
+ indexOfFirstStatementAfterSuper += parameterPropertyDeclarationCount;
93092
93184
  }
93093
- indexOfFirstStatement = afterParameterProperties;
93094
93185
  }
93095
93186
  }
93096
93187
  var receiver = factory.createThis();
93097
93188
  // private methods can be called in property initializers, they should execute first.
93098
93189
  addMethodStatements(statements, privateMethodsAndAccessors, receiver);
93099
93190
  addPropertyOrClassStaticBlockStatements(statements, properties, receiver);
93100
- // Add existing statements, skipping the initial super call.
93191
+ // Add existing statements after the initial prologues and super call
93101
93192
  if (constructor) {
93102
- ts.addRange(statements, ts.visitNodes(constructor.body.statements, visitor, ts.isStatement, indexOfFirstStatement));
93193
+ ts.addRange(statements, ts.visitNodes(constructor.body.statements, visitBodyStatement, ts.isStatement, indexOfFirstStatementAfterSuper + prologueStatementCount));
93103
93194
  }
93104
93195
  statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment());
93105
93196
  return ts.setTextRange(factory.createBlock(ts.setTextRange(factory.createNodeArray(statements),
93106
93197
  /*location*/ constructor ? constructor.body.statements : node.members),
93107
93198
  /*multiLine*/ true),
93108
93199
  /*location*/ constructor ? constructor.body : undefined);
93200
+ function visitBodyStatement(statement) {
93201
+ if (useDefineForClassFields && ts.isParameterPropertyDeclaration(ts.getOriginalNode(statement), constructor)) {
93202
+ return undefined;
93203
+ }
93204
+ return visitor(statement);
93205
+ }
93109
93206
  }
93110
93207
  /**
93111
93208
  * Generates assignment statements for property initializers.
@@ -96897,37 +96994,39 @@ var ts;
96897
96994
  var prologue = [];
96898
96995
  var statements = [];
96899
96996
  resumeLexicalEnvironment();
96997
+ // In derived classes, there may be code before the necessary super() call
96998
+ // We'll remove pre-super statements to be tacked on after the rest of the body
96999
+ var existingPrologue = ts.takeWhile(constructor.body.statements, ts.isPrologueDirective);
97000
+ var _a = findSuperCallAndStatementIndex(constructor.body.statements, existingPrologue), superCall = _a.superCall, superStatementIndex = _a.superStatementIndex;
97001
+ var postSuperStatementsStart = superStatementIndex === -1 ? existingPrologue.length : superStatementIndex + 1;
96900
97002
  // If a super call has already been synthesized,
96901
97003
  // we're going to assume that we should just transform everything after that.
96902
97004
  // The assumption is that no prior step in the pipeline has added any prologue directives.
96903
- var statementOffset = 0;
97005
+ var statementOffset = postSuperStatementsStart;
96904
97006
  if (!hasSynthesizedSuper)
96905
- statementOffset = factory.copyStandardPrologue(constructor.body.statements, prologue, /*ensureUseStrict*/ false);
96906
- addDefaultValueAssignmentsIfNeeded(statements, constructor);
96907
- addRestParameterIfNeeded(statements, constructor, hasSynthesizedSuper);
97007
+ statementOffset = factory.copyStandardPrologue(constructor.body.statements, prologue, statementOffset, /*ensureUseStrict*/ false);
96908
97008
  if (!hasSynthesizedSuper)
96909
- statementOffset = factory.copyCustomPrologue(constructor.body.statements, statements, statementOffset, visitor);
96910
- // If the first statement is a call to `super()`, visit the statement directly
97009
+ statementOffset = factory.copyCustomPrologue(constructor.body.statements, statements, statementOffset, visitor, /*filter*/ undefined);
97010
+ // If there already exists a call to `super()`, visit the statement directly
96911
97011
  var superCallExpression;
96912
97012
  if (hasSynthesizedSuper) {
96913
97013
  superCallExpression = createDefaultSuperCallOrThis();
96914
97014
  }
96915
- else if (isDerivedClass && statementOffset < constructor.body.statements.length) {
96916
- var firstStatement = constructor.body.statements[statementOffset];
96917
- if (ts.isExpressionStatement(firstStatement) && ts.isSuperCall(firstStatement.expression)) {
96918
- superCallExpression = visitImmediateSuperCallInBody(firstStatement.expression);
96919
- }
97015
+ else if (superCall) {
97016
+ superCallExpression = visitSuperCallInBody(superCall);
96920
97017
  }
96921
97018
  if (superCallExpression) {
96922
97019
  hierarchyFacts |= 8192 /* ConstructorWithCapturedSuper */;
96923
- statementOffset++; // skip this statement, we will add it after visiting the rest of the body.
96924
97020
  }
97021
+ // Add parameter defaults at the beginning of the output, with prologue statements
97022
+ addDefaultValueAssignmentsIfNeeded(prologue, constructor);
97023
+ addRestParameterIfNeeded(prologue, constructor, hasSynthesizedSuper);
96925
97024
  // visit the remaining statements
96926
97025
  ts.addRange(statements, ts.visitNodes(constructor.body.statements, visitor, ts.isStatement, /*start*/ statementOffset));
96927
97026
  factory.mergeLexicalEnvironment(prologue, endLexicalEnvironment());
96928
97027
  insertCaptureNewTargetIfNeeded(prologue, constructor, /*copyOnWrite*/ false);
96929
- if (isDerivedClass) {
96930
- if (superCallExpression && statementOffset === constructor.body.statements.length && !(constructor.body.transformFlags & 8192 /* ContainsLexicalThis */)) {
97028
+ if (isDerivedClass || superCallExpression) {
97029
+ if (superCallExpression && postSuperStatementsStart === constructor.body.statements.length && !(constructor.body.transformFlags & 8192 /* ContainsLexicalThis */)) {
96931
97030
  // If the subclass constructor does *not* contain `this` and *ends* with a `super()` call, we will use the
96932
97031
  // following representation:
96933
97032
  //
@@ -96947,10 +97046,10 @@ var ts;
96947
97046
  // return C;
96948
97047
  // })(Base);
96949
97048
  // ```
96950
- var superCall = ts.cast(ts.cast(superCallExpression, ts.isBinaryExpression).left, ts.isCallExpression);
97049
+ var superCall_1 = ts.cast(ts.cast(superCallExpression, ts.isBinaryExpression).left, ts.isCallExpression);
96951
97050
  var returnStatement = factory.createReturnStatement(superCallExpression);
96952
- ts.setCommentRange(returnStatement, ts.getCommentRange(superCall));
96953
- ts.setEmitFlags(superCall, 1536 /* NoComments */);
97051
+ ts.setCommentRange(returnStatement, ts.getCommentRange(superCall_1));
97052
+ ts.setEmitFlags(superCall_1, 1536 /* NoComments */);
96954
97053
  statements.push(returnStatement);
96955
97054
  }
96956
97055
  else {
@@ -96975,9 +97074,19 @@ var ts;
96975
97074
  // return C;
96976
97075
  // })(Base);
96977
97076
  // ```
96978
- // Since the `super()` call was the first statement, we insert the `this` capturing call to
96979
- // `super()` at the top of the list of `statements` (after any pre-existing custom prologues).
96980
- insertCaptureThisForNode(statements, constructor, superCallExpression || createActualThis());
97077
+ // If the super() call is the first statement, we can directly create and assign its result to `_this`
97078
+ if (superStatementIndex <= existingPrologue.length) {
97079
+ insertCaptureThisForNode(statements, constructor, superCallExpression || createActualThis());
97080
+ }
97081
+ // Since the `super()` call isn't the first statement, it's split across 1-2 statements:
97082
+ // * A prologue `var _this = this;`, in case the constructor accesses this before super()
97083
+ // * If it exists, a reassignment to that `_this` of the super() call
97084
+ else {
97085
+ insertCaptureThisForNode(prologue, constructor, createActualThis());
97086
+ if (superCallExpression) {
97087
+ insertSuperThisCaptureThisForNode(statements, superCallExpression);
97088
+ }
97089
+ }
96981
97090
  if (!isSufficientlyCoveredByReturnStatements(constructor.body)) {
96982
97091
  statements.push(factory.createReturnStatement(factory.createUniqueName("_this", 16 /* Optimistic */ | 32 /* FileLevel */)));
96983
97092
  }
@@ -97000,11 +97109,27 @@ var ts;
97000
97109
  // ```
97001
97110
  insertCaptureThisForNodeIfNeeded(prologue, constructor);
97002
97111
  }
97003
- var block = factory.createBlock(ts.setTextRange(factory.createNodeArray(ts.concatenate(prologue, statements)),
97112
+ 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)),
97004
97113
  /*location*/ constructor.body.statements),
97005
97114
  /*multiLine*/ true);
97006
- ts.setTextRange(block, constructor.body);
97007
- return block;
97115
+ ts.setTextRange(body, constructor.body);
97116
+ return body;
97117
+ }
97118
+ function findSuperCallAndStatementIndex(originalBodyStatements, existingPrologue) {
97119
+ for (var i = existingPrologue.length; i < originalBodyStatements.length; i += 1) {
97120
+ var superCall = ts.getSuperCallFromStatement(originalBodyStatements[i]);
97121
+ if (superCall) {
97122
+ // With a super() call, split the statements into pre-super() and 'body' (post-super())
97123
+ return {
97124
+ superCall: superCall,
97125
+ superStatementIndex: i,
97126
+ };
97127
+ }
97128
+ }
97129
+ // Since there was no super() call found, consider all statements to be in the main 'body' (post-super())
97130
+ return {
97131
+ superStatementIndex: -1,
97132
+ };
97008
97133
  }
97009
97134
  /**
97010
97135
  * We want to try to avoid emitting a return statement in certain cases if a user already returned something.
@@ -97233,6 +97358,18 @@ var ts;
97233
97358
  }
97234
97359
  return false;
97235
97360
  }
97361
+ /**
97362
+ * Assigns the `this` in a constructor to the result of its `super()` call.
97363
+ *
97364
+ * @param statements Statements in the constructor body.
97365
+ * @param superExpression Existing `super()` call for the constructor.
97366
+ */
97367
+ function insertSuperThisCaptureThisForNode(statements, superExpression) {
97368
+ enableSubstitutionsForCapturedThis();
97369
+ var assignSuperExpression = factory.createExpressionStatement(factory.createBinaryExpression(factory.createThis(), 63 /* EqualsToken */, superExpression));
97370
+ ts.insertStatementAfterCustomPrologue(statements, assignSuperExpression);
97371
+ ts.setCommentRange(assignSuperExpression, ts.getOriginalNode(superExpression).parent);
97372
+ }
97236
97373
  function insertCaptureThisForNode(statements, node, initializer) {
97237
97374
  enableSubstitutionsForCapturedThis();
97238
97375
  var captureThisStatement = factory.createVariableStatement(
@@ -97542,7 +97679,7 @@ var ts;
97542
97679
  if (ts.isBlock(body)) {
97543
97680
  // ensureUseStrict is false because no new prologue-directive should be added.
97544
97681
  // addStandardPrologue will put already-existing directives at the beginning of the target statement-array
97545
- statementOffset = factory.copyStandardPrologue(body.statements, prologue, /*ensureUseStrict*/ false);
97682
+ statementOffset = factory.copyStandardPrologue(body.statements, prologue, 0, /*ensureUseStrict*/ false);
97546
97683
  statementOffset = factory.copyCustomPrologue(body.statements, statements, statementOffset, visitor, ts.isHoistedFunction);
97547
97684
  statementOffset = factory.copyCustomPrologue(body.statements, statements, statementOffset, visitor, ts.isHoistedVariableStatement);
97548
97685
  }
@@ -98913,7 +99050,7 @@ var ts;
98913
99050
  /*type*/ undefined, factory.updateBlock(func.body, statements))),
98914
99051
  /*typeArguments*/ undefined, call.arguments))));
98915
99052
  }
98916
- function visitImmediateSuperCallInBody(node) {
99053
+ function visitSuperCallInBody(node) {
98917
99054
  return visitCallExpressionWithPotentialCapturedThisAssignment(node, /*assignToCapturedThis*/ false);
98918
99055
  }
98919
99056
  function visitCallExpressionWithPotentialCapturedThisAssignment(node, assignToCapturedThis) {
@@ -129587,7 +129724,7 @@ var ts;
129587
129724
  return (location === null || location === void 0 ? void 0 : location.kind) === 79 /* Identifier */ ? ts.createTextSpanFromNode(location) : undefined;
129588
129725
  }
129589
129726
  function completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext) {
129590
- var symbols = completionData.symbols, contextToken = completionData.contextToken, completionKind = completionData.completionKind, isInSnippetScope = completionData.isInSnippetScope, isNewIdentifierLocation = completionData.isNewIdentifierLocation, location = completionData.location, propertyAccessToConvert = completionData.propertyAccessToConvert, keywordFilters = completionData.keywordFilters, literals = completionData.literals, symbolToOriginInfoMap = completionData.symbolToOriginInfoMap, recommendedCompletion = completionData.recommendedCompletion, isJsxInitializer = completionData.isJsxInitializer, isTypeOnlyLocation = completionData.isTypeOnlyLocation, isJsxIdentifierExpected = completionData.isJsxIdentifierExpected, importCompletionNode = completionData.importCompletionNode, insideJsDocTagTypeExpression = completionData.insideJsDocTagTypeExpression, symbolToSortTextIdMap = completionData.symbolToSortTextIdMap, hasUnresolvedAutoImports = completionData.hasUnresolvedAutoImports;
129727
+ var symbols = completionData.symbols, contextToken = completionData.contextToken, completionKind = completionData.completionKind, isInSnippetScope = completionData.isInSnippetScope, isNewIdentifierLocation = completionData.isNewIdentifierLocation, location = completionData.location, propertyAccessToConvert = completionData.propertyAccessToConvert, keywordFilters = completionData.keywordFilters, literals = completionData.literals, symbolToOriginInfoMap = completionData.symbolToOriginInfoMap, recommendedCompletion = completionData.recommendedCompletion, isJsxInitializer = completionData.isJsxInitializer, isTypeOnlyLocation = completionData.isTypeOnlyLocation, isJsxIdentifierExpected = completionData.isJsxIdentifierExpected, isRightOfOpenTag = completionData.isRightOfOpenTag, importCompletionNode = completionData.importCompletionNode, insideJsDocTagTypeExpression = completionData.insideJsDocTagTypeExpression, symbolToSortTextIdMap = completionData.symbolToSortTextIdMap, hasUnresolvedAutoImports = completionData.hasUnresolvedAutoImports;
129591
129728
  // Verify if the file is JSX language variant
129592
129729
  if (ts.getLanguageVariant(sourceFile.scriptKind) === 1 /* JSX */) {
129593
129730
  var completionInfo = getJsxClosingTagCompletion(location, sourceFile);
@@ -129598,7 +129735,7 @@ var ts;
129598
129735
  var entries = ts.createSortedArray();
129599
129736
  if (isUncheckedFile(sourceFile, compilerOptions)) {
129600
129737
  var uniqueNames = getCompletionEntriesFromSymbols(symbols, entries,
129601
- /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
129738
+ /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag);
129602
129739
  getJSCompletionEntries(sourceFile, location.pos, uniqueNames, ts.getEmitScriptTarget(compilerOptions), entries); // TODO: GH#18217
129603
129740
  }
129604
129741
  else {
@@ -129606,7 +129743,7 @@ var ts;
129606
129743
  return undefined;
129607
129744
  }
129608
129745
  getCompletionEntriesFromSymbols(symbols, entries,
129609
- /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
129746
+ /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag);
129610
129747
  }
129611
129748
  if (keywordFilters !== 0 /* None */) {
129612
129749
  var entryNames = new ts.Set(entries.map(function (e) { return e.name; }));
@@ -129712,7 +129849,7 @@ var ts;
129712
129849
  function createCompletionEntryForLiteral(sourceFile, preferences, literal) {
129713
129850
  return { name: completionNameForLiteral(sourceFile, preferences, literal), kind: "string" /* string */, kindModifiers: "" /* none */, sortText: SortText.LocationPriority };
129714
129851
  }
129715
- function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences, completionKind, formatContext) {
129852
+ function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences, completionKind, formatContext, isJsxIdentifierExpected, isRightOfOpenTag) {
129716
129853
  var _a, _b;
129717
129854
  var insertText;
129718
129855
  var replacementSpan = ts.getReplacementSpanForContextToken(replacementToken);
@@ -129783,8 +129920,7 @@ var ts;
129783
129920
  source = CompletionSource.ClassMemberSnippet;
129784
129921
  }
129785
129922
  }
129786
- var kind = ts.SymbolDisplay.getSymbolKind(typeChecker, symbol, location);
129787
- if (kind === "JSX attribute" /* jsxAttribute */ && preferences.includeCompletionsWithSnippetText && preferences.jsxAttributeCompletionStyle && preferences.jsxAttributeCompletionStyle !== "none") {
129923
+ if (isJsxIdentifierExpected && !isRightOfOpenTag && preferences.includeCompletionsWithSnippetText && preferences.jsxAttributeCompletionStyle && preferences.jsxAttributeCompletionStyle !== "none") {
129788
129924
  var useBraces_1 = preferences.jsxAttributeCompletionStyle === "braces";
129789
129925
  var type = typeChecker.getTypeOfSymbolAtLocation(symbol, location);
129790
129926
  // If is boolean like or undefined, don't return a snippet we want just to return the completion.
@@ -129822,7 +129958,7 @@ var ts;
129822
129958
  // entries (like JavaScript identifier entries).
129823
129959
  return {
129824
129960
  name: name,
129825
- kind: kind,
129961
+ kind: ts.SymbolDisplay.getSymbolKind(typeChecker, symbol, location),
129826
129962
  kindModifiers: ts.SymbolDisplay.getSymbolModifiers(typeChecker, symbol),
129827
129963
  sortText: sortText,
129828
129964
  source: source,
@@ -130118,7 +130254,7 @@ var ts;
130118
130254
  return CompletionSource.ThisProperty;
130119
130255
  }
130120
130256
  }
130121
- function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap) {
130257
+ function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag) {
130122
130258
  var _a;
130123
130259
  var start = ts.timestamp();
130124
130260
  var variableDeclaration = getVariableDeclaration(location);
@@ -130139,7 +130275,7 @@ var ts;
130139
130275
  var name = info.name, needsConvertPropertyAccess = info.needsConvertPropertyAccess;
130140
130276
  var sortTextId = (_a = symbolToSortTextIdMap === null || symbolToSortTextIdMap === void 0 ? void 0 : symbolToSortTextIdMap[ts.getSymbolId(symbol)]) !== null && _a !== void 0 ? _a : 11 /* LocationPriority */;
130141
130277
  var sortText = (isDeprecated(symbol, typeChecker) ? 8 /* DeprecatedOffset */ + sortTextId : sortTextId).toString();
130142
- var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences, kind, formatContext);
130278
+ var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences, kind, formatContext, isJsxIdentifierExpected, isRightOfOpenTag);
130143
130279
  if (!entry) {
130144
130280
  continue;
130145
130281
  }
@@ -130733,6 +130869,7 @@ var ts;
130733
130869
  symbolToSortTextIdMap: symbolToSortTextIdMap,
130734
130870
  isTypeOnlyLocation: isTypeOnlyLocation,
130735
130871
  isJsxIdentifierExpected: isJsxIdentifierExpected,
130872
+ isRightOfOpenTag: isRightOfOpenTag,
130736
130873
  importCompletionNode: importCompletionNode,
130737
130874
  hasUnresolvedAutoImports: hasUnresolvedAutoImports,
130738
130875
  };
@@ -145712,7 +145849,11 @@ var ts;
145712
145849
  oldTags[i] = merged;
145713
145850
  return !!merged;
145714
145851
  }); });
145715
- var tag = ts.factory.createJSDocComment(ts.factory.createNodeArray(ts.intersperse(comments, ts.factory.createJSDocText("\n"))), ts.factory.createNodeArray(__spreadArray(__spreadArray([], oldTags, true), unmergedNewTags, true)));
145852
+ var tags = __spreadArray(__spreadArray([], oldTags, true), unmergedNewTags, true);
145853
+ var jsDoc = ts.singleOrUndefined(parent.jsDoc);
145854
+ var comment = jsDoc && ts.positionsAreOnSameLine(jsDoc.pos, jsDoc.end, sourceFile) && !ts.length(comments) ? undefined :
145855
+ ts.factory.createNodeArray(ts.intersperse(comments, ts.factory.createJSDocText("\n")));
145856
+ var tag = ts.factory.createJSDocComment(comment, ts.factory.createNodeArray(tags));
145716
145857
  var host = updateJSDocHost(parent);
145717
145858
  this.insertJsdocCommentBefore(sourceFile, host, tag);
145718
145859
  };
@@ -146142,6 +146283,8 @@ var ts;
146142
146283
  }
146143
146284
  case 339 /* JSDocReturnTag */:
146144
146285
  return ts.factory.createJSDocReturnTag(/*tagName*/ undefined, newTag.typeExpression, oldTag.comment);
146286
+ case 341 /* JSDocTypeTag */:
146287
+ return ts.factory.createJSDocTypeTag(/*tagName*/ undefined, newTag.typeExpression, oldTag.comment);
146145
146288
  }
146146
146289
  }
146147
146290
  // find first non-whitespace position in the leading trivia of the node
@@ -146842,20 +146985,31 @@ var ts;
146842
146985
  codefix.registerCodeFix({
146843
146986
  errorCodes: errorCodes,
146844
146987
  getCodeActions: function getCodeActionsToAddConvertToUnknownForNonOverlappingTypes(context) {
146845
- var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return makeChange(t, context.sourceFile, context.span.start); });
146988
+ var assertion = getAssertion(context.sourceFile, context.span.start);
146989
+ if (assertion === undefined)
146990
+ return undefined;
146991
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return makeChange(t, context.sourceFile, assertion); });
146846
146992
  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)];
146847
146993
  },
146848
146994
  fixIds: [fixId],
146849
- getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) { return makeChange(changes, diag.file, diag.start); }); },
146995
+ getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
146996
+ var assertion = getAssertion(diag.file, diag.start);
146997
+ if (assertion) {
146998
+ makeChange(changes, diag.file, assertion);
146999
+ }
147000
+ }); },
146850
147001
  });
146851
- function makeChange(changeTracker, sourceFile, pos) {
146852
- var token = ts.getTokenAtPosition(sourceFile, pos);
146853
- var assertion = ts.Debug.checkDefined(ts.findAncestor(token, function (n) { return ts.isAsExpression(n) || ts.isTypeAssertionExpression(n); }), "Expected to find an assertion expression");
147002
+ function makeChange(changeTracker, sourceFile, assertion) {
146854
147003
  var replacement = ts.isAsExpression(assertion)
146855
147004
  ? ts.factory.createAsExpression(assertion.expression, ts.factory.createKeywordTypeNode(154 /* UnknownKeyword */))
146856
147005
  : ts.factory.createTypeAssertion(ts.factory.createKeywordTypeNode(154 /* UnknownKeyword */), assertion.expression);
146857
147006
  changeTracker.replaceNode(sourceFile, assertion.expression, replacement);
146858
147007
  }
147008
+ function getAssertion(sourceFile, pos) {
147009
+ if (ts.isInJSFile(sourceFile))
147010
+ return undefined;
147011
+ return ts.findAncestor(ts.getTokenAtPosition(sourceFile, pos), function (n) { return ts.isAsExpression(n) || ts.isTypeAssertionExpression(n); });
147012
+ }
146859
147013
  })(codefix = ts.codefix || (ts.codefix = {}));
146860
147014
  })(ts || (ts = {}));
146861
147015
  /* @internal */
@@ -149973,10 +150127,15 @@ var ts;
149973
150127
  if (a.kind !== 0 /* UseNamespace */ && b.kind !== 0 /* UseNamespace */) {
149974
150128
  return ts.compareBooleans(allowsImportingSpecifier(b.moduleSpecifier), allowsImportingSpecifier(a.moduleSpecifier))
149975
150129
  || compareNodeCoreModuleSpecifiers(a.moduleSpecifier, b.moduleSpecifier, importingFile, program)
150130
+ || ts.compareBooleans(isOnlyDotsAndSlashes(a.moduleSpecifier), isOnlyDotsAndSlashes(b.moduleSpecifier))
149976
150131
  || ts.compareNumberOfDirectorySeparators(a.moduleSpecifier, b.moduleSpecifier);
149977
150132
  }
149978
150133
  return 0 /* EqualTo */;
149979
150134
  }
150135
+ var notDotOrSlashPattern = /[^.\/]/;
150136
+ function isOnlyDotsAndSlashes(path) {
150137
+ return !notDotOrSlashPattern.test(path);
150138
+ }
149980
150139
  function compareNodeCoreModuleSpecifiers(a, b, importingFile, program) {
149981
150140
  if (ts.startsWith(a, "node:") && !ts.startsWith(b, "node:"))
149982
150141
  return ts.shouldUseUriStyleNodeCoreModules(importingFile, program) ? -1 /* LessThan */ : 1 /* GreaterThan */;
@@ -154589,35 +154748,34 @@ var ts;
154589
154748
  codefix.registerCodeFix({
154590
154749
  errorCodes: errorCodes,
154591
154750
  getCodeActions: function getCodeActionsForStrictClassInitializationErrors(context) {
154592
- var propertyDeclaration = getPropertyDeclaration(context.sourceFile, context.span.start);
154593
- if (!propertyDeclaration)
154751
+ var info = getInfo(context.sourceFile, context.span.start);
154752
+ if (!info)
154594
154753
  return;
154595
- var result = [
154596
- getActionForAddMissingUndefinedType(context, propertyDeclaration),
154597
- getActionForAddMissingDefiniteAssignmentAssertion(context, propertyDeclaration)
154598
- ];
154599
- ts.append(result, getActionForAddMissingInitializer(context, propertyDeclaration));
154754
+ var result = [];
154755
+ ts.append(result, getActionForAddMissingUndefinedType(context, info));
154756
+ ts.append(result, getActionForAddMissingDefiniteAssignmentAssertion(context, info));
154757
+ ts.append(result, getActionForAddMissingInitializer(context, info));
154600
154758
  return result;
154601
154759
  },
154602
154760
  fixIds: [fixIdAddDefiniteAssignmentAssertions, fixIdAddUndefinedType, fixIdAddInitializer],
154603
154761
  getAllCodeActions: function (context) {
154604
154762
  return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
154605
- var propertyDeclaration = getPropertyDeclaration(diag.file, diag.start);
154606
- if (!propertyDeclaration)
154763
+ var info = getInfo(diag.file, diag.start);
154764
+ if (!info)
154607
154765
  return;
154608
154766
  switch (context.fixId) {
154609
154767
  case fixIdAddDefiniteAssignmentAssertions:
154610
- addDefiniteAssignmentAssertion(changes, diag.file, propertyDeclaration);
154768
+ addDefiniteAssignmentAssertion(changes, diag.file, info.prop);
154611
154769
  break;
154612
154770
  case fixIdAddUndefinedType:
154613
- addUndefinedType(changes, diag.file, propertyDeclaration);
154771
+ addUndefinedType(changes, diag.file, info);
154614
154772
  break;
154615
154773
  case fixIdAddInitializer:
154616
154774
  var checker = context.program.getTypeChecker();
154617
- var initializer = getInitializer(checker, propertyDeclaration);
154775
+ var initializer = getInitializer(checker, info.prop);
154618
154776
  if (!initializer)
154619
154777
  return;
154620
- addInitializer(changes, diag.file, propertyDeclaration, initializer);
154778
+ addInitializer(changes, diag.file, info.prop, initializer);
154621
154779
  break;
154622
154780
  default:
154623
154781
  ts.Debug.fail(JSON.stringify(context.fixId));
@@ -154625,35 +154783,50 @@ var ts;
154625
154783
  });
154626
154784
  },
154627
154785
  });
154628
- function getPropertyDeclaration(sourceFile, pos) {
154786
+ function getInfo(sourceFile, pos) {
154629
154787
  var token = ts.getTokenAtPosition(sourceFile, pos);
154630
- return ts.isIdentifier(token) ? ts.cast(token.parent, ts.isPropertyDeclaration) : undefined;
154788
+ if (ts.isIdentifier(token) && ts.isPropertyDeclaration(token.parent)) {
154789
+ var type = ts.getEffectiveTypeAnnotationNode(token.parent);
154790
+ if (type) {
154791
+ return { type: type, prop: token.parent, isJs: ts.isInJSFile(token.parent) };
154792
+ }
154793
+ }
154794
+ return undefined;
154631
154795
  }
154632
- function getActionForAddMissingDefiniteAssignmentAssertion(context, propertyDeclaration) {
154633
- var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addDefiniteAssignmentAssertion(t, context.sourceFile, propertyDeclaration); });
154634
- return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_definite_assignment_assertion_to_property_0, propertyDeclaration.getText()], fixIdAddDefiniteAssignmentAssertions, ts.Diagnostics.Add_definite_assignment_assertions_to_all_uninitialized_properties);
154796
+ function getActionForAddMissingDefiniteAssignmentAssertion(context, info) {
154797
+ if (info.isJs)
154798
+ return undefined;
154799
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addDefiniteAssignmentAssertion(t, context.sourceFile, info.prop); });
154800
+ return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_definite_assignment_assertion_to_property_0, info.prop.getText()], fixIdAddDefiniteAssignmentAssertions, ts.Diagnostics.Add_definite_assignment_assertions_to_all_uninitialized_properties);
154635
154801
  }
154636
154802
  function addDefiniteAssignmentAssertion(changeTracker, propertyDeclarationSourceFile, propertyDeclaration) {
154637
154803
  var property = ts.factory.updatePropertyDeclaration(propertyDeclaration, propertyDeclaration.decorators, propertyDeclaration.modifiers, propertyDeclaration.name, ts.factory.createToken(53 /* ExclamationToken */), propertyDeclaration.type, propertyDeclaration.initializer);
154638
154804
  changeTracker.replaceNode(propertyDeclarationSourceFile, propertyDeclaration, property);
154639
154805
  }
154640
- function getActionForAddMissingUndefinedType(context, propertyDeclaration) {
154641
- var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addUndefinedType(t, context.sourceFile, propertyDeclaration); });
154642
- return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_undefined_type_to_property_0, propertyDeclaration.name.getText()], fixIdAddUndefinedType, ts.Diagnostics.Add_undefined_type_to_all_uninitialized_properties);
154806
+ function getActionForAddMissingUndefinedType(context, info) {
154807
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addUndefinedType(t, context.sourceFile, info); });
154808
+ return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_undefined_type_to_property_0, info.prop.name.getText()], fixIdAddUndefinedType, ts.Diagnostics.Add_undefined_type_to_all_uninitialized_properties);
154643
154809
  }
154644
- function addUndefinedType(changeTracker, propertyDeclarationSourceFile, propertyDeclaration) {
154810
+ function addUndefinedType(changeTracker, sourceFile, info) {
154645
154811
  var undefinedTypeNode = ts.factory.createKeywordTypeNode(152 /* UndefinedKeyword */);
154646
- var type = propertyDeclaration.type; // TODO: GH#18217
154647
- var types = ts.isUnionTypeNode(type) ? type.types.concat(undefinedTypeNode) : [type, undefinedTypeNode];
154648
- changeTracker.replaceNode(propertyDeclarationSourceFile, type, ts.factory.createUnionTypeNode(types));
154812
+ var types = ts.isUnionTypeNode(info.type) ? info.type.types.concat(undefinedTypeNode) : [info.type, undefinedTypeNode];
154813
+ var unionTypeNode = ts.factory.createUnionTypeNode(types);
154814
+ if (info.isJs) {
154815
+ changeTracker.addJSDocTags(sourceFile, info.prop, [ts.factory.createJSDocTypeTag(/*tagName*/ undefined, ts.factory.createJSDocTypeExpression(unionTypeNode))]);
154816
+ }
154817
+ else {
154818
+ changeTracker.replaceNode(sourceFile, info.type, unionTypeNode);
154819
+ }
154649
154820
  }
154650
- function getActionForAddMissingInitializer(context, propertyDeclaration) {
154821
+ function getActionForAddMissingInitializer(context, info) {
154822
+ if (info.isJs)
154823
+ return undefined;
154651
154824
  var checker = context.program.getTypeChecker();
154652
- var initializer = getInitializer(checker, propertyDeclaration);
154825
+ var initializer = getInitializer(checker, info.prop);
154653
154826
  if (!initializer)
154654
154827
  return undefined;
154655
- var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addInitializer(t, context.sourceFile, propertyDeclaration, initializer); });
154656
- return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_initializer_to_property_0, propertyDeclaration.name.getText()], fixIdAddInitializer, ts.Diagnostics.Add_initializers_to_all_uninitialized_properties);
154828
+ var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addInitializer(t, context.sourceFile, info.prop, initializer); });
154829
+ return codefix.createCodeFixAction(fixName, changes, [ts.Diagnostics.Add_initializer_to_property_0, info.prop.name.getText()], fixIdAddInitializer, ts.Diagnostics.Add_initializers_to_all_uninitialized_properties);
154657
154830
  }
154658
154831
  function addInitializer(changeTracker, propertyDeclarationSourceFile, propertyDeclaration, initializer) {
154659
154832
  var property = ts.factory.updatePropertyDeclaration(propertyDeclaration, propertyDeclaration.decorators, propertyDeclaration.modifiers, propertyDeclaration.name, propertyDeclaration.questionToken, propertyDeclaration.type, initializer);