typescript 4.6.0-dev.20220110 → 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.20220110";
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) {
@@ -19791,16 +19820,6 @@ var ts;
19791
19820
  (symlinkedDirectories || (symlinkedDirectories = new ts.Map())).set(symlinkPath, real);
19792
19821
  }
19793
19822
  },
19794
- setSymlinkedDirectoryFromSymlinkedFile: function (symlink, real) {
19795
- this.setSymlinkedFile(ts.toPath(symlink, cwd, getCanonicalFileName), real);
19796
- var _a = guessDirectorySymlink(real, symlink, cwd, getCanonicalFileName) || ts.emptyArray, commonResolved = _a[0], commonOriginal = _a[1];
19797
- if (commonResolved && commonOriginal) {
19798
- this.setSymlinkedDirectory(commonOriginal, {
19799
- real: commonResolved,
19800
- realPath: ts.toPath(commonResolved, cwd, getCanonicalFileName),
19801
- });
19802
- }
19803
- },
19804
19823
  setSymlinksFromResolutions: function (files, typeReferenceDirectives) {
19805
19824
  var _this = this;
19806
19825
  var _a;
@@ -26067,7 +26086,7 @@ var ts;
26067
26086
  * @param visitor Optional callback used to visit any custom prologue directives.
26068
26087
  */
26069
26088
  function copyPrologue(source, target, ensureUseStrict, visitor) {
26070
- var offset = copyStandardPrologue(source, target, ensureUseStrict);
26089
+ var offset = copyStandardPrologue(source, target, 0, ensureUseStrict);
26071
26090
  return copyCustomPrologue(source, target, offset, visitor);
26072
26091
  }
26073
26092
  function isUseStrictPrologue(node) {
@@ -26080,12 +26099,14 @@ var ts;
26080
26099
  * Copies only the standard (string-expression) prologue-directives into the target statement-array.
26081
26100
  * @param source origin statements array
26082
26101
  * @param target result statements array
26102
+ * @param statementOffset The offset at which to begin the copy.
26083
26103
  * @param ensureUseStrict boolean determining whether the function need to add prologue-directives
26104
+ * @returns Count of how many directive statements were copied.
26084
26105
  */
26085
- function copyStandardPrologue(source, target, ensureUseStrict) {
26106
+ function copyStandardPrologue(source, target, statementOffset, ensureUseStrict) {
26107
+ if (statementOffset === void 0) { statementOffset = 0; }
26086
26108
  ts.Debug.assert(target.length === 0, "Prologue directives should be at the first statement in the target statements array");
26087
26109
  var foundUseStrict = false;
26088
- var statementOffset = 0;
26089
26110
  var numStatements = source.length;
26090
26111
  while (statementOffset < numStatements) {
26091
26112
  var statement = source[statementOffset];
@@ -27508,7 +27529,7 @@ var ts;
27508
27529
  importName: "__createBinding",
27509
27530
  scoped: false,
27510
27531
  priority: 1,
27511
- 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 }));"
27512
27533
  };
27513
27534
  ts.setModuleDefaultHelper = {
27514
27535
  name: "typescript:commonjscreatevalue",
@@ -41143,7 +41164,7 @@ var ts;
41143
41164
  ? 1 /* Recursive */ : 0 /* None */
41144
41165
  };
41145
41166
  }
41146
- if (ts.isImplicitGlob(spec)) {
41167
+ if (ts.isImplicitGlob(spec.substring(spec.lastIndexOf(ts.directorySeparator) + 1))) {
41147
41168
  return {
41148
41169
  key: useCaseSensitiveFileNames ? spec : ts.toFileNameLowerCase(spec),
41149
41170
  flags: 1 /* Recursive */
@@ -41509,9 +41530,7 @@ var ts;
41509
41530
  }
41510
41531
  }
41511
41532
  var failedLookupLocations = [];
41512
- var features = ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 ? NodeResolutionFeatures.Node12Default :
41513
- ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext ? NodeResolutionFeatures.NodeNextDefault :
41514
- NodeResolutionFeatures.None;
41533
+ var features = getDefaultNodeResolutionFeatures(options);
41515
41534
  var moduleResolutionState = { compilerOptions: options, host: host, traceEnabled: traceEnabled, failedLookupLocations: failedLookupLocations, packageJsonInfoCache: cache, features: features, conditions: ["node", "require", "types"] };
41516
41535
  var resolved = primaryLookup();
41517
41536
  var primary = true;
@@ -41596,6 +41615,34 @@ var ts;
41596
41615
  }
41597
41616
  }
41598
41617
  ts.resolveTypeReferenceDirective = resolveTypeReferenceDirective;
41618
+ function getDefaultNodeResolutionFeatures(options) {
41619
+ return ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 ? NodeResolutionFeatures.Node12Default :
41620
+ ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext ? NodeResolutionFeatures.NodeNextDefault :
41621
+ NodeResolutionFeatures.None;
41622
+ }
41623
+ /**
41624
+ * @internal
41625
+ * Does not try `@types/${packageName}` - use a second pass if needed.
41626
+ */
41627
+ function resolvePackageNameToPackageJson(packageName, containingDirectory, options, host, cache) {
41628
+ var moduleResolutionState = {
41629
+ compilerOptions: options,
41630
+ host: host,
41631
+ traceEnabled: isTraceEnabled(options, host),
41632
+ failedLookupLocations: [],
41633
+ packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
41634
+ conditions: ts.emptyArray,
41635
+ features: NodeResolutionFeatures.None,
41636
+ };
41637
+ return ts.forEachAncestorDirectory(containingDirectory, function (ancestorDirectory) {
41638
+ if (ts.getBaseFileName(ancestorDirectory) !== "node_modules") {
41639
+ var nodeModulesFolder = ts.combinePaths(ancestorDirectory, "node_modules");
41640
+ var candidate = ts.combinePaths(nodeModulesFolder, packageName);
41641
+ return getPackageJsonInfo(candidate, /*onlyRecordFailures*/ false, moduleResolutionState);
41642
+ }
41643
+ });
41644
+ }
41645
+ ts.resolvePackageNameToPackageJson = resolvePackageNameToPackageJson;
41599
41646
  /**
41600
41647
  * Given a set of options, returns the set of type directive names
41601
41648
  * that should be included for this program automatically.
@@ -42169,11 +42216,6 @@ var ts;
42169
42216
  }
42170
42217
  ts.resolveJSModule = resolveJSModule;
42171
42218
  /* @internal */
42172
- function tryResolveJSModule(moduleName, initialDir, host) {
42173
- return tryResolveJSModuleWorker(moduleName, initialDir, host).resolvedModule;
42174
- }
42175
- ts.tryResolveJSModule = tryResolveJSModule;
42176
- /* @internal */
42177
42219
  var NodeResolutionFeatures;
42178
42220
  (function (NodeResolutionFeatures) {
42179
42221
  NodeResolutionFeatures[NodeResolutionFeatures["None"] = 0] = "None";
@@ -42481,6 +42523,97 @@ var ts;
42481
42523
  var versionPaths = packageInfo && packageInfo.versionPaths;
42482
42524
  return withPackageId(packageInfo, loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageJsonContent, versionPaths));
42483
42525
  }
