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.
@@ -294,7 +294,7 @@ var ts;
294
294
  // The following is baselined as a literal template type without intervention
295
295
  /** The version of the TypeScript compiler release */
296
296
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
297
- ts.version = ts.versionMajorMinor + ".0-dev.20220726";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220729";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -1895,6 +1895,10 @@ var ts;
1895
1895
  /** Does nothing. */
1896
1896
  function noop(_) { }
1897
1897
  ts.noop = noop;
1898
+ ts.noopPush = {
1899
+ push: noop,
1900
+ length: 0
1901
+ };
1898
1902
  /** Do nothing and return false */
1899
1903
  function returnFalse() {
1900
1904
  return false;
@@ -8762,6 +8766,7 @@ var ts;
8762
8766
  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."),
8763
8767
  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."),
8764
8768
  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."),
8769
+ Identifier_or_string_literal_expected: diag(1478, ts.DiagnosticCategory.Error, "Identifier_or_string_literal_expected_1478", "Identifier or string literal expected."),
8765
8770
  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."),
8766
8771
  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."),
8767
8772
  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),
@@ -8975,6 +8980,7 @@ var ts;
8975
8980
  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."),
8976
8981
  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."),
8977
8982
  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."),
8983
+ 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."),
8978
8984
  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}'."),
8979
8985
  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."),
8980
8986
  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."),
@@ -33501,7 +33507,9 @@ var ts;
33501
33507
  case 23 /* ImportOrExportSpecifiers */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
33502
33508
  case 13 /* JsxAttributes */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
33503
33509
  case 14 /* JsxChildren */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected);
33504
- default: return [undefined]; // TODO: GH#18217 `default: Debug.assertNever(context);`
33510
+ case 24 /* AssertEntries */: return parseErrorAtCurrentToken(ts.Diagnostics.Identifier_or_string_literal_expected); // AssertionKey.
33511
+ case 25 /* Count */: return ts.Debug.fail("ParsingContext.Count used as a context"); // Not a real context, only a marker.
33512
+ default: ts.Debug.assertNever(context);
33505
33513
  }
33506
33514
  }
