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.
package/lib/tsserver.js CHANGED
@@ -109,7 +109,7 @@ var ts;
109
109
  // The following is baselined as a literal template type without intervention
110
110
  /** The version of the TypeScript compiler release */
111
111
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
112
- ts.version = ts.versionMajorMinor + ".0-dev.20220726";
112
+ ts.version = ts.versionMajorMinor + ".0-dev.20220729";
113
113
  /* @internal */
114
114
  var Comparison;
115
115
  (function (Comparison) {
@@ -1710,6 +1710,10 @@ var ts;
1710
1710
  /** Does nothing. */
1711
1711
  function noop(_) { }
1712
1712
  ts.noop = noop;
1713
+ ts.noopPush = {
1714
+ push: noop,
1715
+ length: 0
1716
+ };
1713
1717
  /** Do nothing and return false */
1714
1718
  function returnFalse() {
1715
1719
  return false;
@@ -8577,6 +8581,7 @@ var ts;
8577
8581
  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."),
8578
8582
  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."),
8579
8583
  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."),
8584
+ Identifier_or_string_literal_expected: diag(1478, ts.DiagnosticCategory.Error, "Identifier_or_string_literal_expected_1478", "Identifier or string literal expected."),
8580
8585
  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."),
8581
8586
  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."),
8582
8587
  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),
@@ -8790,6 +8795,7 @@ var ts;
8790
8795
  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."),
8791
8796
  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."),
8792
8797
  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."),
8798
+ 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."),
8793
8799
  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}'."),
8794
8800
  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."),
8795
8801
  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."),
@@ -33316,7 +33322,9 @@ var ts;
33316
33322
  case 23 /* ImportOrExportSpecifiers */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
33317
33323
  case 13 /* JsxAttributes */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
33318
33324
  case 14 /* JsxChildren */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
33319
- default: return [undefined]; // TODO: GH#18217 `default: Debug.assertNever(context);`
33325
+ case 24 /* AssertEntries */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_or_string_literal_expected); // AssertionKey.
33326
+ case 25 /* Count */: return ts.Debug.fail("ParsingContext.Count used as a context"); // Not a real context, only a marker.
33327
+ default: ts.Debug.assertNever(context);
33320
33328
  }
33321
33329
  }
