typescript 4.8.0-dev.20220726 → 4.8.0-dev.20220729

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.
@@ -303,7 +303,7 @@ var ts;
303
303
  // The following is baselined as a literal template type without intervention
304
304
  /** The version of the TypeScript compiler release */
305
305
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
306
- ts.version = ts.versionMajorMinor + ".0-dev.20220726";
306
+ ts.version = ts.versionMajorMinor + ".0-dev.20220729";
307
307
  /* @internal */
308
308
  var Comparison;
309
309
  (function (Comparison) {
@@ -1904,6 +1904,10 @@ var ts;
1904
1904
  /** Does nothing. */
1905
1905
  function noop(_) { }
1906
1906
  ts.noop = noop;
1907
+ ts.noopPush = {
1908
+ push: noop,
1909
+ length: 0
1910
+ };
1907
1911
  /** Do nothing and return false */
1908
1912
  function returnFalse() {
1909
1913
  return false;
@@ -8771,6 +8775,7 @@ var ts;
8771
8775
  Control_what_method_is_used_to_detect_module_format_JS_files: diag(1475, ts.DiagnosticCategory.Message, "Control_what_method_is_used_to_detect_module_format_JS_files_1475", "Control what method is used to detect module-format JS files."),
8772
8776
  auto_Colon_Treat_files_with_imports_exports_import_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_with_module_Colon_node16_as_modules: diag(1476, ts.DiagnosticCategory.Message, "auto_Colon_Treat_files_with_imports_exports_import_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_w_1476", "\"auto\": Treat files with imports, exports, import.meta, jsx (with jsx: react-jsx), or esm format (with module: node16+) as modules."),
8773
8777
  An_instantiation_expression_cannot_be_followed_by_a_property_access: diag(1477, ts.DiagnosticCategory.Error, "An_instantiation_expression_cannot_be_followed_by_a_property_access_1477", "An instantiation expression cannot be followed by a property access."),
8778
+ Identifier_or_string_literal_expected: diag(1478, ts.DiagnosticCategory.Error, "Identifier_or_string_literal_expected_1478", "Identifier or string literal expected."),
8774
8779
  The_types_of_0_are_incompatible_between_these_types: diag(2200, ts.DiagnosticCategory.Error, "The_types_of_0_are_incompatible_between_these_types_2200", "The types of '{0}' are incompatible between these types."),
8775
8780
  The_types_returned_by_0_are_incompatible_between_these_types: diag(2201, ts.DiagnosticCategory.Error, "The_types_returned_by_0_are_incompatible_between_these_types_2201", "The types returned by '{0}' are incompatible between these types."),
8776
8781
  Call_signature_return_types_0_and_1_are_incompatible: diag(2202, ts.DiagnosticCategory.Error, "Call_signature_return_types_0_and_1_are_incompatible_2202", "Call signature return types '{0}' and '{1}' are incompatible.", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ true),
@@ -8984,6 +8989,7 @@ var ts;
8984
8989
  Cannot_create_an_instance_of_an_abstract_class: diag(2511, ts.DiagnosticCategory.Error, "Cannot_create_an_instance_of_an_abstract_class_2511", "Cannot create an instance of an abstract class."),
8985
8990
  Overload_signatures_must_all_be_abstract_or_non_abstract: diag(2512, ts.DiagnosticCategory.Error, "Overload_signatures_must_all_be_abstract_or_non_abstract_2512", "Overload signatures must all be abstract or non-abstract."),
8986
8991
  Abstract_method_0_in_class_1_cannot_be_accessed_via_super_expression: diag(2513, ts.DiagnosticCategory.Error, "Abstract_method_0_in_class_1_cannot_be_accessed_via_super_expression_2513", "Abstract method '{0}' in class '{1}' cannot be accessed via super expression."),
8992
+ A_tuple_type_cannot_be_indexed_with_a_negative_value: diag(2514, ts.DiagnosticCategory.Error, "A_tuple_type_cannot_be_indexed_with_a_negative_value_2514", "A tuple type cannot be indexed with a negative value."),
8987
8993
  Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2: diag(2515, ts.DiagnosticCategory.Error, "Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2_2515", "Non-abstract class '{0}' does not implement inherited abstract member '{1}' from class '{2}'."),
8988
8994
  All_declarations_of_an_abstract_method_must_be_consecutive: diag(2516, ts.DiagnosticCategory.Error, "All_declarations_of_an_abstract_method_must_be_consecutive_2516", "All declarations of an abstract method must be consecutive."),
8989
8995
  Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type: diag(2517, ts.DiagnosticCategory.Error, "Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type_2517", "Cannot assign an abstract constructor type to a non-abstract constructor type."),
@@ -33510,7 +33516,9 @@ var ts;
33510
33516
  case 23 /* ImportOrExportSpecifiers */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
33511
33517
  case 13 /* JsxAttributes */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
33512
33518
  case 14 /* JsxChildren */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
33513
- default: return [undefined]; // TODO: GH#18217 `default: Debug.assertNever(context);`
33519
+ case 24 /* AssertEntries */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_or_string_literal_expected); // AssertionKey.
33520
+ case 25 /* Count */: return ts.Debug.fail("ParsingContext.Count used as a context"); // Not a real context, only a marker.
33521
+ default: ts.Debug.assertNever(context);
33514
33522
  }
33515
33523
  }