33507
33515
  function parseDelimitedList(kind, parseElement, considerSemicolonAsDelimiter) {
@@ -43327,18 +43335,7 @@ var ts;
43327
43335
  * Does not try `@types/${packageName}` - use a second pass if needed.
43328
43336
  */
43329
43337
  function resolvePackageNameToPackageJson(packageName, containingDirectory, options, host, cache) {
43330
- var moduleResolutionState = {
43331
- compilerOptions: options,
43332
- host: host,
43333
- traceEnabled: isTraceEnabled(options, host),
43334
- failedLookupLocations: [],
43335
- affectingLocations: [],
43336
- packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
43337
- conditions: ts.emptyArray,
43338
- features: NodeResolutionFeatures.None,
43339
- requestContainingDirectory: containingDirectory,
43340
- reportDiagnostic: ts.noop
43341
- };
43338
+ var moduleResolutionState = getTemporaryModuleResolutionState(cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(), host, options);
43342
43339
  return ts.forEachAncestorDirectory(containingDirectory, function (ancestorDirectory) {
43343
43340
  if (ts.getBaseFileName(ancestorDirectory) !== "node_modules") {
43344
43341
  var nodeModulesFolder = ts.combinePaths(ancestorDirectory, "node_modules");
@@ -44298,18 +44295,9 @@ var ts;
44298
44295
  var entrypoints;
44299
44296
  var extensions = resolveJs ? Extensions.JavaScript : Extensions.TypeScript;
44300
44297
  var features = getDefaultNodeResolutionFeatures(options);
44301
- var requireState = {
44302
- compilerOptions: options,
44303
- host: host,
44304
- traceEnabled: isTraceEnabled(options, host),
44305
- failedLookupLocations: [],
44306
- affectingLocations: [],
44307
- packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
44308
- conditions: ["node", "require", "types"],
44309
- features: features,
44310
- requestContainingDirectory: packageJsonInfo.packageDirectory,
44311
- reportDiagnostic: ts.noop
44312
- };
44298
+ var requireState = getTemporaryModuleResolutionState(cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(), host, options);
44299
+ requireState.conditions = ["node", "require", "types"];
44300
+ requireState.requestContainingDirectory = packageJsonInfo.packageDirectory;
44313
44301
  var requireResolution = loadNodeModuleFromDirectoryWorker(extensions, packageJsonInfo.packageDirectory,
44314
44302
  /*onlyRecordFailures*/ false, requireState, packageJsonInfo.packageJsonContent, packageJsonInfo.versionPaths);
44315
44303
  entrypoints = ts.append(entrypoints, requireResolution === null || requireResolution === void 0 ? void 0 : requireResolution.path);
@@ -44382,23 +44370,27 @@ var ts;
44382
44370
  }
44383
44371
  }
44384
44372
  }
44385
- /**
44386
- * A function for locating the package.json scope for a given path
44387
- */
44388
44373
  /*@internal*/
44389
- function getPackageScopeForPath(fileName, packageJsonInfoCache, host, options) {
44390
- var state = {
44374
+ function getTemporaryModuleResolutionState(packageJsonInfoCache, host, options) {
44375
+ return {
44391
44376
  host: host,
44392
44377
  compilerOptions: options,
44393
44378
  traceEnabled: isTraceEnabled(options, host),
44394
- failedLookupLocations: [],
44395
- affectingLocations: [],
44379
+ failedLookupLocations: ts.noopPush,
44380
+ affectingLocations: ts.noopPush,
44396
44381
  packageJsonInfoCache: packageJsonInfoCache,
44397
- features: 0,
44398
- conditions: [],
44382
+ features: NodeResolutionFeatures.None,
44383
+ conditions: ts.emptyArray,
44399
44384
  requestContainingDirectory: undefined,
44400
44385
  reportDiagnostic: ts.noop
44401
44386
  };
44387
+ }
44388
+ ts.getTemporaryModuleResolutionState = getTemporaryModuleResolutionState;
44389
+ /**
44390
+ * A function for locating the package.json scope for a given path
44391
+ */
44392
+ /*@internal*/
44393
+ function getPackageScopeForPath(fileName, state) {
44402
44394
  var parts = ts.getPathComponents(fileName);
44403
44395
  parts.pop();
44404
44396
  while (parts.length > 0) {
@@ -44569,7 +44561,7 @@ var ts;
44569
44561
  var _a, _b;
44570
44562
  var useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames;
44571
44563
  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));
44572
- var scope = getPackageScopeForPath(directoryPath, state.packageJsonInfoCache, state.host, state.compilerOptions);
44564
+ var scope = getPackageScopeForPath(directoryPath, state);
44573
44565
  if (!scope || !scope.packageJsonContent.exports) {
44574
44566
  return undefined;
44575
44567
  }
@@ -44628,7 +44620,7 @@ var ts;
44628
44620
  }
44629
44621
  var useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames;
44630
44622
  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));
44631
- var scope = getPackageScopeForPath(directoryPath, state.packageJsonInfoCache, state.host, state.compilerOptions);
44623
+ var scope = getPackageScopeForPath(directoryPath, state);
44632
44624
  if (!scope) {
44633
44625
  if (state.traceEnabled) {
44634
44626
  trace(state.host, ts.Diagnostics.Directory_0_has_no_containing_package_json_scope_Imports_will_not_resolve, directoryPath);
@@ -53088,6 +53080,12 @@ var ts;
53088
53080
  return context.truncating = context.approximateLength > ((context.flags & 1 /* NoTruncation */) ? ts.noTruncationMaximumTruncationLength : ts.defaultMaximumTruncationLength);
53089
53081
  }
53090
53082
  function typeToTypeNodeHelper(type, context) {
53083
+ var savedFlags = context.flags;
53084
+ var typeNode = typeToTypeNodeWorker(type, context);
53085
+ context.flags = savedFlags;
53086
+ return typeNode;
53087
+ }
53088
+ function typeToTypeNodeWorker(type, context) {
53091
53089
  if (cancellationToken && cancellationToken.throwIfCancellationRequested) {
53092
53090
  cancellationToken.throwIfCancellationRequested();
53093
53091
  }
@@ -59607,7 +59605,8 @@ var ts;
59607
59605
  }
59608
59606
  }
59609
59607
  }