33322
33330
  function parseDelimitedList(kind, parseElement, considerSemicolonAsDelimiter) {
@@ -43142,18 +43150,7 @@ var ts;
43142
43150
  * Does not try `@types/${packageName}` - use a second pass if needed.
43143
43151
  */
43144
43152
  function resolvePackageNameToPackageJson(packageName, containingDirectory, options, host, cache) {
43145
- var moduleResolutionState = {
43146
- compilerOptions: options,
43147
- host: host,
43148
- traceEnabled: isTraceEnabled(options, host),
43149
- failedLookupLocations: [],
43150
- affectingLocations: [],
43151
- packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
43152
- conditions: ts.emptyArray,
43153
- features: NodeResolutionFeatures.None,
43154
- requestContainingDirectory: containingDirectory,
43155
- reportDiagnostic: ts.noop
43156
- };
43153
+ var moduleResolutionState = getTemporaryModuleResolutionState(cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(), host, options);
43157
43154
  return ts.forEachAncestorDirectory(containingDirectory, function (ancestorDirectory) {
43158
43155
  if (ts.getBaseFileName(ancestorDirectory) !== "node_modules") {
43159
43156
  var nodeModulesFolder = ts.combinePaths(ancestorDirectory, "node_modules");
@@ -44113,18 +44110,9 @@ var ts;
44113
44110
  var entrypoints;
44114
44111
  var extensions = resolveJs ? Extensions.JavaScript : Extensions.TypeScript;
44115
44112
  var features = getDefaultNodeResolutionFeatures(options);
44116
- var requireState = {
44117
- compilerOptions: options,
44118
- host: host,
44119
- traceEnabled: isTraceEnabled(options, host),
44120
- failedLookupLocations: [],
44121
- affectingLocations: [],
44122
- packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
44123
- conditions: ["node", "require", "types"],
44124
- features: features,
44125
- requestContainingDirectory: packageJsonInfo.packageDirectory,
44126
- reportDiagnostic: ts.noop
44127
- };
44113
+ var requireState = getTemporaryModuleResolutionState(cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(), host, options);
44114
+ requireState.conditions = ["node", "require", "types"];
44115
+ requireState.requestContainingDirectory = packageJsonInfo.packageDirectory;
44128
44116
  var requireResolution = loadNodeModuleFromDirectoryWorker(extensions, packageJsonInfo.packageDirectory,
44129
44117
  /*onlyRecordFailures*/ false, requireState, packageJsonInfo.packageJsonContent, packageJsonInfo.versionPaths);
44130
44118
  entrypoints = ts.append(entrypoints, requireResolution === null || requireResolution === void 0 ? void 0 : requireResolution.path);
@@ -44197,23 +44185,27 @@ var ts;
44197
44185
  }
44198
44186
  }
44199
44187
  }
44200
- /**
44201
- * A function for locating the package.json scope for a given path
44202
- */
44203
44188
  /*@internal*/
44204
- function getPackageScopeForPath(fileName, packageJsonInfoCache, host, options) {
44205
- var state = {
44189
+ function getTemporaryModuleResolutionState(packageJsonInfoCache, host, options) {
44190
+ return {
44206
44191
  host: host,
44207
44192
  compilerOptions: options,
44208
44193
  traceEnabled: isTraceEnabled(options, host),
44209
- failedLookupLocations: [],
44210
- affectingLocations: [],
44194
+ failedLookupLocations: ts.noopPush,
44195
+ affectingLocations: ts.noopPush,
44211
44196
  packageJsonInfoCache: packageJsonInfoCache,
44212
- features: 0,
44213
- conditions: [],
44197
+ features: NodeResolutionFeatures.None,
44198
+ conditions: ts.emptyArray,
44214
44199
  requestContainingDirectory: undefined,
44215
44200
  reportDiagnostic: ts.noop
44216
44201
  };
44202
+ }
44203
+ ts.getTemporaryModuleResolutionState = getTemporaryModuleResolutionState;
44204
+ /**
44205
+ * A function for locating the package.json scope for a given path
44206
+ */
44207
+ /*@internal*/
44208
+ function getPackageScopeForPath(fileName, state) {
44217
44209
  var parts = ts.getPathComponents(fileName);
44218
44210
  parts.pop();
44219
44211
  while (parts.length > 0) {
@@ -44384,7 +44376,7 @@ var ts;
44384
44376
  var _a, _b;
44385
44377
  var useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames;
44386
44378
  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));
44387
- var scope = getPackageScopeForPath(directoryPath, state.packageJsonInfoCache, state.host, state.compilerOptions);
44379
+ var scope = getPackageScopeForPath(directoryPath, state);
44388
44380
  if (!scope || !scope.packageJsonContent.exports) {
44389
44381
  return undefined;
44390
44382
  }
@@ -44443,7 +44435,7 @@ var ts;
44443
44435
  }
44444
44436
  var useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames;
44445
44437
  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));
44446
- var scope = getPackageScopeForPath(directoryPath, state.packageJsonInfoCache, state.host, state.compilerOptions);
44438
+ var scope = getPackageScopeForPath(directoryPath, state);
44447
44439
  if (!scope) {
44448
44440
  if (state.traceEnabled) {
44449
44441
  trace(state.host, ts.Diagnostics.Directory_0_has_no_containing_package_json_scope_Imports_will_not_resolve, directoryPath);
@@ -52903,6 +52895,12 @@ var ts;
52903
52895
  return context.truncating = context.approximateLength > ((context.flags & 1 /* NoTruncation */) ? ts.noTruncationMaximumTruncationLength : ts.defaultMaximumTruncationLength);
52904
52896
  }
52905
52897
  function typeToTypeNodeHelper(type, context) {
52898
+ var savedFlags = context.flags;
52899
+ var typeNode = typeToTypeNodeWorker(type, context);
52900
+ context.flags = savedFlags;
52901
+ return typeNode;
52902
+ }
52903
+ function typeToTypeNodeWorker(type, context) {
52906
52904
  if (cancellationToken && cancellationToken.throwIfCancellationRequested) {
52907
52905
  cancellationToken.throwIfCancellationRequested();
52908
52906
  }
@@ -59422,7 +59420,8 @@ var ts;
59422
59420
  }
59423
59421
  }
59424
59422
  }