33516
33524
  function parseDelimitedList(kind, parseElement, considerSemicolonAsDelimiter) {
@@ -43336,18 +43344,7 @@ var ts;
43336
43344
  * Does not try `@types/${packageName}` - use a second pass if needed.
43337
43345
  */
43338
43346
  function resolvePackageNameToPackageJson(packageName, containingDirectory, options, host, cache) {
43339
- var moduleResolutionState = {
43340
- compilerOptions: options,
43341
- host: host,
43342
- traceEnabled: isTraceEnabled(options, host),
43343
- failedLookupLocations: [],
43344
- affectingLocations: [],
43345
- packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
43346
- conditions: ts.emptyArray,
43347
- features: NodeResolutionFeatures.None,
43348
- requestContainingDirectory: containingDirectory,
43349
- reportDiagnostic: ts.noop
43350
- };
43347
+ var moduleResolutionState = getTemporaryModuleResolutionState(cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(), host, options);
43351
43348
  return ts.forEachAncestorDirectory(containingDirectory, function (ancestorDirectory) {
43352
43349
  if (ts.getBaseFileName(ancestorDirectory) !== "node_modules") {
43353
43350
  var nodeModulesFolder = ts.combinePaths(ancestorDirectory, "node_modules");
@@ -44307,18 +44304,9 @@ var ts;
44307
44304
  var entrypoints;
44308
44305
  var extensions = resolveJs ? Extensions.JavaScript : Extensions.TypeScript;
44309
44306
  var features = getDefaultNodeResolutionFeatures(options);
44310
- var requireState = {
44311
- compilerOptions: options,
44312
- host: host,
44313
- traceEnabled: isTraceEnabled(options, host),
44314
- failedLookupLocations: [],
44315
- affectingLocations: [],
44316
- packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
44317
- conditions: ["node", "require", "types"],
44318
- features: features,
44319
- requestContainingDirectory: packageJsonInfo.packageDirectory,
44320
- reportDiagnostic: ts.noop
44321
- };
44307
+ var requireState = getTemporaryModuleResolutionState(cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(), host, options);
44308
+ requireState.conditions = ["node", "require", "types"];
44309
+ requireState.requestContainingDirectory = packageJsonInfo.packageDirectory;
44322
44310
  var requireResolution = loadNodeModuleFromDirectoryWorker(extensions, packageJsonInfo.packageDirectory,
44323
44311
  /*onlyRecordFailures*/ false, requireState, packageJsonInfo.packageJsonContent, packageJsonInfo.versionPaths);
44324
44312
  entrypoints = ts.append(entrypoints, requireResolution === null || requireResolution === void 0 ? void 0 : requireResolution.path);
@@ -44391,23 +44379,27 @@ var ts;
44391
44379
  }
44392
44380
  }
44393
44381
  }
44394
- /**
44395
- * A function for locating the package.json scope for a given path
44396
- */
44397
44382
  /*@internal*/
44398
- function getPackageScopeForPath(fileName, packageJsonInfoCache, host, options) {
44399
- var state = {
44383
+ function getTemporaryModuleResolutionState(packageJsonInfoCache, host, options) {
44384
+ return {
44400
44385
  host: host,
44401
44386
  compilerOptions: options,
44402
44387
  traceEnabled: isTraceEnabled(options, host),
44403
- failedLookupLocations: [],
44404
- affectingLocations: [],
44388
+ failedLookupLocations: ts.noopPush,
44389
+ affectingLocations: ts.noopPush,
44405
44390
  packageJsonInfoCache: packageJsonInfoCache,
44406
- features: 0,
44407
- conditions: [],
44391
+ features: NodeResolutionFeatures.None,
44392
+ conditions: ts.emptyArray,
44408
44393
  requestContainingDirectory: undefined,
44409
44394
  reportDiagnostic: ts.noop
44410
44395
  };
44396
+ }
44397
+ ts.getTemporaryModuleResolutionState = getTemporaryModuleResolutionState;
44398
+ /**
44399
+ * A function for locating the package.json scope for a given path
44400
+ */
44401
+ /*@internal*/
44402
+ function getPackageScopeForPath(fileName, state) {
44411
44403
  var parts = ts.getPathComponents(fileName);
44412
44404
  parts.pop();
44413
44405
  while (parts.length > 0) {
@@ -44578,7 +44570,7 @@ var ts;
44578
44570
  var _a, _b;
44579
44571
  var useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames;
44580
44572
  var directoryPath = ts.toPath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a), ts.createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames));
44581
- var scope = getPackageScopeForPath(directoryPath, state.packageJsonInfoCache, state.host, state.compilerOptions);
44573
+ var scope = getPackageScopeForPath(directoryPath, state);
44582
44574
  if (!scope || !scope.packageJsonContent.exports) {
44583
44575
  return undefined;
44584
44576
  }
@@ -44637,7 +44629,7 @@ var ts;
44637
44629
  }
44638
44630
  var useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames;
44639
44631
  var directoryPath = ts.toPath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a), ts.createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames));