59610
- return getIntersectionType(constraints);
59608
+ // The source types were normalized; ensure the result is normalized too.
59609
+ return getNormalizedType(getIntersectionType(constraints), /*writing*/ false);
59611
59610
  }
59612
59611
  return undefined;
59613
59612
  }
@@ -62825,21 +62824,28 @@ var ts;
62825
62824
  getFlowTypeOfReference(accessExpression, propType) :
62826
62825
  propType;
62827
62826
  }
62828
- if (everyType(objectType, isTupleType) && ts.isNumericLiteralName(propName) && +propName >= 0) {
62827
+ if (everyType(objectType, isTupleType) && ts.isNumericLiteralName(propName)) {
62828
+ var index = +propName;
62829
62829
  if (accessNode && everyType(objectType, function (t) { return !t.target.hasRestElement; }) && !(accessFlags & 16 /* NoTupleBoundsCheck */)) {
62830
62830
  var indexNode = getIndexNodeForAccessExpression(accessNode);
62831
62831
  if (isTupleType(objectType)) {
62832
+ if (index < 0) {
62833
+ error(indexNode, ts.Diagnostics.A_tuple_type_cannot_be_indexed_with_a_negative_value);
62834
+ return undefinedType;
62835
+ }
62832
62836
  error(indexNode, ts.Diagnostics.Tuple_type_0_of_length_1_has_no_element_at_index_2, typeToString(objectType), getTypeReferenceArity(objectType), ts.unescapeLeadingUnderscores(propName));
62833
62837
  }
62834
62838
  else {
62835
62839
  error(indexNode, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.unescapeLeadingUnderscores(propName), typeToString(objectType));
62836
62840
  }
62837
62841
  }
62838
- errorIfWritingToReadonlyIndex(getIndexInfoOfType(objectType, numberType));
62839
- return mapType(objectType, function (t) {
62840
- var restType = getRestTypeOfTupleType(t) || undefinedType;
62841
- return accessFlags & 1 /* IncludeUndefined */ ? getUnionType([restType, undefinedType]) : restType;
62842
- });
62842
+ if (index >= 0) {
62843
+ errorIfWritingToReadonlyIndex(getIndexInfoOfType(objectType, numberType));
62844
+ return mapType(objectType, function (t) {
62845
+ var restType = getRestTypeOfTupleType(t) || undefinedType;
62846
+ return accessFlags & 1 /* IncludeUndefined */ ? getUnionType([restType, undefinedType]) : restType;
62847
+ });
62848
+ }
62843
62849
  }
62844
62850
  }
62845
62851
  if (!(indexType.flags & 98304 /* Nullable */) && isTypeAssignableToKind(indexType, 402653316 /* StringLike */ | 296 /* NumberLike */ | 12288 /* ESSymbolLike */)) {
@@ -72133,8 +72139,12 @@ var ts;
72133
72139
  var discriminant = keyPropertyName && getTypeOfPropertyOfType(c, keyPropertyName);
72134
72140
  var matching = discriminant && getConstituentTypeForKeyType(type, discriminant);
72135
72141
  // For each constituent t in the current type, if t and and c are directly related, pick the most
72136
- // specific of the two.
72137
- var directlyRelated = mapType(matching || type, function (t) { return isRelated(t, c) ? t : isRelated(c, t) ? c : neverType; });
72142
+ // specific of the two. When t and c are related in both directions, we prefer c for type predicates
72143
+ // because that is the asserted type, but t for `instanceof` because generics aren't reflected in
72144
+ // prototype object types.
72145
+ var directlyRelated = mapType(matching || type, checkDerived ?
72146
+ function (t) { return isTypeDerivedFrom(t, c) ? t : isTypeDerivedFrom(c, t) ? c : neverType; } :
72147
+ function (t) { return isTypeSubtypeOf(c, t) ? c : isTypeSubtypeOf(t, c) ? t : neverType; });
72138
72148
  // If no constituents are directly related, create intersections for any generic constituents that
72139
72149
  // are related by constraint.
72140
72150
  return directlyRelated.flags & 131072 /* Never */ ?
@@ -84846,8 +84856,9 @@ var ts;
84846
84856
  }