59425
- return getIntersectionType(constraints);
59423
+ // The source types were normalized; ensure the result is normalized too.
59424
+ return getNormalizedType(getIntersectionType(constraints), /*writing*/ false);
59426
59425
  }
59427
59426
  return undefined;
59428
59427
  }
@@ -62640,21 +62639,28 @@ var ts;
62640
62639
  getFlowTypeOfReference(accessExpression, propType) :
62641
62640
  propType;
62642
62641
  }
62643
- if (everyType(objectType, isTupleType) && ts.isNumericLiteralName(propName) && +propName >= 0) {
62642
+ if (everyType(objectType, isTupleType) && ts.isNumericLiteralName(propName)) {
62643
+ var index = +propName;
62644
62644
  if (accessNode && everyType(objectType, function (t) { return !t.target.hasRestElement; }) && !(accessFlags & 16 /* NoTupleBoundsCheck */)) {
62645
62645
  var indexNode = getIndexNodeForAccessExpression(accessNode);
62646
62646
  if (isTupleType(objectType)) {
62647
+ if (index < 0) {
62648
+ error(indexNode, ts.Diagnostics.A_tuple_type_cannot_be_indexed_with_a_negative_value);
62649
+ return undefinedType;
62650
+ }
62647
62651
  error(indexNode, ts.Diagnostics.Tuple_type_0_of_length_1_has_no_element_at_index_2, typeToString(objectType), getTypeReferenceArity(objectType), ts.unescapeLeadingUnderscores(propName));
62648
62652
  }
62649
62653
  else {
62650
62654
  error(indexNode, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.unescapeLeadingUnderscores(propName), typeToString(objectType));
62651
62655
  }
62652
62656
  }
62653
- errorIfWritingToReadonlyIndex(getIndexInfoOfType(objectType, numberType));
62654
- return mapType(objectType, function (t) {
62655
- var restType = getRestTypeOfTupleType(t) || undefinedType;
62656
- return accessFlags & 1 /* IncludeUndefined */ ? getUnionType([restType, undefinedType]) : restType;
62657
- });
62657
+ if (index >= 0) {
62658
+ errorIfWritingToReadonlyIndex(getIndexInfoOfType(objectType, numberType));
62659
+ return mapType(objectType, function (t) {
62660
+ var restType = getRestTypeOfTupleType(t) || undefinedType;
62661
+ return accessFlags & 1 /* IncludeUndefined */ ? getUnionType([restType, undefinedType]) : restType;
62662
+ });
62663
+ }
62658
62664
  }
62659
62665
  }
62660
62666
  if (!(indexType.flags & 98304 /* Nullable */) && isTypeAssignableToKind(indexType, 402653316 /* StringLike */ | 296 /* NumberLike */ | 12288 /* ESSymbolLike */)) {
@@ -71948,8 +71954,12 @@ var ts;
71948
71954
  var discriminant = keyPropertyName && getTypeOfPropertyOfType(c, keyPropertyName);
71949
71955
  var matching = discriminant && getConstituentTypeForKeyType(type, discriminant);
71950
71956
  // For each constituent t in the current type, if t and and c are directly related, pick the most
71951
- // specific of the two.
71952
- var directlyRelated = mapType(matching || type, function (t) { return isRelated(t, c) ? t : isRelated(c, t) ? c : neverType; });
71957
+ // specific of the two. When t and c are related in both directions, we prefer c for type predicates
71958
+ // because that is the asserted type, but t for `instanceof` because generics aren't reflected in
71959
+ // prototype object types.
71960
+ var directlyRelated = mapType(matching || type, checkDerived ?
71961
+ function (t) { return isTypeDerivedFrom(t, c) ? t : isTypeDerivedFrom(c, t) ? c : neverType; } :
71962
+ function (t) { return isTypeSubtypeOf(c, t) ? c : isTypeSubtypeOf(t, c) ? t : neverType; });
71953
71963
  // If no constituents are directly related, create intersections for any generic constituents that
71954
71964
  // are related by constraint.
71955
71965
  return directlyRelated.flags & 131072 /* Never */ ?
@@ -84661,8 +84671,9 @@ var ts;
84661
84671
  }
84662
84672
  var indexInfos = getApplicableIndexInfos(type, propNameType);