44640
- var scope = getPackageScopeForPath(directoryPath, state.packageJsonInfoCache, state.host, state.compilerOptions);
44632
+ var scope = getPackageScopeForPath(directoryPath, state);
44641
44633
  if (!scope) {
44642
44634
  if (state.traceEnabled) {
44643
44635
  trace(state.host, ts.Diagnostics.Directory_0_has_no_containing_package_json_scope_Imports_will_not_resolve, directoryPath);
@@ -53097,6 +53089,12 @@ var ts;
53097
53089
  return context.truncating = context.approximateLength > ((context.flags & 1 /* NoTruncation */) ? ts.noTruncationMaximumTruncationLength : ts.defaultMaximumTruncationLength);
53098
53090
  }
53099
53091
  function typeToTypeNodeHelper(type, context) {
53092
+ var savedFlags = context.flags;
53093
+ var typeNode = typeToTypeNodeWorker(type, context);
53094
+ context.flags = savedFlags;
53095
+ return typeNode;
53096
+ }
53097
+ function typeToTypeNodeWorker(type, context) {
53100
53098
  if (cancellationToken && cancellationToken.throwIfCancellationRequested) {
53101
53099
  cancellationToken.throwIfCancellationRequested();
53102
53100
  }
@@ -59616,7 +59614,8 @@ var ts;
59616
59614
  }
59617
59615
  }
59618
59616
  }
59619
- return getIntersectionType(constraints);
59617
+ // The source types were normalized; ensure the result is normalized too.
59618
+ return getNormalizedType(getIntersectionType(constraints), /*writing*/ false);
59620
59619
  }
59621
59620
  return undefined;
59622
59621
  }
@@ -62834,21 +62833,28 @@ var ts;
62834
62833
  getFlowTypeOfReference(accessExpression, propType) :
62835
62834
  propType;
62836
62835
  }
62837
- if (everyType(objectType, isTupleType) && ts.isNumericLiteralName(propName) && +propName >= 0) {
62836
+ if (everyType(objectType, isTupleType) && ts.isNumericLiteralName(propName)) {
62837
+ var index = +propName;
62838
62838
  if (accessNode && everyType(objectType, function (t) { return !t.target.hasRestElement; }) && !(accessFlags & 16 /* NoTupleBoundsCheck */)) {
62839
62839
  var indexNode = getIndexNodeForAccessExpression(accessNode);
62840
62840
  if (isTupleType(objectType)) {
62841
+ if (index < 0) {
62842
+ error(indexNode, ts.Diagnostics.A_tuple_type_cannot_be_indexed_with_a_negative_value);
62843
+ return undefinedType;
62844
+ }
62841
62845
  error(indexNode, ts.Diagnostics.Tuple_type_0_of_length_1_has_no_element_at_index_2, typeToString(objectType), getTypeReferenceArity(objectType), ts.unescapeLeadingUnderscores(propName));
62842
62846
  }
62843
62847
  else {
62844
62848
  error(indexNode, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.unescapeLeadingUnderscores(propName), typeToString(objectType));
62845
62849
  }
62846
62850
  }
62847
- errorIfWritingToReadonlyIndex(getIndexInfoOfType(objectType, numberType));
62848
- return mapType(objectType, function (t) {
62849
- var restType = getRestTypeOfTupleType(t) || undefinedType;
62850
- return accessFlags & 1 /* IncludeUndefined */ ? getUnionType([restType, undefinedType]) : restType;
62851
- });
62851
+ if (index >= 0) {
62852
+ errorIfWritingToReadonlyIndex(getIndexInfoOfType(objectType, numberType));
62853
+ return mapType(objectType, function (t) {
62854
+ var restType = getRestTypeOfTupleType(t) || undefinedType;
62855
+ return accessFlags & 1 /* IncludeUndefined */ ? getUnionType([restType, undefinedType]) : restType;
62856
+ });
62857
+ }
62852
62858
  }
62853
62859
  }