42526
+ /* @internal */
42527
+ function getEntrypointsFromPackageJsonInfo(packageJsonInfo, options, host, cache, resolveJs) {
42528
+ if (!resolveJs && packageJsonInfo.resolvedEntrypoints !== undefined) {
42529
+ // Cached value excludes resolutions to JS files - those could be
42530
+ // cached separately, but they're used rarely.
42531
+ return packageJsonInfo.resolvedEntrypoints;
42532
+ }
42533
+ var entrypoints;
42534
+ var extensions = resolveJs ? Extensions.JavaScript : Extensions.TypeScript;
42535
+ var features = getDefaultNodeResolutionFeatures(options);
42536
+ var requireState = {
42537
+ compilerOptions: options,
42538
+ host: host,
42539
+ traceEnabled: isTraceEnabled(options, host),
42540
+ failedLookupLocations: [],
42541
+ packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
42542
+ conditions: ["node", "require", "types"],
42543
+ features: features,
42544
+ };
42545
+ var requireResolution = loadNodeModuleFromDirectoryWorker(extensions, packageJsonInfo.packageDirectory,
42546
+ /*onlyRecordFailures*/ false, requireState, packageJsonInfo.packageJsonContent, packageJsonInfo.versionPaths);
42547
+ entrypoints = ts.append(entrypoints, requireResolution === null || requireResolution === void 0 ? void 0 : requireResolution.path);
42548
+ if (features & NodeResolutionFeatures.Exports && packageJsonInfo.packageJsonContent.exports) {
42549
+ for (var _i = 0, _a = [["node", "import", "types"], ["node", "require", "types"]]; _i < _a.length; _i++) {
42550
+ var conditions = _a[_i];
42551
+ var exportState = __assign(__assign({}, requireState), { failedLookupLocations: [], conditions: conditions });
42552
+ var exportResolutions = loadEntrypointsFromExportMap(packageJsonInfo, packageJsonInfo.packageJsonContent.exports, exportState, extensions);
42553
+ if (exportResolutions) {
42554
+ for (var _b = 0, exportResolutions_1 = exportResolutions; _b < exportResolutions_1.length; _b++) {
42555
+ var resolution = exportResolutions_1[_b];
42556
+ entrypoints = ts.appendIfUnique(entrypoints, resolution.path);
42557
+ }
42558
+ }
42559
+ }
42560
+ }
42561
+ return packageJsonInfo.resolvedEntrypoints = entrypoints || false;
42562
+ }
42563
+ ts.getEntrypointsFromPackageJsonInfo = getEntrypointsFromPackageJsonInfo;
42564
+ function loadEntrypointsFromExportMap(scope, exports, state, extensions) {
42565
+ var entrypoints;
42566
+ if (ts.isArray(exports)) {
42567
+ for (var _i = 0, exports_1 = exports; _i < exports_1.length; _i++) {
42568
+ var target = exports_1[_i];
42569
+ loadEntrypointsFromTargetExports(target);
42570
+ }
42571
+ }
42572
+ // eslint-disable-next-line no-null/no-null
42573
+ else if (typeof exports === "object" && exports !== null && allKeysStartWithDot(exports)) {
42574
+ for (var key in exports) {
42575
+ loadEntrypointsFromTargetExports(exports[key]);
42576
+ }
42577
+ }
42578
+ else {
42579
+ loadEntrypointsFromTargetExports(exports);
42580
+ }
42581
+ return entrypoints;
42582
+ function loadEntrypointsFromTargetExports(target) {
42583
+ var _a, _b;
42584
+ if (typeof target === "string" && ts.startsWith(target, "./") && target.indexOf("*") === -1) {
42585
+ var partsAfterFirst = ts.getPathComponents(target).slice(2);
42586
+ if (partsAfterFirst.indexOf("..") >= 0 || partsAfterFirst.indexOf(".") >= 0 || partsAfterFirst.indexOf("node_modules") >= 0) {
42587
+ return false;
42588
+ }
42589
+ var resolvedTarget = ts.combinePaths(scope.packageDirectory, target);
42590
+ var finalPath = ts.getNormalizedAbsolutePath(resolvedTarget, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a));
42591
+ var result = loadJSOrExactTSFileName(extensions, finalPath, /*recordOnlyFailures*/ false, state);
42592
+ if (result) {
42593
+ entrypoints = ts.appendIfUnique(entrypoints, result, function (a, b) { return a.path === b.path; });
42594
+ return true;
42595
+ }
42596
+ }
42597
+ else if (Array.isArray(target)) {
42598
+ for (var _i = 0, target_1 = target; _i < target_1.length; _i++) {
42599
+ var t = target_1[_i];
42600
+ var success = loadEntrypointsFromTargetExports(t);
42601
+ if (success) {
42602
+ return true;
42603
+ }
42604
+ }
42605
+ }
42606
+ // eslint-disable-next-line no-null/no-null
42607
+ else if (typeof target === "object" && target !== null) {
42608
+ return ts.forEach(ts.getOwnKeys(target), function (key) {
42609
+ if (key === "default" || ts.contains(state.conditions, key) || isApplicableVersionedTypesKey(state.conditions, key)) {
42610
+ loadEntrypointsFromTargetExports(target[key]);
42611
+ return true;
42612
+ }
42613
+ });
42614
+ }
42615
+ }
42616
+ }
42484
42617
  /**
42485
42618
  * A function for locating the package.json scope for a given path
42486
42619
  */
@@ -42537,7 +42670,7 @@ var ts;
42537
42670
  trace(host, ts.Diagnostics.Found_package_json_at_0, packageJsonPath);
42538
42671
  }
42539
42672
  var versionPaths = readPackageJsonTypesVersionPaths(packageJsonContent, state);
42540
- var result = { packageDirectory: packageDirectory, packageJsonContent: packageJsonContent, versionPaths: versionPaths };
42673
+ var result = { packageDirectory: packageDirectory, packageJsonContent: packageJsonContent, versionPaths: versionPaths, resolvedEntrypoints: undefined };
42541
42674
  (_b = state.packageJsonInfoCache) === null || _b === void 0 ? void 0 : _b.setPackageJsonInfo(packageJsonPath, result);
42542
42675
  return result;
42543
42676
  }
@@ -42834,8 +42967,8 @@ var ts;
42834
42967
  }
42835
42968
  return toSearchResult(/*value*/ undefined);
42836
42969
  }