84663
84673
  var interfaceDeclaration = ts.getObjectFlags(type) & 2 /* Interface */ ? ts.getDeclarationOfKind(type.symbol, 258 /* InterfaceDeclaration */) : undefined;
84664
- var localPropDeclaration = declaration && declaration.kind === 221 /* BinaryExpression */ ||
84665
- name && name.kind === 162 /* ComputedPropertyName */ || getParentOfSymbol(prop) === type.symbol ? declaration : undefined;
84674
+ var propDeclaration = declaration && declaration.kind === 221 /* BinaryExpression */ ||
84675
+ name && name.kind === 162 /* ComputedPropertyName */ ? declaration : undefined;
84676
+ var localPropDeclaration = getParentOfSymbol(prop) === type.symbol ? declaration : undefined;
84666
84677
  var _loop_30 = function (info) {
84667
84678
  var localIndexDeclaration = info.declaration && getParentOfSymbol(getSymbolOfNode(info.declaration)) === type.symbol ? info.declaration : undefined;
84668
84679
  // We check only when (a) the property is declared in the containing type, or (b) the applicable index signature is declared
@@ -84671,7 +84682,11 @@ var ts;
84671
84682
  var errorNode = localPropDeclaration || localIndexDeclaration ||
84672
84683
  (interfaceDeclaration && !ts.some(getBaseTypes(type), function (base) { return !!getPropertyOfObjectType(base, prop.escapedName) && !!getIndexTypeOfType(base, info.keyType); }) ? interfaceDeclaration : undefined);
84673
84684
  if (errorNode && !isTypeAssignableTo(propType, info.type)) {
84674
- 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));
84685
+ 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));
84686
+ if (propDeclaration && errorNode !== propDeclaration) {
84687
+ ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(propDeclaration, ts.Diagnostics._0_is_declared_here, symbolToString(prop)));
84688
+ }
84689
+ diagnostics.add(diagnostic);
84675
84690
  }
84676
84691
  };
84677
84692
  for (var _i = 0, indexInfos_9 = indexInfos; _i < indexInfos_9.length; _i++) {
@@ -117656,7 +117671,7 @@ var ts;
117656
117671
  return undefined;
117657
117672
  }
117658
117673
  function lookupFromPackageJson() {
117659
- var scope = ts.getPackageScopeForPath(fileName, packageJsonInfoCache, host, options);
117674
+ var scope = ts.getPackageScopeForPath(fileName, ts.getTemporaryModuleResolutionState(packageJsonInfoCache, host, options));
117660
117675
  return (scope === null || scope === void 0 ? void 0 : scope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS;
117661
117676
  }
117662
117677
  }
@@ -118322,7 +118337,7 @@ var ts;
118322
118337
  // `result[i]` is either a `ResolvedModuleFull` or a marker.
118323
118338
  // If it is the former, we can leave it as is.
118324
118339
  if (result[i] === predictedToResolveToAmbientModuleMarker) {
118325
- result[i] = undefined; // TODO: GH#18217
118340
+ result[i] = undefined;
118326
118341
  }
118327
118342
  }
118328
118343
  else {
@@ -148619,6 +148634,7 @@ var ts;
148619
148634
  var options = _a.options, getRules = _a.getRules, host = _a.host;
148620
148635
  // formatting context is used by rules provider
148621
148636
  var formattingContext = new formatting.FormattingContext(sourceFile, requestKind, options);
148637
+ var previousRangeTriviaEnd;
148622
148638
  var previousRange;
148623
148639
  var previousParent;
148624
148640
  var previousRangeStartLine;
@@ -148647,10 +148663,30 @@ var ts;
148647
148663
  }
148648
148664
  }