62854
62860
  if (!(indexType.flags & 98304 /* Nullable */) && isTypeAssignableToKind(indexType, 402653316 /* StringLike */ | 296 /* NumberLike */ | 12288 /* ESSymbolLike */)) {
@@ -72142,8 +72148,12 @@ var ts;
72142
72148
  var discriminant = keyPropertyName && getTypeOfPropertyOfType(c, keyPropertyName);
72143
72149
  var matching = discriminant && getConstituentTypeForKeyType(type, discriminant);
72144
72150
  // For each constituent t in the current type, if t and and c are directly related, pick the most
72145
- // specific of the two.
72146
- var directlyRelated = mapType(matching || type, function (t) { return isRelated(t, c) ? t : isRelated(c, t) ? c : neverType; });
72151
+ // specific of the two. When t and c are related in both directions, we prefer c for type predicates
72152
+ // because that is the asserted type, but t for `instanceof` because generics aren't reflected in
72153
+ // prototype object types.
72154
+ var directlyRelated = mapType(matching || type, checkDerived ?
72155
+ function (t) { return isTypeDerivedFrom(t, c) ? t : isTypeDerivedFrom(c, t) ? c : neverType; } :
72156
+ function (t) { return isTypeSubtypeOf(c, t) ? c : isTypeSubtypeOf(t, c) ? t : neverType; });
72147
72157
  // If no constituents are directly related, create intersections for any generic constituents that
72148
72158
  // are related by constraint.
72149
72159
  return directlyRelated.flags & 131072 /* Never */ ?
@@ -84855,8 +84865,9 @@ var ts;
84855
84865
  }
84856
84866
  var indexInfos = getApplicableIndexInfos(type, propNameType);
84857
84867
  var interfaceDeclaration = ts.getObjectFlags(type) & 2 /* Interface */ ? ts.getDeclarationOfKind(type.symbol, 258 /* InterfaceDeclaration */) : undefined;
84858
- var localPropDeclaration = declaration && declaration.kind === 221 /* BinaryExpression */ ||
84859
- name && name.kind === 162 /* ComputedPropertyName */ || getParentOfSymbol(prop) === type.symbol ? declaration : undefined;
84868
+ var propDeclaration = declaration && declaration.kind === 221 /* BinaryExpression */ ||
84869
+ name && name.kind === 162 /* ComputedPropertyName */ ? declaration : undefined;
84870
+ var localPropDeclaration = getParentOfSymbol(prop) === type.symbol ? declaration : undefined;
84860
84871
  var _loop_30 = function (info) {
84861
84872
  var localIndexDeclaration = info.declaration && getParentOfSymbol(getSymbolOfNode(info.declaration)) === type.symbol ? info.declaration : undefined;
84862
84873
  // We check only when (a) the property is declared in the containing type, or (b) the applicable index signature is declared
@@ -84865,7 +84876,11 @@ var ts;
84865
84876
  var errorNode = localPropDeclaration || localIndexDeclaration ||
84866
84877
  (interfaceDeclaration && !ts.some(getBaseTypes(type), function (base) { return !!getPropertyOfObjectType(base, prop.escapedName) && !!getIndexTypeOfType(base, info.keyType); }) ? interfaceDeclaration : undefined);
84867
84878
  if (errorNode && !isTypeAssignableTo(propType, info.type)) {
84868
- error(errorNode, ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_2_index_type_3, symbolToString(prop), typeToString(propType), typeToString(info.keyType), typeToString(info.type));
84879
+ var diagnostic = createError(errorNode, ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_2_index_type_3, symbolToString(prop), typeToString(propType), typeToString(info.keyType), typeToString(info.type));
84880
+ if (propDeclaration && errorNode !== propDeclaration) {
84881
+ ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(propDeclaration, ts.Diagnostics._0_is_declared_here, symbolToString(prop)));
84882
+ }
84883
+ diagnostics.add(diagnostic);
84869
84884
  }
84870
84885
  };
84871
84886
  for (var _i = 0, indexInfos_9 = indexInfos; _i < indexInfos_9.length; _i++) {
@@ -117850,7 +117865,7 @@ var ts;
117850
117865
  return undefined;
117851
117866
  }
117852
117867
  function lookupFromPackageJson() {
117853
- var scope = ts.getPackageScopeForPath(fileName, packageJsonInfoCache, host, options);
117868
+ var scope = ts.getPackageScopeForPath(fileName, ts.getTemporaryModuleResolutionState(packageJsonInfoCache, host, options));
117854
117869
  return (scope === null || scope === void 0 ? void 0 : scope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS;
117855
117870
  }
117856
117871
  }
@@ -118516,7 +118531,7 @@ var ts;
118516
118531
  // `result[i]` is either a `ResolvedModuleFull` or a marker.