84847
84857
  var indexInfos = getApplicableIndexInfos(type, propNameType);
84848
84858
  var interfaceDeclaration = ts.getObjectFlags(type) & 2 /* Interface */ ? ts.getDeclarationOfKind(type.symbol, 258 /* InterfaceDeclaration */) : undefined;
84849
- var localPropDeclaration = declaration && declaration.kind === 221 /* BinaryExpression */ ||
84850
- name && name.kind === 162 /* ComputedPropertyName */ || getParentOfSymbol(prop) === type.symbol ? declaration : undefined;
84859
+ var propDeclaration = declaration && declaration.kind === 221 /* BinaryExpression */ ||
84860
+ name && name.kind === 162 /* ComputedPropertyName */ ? declaration : undefined;
84861
+ var localPropDeclaration = getParentOfSymbol(prop) === type.symbol ? declaration : undefined;
84851
84862
  var _loop_30 = function (info) {
84852
84863
  var localIndexDeclaration = info.declaration && getParentOfSymbol(getSymbolOfNode(info.declaration)) === type.symbol ? info.declaration : undefined;
84853
84864
  // We check only when (a) the property is declared in the containing type, or (b) the applicable index signature is declared
@@ -84856,7 +84867,11 @@ var ts;
84856
84867
  var errorNode = localPropDeclaration || localIndexDeclaration ||
84857
84868
  (interfaceDeclaration && !ts.some(getBaseTypes(type), function (base) { return !!getPropertyOfObjectType(base, prop.escapedName) && !!getIndexTypeOfType(base, info.keyType); }) ? interfaceDeclaration : undefined);
84858
84869
  if (errorNode && !isTypeAssignableTo(propType, info.type)) {
84859
- 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));
84870
+ 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));
84871
+ if (propDeclaration && errorNode !== propDeclaration) {
84872
+ ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(propDeclaration, ts.Diagnostics._0_is_declared_here, symbolToString(prop)));
84873
+ }
84874
+ diagnostics.add(diagnostic);
84860
84875
  }
84861
84876
  };
84862
84877
  for (var _i = 0, indexInfos_9 = indexInfos; _i < indexInfos_9.length; _i++) {
@@ -117841,7 +117856,7 @@ var ts;
117841
117856
  return undefined;
117842
117857
  }
117843
117858
  function lookupFromPackageJson() {
117844
- var scope = ts.getPackageScopeForPath(fileName, packageJsonInfoCache, host, options);
117859
+ var scope = ts.getPackageScopeForPath(fileName, ts.getTemporaryModuleResolutionState(packageJsonInfoCache, host, options));
117845
117860
  return (scope === null || scope === void 0 ? void 0 : scope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS;
117846
117861
  }
117847
117862
  }
@@ -118507,7 +118522,7 @@ var ts;
118507
118522
  // `result[i]` is either a `ResolvedModuleFull` or a marker.
118508
118523
  // If it is the former, we can leave it as is.
118509
118524
  if (result[i] === predictedToResolveToAmbientModuleMarker) {
118510
- result[i] = undefined; // TODO: GH#18217
118525
+ result[i] = undefined;
118511
118526
  }
118512
118527
  }
118513
118528
  else {
@@ -149223,6 +149238,7 @@ var ts;
149223
149238
  var options = _a.options, getRules = _a.getRules, host = _a.host;
149224
149239
  // formatting context is used by rules provider
149225
149240
  var formattingContext = new formatting.FormattingContext(sourceFile, requestKind, options);
149241
+ var previousRangeTriviaEnd;
149226
149242
  var previousRange;
149227
149243
  var previousParent;
149228
149244
  var previousRangeStartLine;
@@ -149251,10 +149267,30 @@ var ts;
149251
149267
  }
149252
149268
  }