148649
148665
  if (previousRange && formattingScanner.getStartPos() >= originalRange.end) {
148666
+ // Formatting edits happen by looking at pairs of contiguous tokens (see `processPair`),
148667
+ // typically inserting or deleting whitespace between them. The recursive `processNode`
148668
+ // logic above bails out as soon as it encounters a token that is beyond the end of the
148669
+ // range we're supposed to format (or if we reach the end of the file). But this potentially
148670
+ // leaves out an edit that would occur *inside* the requested range but cannot be discovered
148671
+ // without looking at one token *beyond* the end of the range: consider the line `x = { }`
148672
+ // with a selection from the beginning of the line to the space inside the curly braces,
148673
+ // inclusive. We would expect a format-selection would delete the space (if rules apply),
148674
+ // but in order to do that, we need to process the pair ["{", "}"], but we stopped processing
148675
+ // just before getting there. This block handles this trailing edit.
148650
148676
  var tokenInfo = formattingScanner.isOnEOF() ? formattingScanner.readEOFTokenRange() :
148651
148677
  formattingScanner.isOnToken() ? formattingScanner.readTokenInfo(enclosingNode).token :
148652
148678
  undefined;
148653
- if (tokenInfo) {
148679
+ if (tokenInfo && tokenInfo.pos === previousRangeTriviaEnd) {
148680
+ // We need to check that tokenInfo and previousRange are contiguous: the `originalRange`
148681
+ // may have ended in the middle of a token, which means we will have stopped formatting
148682
+ // on that token, leaving `previousRange` pointing to the token before it, but already
148683
+ // having moved the formatting scanner (where we just got `tokenInfo`) to the next token.
148684
+ // If this happens, our supposed pair [previousRange, tokenInfo] actually straddles the
148685
+ // token that intersects the end of the range we're supposed to format, so the pair will
148686
+ // produce bogus edits if we try to `processPair`. Recall that the point of this logic is
148687
+ // to perform a trailing edit at the end of the selection range: but there can be no valid
148688
+ // edit in the middle of a token where the range ended, so if we have a non-contiguous
148689
+ // pair here, we're already done and we can ignore it.
148654
148690
  var parent = ((_b = ts.findPrecedingToken(tokenInfo.end, sourceFile, enclosingNode)) === null || _b === void 0 ? void 0 : _b.parent) || previousParent;
148655
148691
  processPair(tokenInfo, sourceFile.getLineAndCharacterOfPosition(tokenInfo.pos).line, parent, previousRange, previousRangeStartLine, previousParent, parent,
148656
148692
  /*dynamicIndentation*/ undefined);
@@ -149008,6 +149044,7 @@ var ts;
149008
149044
  }
149009
149045
  }
149010
149046
  if (currentTokenInfo.trailingTrivia) {
149047
+ previousRangeTriviaEnd = ts.last(currentTokenInfo.trailingTrivia).end;
149011
149048
  processTrivia(currentTokenInfo.trailingTrivia, parent, childContextNode, dynamicIndentation);
149012
149049
  }
149013
149050
  if (indentToken) {
@@ -149078,6 +149115,7 @@ var ts;
149078
149115
  }
149079
149116
  }
149080
149117
  previousRange = range;
149118
+ previousRangeTriviaEnd = range.end;
149081
149119
  previousParent = parent;
149082
149120
  previousRangeStartLine = rangeStart.line;
149083
149121
  return lineAction;