118517
118532
  // If it is the former, we can leave it as is.
118518
118533
  if (result[i] === predictedToResolveToAmbientModuleMarker) {
118519
- result[i] = undefined; // TODO: GH#18217
118534
+ result[i] = undefined;
118520
118535
  }
118521
118536
  }
118522
118537
  else {
@@ -149232,6 +149247,7 @@ var ts;
149232
149247
  var options = _a.options, getRules = _a.getRules, host = _a.host;
149233
149248
  // formatting context is used by rules provider
149234
149249
  var formattingContext = new formatting.FormattingContext(sourceFile, requestKind, options);
149250
+ var previousRangeTriviaEnd;
149235
149251
  var previousRange;
149236
149252
  var previousParent;
149237
149253
  var previousRangeStartLine;
@@ -149260,10 +149276,30 @@ var ts;
149260
149276
  }
149261
149277
  }
149262
149278
  if (previousRange && formattingScanner.getStartPos() >= originalRange.end) {
149279
+ // Formatting edits happen by looking at pairs of contiguous tokens (see `processPair`),
149280
+ // typically inserting or deleting whitespace between them. The recursive `processNode`
149281
+ // logic above bails out as soon as it encounters a token that is beyond the end of the
149282
+ // range we're supposed to format (or if we reach the end of the file). But this potentially
149283
+ // leaves out an edit that would occur *inside* the requested range but cannot be discovered
149284
+ // without looking at one token *beyond* the end of the range: consider the line `x = { }`
149285
+ // with a selection from the beginning of the line to the space inside the curly braces,
149286
+ // inclusive. We would expect a format-selection would delete the space (if rules apply),
149287
+ // but in order to do that, we need to process the pair ["{", "}"], but we stopped processing
149288
+ // just before getting there. This block handles this trailing edit.
149263
149289
  var tokenInfo = formattingScanner.isOnEOF() ? formattingScanner.readEOFTokenRange() :
149264
149290
  formattingScanner.isOnToken() ? formattingScanner.readTokenInfo(enclosingNode).token :
149265
149291
  undefined;
149266
- if (tokenInfo) {
149292
+ if (tokenInfo && tokenInfo.pos === previousRangeTriviaEnd) {
149293
+ // We need to check that tokenInfo and previousRange are contiguous: the `originalRange`
149294
+ // may have ended in the middle of a token, which means we will have stopped formatting
149295
+ // on that token, leaving `previousRange` pointing to the token before it, but already
149296
+ // having moved the formatting scanner (where we just got `tokenInfo`) to the next token.
149297
+ // If this happens, our supposed pair [previousRange, tokenInfo] actually straddles the
149298
+ // token that intersects the end of the range we're supposed to format, so the pair will
149299
+ // produce bogus edits if we try to `processPair`. Recall that the point of this logic is
149300
+ // to perform a trailing edit at the end of the selection range: but there can be no valid
149301
+ // edit in the middle of a token where the range ended, so if we have a non-contiguous
149302
+ // pair here, we're already done and we can ignore it.
149267
149303
  var parent = ((_b = ts.findPrecedingToken(tokenInfo.end, sourceFile, enclosingNode)) === null || _b === void 0 ? void 0 : _b.parent) || previousParent;
149268
149304
  processPair(tokenInfo, sourceFile.getLineAndCharacterOfPosition(tokenInfo.pos).line, parent, previousRange, previousRangeStartLine, previousParent, parent,
149269
149305
  /*dynamicIndentation*/ undefined);
@@ -149621,6 +149657,7 @@ var ts;
149621
149657
  }
149622
149658
  }
149623
149659
  if (currentTokenInfo.trailingTrivia) {
149660
+ previousRangeTriviaEnd = ts.last(currentTokenInfo.trailingTrivia).end;
149624
149661
  processTrivia(currentTokenInfo.trailingTrivia, parent, childContextNode, dynamicIndentation);
149625
149662
  }
149626
149663
  if (indentToken) {
@@ -149691,6 +149728,7 @@ var ts;
149691
149728
  }
149692
149729
  }
149693
149730
  previousRange = range;
149731
+ previousRangeTriviaEnd = range.end;
149694
149732
  previousParent = parent;
149695
149733
  previousRangeStartLine = rangeStart.line;
149696
149734
  return lineAction;