149253
149269
  if (previousRange && formattingScanner.getStartPos() >= originalRange.end) {
149270
+ // Formatting edits happen by looking at pairs of contiguous tokens (see `processPair`),
149271
+ // typically inserting or deleting whitespace between them. The recursive `processNode`
149272
+ // logic above bails out as soon as it encounters a token that is beyond the end of the
149273
+ // range we're supposed to format (or if we reach the end of the file). But this potentially
149274
+ // leaves out an edit that would occur *inside* the requested range but cannot be discovered
149275
+ // without looking at one token *beyond* the end of the range: consider the line `x = { }`
149276
+ // with a selection from the beginning of the line to the space inside the curly braces,
149277
+ // inclusive. We would expect a format-selection would delete the space (if rules apply),
149278
+ // but in order to do that, we need to process the pair ["{", "}"], but we stopped processing
149279
+ // just before getting there. This block handles this trailing edit.
149254
149280
  var tokenInfo = formattingScanner.isOnEOF() ? formattingScanner.readEOFTokenRange() :
149255
149281
  formattingScanner.isOnToken() ? formattingScanner.readTokenInfo(enclosingNode).token :
149256
149282
  undefined;
149257
- if (tokenInfo) {
149283
+ if (tokenInfo && tokenInfo.pos === previousRangeTriviaEnd) {
149284
+ // We need to check that tokenInfo and previousRange are contiguous: the `originalRange`
149285
+ // may have ended in the middle of a token, which means we will have stopped formatting
149286
+ // on that token, leaving `previousRange` pointing to the token before it, but already
149287
+ // having moved the formatting scanner (where we just got `tokenInfo`) to the next token.
149288
+ // If this happens, our supposed pair [previousRange, tokenInfo] actually straddles the
149289
+ // token that intersects the end of the range we're supposed to format, so the pair will
149290
+ // produce bogus edits if we try to `processPair`. Recall that the point of this logic is
149291
+ // to perform a trailing edit at the end of the selection range: but there can be no valid
149292
+ // edit in the middle of a token where the range ended, so if we have a non-contiguous
149293
+ // pair here, we're already done and we can ignore it.
149258
149294
  var parent = ((_b = ts.findPrecedingToken(tokenInfo.end, sourceFile, enclosingNode)) === null || _b === void 0 ? void 0 : _b.parent) || previousParent;
149259
149295
  processPair(tokenInfo, sourceFile.getLineAndCharacterOfPosition(tokenInfo.pos).line, parent, previousRange, previousRangeStartLine, previousParent, parent,
149260
149296
  /*dynamicIndentation*/ undefined);
@@ -149612,6 +149648,7 @@ var ts;
149612
149648
  }
149613
149649
  }
149614
149650
  if (currentTokenInfo.trailingTrivia) {
149651
+ previousRangeTriviaEnd = ts.last(currentTokenInfo.trailingTrivia).end;
149615
149652
  processTrivia(currentTokenInfo.trailingTrivia, parent, childContextNode, dynamicIndentation);
149616
149653
  }
149617
149654
  if (indentToken) {
@@ -149682,6 +149719,7 @@ var ts;
149682
149719
  }
149683
149720
  }
149684
149721
  previousRange = range;
149722
+ previousRangeTriviaEnd = range.end;
149685
149723
  previousParent = parent;
149686
149724
  previousRangeStartLine = rangeStart.line;
149687
149725
  return lineAction;