@@ -155389,8 +155427,7 @@ var ts;
155389
155427
  codefix.eachDiagnostic(context, errorCodes, function (diag) {
155390
155428
  var info = getInfo(program, diag.file, ts.createTextSpan(diag.start, diag.length));
155391
155429
  if (info) {
155392
- var id = ts.getNodeId(info.declaration) + "#" + info.token.getText();
155393
- if (ts.addToSeen(seen, id)) {
155430
+ if (ts.addToSeen(seen, ts.getNodeId(info.declaration))) {
155394
155431
  return addMissingConstraint(changes, program, preferences, host, diag.file, info);
155395
155432
  }
155396
155433
  }
@@ -159358,21 +159395,16 @@ var ts;
159358
159395
  var names = ts.map(args, function (arg) {
159359
159396
  return ts.isIdentifier(arg) ? arg.text : ts.isPropertyAccessExpression(arg) && ts.isIdentifier(arg.name) ? arg.name.text : undefined;
159360
159397
  });
159361
- var types = isJs ? [] : ts.map(args, function (arg) {
159362
- return typeToAutoImportableTypeNode(checker, importAdder, checker.getBaseTypeOfLiteralType(checker.getTypeAtLocation(arg)), contextNode, scriptTarget, /*flags*/ undefined, tracker);
159363
- });
159398
+ var instanceTypes = isJs ? [] : ts.map(args, function (arg) { return checker.getTypeAtLocation(arg); });
159399
+ var _a = getArgumentTypesAndTypeParameters(checker, importAdder, instanceTypes, contextNode, scriptTarget, /*flags*/ undefined, tracker), argumentTypeNodes = _a.argumentTypeNodes, argumentTypeParameters = _a.argumentTypeParameters;
159364
159400
  var modifiers = modifierFlags
159365
159401
  ? ts.factory.createNodeArray(ts.factory.createModifiersFromModifierFlags(modifierFlags))
159366
159402
  : undefined;
159367
159403
  var asteriskToken = ts.isYieldExpression(parent)
159368
159404
  ? ts.factory.createToken(41 /* AsteriskToken */)
159369
159405
  : undefined;
159370
- var typeParameters = isJs || typeArguments === undefined
159371
- ? undefined
159372
- : ts.map(typeArguments, function (_, i) {
159373
- return ts.factory.createTypeParameterDeclaration(/*modifiers*/ undefined, 84 /* T */ + typeArguments.length - 1 <= 90 /* Z */ ? String.fromCharCode(84 /* T */ + i) : "T" + i);
159374
- });
159375
- var parameters = createDummyParameters(args.length, names, types, /*minArgumentCount*/ undefined, isJs);
159406
+ var typeParameters = isJs ? undefined : createTypeParametersForArguments(checker, argumentTypeParameters, typeArguments);
159407
+ var parameters = createDummyParameters(args.length, names, argumentTypeNodes, /*minArgumentCount*/ undefined, isJs);
159376
159408
  var type = isJs || contextualType === undefined
159377
159409
  ? undefined
159378
159410
  : checker.typeToTypeNode(contextualType, contextNode, /*flags*/ undefined, tracker);
@@ -159390,6 +159422,23 @@ var ts;
159390
159422
  }
159391
159423
  }
159392
159424
  codefix.createSignatureDeclarationFromCallExpression = createSignatureDeclarationFromCallExpression;
159425
+ function createTypeParametersForArguments(checker, argumentTypeParameters, typeArguments) {
159426
+ var usedNames = new ts.Set(argumentTypeParameters.map(function (pair) { return pair[0]; }));
159427
+ var constraintsByName = new ts.Map(argumentTypeParameters);
159428
+ if (typeArguments) {
159429
+ 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); }); });
159430
+ var targetSize = usedNames.size + typeArgumentsWithNewTypes.length;
159431
+ for (var i = 0; usedNames.size < targetSize; i += 1) {
159432
+ usedNames.add(createTypeParameterName(i));
159433
+ }
159434
+ }
159435
+ 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); });
159436
+ }
159437
+ function createTypeParameterName(index) {
159438
+ return 84 /* T */ + index <= 90 /* Z */
159439
+ ? String.fromCharCode(84 /* T */ + index)
159440
+ : "T" + index;
159441
+ }
159393
159442
  function typeToAutoImportableTypeNode(checker, importAdder, type, contextNode, scriptTarget, flags, tracker) {
159394
159443
  var typeNode = checker.typeToTypeNode(type, contextNode, flags, tracker);
159395
159444
  if (typeNode && ts.isImportTypeNode(typeNode)) {
@@ -159403,15 +159452,107 @@ var ts;
159403
159452
  return ts.getSynthesizedDeepClone(typeNode);
159404
159453
  }
159405
159454
  codefix.typeToAutoImportableTypeNode = typeToAutoImportableTypeNode;
159455
+ function typeContainsTypeParameter(type) {
159456
+ if (type.isUnionOrIntersection()) {
159457
+ return type.types.some(typeContainsTypeParameter);
159458
+ }
159459
+ return type.flags & 262144 /* TypeParameter */;
159460
+ }
159461
+ function getArgumentTypesAndTypeParameters(checker, importAdder, instanceTypes, contextNode, scriptTarget, flags, tracker) {
159462
+ // Types to be used as the types of the parameters in the new function
159463
+ // E.g. from this source:
159464
+ // added("", 0)
159465
+ // The value will look like:
159466
+ // [{ typeName: { text: "string" } }, { typeName: { text: "number" }]
159467
+ // And in the output function will generate:
159468
+ // function added(a: string, b: number) { ... }
159469
+ var argumentTypeNodes = [];
159470
+ // Names of type parameters provided as arguments to the call
159471
+ // E.g. from this source:
159472
+ // added<T, U>(value);
159473
+ // The value will look like:
159474
+ // [
159475
+ // ["T", { argumentType: { typeName: { text: "T" } } } ],
159476
+ // ["U", { argumentType: { typeName: { text: "U" } } } ],
159477
+ // ]
159478
+ // And in the output function will generate:
159479
+ // function added<T, U>() { ... }
159480
+ var argumentTypeParameters = new ts.Map();
159481
+ for (var i = 0; i < instanceTypes.length; i += 1) {
159482
+ var instanceType = instanceTypes[i];
159483
+ // If the instance type contains a deep reference to an existing type parameter,
159484
+ // instead of copying the full union or intersection, create a new type parameter
159485
+ // E.g. from this source:
159486
+ // function existing<T, U>(value: T | U & string) {
159487
+ // added/*1*/(value);
159488
+ // We don't want to output this:
159489
+ // function added<T>(value: T | U & string) { ... }
159490
+ // We instead want to output:
159491
+ // function added<T>(value: T) { ... }
159492
+ if (instanceType.isUnionOrIntersection() && instanceType.types.some(typeContainsTypeParameter)) {
159493
+ var synthesizedTypeParameterName = createTypeParameterName(i);
159494
+ argumentTypeNodes.push(ts.factory.createTypeReferenceNode(synthesizedTypeParameterName));
159495
+ argumentTypeParameters.set(synthesizedTypeParameterName, undefined);
159496
+ continue;
159497
+ }
159498
+ // Widen the type so we don't emit nonsense annotations like "function fn(x: 3) {"
159499
+ var widenedInstanceType = checker.getBaseTypeOfLiteralType(instanceType);
159500
+ var argumentTypeNode = typeToAutoImportableTypeNode(checker, importAdder, widenedInstanceType, contextNode, scriptTarget, flags, tracker);
159501
+ if (!argumentTypeNode) {
159502
+ continue;
159503
+ }
159504
+ argumentTypeNodes.push(argumentTypeNode);
159505
+ var argumentTypeParameter = getFirstTypeParameterName(instanceType);
159506
+ // If the instance type is a type parameter with a constraint (other than an anonymous object),
159507
+ // remember that constraint for when we create the new type parameter
159508
+ // E.g. from this source:
159509
+ // function existing<T extends string>(value: T) {
159510
+ // added/*1*/(value);
159511
+ // We don't want to output this:
159512
+ // function added<T>(value: T) { ... }
159513
+ // We instead want to output:
159514
+ // function added<T extends string>(value: T) { ... }
159515
+ var instanceTypeConstraint = instanceType.isTypeParameter() && instanceType.constraint && !isAnonymousObjectConstraintType(instanceType.constraint)
159516
+ ? typeToAutoImportableTypeNode(checker, importAdder, instanceType.constraint, contextNode, scriptTarget, flags, tracker)
159517
+ : undefined;
159518
+ if (argumentTypeParameter) {
159519
+ argumentTypeParameters.set(argumentTypeParameter, { argumentType: instanceType, constraint: instanceTypeConstraint });
159520
+ }
159521
+ }
159522
+ return { argumentTypeNodes: argumentTypeNodes, argumentTypeParameters: ts.arrayFrom(argumentTypeParameters.entries()) };
159523
+ }
159524
+ codefix.getArgumentTypesAndTypeParameters = getArgumentTypesAndTypeParameters;
159525
+ function isAnonymousObjectConstraintType(type) {
159526
+ return (type.flags & 524288 /* Object */) && type.objectFlags === 16 /* Anonymous */;
159527
+ }
159528
+ function getFirstTypeParameterName(type) {
159529
+ var _a;
159530
+ if (type.flags & (1048576 /* Union */ | 2097152 /* Intersection */)) {
159531
+ for (var _i = 0, _b = type.types; _i < _b.length; _i++) {
159532
+ var subType = _b[_i];
159533
+ var subTypeName = getFirstTypeParameterName(subType);
159534
+ if (subTypeName) {
159535
+ return subTypeName;
159536
+ }
159537
+ }
159538
+ }
159539
+ return type.flags & 262144 /* TypeParameter */
159540
+ ? (_a = type.getSymbol()) === null || _a === void 0 ? void 0 : _a.getName()
159541
+ : undefined;
159542
+ }
159406
159543
  function createDummyParameters(argCount, names, types, minArgumentCount, inJs) {
159407
159544
  var parameters = [];
159545
+ var parameterNameCounts = new ts.Map();
159408
159546
  for (var i = 0; i < argCount; i++) {
159547
+ var parameterName = (names === null || names === void 0 ? void 0 : names[i]) || "arg" + i;
159548
+ var parameterNameCount = parameterNameCounts.get(parameterName);
159549
+ parameterNameCounts.set(parameterName, (parameterNameCount || 0) + 1);
159409
159550
  var newParameter = ts.factory.createParameterDeclaration(
159410
159551
  /*modifiers*/ undefined,
159411
159552
  /*dotDotDotToken*/ undefined,
159412
- /*name*/ names && names[i] || "arg" + i,
159553
+ /*name*/ parameterName + (parameterNameCount || ""),
159413
159554
  /*questionToken*/ minArgumentCount !== undefined && i >= minArgumentCount ? ts.factory.createToken(57 /* QuestionToken */) : undefined,
159414
- /*type*/ inJs ? undefined : types && types[i] || ts.factory.createKeywordTypeNode(155 /* UnknownKeyword */),
159555
+ /*type*/ inJs ? undefined : (types === null || types === void 0 ? void 0 : types[i]) || ts.factory.createKeywordTypeNode(155 /* UnknownKeyword */),
159415
159556
  /*initializer*/ undefined);
159416
159557
  parameters.push(newParameter);
159417
159558
  }
@@ -163543,7 +163684,7 @@ var ts;
163543
163684
  var usage = getUsageInfo(oldFile, toMove.all, checker);
163544
163685
  var currentDirectory = ts.getDirectoryPath(oldFile.fileName);
163545
163686
  var extension = ts.extensionFromPath(oldFile.fileName);
163546
- var newModuleName = makeUniqueModuleName(getNewModuleName(usage.movedSymbols), extension, currentDirectory, host);
163687
+ var newModuleName = makeUniqueModuleName(getNewModuleName(usage.oldFileImportsFromNewFile, usage.movedSymbols), extension, currentDirectory, host);
163547
163688
  var newFileNameWithExtension = newModuleName + extension;
163548
163689
  // If previous file was global, this is easy.
163549
163690
  changes.createNewFile(oldFile, ts.combinePaths(currentDirectory, newFileNameWithExtension), getNewStatementsAndRemoveFromOldFile(oldFile, usage, changes, toMove, program, newModuleName, preferences));
@@ -163907,8 +164048,8 @@ var ts;
163907
164048
  newModuleName = moduleName + "." + i;
163908
164049
  }
163909
164050
  }