42837
- for (var _d = 0, target_1 = target; _d < target_1.length; _d++) {
42838
- var elem = target_1[_d];
42970
+ for (var _d = 0, target_2 = target; _d < target_2.length; _d++) {
42971
+ var elem = target_2[_d];
42839
42972
  var result = loadModuleFromTargetImportOrExport(elem, subpath, pattern);
42840
42973
  if (result) {
42841
42974
  return result;
@@ -49864,7 +49997,7 @@ var ts;
49864
49997
  if (!sigs || !sigs.length) {
49865
49998
  sigs = getSignaturesOfStructuredType(type, 1 /* Construct */);
49866
49999
  }
49867
- if ((sigs && sigs.length) || getPropertyOfType(type, "default" /* Default */)) {
50000
+ if ((sigs && sigs.length) || getPropertyOfType(type, "default" /* Default */, /*skipObjectFunctionPropertyAugment*/ true)) {
49868
50001
  var moduleType = getTypeWithSyntheticDefaultImportType(type, symbol, moduleSymbol, reference);
49869
50002
  return cloneTypeAsModuleType(symbol, moduleType, referenceParent);
49870
50003
  }
@@ -52068,8 +52201,8 @@ var ts;
52068
52201
  }
52069
52202
  else {
52070
52203
  if (parent && getExportsOfSymbol(parent)) {
52071
- var exports_1 = getExportsOfSymbol(parent);
52072
- ts.forEachEntry(exports_1, function (ex, name) {
52204
+ var exports_2 = getExportsOfSymbol(parent);
52205
+ ts.forEachEntry(exports_2, function (ex, name) {
52073
52206
  if (getSymbolIfSameReference(ex, symbol) && !isLateBoundName(name) && name !== "export=" /* ExportEquals */) {
52074
52207
  symbolName = ts.unescapeLeadingUnderscores(name);
52075
52208
  return true;
@@ -57180,6 +57313,11 @@ var ts;
57180
57313
  return simplified !== type ? simplified : getConstraintOfType(type);
57181
57314
  }
57182
57315
  function getConstraintFromIndexedAccess(type) {
57316
+ if (isMappedTypeGenericIndexedAccess(type)) {
57317
+ // For indexed access types of the form { [P in K]: E }[X], where K is non-generic and X is generic,
57318
+ // we substitute an instantiation of E where P is replaced with X.
57319
+ return substituteIndexedMappedType(type.objectType, type.indexType);
57320
+ }
57183
57321
  var indexConstraint = getSimplifiedTypeOrConstraint(type.indexType);
57184
57322
  if (indexConstraint && indexConstraint !== type.indexType) {
57185
57323
  var indexedAccess = getIndexedAccessTypeOrUndefined(type.objectType, indexConstraint, type.accessFlags);
@@ -57384,6 +57522,11 @@ var ts;
57384
57522
  return constraint ? getStringMappingType(t.symbol, constraint) : stringType;
57385
57523
  }
57386
57524
  if (t.flags & 8388608 /* IndexedAccess */) {
57525
+ if (isMappedTypeGenericIndexedAccess(t)) {
57526
+ // For indexed access types of the form { [P in K]: E }[X], where K is non-generic and X is generic,
57527
+ // we substitute an instantiation of E where P is replaced with X.
57528
+ return getBaseConstraint(substituteIndexedMappedType(t.objectType, t.indexType));
57529
+ }
57387
57530
  var baseObjectType = getBaseConstraint(t.objectType);
57388
57531
  var baseIndexType = getBaseConstraint(t.indexType);
57389
57532
  var baseIndexedAccess = baseObjectType && baseIndexType && getIndexedAccessTypeOrUndefined(baseObjectType, baseIndexType, t.accessFlags);
@@ -57468,13 +57611,7 @@ var ts;
57468
57611
  * type itself.
57469
57612
  */
57470
57613
  function getApparentType(type) {
57471
- // We obtain the base constraint for all instantiable types, except indexed access types of the form
57472
- // { [P in K]: E }[X], where K is non-generic and X is generic. For those types, we instead substitute an
57473
- // instantiation of E where P is replaced with X. We do this because getBaseConstraintOfType directly
57474
- // lowers to an instantiation where X's constraint is substituted for X, which isn't always desirable.
57475
- var t = !(type.flags & 465829888 /* Instantiable */) ? type :
57476
- isMappedTypeGenericIndexedAccess(type) ? substituteIndexedMappedType(type.objectType, type.indexType) :
57477
- getBaseConstraintOfType(type) || unknownType;
57614
+ var t = !(type.flags & 465829888 /* Instantiable */) ? type : getBaseConstraintOfType(type) || unknownType;
57478
57615
  return ts.getObjectFlags(t) & 32 /* Mapped */ ? getApparentTypeOfMappedType(t) :
57479
57616
  t.flags & 2097152 /* Intersection */ ? getApparentTypeOfIntersectionType(t) :
57480
57617
  t.flags & 402653316 /* StringLike */ ? globalStringType :
@@ -64138,6 +64275,17 @@ var ts;
64138
64275
  resetErrorInfo(saveErrorInfo);
64139
64276
  return result;
64140
64277
  }
64278
+ if (isMappedTypeGenericIndexedAccess(source)) {
64279
+ // For an indexed access type { [P in K]: E}[X], above we have already explored an instantiation of E with X
64280
+ // substituted for P. We also want to explore type { [P in K]: E }[C], where C is the constraint of X.
64281
+ var indexConstraint = getConstraintOfType(source.indexType);
64282
+ if (indexConstraint) {
64283
+ if (result = isRelatedTo(getIndexedAccessType(source.objectType, indexConstraint), target, 1 /* Source */, reportErrors)) {
64284
+ resetErrorInfo(saveErrorInfo);
64285
+ return result;
64286
+ }
64287
+ }
64288
+ }
64141
64289
  }
64142
64290
  }
64143
64291
  else if (source.flags & 4194304 /* Index */) {
@@ -78401,32 +78549,38 @@ var ts;
78401
78549
  if (classExtendsNull) {
78402
78550
  error(superCall, ts.Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null);
78403
78551
  }
78404
- // The first statement in the body of a constructor (excluding prologue directives) must be a super call
78405
- // 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:
78406
78553
  // - The containing class is a derived class.
78407
78554
  // - The constructor declares parameter properties
78408
78555
  // or the containing class declares instance member variables with initializers.
78409
- var superCallShouldBeFirst = (ts.getEmitScriptTarget(compilerOptions) !== 99 /* ESNext */ || !useDefineForClassFields) &&
78556
+ var superCallShouldBeRootLevel = (ts.getEmitScriptTarget(compilerOptions) !== 99 /* ESNext */ || !useDefineForClassFields) &&
78410
78557
  (ts.some(node.parent.members, isInstancePropertyWithInitializerOrPrivateIdentifierProperty) ||
78411
78558
  ts.some(node.parameters, function (p) { return ts.hasSyntacticModifier(p, 16476 /* ParameterPropertyModifier */); }));
78412
- // Skip past any prologue directives to find the first statement
78413
- // to ensure that it was a super call.
78414
- if (superCallShouldBeFirst) {
78415
- var statements = node.body.statements;
78416
- var superCallStatement = void 0;
78417
- for (var _i = 0, statements_4 = statements; _i < statements_4.length; _i++) {
78418
- var statement = statements_4[_i];
78419
- if (statement.kind === 237 /* ExpressionStatement */ && ts.isSuperCall(statement.expression)) {
78420
- superCallStatement = statement;
78421
- 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
+ }
78422
78577
  }
78423
- if (!ts.isPrologueDirective(statement)) {
78424
- 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);
78425
78582
  }
78426
78583
  }
78427
- if (!superCallStatement) {
78428
- 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);
78429
- }
78430
78584
  }
78431
78585
  }
78432
78586
  else if (!classExtendsNull) {
@@ -78434,6 +78588,19 @@ var ts;
78434
78588
  }
78435
78589
  }
78436
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
+ }
78437
78604
  function checkAccessorDeclaration(node) {
78438
78605
  if (produceDiagnostics) {
78439
78606
  // Grammar checking accessors
@@ -83256,9 +83423,9 @@ var ts;
83256
83423
  }
83257
83424
  }
83258
83425
  // Checks for export * conflicts
83259
- var exports_2 = getExportsOfModule(moduleSymbol);
83260
- if (exports_2) {
83261
- exports_2.forEach(function (_a, id) {
83426
+ var exports_3 = getExportsOfModule(moduleSymbol);
83427
+ if (exports_3) {
83428
+ exports_3.forEach(function (_a, id) {
83262
83429
  var declarations = _a.declarations, flags = _a.flags;
83263
83430
  if (id === "__export") {
83264
83431
  return;
@@ -88556,34 +88723,31 @@ var ts;
88556
88723
  }
88557
88724
  ts.getNonAssignmentOperatorForCompoundAssignment = getNonAssignmentOperatorForCompoundAssignment;
88558
88725
  /**
88559
- * Adds super call and preceding prologue directives into the list of statements.
88560
- *
88561
- * @param ctor The constructor node.
88562
- * @param result The list of statements.
88563
- * @param visitor The visitor to apply to each node added to the result array.
88564
- * @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.
88565
88740
  */
88566
- function addPrologueDirectivesAndInitialSuperCall(factory, ctor, result, visitor) {
88567
- if (ctor.body) {
88568
- var statements = ctor.body.statements;
88569
- // add prologue directives to the list (if any)
88570
- var index = factory.copyPrologue(statements, result, /*ensureUseStrict*/ false, visitor);
88571
- if (index === statements.length) {
88572
- // list contains nothing but prologue directives (or empty) - exit
88573
- return index;
88574
- }
88575
- var superIndex = ts.findIndex(statements, function (s) { return ts.isExpressionStatement(s) && ts.isSuperCall(s.expression); }, index);
88576
- if (superIndex > -1) {
88577
- for (var i = index; i <= superIndex; i++) {
88578
- result.push(ts.visitNode(statements[i], visitor, ts.isStatement));
88579
- }
88580
- 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;
88581
88746
  }
88582
- return index;
88583
88747
  }
88584
- return 0;
88748
+ return -1;
88585
88749
  }
88586
- ts.addPrologueDirectivesAndInitialSuperCall = addPrologueDirectivesAndInitialSuperCall;
88750
+ ts.findSuperStatementIndex = findSuperStatementIndex;
88587
88751
  function getProperties(node, requireInitializer, isStatic) {
88588
88752
  return ts.filter(node.members, function (m) { return isInitializedOrStaticProperty(m, requireInitializer, isStatic); });
88589
88753
  }
@@ -90482,6 +90646,7 @@ var ts;
90482
90646
  case 176 /* TypePredicate */:
90483
90647
  case 133 /* BooleanKeyword */:
90484
90648
  return factory.createIdentifier("Boolean");
90649
+ case 197 /* TemplateLiteralType */:
90485
90650
  case 149 /* StringKeyword */:
90486
90651
  return factory.createIdentifier("String");
90487
90652
  case 147 /* ObjectKeyword */:
@@ -90820,10 +90985,14 @@ var ts;
90820
90985
  return ts.visitFunctionBody(body, visitor, context);
90821
90986
  }
90822
90987
  var statements = [];
90823
- var indexOfFirstStatement = 0;
90824
90988
  resumeLexicalEnvironment();
90825
- indexOfFirstStatement = ts.addPrologueDirectivesAndInitialSuperCall(factory, constructor, statements, visitor);
90826
- // 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:
90827
90996
  //
90828
90997
  // constructor (public x, public y) {
90829
90998
  // }
@@ -90835,9 +91004,17 @@ var ts;
90835
91004
  // this.y = y;
90836
91005
  // }
90837
91006
  //
90838
- ts.addRange(statements, ts.map(parametersWithPropertyAssignments, transformParameterWithPropertyAssignment));
90839
- // Add the existing statements, skipping the initial super call.
90840
- 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));
90841
91018
  // End the lexical environment.
90842
91019
  statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment());
90843
91020
  var block = factory.createBlock(ts.setTextRange(factory.createNodeArray(statements), body.statements), /*multiLine*/ true);
@@ -92735,6 +92912,7 @@ var ts;
92735
92912
  /*modifiers*/ undefined, parameters !== null && parameters !== void 0 ? parameters : [], body), constructor || node), constructor));
92736
92913
  }
92737
92914
  function transformConstructorBody(node, constructor, isDerivedClass) {
92915
+ var _a;
92738
92916
  var properties = ts.getProperties(node, /*requireInitializer*/ false, /*isStatic*/ false);
92739
92917
  if (!useDefineForClassFields) {
92740
92918
  properties = ts.filter(properties, function (property) { return !!property.initializer || ts.isPrivateIdentifier(property.name); });
@@ -92746,9 +92924,21 @@ var ts;
92746
92924
  return ts.visitFunctionBody(/*node*/ undefined, visitor, context);
92747
92925
  }
92748
92926
  resumeLexicalEnvironment();
92749
- var indexOfFirstStatement = 0;
92927
+ var needsSyntheticConstructor = !constructor && isDerivedClass;
92928
+ var indexOfFirstStatementAfterSuper = 0;
92929
+ var prologueStatementCount = 0;
92930
+ var superStatementIndex = -1;
92750
92931
  var statements = [];
92751
- 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) {
92752
92942
  // Add a synthetic `super` call:
92753
92943
  //
92754
92944
  // super(...arguments);
@@ -92756,9 +92946,6 @@ var ts;
92756
92946
  statements.push(factory.createExpressionStatement(factory.createCallExpression(factory.createSuper(),
92757
92947
  /*typeArguments*/ undefined, [factory.createSpreadElement(factory.createIdentifier("arguments"))])));
92758
92948
  }
92759
- if (constructor) {
92760
- indexOfFirstStatement = ts.addPrologueDirectivesAndInitialSuperCall(factory, constructor, statements, visitor);
92761
- }
92762
92949
  // Add the property initializers. Transforms this:
92763
92950
  //
92764
92951
  // public x = 1;
@@ -92769,31 +92956,59 @@ var ts;
92769
92956
  // this.x = 1;
92770
92957
  // }
92771
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;
92772
92962
  if (constructor === null || constructor === void 0 ? void 0 : constructor.body) {
92773
- var afterParameterProperties = ts.findIndex(constructor.body.statements, function (s) { return !ts.isParameterPropertyDeclaration(ts.getOriginalNode(s), constructor); }, indexOfFirstStatement);
92774
- if (afterParameterProperties === -1) {
92775
- afterParameterProperties = constructor.body.statements.length;
92963
+ if (useDefineForClassFields) {
92964
+ statements = statements.filter(function (statement) { return !ts.isParameterPropertyDeclaration(ts.getOriginalNode(statement), constructor); });
92776
92965
  }
92777
- if (afterParameterProperties > indexOfFirstStatement) {
92778
- if (!useDefineForClassFields) {
92779
- 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;
92780
92990
  }
92781
- indexOfFirstStatement = afterParameterProperties;
92782
92991
  }
92783
92992
  }
92784
92993
  var receiver = factory.createThis();
92785
92994
  // private methods can be called in property initializers, they should execute first.
92786
92995
  addMethodStatements(statements, privateMethodsAndAccessors, receiver);
92787
92996
  addPropertyOrClassStaticBlockStatements(statements, properties, receiver);
92788
- // Add existing statements, skipping the initial super call.
92997
+ // Add existing statements after the initial prologues and super call
92789
92998
  if (constructor) {
92790
- 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));
92791
93000
  }