@@ -155993,8 +156031,7 @@ var ts;
155993
156031
  codefix.eachDiagnostic(context, errorCodes, function (diag) {
155994
156032
  var info = getInfo(program, diag.file, ts.createTextSpan(diag.start, diag.length));
155995
156033
  if (info) {
155996
- var id = ts.getNodeId(info.declaration) + "#" + info.token.getText();
155997
- if (ts.addToSeen(seen, id)) {
156034
+ if (ts.addToSeen(seen, ts.getNodeId(info.declaration))) {
155998
156035
  return addMissingConstraint(changes, program, preferences, host, diag.file, info);
155999
156036
  }
156000
156037
  }
@@ -159962,21 +159999,16 @@ var ts;
159962
159999
  var names = ts.map(args, function (arg) {
159963
160000
  return ts.isIdentifier(arg) ? arg.text : ts.isPropertyAccessExpression(arg) && ts.isIdentifier(arg.name) ? arg.name.text : undefined;
159964
160001
  });
159965
- var types = isJs ? [] : ts.map(args, function (arg) {
159966
- return typeToAutoImportableTypeNode(checker, importAdder, checker.getBaseTypeOfLiteralType(checker.getTypeAtLocation(arg)), contextNode, scriptTarget, /*flags*/ undefined, tracker);
159967
- });
160002
+ var instanceTypes = isJs ? [] : ts.map(args, function (arg) { return checker.getTypeAtLocation(arg); });
160003
+ var _a = getArgumentTypesAndTypeParameters(checker, importAdder, instanceTypes, contextNode, scriptTarget, /*flags*/ undefined, tracker), argumentTypeNodes = _a.argumentTypeNodes, argumentTypeParameters = _a.argumentTypeParameters;
159968
160004
  var modifiers = modifierFlags
159969
160005
  ? ts.factory.createNodeArray(ts.factory.createModifiersFromModifierFlags(modifierFlags))
159970
160006
  : undefined;
159971
160007
  var asteriskToken = ts.isYieldExpression(parent)
159972
160008
  ? ts.factory.createToken(41 /* AsteriskToken */)
159973
160009
  : undefined;
159974
- var typeParameters = isJs || typeArguments === undefined
159975
- ? undefined
159976
- : ts.map(typeArguments, function (_, i) {
159977
- return ts.factory.createTypeParameterDeclaration(/*modifiers*/ undefined, 84 /* T */ + typeArguments.length - 1 <= 90 /* Z */ ? String.fromCharCode(84 /* T */ + i) : "T" + i);
159978
- });
159979
- var parameters = createDummyParameters(args.length, names, types, /*minArgumentCount*/ undefined, isJs);
160010
+ var typeParameters = isJs ? undefined : createTypeParametersForArguments(checker, argumentTypeParameters, typeArguments);
160011
+ var parameters = createDummyParameters(args.length, names, argumentTypeNodes, /*minArgumentCount*/ undefined, isJs);
159980
160012
  var type = isJs || contextualType === undefined
159981
160013
  ? undefined
159982
160014
  : checker.typeToTypeNode(contextualType, contextNode, /*flags*/ undefined, tracker);
@@ -159994,6 +160026,23 @@ var ts;
159994
160026
  }
159995
160027
  }
159996
160028
  codefix.createSignatureDeclarationFromCallExpression = createSignatureDeclarationFromCallExpression;
160029
+ function createTypeParametersForArguments(checker, argumentTypeParameters, typeArguments) {
160030
+ var usedNames = new ts.Set(argumentTypeParameters.map(function (pair) { return pair[0]; }));
160031
+ var constraintsByName = new ts.Map(argumentTypeParameters);
160032
+ if (typeArguments) {
160033
+ 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); }); });
160034
+ var targetSize = usedNames.size + typeArgumentsWithNewTypes.length;
160035
+ for (var i = 0; usedNames.size < targetSize; i += 1) {
160036
+ usedNames.add(createTypeParameterName(i));
160037
+ }
160038
+ }
160039
+ 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); });
160040
+ }
160041
+ function createTypeParameterName(index) {
160042
+ return 84 /* T */ + index <= 90 /* Z */
160043
+ ? String.fromCharCode(84 /* T */ + index)
160044
+ : "T" + index;
160045
+ }
159997
160046
  function typeToAutoImportableTypeNode(checker, importAdder, type, contextNode, scriptTarget, flags, tracker) {
159998
160047
  var typeNode = checker.typeToTypeNode(type, contextNode, flags, tracker);
159999
160048
  if (typeNode && ts.isImportTypeNode(typeNode)) {
@@ -160007,15 +160056,107 @@ var ts;
160007
160056
  return ts.getSynthesizedDeepClone(typeNode);
160008
160057
  }
160009
160058
  codefix.typeToAutoImportableTypeNode = typeToAutoImportableTypeNode;
160059
+ function typeContainsTypeParameter(type) {
160060
+ if (type.isUnionOrIntersection()) {
160061
+ return type.types.some(typeContainsTypeParameter);
160062
+ }
160063
+ return type.flags & 262144 /* TypeParameter */;
160064
+ }
160065
+ function getArgumentTypesAndTypeParameters(checker, importAdder, instanceTypes, contextNode, scriptTarget, flags, tracker) {
160066
+ // Types to be used as the types of the parameters in the new function
160067
+ // E.g. from this source:
160068
+ // added("", 0)
160069
+ // The value will look like:
160070
+ // [{ typeName: { text: "string" } }, { typeName: { text: "number" }]
160071
+ // And in the output function will generate:
160072
+ // function added(a: string, b: number) { ... }
160073
+ var argumentTypeNodes = [];
160074
+ // Names of type parameters provided as arguments to the call
160075
+ // E.g. from this source:
160076
+ // added<T, U>(value);
160077
+ // The value will look like:
160078
+ // [
160079
+ // ["T", { argumentType: { typeName: { text: "T" } } } ],
160080
+ // ["U", { argumentType: { typeName: { text: "U" } } } ],
160081
+ // ]
160082
+ // And in the output function will generate:
160083
+ // function added<T, U>() { ... }
160084
+ var argumentTypeParameters = new ts.Map();
160085
+ for (var i = 0; i < instanceTypes.length; i += 1) {
160086
+ var instanceType = instanceTypes[i];
160087
+ // If the instance type contains a deep reference to an existing type parameter,
160088
+ // instead of copying the full union or intersection, create a new type parameter
160089
+ // E.g. from this source:
160090
+ // function existing<T, U>(value: T | U & string) {
160091
+ // added/*1*/(value);
160092
+ // We don't want to output this:
160093
+ // function added<T>(value: T | U & string) { ... }
160094
+ // We instead want to output:
160095
+ // function added<T>(value: T) { ... }
160096
+ if (instanceType.isUnionOrIntersection() && instanceType.types.some(typeContainsTypeParameter)) {
160097
+ var synthesizedTypeParameterName = createTypeParameterName(i);
160098
+ argumentTypeNodes.push(ts.factory.createTypeReferenceNode(synthesizedTypeParameterName));
160099
+ argumentTypeParameters.set(synthesizedTypeParameterName, undefined);
160100
+ continue;
160101
+ }
160102
+ // Widen the type so we don't emit nonsense annotations like "function fn(x: 3) {"
160103
+ var widenedInstanceType = checker.getBaseTypeOfLiteralType(instanceType);
160104
+ var argumentTypeNode = typeToAutoImportableTypeNode(checker, importAdder, widenedInstanceType, contextNode, scriptTarget, flags, tracker);
160105
+ if (!argumentTypeNode) {
160106
+ continue;
160107
+ }
160108
+ argumentTypeNodes.push(argumentTypeNode);
160109
+ var argumentTypeParameter = getFirstTypeParameterName(instanceType);
160110
+ // If the instance type is a type parameter with a constraint (other than an anonymous object),
160111
+ // remember that constraint for when we create the new type parameter
160112
+ // E.g. from this source:
160113
+ // function existing<T extends string>(value: T) {
160114
+ // added/*1*/(value);
160115
+ // We don't want to output this:
160116
+ // function added<T>(value: T) { ... }
160117
+ // We instead want to output:
160118
+ // function added<T extends string>(value: T) { ... }
160119
+ var instanceTypeConstraint = instanceType.isTypeParameter() && instanceType.constraint && !isAnonymousObjectConstraintType(instanceType.constraint)
160120
+ ? typeToAutoImportableTypeNode(checker, importAdder, instanceType.constraint, contextNode, scriptTarget, flags, tracker)
160121
+ : undefined;
160122
+ if (argumentTypeParameter) {
160123
+ argumentTypeParameters.set(argumentTypeParameter, { argumentType: instanceType, constraint: instanceTypeConstraint });
160124
+ }
160125
+ }
160126
+ return { argumentTypeNodes: argumentTypeNodes, argumentTypeParameters: ts.arrayFrom(argumentTypeParameters.entries()) };
160127
+ }
160128
+ codefix.getArgumentTypesAndTypeParameters = getArgumentTypesAndTypeParameters;
160129
+ function isAnonymousObjectConstraintType(type) {
160130
+ return (type.flags & 524288 /* Object */) && type.objectFlags === 16 /* Anonymous */;
160131
+ }
160132
+ function getFirstTypeParameterName(type) {
160133
+ var _a;
160134
+ if (type.flags & (1048576 /* Union */ | 2097152 /* Intersection */)) {
160135
+ for (var _i = 0, _b = type.types; _i < _b.length; _i++) {
160136
+ var subType = _b[_i];
160137
+ var subTypeName = getFirstTypeParameterName(subType);
160138
+ if (subTypeName) {
160139
+ return subTypeName;
160140
+ }
160141
+ }
160142
+ }
160143
+ return type.flags & 262144 /* TypeParameter */
160144
+ ? (_a = type.getSymbol()) === null || _a === void 0 ? void 0 : _a.getName()
160145
+ : undefined;
160146
+ }
160010
160147
  function createDummyParameters(argCount, names, types, minArgumentCount, inJs) {
160011
160148
  var parameters = [];
160149
+ var parameterNameCounts = new ts.Map();
160012
160150
  for (var i = 0; i < argCount; i++) {
160151
+ var parameterName = (names === null || names === void 0 ? void 0 : names[i]) || "arg" + i;
160152
+ var parameterNameCount = parameterNameCounts.get(parameterName);
160153
+ parameterNameCounts.set(parameterName, (parameterNameCount || 0) + 1);
160013
160154
  var newParameter = ts.factory.createParameterDeclaration(
160014
160155
  /*modifiers*/ undefined,
160015
160156
  /*dotDotDotToken*/ undefined,
160016
- /*name*/ names && names[i] || "arg" + i,
160157
+ /*name*/ parameterName + (parameterNameCount || ""),
160017
160158
  /*questionToken*/ minArgumentCount !== undefined && i >= minArgumentCount ? ts.factory.createToken(57 /* QuestionToken */) : undefined,
160018
- /*type*/ inJs ? undefined : types && types[i] || ts.factory.createKeywordTypeNode(155 /* UnknownKeyword */),
160159
+ /*type*/ inJs ? undefined : (types === null || types === void 0 ? void 0 : types[i]) || ts.factory.createKeywordTypeNode(155 /* UnknownKeyword */),
160019
160160
  /*initializer*/ undefined);
160020
160161
  parameters.push(newParameter);
160021
160162
  }
@@ -164147,7 +164288,7 @@ var ts;
164147
164288
  var usage = getUsageInfo(oldFile, toMove.all, checker);
164148
164289
  var currentDirectory = ts.getDirectoryPath(oldFile.fileName);
164149
164290
  var extension = ts.extensionFromPath(oldFile.fileName);
164150
- var newModuleName = makeUniqueModuleName(getNewModuleName(usage.movedSymbols), extension, currentDirectory, host);
164291
+ var newModuleName = makeUniqueModuleName(getNewModuleName(usage.oldFileImportsFromNewFile, usage.movedSymbols), extension, currentDirectory, host);
164151
164292
  var newFileNameWithExtension = newModuleName + extension;
164152
164293
  // If previous file was global, this is easy.
164153
164294
  changes.createNewFile(oldFile, ts.combinePaths(currentDirectory, newFileNameWithExtension), getNewStatementsAndRemoveFromOldFile(oldFile, usage, changes, toMove, program, newModuleName, preferences));
@@ -164511,8 +164652,8 @@ var ts;
164511
164652
  newModuleName = moduleName + "." + i;
164512
164653
  }
164513
164654
  }
164514
- function getNewModuleName(movedSymbols) {
164515
- return movedSymbols.forEachEntry(ts.symbolNameNoDefault) || "newFile";
164655
+ function getNewModuleName(importsFromNewFile, movedSymbols) {
164656
+ return importsFromNewFile.forEachEntry(ts.symbolNameNoDefault) || movedSymbols.forEachEntry(ts.symbolNameNoDefault) || "newFile";
164516
164657
  }
164517
164658
  function getUsageInfo(oldFile, toMove, checker) {
164518
164659
  var movedSymbols = new SymbolSet();