163910
- function getNewModuleName(movedSymbols) {
163911
- return movedSymbols.forEachEntry(ts.symbolNameNoDefault) || "newFile";
164051
+ function getNewModuleName(importsFromNewFile, movedSymbols) {
164052
+ return importsFromNewFile.forEachEntry(ts.symbolNameNoDefault) || movedSymbols.forEachEntry(ts.symbolNameNoDefault) || "newFile";
163912
164053
  }
163913
164054
  function getUsageInfo(oldFile, toMove, checker) {
163914
164055
  var movedSymbols = new SymbolSet();
@@ -178324,7 +178465,7 @@ var ts;
178324
178465
  var packageDirectory = fileName.substring(0, nodeModulesPathParts.packageRootIndex);
178325
178466
  var packageJsonCache = (_a = project.getModuleResolutionCache()) === null || _a === void 0 ? void 0 : _a.getPackageJsonInfoCache();
178326
178467
  var compilerOptions = project.getCompilationSettings();
178327
- var packageJson = ts.getPackageScopeForPath(project.toPath(packageDirectory + "/package.json"), packageJsonCache, project, compilerOptions);
178468
+ var packageJson = ts.getPackageScopeForPath(project.toPath(packageDirectory + "/package.json"), ts.getTemporaryModuleResolutionState(packageJsonCache, project, compilerOptions));
178328
178469
  if (!packageJson)
178329
178470
  return undefined;
178330
178471
  // Use fake options instead of actual compiler options to avoid following export map if the project uses node16 or nodenext -