@@ -156002,8 +156040,7 @@ var ts;
156002
156040
  codefix.eachDiagnostic(context, errorCodes, function (diag) {
156003
156041
  var info = getInfo(program, diag.file, ts.createTextSpan(diag.start, diag.length));
156004
156042
  if (info) {
156005
- var id = ts.getNodeId(info.declaration) + "#" + info.token.getText();
156006
- if (ts.addToSeen(seen, id)) {
156043
+ if (ts.addToSeen(seen, ts.getNodeId(info.declaration))) {
156007
156044
  return addMissingConstraint(changes, program, preferences, host, diag.file, info);
156008
156045
  }
156009
156046
  }
@@ -159971,21 +160008,16 @@ var ts;
159971
160008
  var names = ts.map(args, function (arg) {
159972
160009
  return ts.isIdentifier(arg) ? arg.text : ts.isPropertyAccessExpression(arg) && ts.isIdentifier(arg.name) ? arg.name.text : undefined;
159973
160010
  });
159974
- var types = isJs ? [] : ts.map(args, function (arg) {
159975
- return typeToAutoImportableTypeNode(checker, importAdder, checker.getBaseTypeOfLiteralType(checker.getTypeAtLocation(arg)), contextNode, scriptTarget, /*flags*/ undefined, tracker);
159976
- });
160011
+ var instanceTypes = isJs ? [] : ts.map(args, function (arg) { return checker.getTypeAtLocation(arg); });
160012
+ var _a = getArgumentTypesAndTypeParameters(checker, importAdder, instanceTypes, contextNode, scriptTarget, /*flags*/ undefined, tracker), argumentTypeNodes = _a.argumentTypeNodes, argumentTypeParameters = _a.argumentTypeParameters;
159977
160013
  var modifiers = modifierFlags
159978
160014
  ? ts.factory.createNodeArray(ts.factory.createModifiersFromModifierFlags(modifierFlags))
159979
160015
  : undefined;
159980
160016
  var asteriskToken = ts.isYieldExpression(parent)
159981
160017
  ? ts.factory.createToken(41 /* AsteriskToken */)
159982
160018
  : undefined;
159983
- var typeParameters = isJs || typeArguments === undefined
159984
- ? undefined
159985
- : ts.map(typeArguments, function (_, i) {
159986
- return ts.factory.createTypeParameterDeclaration(/*modifiers*/ undefined, 84 /* T */ + typeArguments.length - 1 <= 90 /* Z */ ? String.fromCharCode(84 /* T */ + i) : "T" + i);
159987
- });
159988
- var parameters = createDummyParameters(args.length, names, types, /*minArgumentCount*/ undefined, isJs);
160019
+ var typeParameters = isJs ? undefined : createTypeParametersForArguments(checker, argumentTypeParameters, typeArguments);
160020
+ var parameters = createDummyParameters(args.length, names, argumentTypeNodes, /*minArgumentCount*/ undefined, isJs);
159989
160021
  var type = isJs || contextualType === undefined
159990
160022
  ? undefined
159991
160023
  : checker.typeToTypeNode(contextualType, contextNode, /*flags*/ undefined, tracker);
@@ -160003,6 +160035,23 @@ var ts;
160003
160035
  }
160004
160036
  }
160005
160037
  codefix.createSignatureDeclarationFromCallExpression = createSignatureDeclarationFromCallExpression;
160038
+ function createTypeParametersForArguments(checker, argumentTypeParameters, typeArguments) {
160039
+ var usedNames = new ts.Set(argumentTypeParameters.map(function (pair) { return pair[0]; }));
160040
+ var constraintsByName = new ts.Map(argumentTypeParameters);
160041
+ if (typeArguments) {
160042
+ var typeArgumentsWithNewTypes = typeArguments.filter(function (typeArgument) { return !argumentTypeParameters.some(function (pair) { var _a; return checker.getTypeAtLocation(typeArgument) === ((_a = pair[1]) === null || _a === void 0 ? void 0 : _a.argumentType); }); });
160043
+ var targetSize = usedNames.size + typeArgumentsWithNewTypes.length;
160044
+ for (var i = 0; usedNames.size < targetSize; i += 1) {
160045
+ usedNames.add(createTypeParameterName(i));
160046
+ }
160047
+ }
160048
+ return ts.map(ts.arrayFrom(usedNames.values()), function (usedName) { var _a; return ts.factory.createTypeParameterDeclaration(/*modifiers*/ undefined, usedName, (_a = constraintsByName.get(usedName)) === null || _a === void 0 ? void 0 : _a.constraint); });
160049
+ }
160050
+ function createTypeParameterName(index) {
160051
+ return 84 /* T */ + index <= 90 /* Z */
160052
+ ? String.fromCharCode(84 /* T */ + index)
160053
+ : "T" + index;
160054
+ }
160006
160055
  function typeToAutoImportableTypeNode(checker, importAdder, type, contextNode, scriptTarget, flags, tracker) {
160007
160056
  var typeNode = checker.typeToTypeNode(type, contextNode, flags, tracker);
160008
160057
  if (typeNode && ts.isImportTypeNode(typeNode)) {
@@ -160016,15 +160065,107 @@ var ts;
160016
160065
  return ts.getSynthesizedDeepClone(typeNode);
160017
160066
  }
160018
160067
  codefix.typeToAutoImportableTypeNode = typeToAutoImportableTypeNode;
160068
+ function typeContainsTypeParameter(type) {
160069
+ if (type.isUnionOrIntersection()) {
160070
+ return type.types.some(typeContainsTypeParameter);
160071
+ }
160072
+ return type.flags & 262144 /* TypeParameter */;
160073
+ }
160074
+ function getArgumentTypesAndTypeParameters(checker, importAdder, instanceTypes, contextNode, scriptTarget, flags, tracker) {
160075
+ // Types to be used as the types of the parameters in the new function
160076
+ // E.g. from this source:
160077
+ // added("", 0)
160078
+ // The value will look like:
160079
+ // [{ typeName: { text: "string" } }, { typeName: { text: "number" }]
160080
+ // And in the output function will generate:
160081
+ // function added(a: string, b: number) { ... }
160082
+ var argumentTypeNodes = [];
160083
+ // Names of type parameters provided as arguments to the call
160084
+ // E.g. from this source:
160085
+ // added<T, U>(value);
160086
+ // The value will look like:
160087
+ // [
160088
+ // ["T", { argumentType: { typeName: { text: "T" } } } ],
160089
+ // ["U", { argumentType: { typeName: { text: "U" } } } ],
160090
+ // ]
160091
+ // And in the output function will generate:
160092
+ // function added<T, U>() { ... }
160093
+ var argumentTypeParameters = new ts.Map();
160094
+ for (var i = 0; i < instanceTypes.length; i += 1) {
160095
+ var instanceType = instanceTypes[i];
160096
+ // If the instance type contains a deep reference to an existing type parameter,
160097
+ // instead of copying the full union or intersection, create a new type parameter
160098
+ // E.g. from this source:
160099
+ // function existing<T, U>(value: T | U & string) {
160100
+ // added/*1*/(value);
160101
+ // We don't want to output this:
160102
+ // function added<T>(value: T | U & string) { ... }
160103
+ // We instead want to output:
160104
+ // function added<T>(value: T) { ... }
160105
+ if (instanceType.isUnionOrIntersection() && instanceType.types.some(typeContainsTypeParameter)) {
160106
+ var synthesizedTypeParameterName = createTypeParameterName(i);
160107
+ argumentTypeNodes.push(ts.factory.createTypeReferenceNode(synthesizedTypeParameterName));
160108
+ argumentTypeParameters.set(synthesizedTypeParameterName, undefined);
160109
+ continue;
160110
+ }
160111
+ // Widen the type so we don't emit nonsense annotations like "function fn(x: 3) {"
160112
+ var widenedInstanceType = checker.getBaseTypeOfLiteralType(instanceType);
160113
+ var argumentTypeNode = typeToAutoImportableTypeNode(checker, importAdder, widenedInstanceType, contextNode, scriptTarget, flags, tracker);
160114
+ if (!argumentTypeNode) {
160115
+ continue;
160116
+ }
160117
+ argumentTypeNodes.push(argumentTypeNode);
160118
+ var argumentTypeParameter = getFirstTypeParameterName(instanceType);
160119
+ // If the instance type is a type parameter with a constraint (other than an anonymous object),
160120
+ // remember that constraint for when we create the new type parameter
160121
+ // E.g. from this source:
160122
+ // function existing<T extends string>(value: T) {
160123
+ // added/*1*/(value);
160124
+ // We don't want to output this:
160125
+ // function added<T>(value: T) { ... }
160126
+ // We instead want to output:
160127
+ // function added<T extends string>(value: T) { ... }
160128
+ var instanceTypeConstraint = instanceType.isTypeParameter() && instanceType.constraint && !isAnonymousObjectConstraintType(instanceType.constraint)
160129
+ ? typeToAutoImportableTypeNode(checker, importAdder, instanceType.constraint, contextNode, scriptTarget, flags, tracker)
160130
+ : undefined;
160131
+ if (argumentTypeParameter) {
160132
+ argumentTypeParameters.set(argumentTypeParameter, { argumentType: instanceType, constraint: instanceTypeConstraint });
160133
+ }
160134
+ }
160135
+ return { argumentTypeNodes: argumentTypeNodes, argumentTypeParameters: ts.arrayFrom(argumentTypeParameters.entries()) };
160136
+ }
160137
+ codefix.getArgumentTypesAndTypeParameters = getArgumentTypesAndTypeParameters;
160138
+ function isAnonymousObjectConstraintType(type) {
160139
+ return (type.flags & 524288 /* Object */) && type.objectFlags === 16 /* Anonymous */;
160140
+ }
160141
+ function getFirstTypeParameterName(type) {
160142
+ var _a;
160143
+ if (type.flags & (1048576 /* Union */ | 2097152 /* Intersection */)) {
160144
+ for (var _i = 0, _b = type.types; _i < _b.length; _i++) {
160145
+ var subType = _b[_i];
160146
+ var subTypeName = getFirstTypeParameterName(subType);
160147
+ if (subTypeName) {
160148
+ return subTypeName;
160149
+ }
160150
+ }
160151
+ }
160152
+ return type.flags & 262144 /* TypeParameter */
160153
+ ? (_a = type.getSymbol()) === null || _a === void 0 ? void 0 : _a.getName()
160154
+ : undefined;
160155
+ }
160019
160156
  function createDummyParameters(argCount, names, types, minArgumentCount, inJs) {
160020
160157
  var parameters = [];
160158
+ var parameterNameCounts = new ts.Map();
160021
160159
  for (var i = 0; i < argCount; i++) {
160160
+ var parameterName = (names === null || names === void 0 ? void 0 : names[i]) || "arg" + i;
160161
+ var parameterNameCount = parameterNameCounts.get(parameterName);
160162
+ parameterNameCounts.set(parameterName, (parameterNameCount || 0) + 1);
160022
160163
  var newParameter = ts.factory.createParameterDeclaration(
160023
160164
  /*modifiers*/ undefined,
160024
160165
  /*dotDotDotToken*/ undefined,
160025
- /*name*/ names && names[i] || "arg" + i,
160166
+ /*name*/ parameterName + (parameterNameCount || ""),
160026
160167
  /*questionToken*/ minArgumentCount !== undefined && i >= minArgumentCount ? ts.factory.createToken(57 /* QuestionToken */) : undefined,
160027
- /*type*/ inJs ? undefined : types && types[i] || ts.factory.createKeywordTypeNode(155 /* UnknownKeyword */),
160168
+ /*type*/ inJs ? undefined : (types === null || types === void 0 ? void 0 : types[i]) || ts.factory.createKeywordTypeNode(155 /* UnknownKeyword */),
160028
160169
  /*initializer*/ undefined);
160029
160170
  parameters.push(newParameter);
160030
160171
  }
@@ -164156,7 +164297,7 @@ var ts;
164156
164297
  var usage = getUsageInfo(oldFile, toMove.all, checker);
164157
164298
  var currentDirectory = ts.getDirectoryPath(oldFile.fileName);
164158
164299
  var extension = ts.extensionFromPath(oldFile.fileName);
164159
- var newModuleName = makeUniqueModuleName(getNewModuleName(usage.movedSymbols), extension, currentDirectory, host);
164300
+ var newModuleName = makeUniqueModuleName(getNewModuleName(usage.oldFileImportsFromNewFile, usage.movedSymbols), extension, currentDirectory, host);
164160
164301
  var newFileNameWithExtension = newModuleName + extension;
164161
164302
  // If previous file was global, this is easy.
164162
164303
  changes.createNewFile(oldFile, ts.combinePaths(currentDirectory, newFileNameWithExtension), getNewStatementsAndRemoveFromOldFile(oldFile, usage, changes, toMove, program, newModuleName, preferences));
@@ -164520,8 +164661,8 @@ var ts;
164520
164661
  newModuleName = moduleName + "." + i;
164521
164662
  }
164522
164663
  }
164523
- function getNewModuleName(movedSymbols) {
164524
- return movedSymbols.forEachEntry(ts.symbolNameNoDefault) || "newFile";
164664
+ function getNewModuleName(importsFromNewFile, movedSymbols) {
164665
+ return importsFromNewFile.forEachEntry(ts.symbolNameNoDefault) || movedSymbols.forEachEntry(ts.symbolNameNoDefault) || "newFile";
164525
164666
  }
164526
164667
  function getUsageInfo(oldFile, toMove, checker) {
164527
164668
  var movedSymbols = new SymbolSet();
@@ -178518,7 +178659,7 @@ var ts;
178518
178659
  var packageDirectory = fileName.substring(0, nodeModulesPathParts.packageRootIndex);
178519
178660
  var packageJsonCache = (_a = project.getModuleResolutionCache()) === null || _a === void 0 ? void 0 : _a.getPackageJsonInfoCache();
178520
178661
  var compilerOptions = project.getCompilationSettings();
178521
- var packageJson = ts.getPackageScopeForPath(project.toPath(packageDirectory + "/package.json"), packageJsonCache, project, compilerOptions);
178662
+ var packageJson = ts.getPackageScopeForPath(project.toPath(packageDirectory + "/package.json"), ts.getTemporaryModuleResolutionState(packageJsonCache, project, compilerOptions));
178522
178663
  if (!packageJson)
178523
178664
  return undefined;
178524
178665
  // Use fake options instead of actual compiler options to avoid following export map if the project uses node16 or nodenext -