92792
93001
  statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment());
92793
93002
  return ts.setTextRange(factory.createBlock(ts.setTextRange(factory.createNodeArray(statements),
92794
93003
  /*location*/ constructor ? constructor.body.statements : node.members),
92795
93004
  /*multiLine*/ true),
92796
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
+ }
92797
93012
  }
92798
93013
  /**
92799
93014
  * Generates assignment statements for property initializers.
@@ -92814,6 +93029,11 @@ var ts;
92814
93029
  ts.setSourceMapRange(statement, ts.moveRangePastModifiers(property));
92815
93030
  ts.setCommentRange(statement, property);
92816
93031
  ts.setOriginalNode(statement, property);
93032
+ // `setOriginalNode` *copies* the `emitNode` from `property`, so now both
93033
+ // `statement` and `expression` have a copy of the synthesized comments.
93034
+ // Drop the comments from expression to avoid printing them twice.
93035
+ ts.setSyntheticLeadingComments(expression, undefined);
93036
+ ts.setSyntheticTrailingComments(expression, undefined);
92817
93037
  statements.push(statement);
92818
93038
  }
92819
93039
  }
@@ -96580,37 +96800,39 @@ var ts;
96580
96800
  var prologue = [];
96581
96801
  var statements = [];
96582
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;
96583
96808
  // If a super call has already been synthesized,
96584
96809
  // we're going to assume that we should just transform everything after that.
96585
96810
  // The assumption is that no prior step in the pipeline has added any prologue directives.
96586
- var statementOffset = 0;
96811
+ var statementOffset = postSuperStatementsStart;
96587
96812
  if (!hasSynthesizedSuper)
96588
- statementOffset = factory.copyStandardPrologue(constructor.body.statements, prologue, /*ensureUseStrict*/ false);
96589
- addDefaultValueAssignmentsIfNeeded(statements, constructor);
96590
- addRestParameterIfNeeded(statements, constructor, hasSynthesizedSuper);
96813
+ statementOffset = factory.copyStandardPrologue(constructor.body.statements, prologue, statementOffset, /*ensureUseStrict*/ false);
96591
96814
  if (!hasSynthesizedSuper)
96592
- statementOffset = factory.copyCustomPrologue(constructor.body.statements, statements, statementOffset, visitor);
96593
- // 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
96594
96817
  var superCallExpression;
96595
96818
  if (hasSynthesizedSuper) {
96596
96819
  superCallExpression = createDefaultSuperCallOrThis();
96597
96820
  }
96598
- else if (isDerivedClass && statementOffset < constructor.body.statements.length) {
96599
- var firstStatement = constructor.body.statements[statementOffset];
96600
- if (ts.isExpressionStatement(firstStatement) && ts.isSuperCall(firstStatement.expression)) {
96601
- superCallExpression = visitImmediateSuperCallInBody(firstStatement.expression);
96602
- }
96821
+ else if (superCall) {
96822
+ superCallExpression = visitSuperCallInBody(superCall);
96603
96823
  }
96604
96824
  if (superCallExpression) {
96605
96825
  hierarchyFacts |= 8192 /* ConstructorWithCapturedSuper */;
96606
- statementOffset++; // skip this statement, we will add it after visiting the rest of the body.
96607
96826
  }
96827
+ // Add parameter defaults at the beginning of the output, with prologue statements
96828
+ addDefaultValueAssignmentsIfNeeded(prologue, constructor);
96829
+ addRestParameterIfNeeded(prologue, constructor, hasSynthesizedSuper);
96608
96830
  // visit the remaining statements
96609
96831
  ts.addRange(statements, ts.visitNodes(constructor.body.statements, visitor, ts.isStatement, /*start*/ statementOffset));
96610
96832
  factory.mergeLexicalEnvironment(prologue, endLexicalEnvironment());
96611
96833
  insertCaptureNewTargetIfNeeded(prologue, constructor, /*copyOnWrite*/ false);
96612
- if (isDerivedClass) {
96613
- 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 */)) {
96614
96836
  // If the subclass constructor does *not* contain `this` and *ends* with a `super()` call, we will use the
96615
96837
  // following representation:
96616
96838
  //
@@ -96630,10 +96852,10 @@ var ts;
96630
96852
  // return C;
96631
96853
  // })(Base);
96632
96854
  // ```
96633
- 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);
96634
96856
  var returnStatement = factory.createReturnStatement(superCallExpression);
96635
- ts.setCommentRange(returnStatement, ts.getCommentRange(superCall));
96636
- ts.setEmitFlags(superCall, 1536 /* NoComments */);
96857
+ ts.setCommentRange(returnStatement, ts.getCommentRange(superCall_1));
96858
+ ts.setEmitFlags(superCall_1, 1536 /* NoComments */);
96637
96859
  statements.push(returnStatement);
96638
96860
  }
96639
96861
  else {
@@ -96658,9 +96880,19 @@ var ts;
96658
96880
  // return C;
96659
96881
  // })(Base);
96660
96882
  // ```
96661
- // Since the `super()` call was the first statement, we insert the `this` capturing call to
96662
- // `super()` at the top of the list of `statements` (after any pre-existing custom prologues).
96663
- 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
+ }
96664
96896
  if (!isSufficientlyCoveredByReturnStatements(constructor.body)) {
96665
96897
  statements.push(factory.createReturnStatement(factory.createUniqueName("_this", 16 /* Optimistic */ | 32 /* FileLevel */)));
96666
96898
  }
@@ -96683,11 +96915,27 @@ var ts;
96683
96915
  // ```
96684
96916
  insertCaptureThisForNodeIfNeeded(prologue, constructor);
96685
96917
  }
96686
- 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)),
96687
96919
  /*location*/ constructor.body.statements),
96688
96920
  /*multiLine*/ true);
96689
- ts.setTextRange(block, constructor.body);
96690
- 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
+ };
96691
96939
  }
96692
96940
  /**
96693
96941
  * We want to try to avoid emitting a return statement in certain cases if a user already returned something.
@@ -96916,6 +97164,18 @@ var ts;
96916
97164
  }
96917
97165
  return false;
96918
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
+ }
96919
97179
  function insertCaptureThisForNode(statements, node, initializer) {
96920
97180
  enableSubstitutionsForCapturedThis();
96921
97181
  var captureThisStatement = factory.createVariableStatement(
@@ -97225,7 +97485,7 @@ var ts;
97225
97485
  if (ts.isBlock(body)) {
97226
97486
  // ensureUseStrict is false because no new prologue-directive should be added.
97227
97487
  // addStandardPrologue will put already-existing directives at the beginning of the target statement-array
97228
- statementOffset = factory.copyStandardPrologue(body.statements, prologue, /*ensureUseStrict*/ false);
97488
+ statementOffset = factory.copyStandardPrologue(body.statements, prologue, 0, /*ensureUseStrict*/ false);
97229
97489
  statementOffset = factory.copyCustomPrologue(body.statements, statements, statementOffset, visitor, ts.isHoistedFunction);
97230
97490
  statementOffset = factory.copyCustomPrologue(body.statements, statements, statementOffset, visitor, ts.isHoistedVariableStatement);
97231
97491
  }
@@ -98596,7 +98856,7 @@ var ts;
98596
98856
  /*type*/ undefined, factory.updateBlock(func.body, statements))),
98597
98857
  /*typeArguments*/ undefined, call.arguments))));
98598
98858
  }
98599
- function visitImmediateSuperCallInBody(node) {
98859
+ function visitSuperCallInBody(node) {
98600
98860
  return visitCallExpressionWithPotentialCapturedThisAssignment(node, /*assignToCapturedThis*/ false);
98601
98861
  }
98602
98862
  function visitCallExpressionWithPotentialCapturedThisAssignment(node, assignToCapturedThis) {
@@ -119154,28 +119414,37 @@ var ts;
119154
119414
  useCaseSensitiveFileNames: (_a = host.useCaseSensitiveFileNames) === null || _a === void 0 ? void 0 : _a.call(host),
119155
119415
  };
119156
119416
  }
119157
- function updateModuleSpecifier(compilerOptions, importingSourceFileName, toFileName, host, oldImportSpecifier) {
119158
- var res = getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, getPreferencesForUpdate(compilerOptions, oldImportSpecifier, importingSourceFileName, host), {});
119417
+ // `importingSourceFile` and `importingSourceFileName`? Why not just use `importingSourceFile.path`?
119418
+ // Because when this is called by the file renamer, `importingSourceFile` is the file being renamed,
119419
+ // while `importingSourceFileName` its *new* name. We need a source file just to get its
119420
+ // `impliedNodeFormat` and to detect certain preferences from existing import module specifiers.
119421
+ function updateModuleSpecifier(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, oldImportSpecifier) {
119422
+ var res = getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, getPreferencesForUpdate(compilerOptions, oldImportSpecifier, importingSourceFileName, host), {});
119159
119423
  if (res === oldImportSpecifier)
119160
119424
  return undefined;
119161
119425
  return res;
119162
119426
  }
119163
119427
  moduleSpecifiers_1.updateModuleSpecifier = updateModuleSpecifier;
119164
- // Note: importingSourceFile is just for usesJsExtensionOnImports
119428
+ // `importingSourceFile` and `importingSourceFileName`? Why not just use `importingSourceFile.path`?
119429
+ // Because when this is called by the declaration emitter, `importingSourceFile` is the implementation
119430
+ // file, but `importingSourceFileName` and `toFileName` refer to declaration files (the former to the
119431
+ // one currently being produced; the latter to the one being imported). We need an implementation file
119432
+ // just to get its `impliedNodeFormat` and to detect certain preferences from existing import module
119433
+ // specifiers.
119165
119434
  function getModuleSpecifier(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host) {
119166
- return getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, getPreferences(host, {}, compilerOptions, importingSourceFile), {});
119435
+ return getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, getPreferences(host, {}, compilerOptions, importingSourceFile), {});
119167
119436
  }
119168
119437
  moduleSpecifiers_1.getModuleSpecifier = getModuleSpecifier;
119169
- function getNodeModulesPackageName(compilerOptions, importingSourceFileName, nodeModulesFileName, host, preferences) {
119170
- var info = getInfo(importingSourceFileName, host);
119171
- var modulePaths = getAllModulePaths(importingSourceFileName, nodeModulesFileName, host, preferences);
119172
- return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, host, compilerOptions, /*packageNameOnly*/ true); });
119438
+ function getNodeModulesPackageName(compilerOptions, importingSourceFile, nodeModulesFileName, host, preferences) {
119439
+ var info = getInfo(importingSourceFile.path, host);
119440
+ var modulePaths = getAllModulePaths(importingSourceFile.path, nodeModulesFileName, host, preferences);
119441
+ return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, /*packageNameOnly*/ true); });
119173
119442
  }
119174
119443
  moduleSpecifiers_1.getNodeModulesPackageName = getNodeModulesPackageName;
119175
- function getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, preferences, userPreferences) {
119444
+ function getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, preferences, userPreferences) {
119176
119445
  var info = getInfo(importingSourceFileName, host);
119177
119446
  var modulePaths = getAllModulePaths(importingSourceFileName, toFileName, host, userPreferences);
119178
- return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, host, compilerOptions); }) ||
119447
+ return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions); }) ||
119179
119448
  getLocalModuleSpecifier(toFileName, info, compilerOptions, host, preferences);
119180
119449
  }
119181
119450
  function tryGetModuleSpecifiersFromCache(moduleSymbol, importingSourceFile, host, userPreferences) {
@@ -119242,7 +119511,7 @@ var ts;
119242
119511
  var relativeSpecifiers;
119243
119512
  for (var _i = 0, modulePaths_1 = modulePaths; _i < modulePaths_1.length; _i++) {
119244
119513
  var modulePath = modulePaths_1[_i];
119245
- var specifier = tryGetModuleNameAsNodeModule(modulePath, info, host, compilerOptions);
119514
+ var specifier = tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions);
119246
119515
  nodeModulesSpecifiers = ts.append(nodeModulesSpecifiers, specifier);
119247
119516
  if (specifier && modulePath.isRedirect) {
119248
119517
  // If we got a specifier for a redirect, it was a bare package specifier (e.g. "@foo/bar",
@@ -119634,7 +119903,7 @@ var ts;
119634
119903
  ? removeExtensionAndIndexPostFix(relativePath, ending, compilerOptions)
119635
119904
  : ts.removeFileExtension(relativePath);
119636
119905
  }
119637
- function tryGetModuleNameAsNodeModule(_a, _b, host, options, packageNameOnly) {
119906
+ function tryGetModuleNameAsNodeModule(_a, _b, importingSourceFile, host, options, packageNameOnly) {
119638
119907
  var path = _a.path, isRedirect = _a.isRedirect;
119639
119908
  var getCanonicalFileName = _b.getCanonicalFileName, sourceDirectory = _b.sourceDirectory;
119640
119909
  if (!host.fileExists || !host.readFile) {
@@ -119697,11 +119966,19 @@ var ts;
119697
119966
  var moduleFileToTry = path;
119698
119967
  if (host.fileExists(packageJsonPath)) {
119699
119968
  var packageJsonContent = JSON.parse(host.readFile(packageJsonPath));
119700
- // TODO: Inject `require` or `import` condition based on the intended import mode
119701
119969
  if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) {
119702
- var fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string" ? tryGetModuleNameFromExports(options, path, packageRootPath, packageJsonContent.name, packageJsonContent.exports, ["node", "types"]) : undefined;
119970
+ // `conditions` *could* be made to go against `importingSourceFile.impliedNodeFormat` if something wanted to generate
119971
+ // an ImportEqualsDeclaration in an ESM-implied file or an ImportCall in a CJS-implied file. But since this function is
119972
+ // usually called to conjure an import out of thin air, we don't have an existing usage to call `getModeForUsageAtIndex`
119973
+ // with, so for now we just stick with the mode of the file.
119974
+ var conditions = ["node", importingSourceFile.impliedNodeFormat === ts.ModuleKind.ESNext ? "import" : "require", "types"];
119975
+ var fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string"
119976
+ ? tryGetModuleNameFromExports(options, path, packageRootPath, ts.getPackageNameFromTypesPackageName(packageJsonContent.name), packageJsonContent.exports, conditions)
119977
+ : undefined;
119703
119978
  if (fromExports) {
119704
- var withJsExtension = !ts.hasTSFileExtension(fromExports.moduleFileToTry) ? fromExports : { moduleFileToTry: ts.removeFileExtension(fromExports.moduleFileToTry) + tryGetJSExtensionForFile(fromExports.moduleFileToTry, options) };
119979
+ var withJsExtension = !ts.hasTSFileExtension(fromExports.moduleFileToTry)
119980
+ ? fromExports
119981
+ : { moduleFileToTry: ts.removeFileExtension(fromExports.moduleFileToTry) + tryGetJSExtensionForFile(fromExports.moduleFileToTry, options) };
119705
119982
  return __assign(__assign({}, withJsExtension), { verbatimFromExports: true });
119706
119983
  }
119707
119984
  if (packageJsonContent.exports) {
@@ -119807,8 +120084,8 @@ var ts;
119807
120084
  }
119808
120085
  function getPathRelativeToRootDirs(path, rootDirs, getCanonicalFileName) {
119809
120086
  return ts.firstDefined(rootDirs, function (rootDir) {
119810
- var relativePath = getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName); // TODO: GH#18217
119811
- return isPathRelativeToParent(relativePath) ? undefined : relativePath;
120087
+ var relativePath = getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName);
120088
+ return relativePath !== undefined && isPathRelativeToParent(relativePath) ? undefined : relativePath;
119812
120089
  });
119813
120090
  }
119814
120091
  function removeExtensionAndIndexPostFix(fileName, ending, options) {
@@ -126020,7 +126297,7 @@ var ts;
126020
126297
  if (!ts.stringContains(importedFileName, "node_modules")) {
126021
126298
  return undefined;
126022
126299
  }
126023
- var specifier = ts.moduleSpecifiers.getNodeModulesPackageName(host.getCompilationSettings(), fromFile.path, importedFileName, moduleSpecifierResolutionHost, preferences);
126300
+ var specifier = ts.moduleSpecifiers.getNodeModulesPackageName(host.getCompilationSettings(), fromFile, importedFileName, moduleSpecifierResolutionHost, preferences);
126024
126301
  if (!specifier) {
126025
126302
  return undefined;
126026
126303
  }
@@ -135666,7 +135943,7 @@ var ts;
135666
135943
  : getSourceFileToImport(importedModuleSymbol, importLiteral, sourceFile, program, host, oldToNew);
135667
135944
  // Need an update if the imported file moved, or the importing file moved and was using a relative path.
135668
135945
  return toImport !== undefined && (toImport.updated || (importingSourceFileMoved && ts.pathIsRelative(importLiteral.text)))
135669
- ? ts.moduleSpecifiers.updateModuleSpecifier(program.getCompilerOptions(), getCanonicalFileName(newImportFromPath), toImport.newFileName, ts.createModuleSpecifierResolutionHost(program, host), importLiteral.text)
135946
+ ? ts.moduleSpecifiers.updateModuleSpecifier(program.getCompilerOptions(), sourceFile, getCanonicalFileName(newImportFromPath), toImport.newFileName, ts.createModuleSpecifierResolutionHost(program, host), importLiteral.text)
135670
135947
  : undefined;
135671
135948
  });
135672
135949
  };
@@ -137311,6 +137588,9 @@ var ts;
137311
137588
  // We use 1 NavNode to represent 'A.B.C', but there are multiple source nodes.
137312
137589
  // Only merge module nodes that have the same chain. Don't merge 'A.B.C' with 'A'!
137313
137590
  function areSameModule(a, b) {
137591
+ if (!a.body || !b.body) {
137592
+ return a.body === b.body;
137593
+ }
137314
137594
  return a.body.kind === b.body.kind && (a.body.kind !== 260 /* ModuleDeclaration */ || areSameModule(a.body, b.body));
137315
137595
  }
137316
137596
  /** Merge source into target. Source should be thrown away after this is called. */
@@ -146088,20 +146368,31 @@ var ts;
146088
146368
  codefix.registerCodeFix({
146089
146369
  errorCodes: errorCodes,
146090
146370
  getCodeActions: function getCodeActionsToAddConvertToUnknownForNonOverlappingTypes(context) {
146091
- 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); });
146092
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)];
146093
146376
  },
146094
146377
  fixIds: [fixId],
146095
- 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
+ }); },
146096
146384
  });
146097
- function makeChange(changeTracker, sourceFile, pos) {
146098
- var token = ts.getTokenAtPosition(sourceFile, pos);
146099
- 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) {
146100
146386
  var replacement = ts.isAsExpression(assertion)
146101
146387
  ? ts.factory.createAsExpression(assertion.expression, ts.factory.createKeywordTypeNode(154 /* UnknownKeyword */))
146102
146388
  : ts.factory.createTypeAssertion(ts.factory.createKeywordTypeNode(154 /* UnknownKeyword */), assertion.expression);
146103
146389
  changeTracker.replaceNode(sourceFile, assertion.expression, replacement);
146104
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
+ }
146105
146396
  })(codefix = ts.codefix || (ts.codefix = {}));
146106
146397
  })(ts || (ts = {}));
146107
146398
  /* @internal */
@@ -154525,7 +154816,7 @@ var ts;
154525
154816
  defaultToNamedAction.kind,
154526
154817
  namedToDefaultAction.kind
154527
154818
  ],
154528
- getAvailableActions: function (context) {
154819
+ getAvailableActions: function getRefactorActionsToConvertBetweenNamedAndDefaultExports(context) {
154529
154820
  var info = getInfo(context, context.triggerReason === "invoked");
154530
154821
  if (!info)
154531
154822
  return ts.emptyArray;
@@ -154543,7 +154834,7 @@ var ts;
154543
154834
  }
154544
154835
  return ts.emptyArray;
154545
154836
  },
154546
- getEditsForAction: function (context, actionName) {
154837
+ getEditsForAction: function getRefactorEditsToConvertBetweenNamedAndDefaultExports(context, actionName) {
154547
154838
  ts.Debug.assert(actionName === defaultToNamedAction.name || actionName === namedToDefaultAction.name, "Unexpected action name");
154548
154839
  var info = getInfo(context);
154549
154840
  ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected applicable refactor info");
@@ -154771,7 +155062,7 @@ var ts;
154771
155062
  namespaceToNamedAction.kind,
154772
155063
  namedToNamespaceAction.kind
154773
155064
  ],
154774
- getAvailableActions: function (context) {
155065
+ getAvailableActions: function getRefactorActionsToConvertBetweenNamedAndNamespacedImports(context) {
154775
155066
  var info = getImportToConvert(context, context.triggerReason === "invoked");
154776
155067
  if (!info)
154777
155068
  return ts.emptyArray;
@@ -154790,7 +155081,7 @@ var ts;
154790
155081
  }
154791
155082
  return ts.emptyArray;
154792
155083
  },
154793
- getEditsForAction: function (context, actionName) {
155084
+ getEditsForAction: function getRefactorEditsToConvertBetweenNamedAndNamespacedImports(context, actionName) {
154794
155085
  ts.Debug.assert(actionName === namespaceToNamedAction.name || actionName === namedToNamespaceAction.name, "Unexpected action name");
154795
155086
  var info = getImportToConvert(context);
154796
155087
  ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected applicable refactor info");
@@ -154956,10 +155247,10 @@ var ts;
154956
155247
  };
154957
155248
  refactor.registerRefactor(refactorName, {
154958
155249
  kinds: [toOptionalChainAction.kind],
154959
- getAvailableActions: getAvailableActions,
154960
- getEditsForAction: getEditsForAction
155250
+ getEditsForAction: getRefactorEditsToConvertToOptionalChain,
155251
+ getAvailableActions: getRefactorActionsToConvertToOptionalChain,
154961
155252
  });
154962
- function getAvailableActions(context) {
155253
+ function getRefactorActionsToConvertToOptionalChain(context) {
154963
155254
  var info = getInfo(context, context.triggerReason === "invoked");
154964
155255
  if (!info)
154965
155256
  return ts.emptyArray;
@@ -154979,7 +155270,7 @@ var ts;
154979
155270
  }
154980
155271
  return ts.emptyArray;
154981
155272
  }
154982
- function getEditsForAction(context, actionName) {
155273
+ function getRefactorEditsToConvertToOptionalChain(context, actionName) {
154983
155274
  var info = getInfo(context);
154984
155275
  ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected applicable refactor info");
154985
155276
  var edits = ts.textChanges.ChangeTracker.with(context, function (t) {
@@ -155222,10 +155513,10 @@ var ts;
155222
155513
  };
155223
155514
  refactor.registerRefactor(refactorName, {
155224
155515
  kinds: [functionOverloadAction.kind],
155225
- getEditsForAction: getEditsForAction,
155226
- getAvailableActions: getAvailableActions
155516
+ getEditsForAction: getRefactorEditsToConvertOverloadsToOneSignature,
155517
+ getAvailableActions: getRefactorActionsToConvertOverloadsToOneSignature
155227
155518
  });
155228
- function getAvailableActions(context) {
155519
+ function getRefactorActionsToConvertOverloadsToOneSignature(context) {
155229
155520
  var file = context.file, startPosition = context.startPosition, program = context.program;
155230
155521
  var info = getConvertableOverloadListAtPosition(file, startPosition, program);
155231
155522
  if (!info)
@@ -155236,7 +155527,7 @@ var ts;
155236
155527
  actions: [functionOverloadAction]
155237
155528
  }];
155238
155529
  }
155239
- function getEditsForAction(context) {
155530
+ function getRefactorEditsToConvertOverloadsToOneSignature(context) {
155240
155531
  var file = context.file, startPosition = context.startPosition, program = context.program;
155241
155532
  var signatureDecls = getConvertableOverloadListAtPosition(file, startPosition, program);
155242
155533
  if (!signatureDecls)
@@ -155392,14 +155683,14 @@ var ts;
155392
155683
  extractConstantAction.kind,
155393
155684
  extractFunctionAction.kind
155394
155685
  ],
155395
- getAvailableActions: getAvailableActions,
155396
- getEditsForAction: getEditsForAction
155686
+ getEditsForAction: getRefactorEditsToExtractSymbol,
155687
+ getAvailableActions: getRefactorActionsToExtractSymbol,
155397
155688
  });
155398
155689
  /**
155399
155690
  * Compute the associated code actions
155400
155691
  * Exported for tests.
155401
155692
  */
155402
- function getAvailableActions(context) {
155693
+ function getRefactorActionsToExtractSymbol(context) {
155403
155694
  var requestedRefactor = context.kind;
155404
155695
  var rangeToExtract = getRangeToExtract(context.file, ts.getRefactorContextSpan(context), context.triggerReason === "invoked");
155405
155696
  var targetRange = rangeToExtract.targetRange;
@@ -155528,9 +155819,9 @@ var ts;
155528
155819
  return error;
155529
155820
  }
155530
155821
  }
155531
- extractSymbol.getAvailableActions = getAvailableActions;
155822
+ extractSymbol.getRefactorActionsToExtractSymbol = getRefactorActionsToExtractSymbol;
155532
155823
  /* Exported for tests */
155533
- function getEditsForAction(context, actionName) {
155824
+ function getRefactorEditsToExtractSymbol(context, actionName) {
155534
155825
  var rangeToExtract = getRangeToExtract(context.file, ts.getRefactorContextSpan(context));
155535
155826
  var targetRange = rangeToExtract.targetRange; // TODO:GH#18217
155536
155827
  var parsedFunctionIndexMatch = /^function_scope_(\d+)$/.exec(actionName);
@@ -155547,7 +155838,7 @@ var ts;
155547
155838
  }
155548
155839
  ts.Debug.fail("Unrecognized action name");
155549
155840
  }
155550
- extractSymbol.getEditsForAction = getEditsForAction;
155841
+ extractSymbol.getRefactorEditsToExtractSymbol = getRefactorEditsToExtractSymbol;
155551
155842
  // Move these into diagnostic messages if they become user-facing
155552
155843
  var Messages;
155553
155844
  (function (Messages) {
@@ -157098,7 +157389,7 @@ var ts;
157098
157389
  extractToInterfaceAction.kind,
157099
157390
  extractToTypeDefAction.kind
157100
157391
  ],
157101
- getAvailableActions: function (context) {
157392
+ getAvailableActions: function getRefactorActionsToExtractType(context) {
157102
157393
  var info = getRangeToExtract(context, context.triggerReason === "invoked");
157103
157394
  if (!info)
157104
157395
  return ts.emptyArray;
@@ -157123,7 +157414,7 @@ var ts;
157123
157414
  }
157124
157415
  return ts.emptyArray;
157125
157416
  },
157126
- getEditsForAction: function (context, actionName) {
157417
+ getEditsForAction: function getRefactorEditsToExtractType(context, actionName) {
157127
157418
  var file = context.file;
157128
157419
  var info = getRangeToExtract(context);
157129
157420
  ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected to find a range to extract");
@@ -157291,7 +157582,7 @@ var ts;
157291
157582
  };
157292
157583
  refactor.registerRefactor(actionName, {
157293
157584
  kinds: [generateGetSetAction.kind],
157294
- getEditsForAction: function (context, actionName) {
157585
+ getEditsForAction: function getRefactorActionsToGenerateGetAndSetAccessors(context, actionName) {
157295
157586
  if (!context.endPosition)
157296
157587
  return undefined;
157297
157588
  var info = ts.codefix.getAccessorConvertiblePropertyAtPosition(context.file, context.program, context.startPosition, context.endPosition);
@@ -157370,7 +157661,7 @@ var ts;
157370
157661
  };
157371
157662
  refactor.registerRefactor(refactorName, {
157372
157663
  kinds: [moveToNewFileAction.kind],
157373
- getAvailableActions: function (context) {
157664
+ getAvailableActions: function getRefactorActionsToMoveToNewFile(context) {
157374
157665
  var statements = getStatementsToMove(context);
157375
157666
  if (context.preferences.allowTextChangesInNewFiles && statements) {
157376
157667
  return [{ name: refactorName, description: description, actions: [moveToNewFileAction] }];
@@ -157381,7 +157672,7 @@ var ts;
157381
157672
  }
157382
157673
  return ts.emptyArray;
157383
157674
  },
157384
- getEditsForAction: function (context, actionName) {
157675
+ getEditsForAction: function getRefactorEditsToMoveToNewFile(context, actionName) {
157385
157676
  ts.Debug.assert(actionName === refactorName, "Wrong refactor invoked");
157386
157677
  var statements = ts.Debug.checkDefined(getStatementsToMove(context));
157387
157678
  var edits = ts.textChanges.ChangeTracker.with(context, function (t) { return doChange(context.file, context.program, statements, t, context.host, context.preferences); });
@@ -158112,10 +158403,10 @@ var ts;
158112
158403
  };
158113
158404
  refactor.registerRefactor(refactorName, {
158114
158405
  kinds: [removeBracesAction.kind],
158115
- getEditsForAction: getEditsForAction,
158116
- getAvailableActions: getAvailableActions
158406
+ getEditsForAction: getRefactorEditsToRemoveFunctionBraces,
158407
+ getAvailableActions: getRefactorActionsToRemoveFunctionBraces
158117
158408
  });
158118
- function getAvailableActions(context) {
158409
+ function getRefactorActionsToRemoveFunctionBraces(context) {
158119
158410
  var file = context.file, startPosition = context.startPosition, triggerReason = context.triggerReason;
158120
158411
  var info = getConvertibleArrowFunctionAtPosition(file, startPosition, triggerReason === "invoked");
158121
158412
  if (!info)
@@ -158141,7 +158432,7 @@ var ts;
158141
158432
  }
158142
158433
  return ts.emptyArray;
158143
158434
  }
158144
- function getEditsForAction(context, actionName) {
158435
+ function getRefactorEditsToRemoveFunctionBraces(context, actionName) {
158145
158436
  var file = context.file, startPosition = context.startPosition;
158146
158437
  var info = getConvertibleArrowFunctionAtPosition(file, startPosition);
158147
158438
  ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected applicable refactor info");
@@ -158215,10 +158506,10 @@ var ts;
158215
158506
  };
158216
158507
  refactor.registerRefactor(refactorName, {
158217
158508
  kinds: [toDestructuredAction.kind],
158218
- getEditsForAction: getEditsForAction,
158219
- getAvailableActions: getAvailableActions
158509
+ getEditsForAction: getRefactorEditsToConvertParametersToDestructuredObject,
158510
+ getAvailableActions: getRefactorActionsToConvertParametersToDestructuredObject
158220
158511
  });
158221
- function getAvailableActions(context) {
158512
+ function getRefactorActionsToConvertParametersToDestructuredObject(context) {
158222
158513
  var file = context.file, startPosition = context.startPosition;
158223
158514
  var isJSFile = ts.isSourceFileJS(file);
158224
158515
  if (isJSFile)
@@ -158232,7 +158523,7 @@ var ts;
158232
158523
  actions: [toDestructuredAction]
158233
158524
  }];
158234
158525
  }
158235
- function getEditsForAction(context, actionName) {
158526
+ function getRefactorEditsToConvertParametersToDestructuredObject(context, actionName) {
158236
158527
  ts.Debug.assert(actionName === refactorName, "Unexpected action name");
158237
158528
  var file = context.file, startPosition = context.startPosition, program = context.program, cancellationToken = context.cancellationToken, host = context.host;
158238
158529
  var functionDeclaration = getFunctionDeclarationAtPosition(file, startPosition, program.getTypeChecker());
@@ -158742,10 +159033,10 @@ var ts;
158742
159033
  };
158743
159034
  refactor.registerRefactor(refactorName, {
158744
159035
  kinds: [convertStringAction.kind],
158745
- getEditsForAction: getEditsForAction,
158746
- getAvailableActions: getAvailableActions
159036
+ getEditsForAction: getRefactorEditsToConvertToTemplateString,
159037
+ getAvailableActions: getRefactorActionsToConvertToTemplateString
158747
159038
  });
158748
- function getAvailableActions(context) {
159039
+ function getRefactorActionsToConvertToTemplateString(context) {
158749
159040
  var file = context.file, startPosition = context.startPosition;
158750
159041
  var node = getNodeOrParentOfParentheses(file, startPosition);
158751
159042
  var maybeBinary = getParentBinaryExpression(node);
@@ -158771,7 +159062,7 @@ var ts;
158771
159062
  }
158772
159063
  return node;
158773
159064
  }
158774
- function getEditsForAction(context, actionName) {
159065
+ function getRefactorEditsToConvertToTemplateString(context, actionName) {
158775
159066
  var file = context.file, startPosition = context.startPosition;
158776
159067
  var node = getNodeOrParentOfParentheses(file, startPosition);
158777
159068
  switch (actionName) {
@@ -158985,10 +159276,10 @@ var ts;
158985
159276
  toNamedFunctionAction.kind,
158986
159277
  toArrowFunctionAction.kind
158987
159278
  ],
158988
- getEditsForAction: getEditsForAction,
158989
- getAvailableActions: getAvailableActions
159279
+ getEditsForAction: getRefactorEditsToConvertFunctionExpressions,
159280
+ getAvailableActions: getRefactorActionsToConvertFunctionExpressions
158990
159281
  });
158991
- function getAvailableActions(context) {
159282
+ function getRefactorActionsToConvertFunctionExpressions(context) {
158992
159283
  var file = context.file, startPosition = context.startPosition, program = context.program, kind = context.kind;
158993
159284
  var info = getFunctionInfo(file, startPosition, program);
158994
159285
  if (!info)
@@ -159032,7 +159323,7 @@ var ts;
159032
159323
  errors : possibleActions
159033
159324
  }];
159034
159325
  }
159035
- function getEditsForAction(context, actionName) {
159326
+ function getRefactorEditsToConvertFunctionExpressions(context, actionName) {
159036
159327
  var file = context.file, startPosition = context.startPosition, program = context.program;
159037
159328
  var info = getFunctionInfo(file, startPosition, program);
159038
159329
  if (!info)
@@ -159192,10 +159483,10 @@ var ts;
159192
159483
  };
159193
159484
  refactor.registerRefactor(refactorName, {
159194
159485
  kinds: [inferReturnTypeAction.kind],
159195
- getEditsForAction: getEditsForAction,
159196
- getAvailableActions: getAvailableActions
159486
+ getEditsForAction: getRefactorEditsToInferReturnType,
159487
+ getAvailableActions: getRefactorActionsToInferReturnType
159197
159488
  });
159198
- function getEditsForAction(context) {
159489
+ function getRefactorEditsToInferReturnType(context) {
159199
159490
  var info = getInfo(context);
159200
159491
  if (info && !refactor.isRefactorErrorInfo(info)) {
159201
159492
  var edits = ts.textChanges.ChangeTracker.with(context, function (t) { return doChange(context.file, t, info.declaration, info.returnTypeNode); });
@@ -159203,7 +159494,7 @@ var ts;
159203
159494
  }
159204
159495
  return undefined;
159205
159496
  }
159206
- function getAvailableActions(context) {
159497
+ function getRefactorActionsToInferReturnType(context) {
159207
159498
  var info = getInfo(context);
159208
159499
  if (!info)
159209
159500
  return ts.emptyArray;
@@ -166303,30 +166594,43 @@ var ts;
166303
166594
  (_b = packageJson.peerDependencies) === null || _b === void 0 ? void 0 : _b.forEach(function (_, dependencyName) { return addDependency(dependencyName); });
166304
166595
  }
166305
166596
  if (dependencyNames) {
166306
- var resolutions = ts.mapDefined(ts.arrayFrom(dependencyNames.keys()), function (name) {
166307
- var types = ts.resolveTypeReferenceDirective(name, rootFileName, compilerOptions, moduleResolutionHost);
166308
- if (types.resolvedTypeReferenceDirective) {
166309
- return types.resolvedTypeReferenceDirective;
166310
- }
166311
- if (compilerOptions.allowJs && compilerOptions.maxNodeModuleJsDepth) {
166312
- return ts.tryResolveJSModule(name, hostProject.currentDirectory, moduleResolutionHost);
166313
- }
166314
- });
166597
+ var dependenciesAdded = 0;
166315
166598
  var symlinkCache = hostProject.getSymlinkCache();
166316
- for (var _c = 0, resolutions_1 = resolutions; _c < resolutions_1.length; _c++) {
166317
- var resolution = resolutions_1[_c];
166318
- if (!resolution.resolvedFileName)
166599
+ for (var _c = 0, _d = ts.arrayFrom(dependencyNames.keys()); _c < _d.length; _c++) {
166600
+ var name = _d[_c];
166601
+ // Avoid creating a large project that would significantly slow down time to editor interactivity
166602
+ if (dependencySelection === 2 /* Auto */ && dependenciesAdded > this.maxDependencies) {
166603
+ hostProject.log("Auto-import provider attempted to add more than " + this.maxDependencies + " dependencies.");
166604
+ return ts.emptyArray;
166605
+ }
166606
+ // 1. Try to load from the implementation package. For many dependencies, the
166607
+ // package.json will exist, but the package will not contain any typings,
166608
+ // so `entrypoints` will be undefined. In that case, or if the dependency
166609
+ // is missing altogether, we will move on to trying the @types package (2).
166610
+ var packageJson = ts.resolvePackageNameToPackageJson(name, hostProject.currentDirectory, compilerOptions, moduleResolutionHost, program.getModuleResolutionCache());
166611
+ if (packageJson) {
166612
+ var entrypoints = getRootNamesFromPackageJson(packageJson, program, symlinkCache);
166613
+ if (entrypoints) {
166614
+ rootNames = ts.concatenate(rootNames, entrypoints);
166615
+ dependenciesAdded += entrypoints.length ? 1 : 0;
166616
+ continue;
166617
+ }
166618
+ }
166619
+ // 2. Try to load from the @types package.
166620
+ var typesPackageJson = ts.resolvePackageNameToPackageJson("@types/" + name, hostProject.currentDirectory, compilerOptions, moduleResolutionHost, program.getModuleResolutionCache());
166621
+ if (typesPackageJson) {
166622
+ var entrypoints = getRootNamesFromPackageJson(typesPackageJson, program, symlinkCache);
166623
+ rootNames = ts.concatenate(rootNames, entrypoints);
166624
+ dependenciesAdded += (entrypoints === null || entrypoints === void 0 ? void 0 : entrypoints.length) ? 1 : 0;
166319
166625
  continue;
166320
- var resolvedFileName = resolution.resolvedFileName, originalPath = resolution.originalPath;
166321
- if (originalPath) {
166322
- symlinkCache.setSymlinkedDirectoryFromSymlinkedFile(originalPath, resolvedFileName);
166323
166626
  }
166324
- if (!program.getSourceFile(resolvedFileName) && (!originalPath || !program.getSourceFile(originalPath))) {
166325
- rootNames = ts.append(rootNames, resolvedFileName);
166326
- // Avoid creating a large project that would significantly slow down time to editor interactivity
166327
- if (dependencySelection === 2 /* Auto */ && rootNames.length > this.maxDependencies) {
166328
- return ts.emptyArray;
166329
- }
166627
+ // 3. If the @types package did not exist and the user has settings that
166628
+ // allow processing JS from node_modules, go back to the implementation
166629
+ // package and load the JS.
166630
+ if (packageJson && compilerOptions.allowJs && compilerOptions.maxNodeModuleJsDepth) {
166631
+ var entrypoints = getRootNamesFromPackageJson(packageJson, program, symlinkCache, /*allowJs*/ true);
166632
+ rootNames = ts.concatenate(rootNames, entrypoints);
166633
+ dependenciesAdded += (entrypoints === null || entrypoints === void 0 ? void 0 : entrypoints.length) ? 1 : 0;
166330
166634
  }
166331
166635
  }
166332
166636
  }
@@ -166336,6 +166640,26 @@ var ts;
166336
166640
  (dependencyNames || (dependencyNames = new ts.Set())).add(dependency);
166337
166641
  }
166338
166642
  }
166643
+ function getRootNamesFromPackageJson(packageJson, program, symlinkCache, resolveJs) {
166644
+ var _a;
166645
+ var entrypoints = ts.getEntrypointsFromPackageJsonInfo(packageJson, compilerOptions, moduleResolutionHost, program.getModuleResolutionCache(), resolveJs);
166646
+ if (entrypoints) {
166647
+ var real_1 = (_a = moduleResolutionHost.realpath) === null || _a === void 0 ? void 0 : _a.call(moduleResolutionHost, packageJson.packageDirectory);
166648
+ var isSymlink_1 = real_1 && real_1 !== packageJson.packageDirectory;
166649
+ if (isSymlink_1) {
166650
+ symlinkCache.setSymlinkedDirectory(packageJson.packageDirectory, {
166651
+ real: real_1,
166652
+ realPath: hostProject.toPath(real_1),
166653
+ });
166654
+ }
166655
+ return ts.mapDefined(entrypoints, function (entrypoint) {
166656
+ var resolvedFileName = isSymlink_1 ? entrypoint.replace(packageJson.packageDirectory, real_1) : entrypoint;
166657
+ if (!program.getSourceFile(resolvedFileName) && !(isSymlink_1 && program.getSourceFile(entrypoint))) {
166658
+ return resolvedFileName;
166659
+ }
166660
+ });
166661
+ }
166662
+ }
166339
166663
  };
166340
166664
  /*@internal*/
166341
166665
  AutoImportProviderProject.create = function (dependencySelection, hostProject, moduleResolutionHost, documentRegistry) {