typescript 4.6.0-dev.20220109 → 4.6.0-dev.20220113

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/typescript.js CHANGED
@@ -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.20220109";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220113";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -19985,16 +19985,6 @@ var ts;
19985
19985
  (symlinkedDirectories || (symlinkedDirectories = new ts.Map())).set(symlinkPath, real);
19986
19986
  }
19987
19987
  },
19988
- setSymlinkedDirectoryFromSymlinkedFile: function (symlink, real) {
19989
- this.setSymlinkedFile(ts.toPath(symlink, cwd, getCanonicalFileName), real);
19990
- var _a = guessDirectorySymlink(real, symlink, cwd, getCanonicalFileName) || ts.emptyArray, commonResolved = _a[0], commonOriginal = _a[1];
19991
- if (commonResolved && commonOriginal) {
19992
- this.setSymlinkedDirectory(commonOriginal, {
19993
- real: commonResolved,
19994
- realPath: ts.toPath(commonResolved, cwd, getCanonicalFileName),
19995
- });
19996
- }
19997
- },
19998
19988
  setSymlinksFromResolutions: function (files, typeReferenceDirectives) {
19999
19989
  var _this = this;
20000
19990
  var _a;
@@ -41703,9 +41693,7 @@ var ts;
41703
41693
  }
41704
41694
  }
41705
41695
  var failedLookupLocations = [];
41706
- var features = ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 ? NodeResolutionFeatures.Node12Default :
41707
- ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext ? NodeResolutionFeatures.NodeNextDefault :
41708
- NodeResolutionFeatures.None;
41696
+ var features = getDefaultNodeResolutionFeatures(options);
41709
41697
  var moduleResolutionState = { compilerOptions: options, host: host, traceEnabled: traceEnabled, failedLookupLocations: failedLookupLocations, packageJsonInfoCache: cache, features: features, conditions: ["node", "require", "types"] };
41710
41698
  var resolved = primaryLookup();
41711
41699
  var primary = true;
@@ -41790,6 +41778,34 @@ var ts;
41790
41778
  }
41791
41779
  }
41792
41780
  ts.resolveTypeReferenceDirective = resolveTypeReferenceDirective;
41781
+ function getDefaultNodeResolutionFeatures(options) {
41782
+ return ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 ? NodeResolutionFeatures.Node12Default :
41783
+ ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext ? NodeResolutionFeatures.NodeNextDefault :
41784
+ NodeResolutionFeatures.None;
41785
+ }
41786
+ /**
41787
+ * @internal
41788
+ * Does not try `@types/${packageName}` - use a second pass if needed.
41789
+ */
41790
+ function resolvePackageNameToPackageJson(packageName, containingDirectory, options, host, cache) {
41791
+ var moduleResolutionState = {
41792
+ compilerOptions: options,
41793
+ host: host,
41794
+ traceEnabled: isTraceEnabled(options, host),
41795
+ failedLookupLocations: [],
41796
+ packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
41797
+ conditions: ts.emptyArray,
41798
+ features: NodeResolutionFeatures.None,
41799
+ };
41800
+ return ts.forEachAncestorDirectory(containingDirectory, function (ancestorDirectory) {
41801
+ if (ts.getBaseFileName(ancestorDirectory) !== "node_modules") {
41802
+ var nodeModulesFolder = ts.combinePaths(ancestorDirectory, "node_modules");
41803
+ var candidate = ts.combinePaths(nodeModulesFolder, packageName);
41804
+ return getPackageJsonInfo(candidate, /*onlyRecordFailures*/ false, moduleResolutionState);
41805
+ }
41806
+ });
41807
+ }
41808
+ ts.resolvePackageNameToPackageJson = resolvePackageNameToPackageJson;
41793
41809
  /**
41794
41810
  * Given a set of options, returns the set of type directive names
41795
41811
  * that should be included for this program automatically.
@@ -42363,11 +42379,6 @@ var ts;
42363
42379
  }
42364
42380
  ts.resolveJSModule = resolveJSModule;
42365
42381
  /* @internal */
42366
- function tryResolveJSModule(moduleName, initialDir, host) {
42367
- return tryResolveJSModuleWorker(moduleName, initialDir, host).resolvedModule;
42368
- }
42369
- ts.tryResolveJSModule = tryResolveJSModule;
42370
- /* @internal */
42371
42382
  var NodeResolutionFeatures;
42372
42383
  (function (NodeResolutionFeatures) {
42373
42384
  NodeResolutionFeatures[NodeResolutionFeatures["None"] = 0] = "None";
@@ -42675,6 +42686,97 @@ var ts;
42675
42686
  var versionPaths = packageInfo && packageInfo.versionPaths;
42676
42687
  return withPackageId(packageInfo, loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageJsonContent, versionPaths));
42677
42688
  }
42689
+ /* @internal */
42690
+ function getEntrypointsFromPackageJsonInfo(packageJsonInfo, options, host, cache, resolveJs) {
42691
+ if (!resolveJs && packageJsonInfo.resolvedEntrypoints !== undefined) {
42692
+ // Cached value excludes resolutions to JS files - those could be
42693
+ // cached separately, but they're used rarely.
42694
+ return packageJsonInfo.resolvedEntrypoints;
42695
+ }
42696
+ var entrypoints;
42697
+ var extensions = resolveJs ? Extensions.JavaScript : Extensions.TypeScript;
42698
+ var features = getDefaultNodeResolutionFeatures(options);
42699
+ var requireState = {
42700
+ compilerOptions: options,
42701
+ host: host,
42702
+ traceEnabled: isTraceEnabled(options, host),
42703
+ failedLookupLocations: [],
42704
+ packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
42705
+ conditions: ["node", "require", "types"],
42706
+ features: features,
42707
+ };
42708
+ var requireResolution = loadNodeModuleFromDirectoryWorker(extensions, packageJsonInfo.packageDirectory,
42709
+ /*onlyRecordFailures*/ false, requireState, packageJsonInfo.packageJsonContent, packageJsonInfo.versionPaths);
42710
+ entrypoints = ts.append(entrypoints, requireResolution === null || requireResolution === void 0 ? void 0 : requireResolution.path);
42711
+ if (features & NodeResolutionFeatures.Exports && packageJsonInfo.packageJsonContent.exports) {
42712
+ for (var _i = 0, _a = [["node", "import", "types"], ["node", "require", "types"]]; _i < _a.length; _i++) {
42713
+ var conditions = _a[_i];
42714
+ var exportState = __assign(__assign({}, requireState), { failedLookupLocations: [], conditions: conditions });
42715
+ var exportResolutions = loadEntrypointsFromExportMap(packageJsonInfo, packageJsonInfo.packageJsonContent.exports, exportState, extensions);
42716
+ if (exportResolutions) {
42717
+ for (var _b = 0, exportResolutions_1 = exportResolutions; _b < exportResolutions_1.length; _b++) {
42718
+ var resolution = exportResolutions_1[_b];
42719
+ entrypoints = ts.appendIfUnique(entrypoints, resolution.path);
42720
+ }
42721
+ }
42722
+ }
42723
+ }
42724
+ return packageJsonInfo.resolvedEntrypoints = entrypoints || false;
42725
+ }
42726
+ ts.getEntrypointsFromPackageJsonInfo = getEntrypointsFromPackageJsonInfo;
42727
+ function loadEntrypointsFromExportMap(scope, exports, state, extensions) {
42728
+ var entrypoints;
42729
+ if (ts.isArray(exports)) {
42730
+ for (var _i = 0, exports_1 = exports; _i < exports_1.length; _i++) {
42731
+ var target = exports_1[_i];
42732
+ loadEntrypointsFromTargetExports(target);
42733
+ }
42734
+ }
42735
+ // eslint-disable-next-line no-null/no-null
42736
+ else if (typeof exports === "object" && exports !== null && allKeysStartWithDot(exports)) {
42737
+ for (var key in exports) {
42738
+ loadEntrypointsFromTargetExports(exports[key]);
42739
+ }
42740
+ }
42741
+ else {
42742
+ loadEntrypointsFromTargetExports(exports);
42743
+ }
42744
+ return entrypoints;
42745
+ function loadEntrypointsFromTargetExports(target) {
42746
+ var _a, _b;
42747
+ if (typeof target === "string" && ts.startsWith(target, "./") && target.indexOf("*") === -1) {
42748
+ var partsAfterFirst = ts.getPathComponents(target).slice(2);
42749
+ if (partsAfterFirst.indexOf("..") >= 0 || partsAfterFirst.indexOf(".") >= 0 || partsAfterFirst.indexOf("node_modules") >= 0) {
42750
+ return false;
42751
+ }
42752
+ var resolvedTarget = ts.combinePaths(scope.packageDirectory, target);
42753
+ var finalPath = ts.getNormalizedAbsolutePath(resolvedTarget, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a));
42754
+ var result = loadJSOrExactTSFileName(extensions, finalPath, /*recordOnlyFailures*/ false, state);
42755
+ if (result) {
42756
+ entrypoints = ts.appendIfUnique(entrypoints, result, function (a, b) { return a.path === b.path; });
42757
+ return true;
42758
+ }
42759
+ }
42760
+ else if (Array.isArray(target)) {
42761
+ for (var _i = 0, target_1 = target; _i < target_1.length; _i++) {
42762
+ var t = target_1[_i];
42763
+ var success = loadEntrypointsFromTargetExports(t);
42764
+ if (success) {
42765
+ return true;
42766
+ }
42767
+ }
42768
+ }
42769
+ // eslint-disable-next-line no-null/no-null
42770
+ else if (typeof target === "object" && target !== null) {
42771
+ return ts.forEach(ts.getOwnKeys(target), function (key) {
42772
+ if (key === "default" || ts.contains(state.conditions, key) || isApplicableVersionedTypesKey(state.conditions, key)) {
42773
+ loadEntrypointsFromTargetExports(target[key]);
42774
+ return true;
42775
+ }
42776
+ });
42777
+ }
42778
+ }
42779
+ }
42678
42780
  /**
42679
42781
  * A function for locating the package.json scope for a given path
42680
42782
  */
@@ -42731,7 +42833,7 @@ var ts;
42731
42833
  trace(host, ts.Diagnostics.Found_package_json_at_0, packageJsonPath);
42732
42834
  }
42733
42835
  var versionPaths = readPackageJsonTypesVersionPaths(packageJsonContent, state);
42734
- var result = { packageDirectory: packageDirectory, packageJsonContent: packageJsonContent, versionPaths: versionPaths };
42836
+ var result = { packageDirectory: packageDirectory, packageJsonContent: packageJsonContent, versionPaths: versionPaths, resolvedEntrypoints: undefined };
42735
42837
  (_b = state.packageJsonInfoCache) === null || _b === void 0 ? void 0 : _b.setPackageJsonInfo(packageJsonPath, result);
42736
42838
  return result;
42737
42839
  }
@@ -43028,8 +43130,8 @@ var ts;
43028
43130
  }
43029
43131
  return toSearchResult(/*value*/ undefined);
43030
43132
  }
43031
- for (var _d = 0, target_1 = target; _d < target_1.length; _d++) {
43032
- var elem = target_1[_d];
43133
+ for (var _d = 0, target_2 = target; _d < target_2.length; _d++) {
43134
+ var elem = target_2[_d];
43033
43135
  var result = loadModuleFromTargetImportOrExport(elem, subpath, pattern);
43034
43136
  if (result) {
43035
43137
  return result;
@@ -50058,7 +50160,7 @@ var ts;
50058
50160
  if (!sigs || !sigs.length) {
50059
50161
  sigs = getSignaturesOfStructuredType(type, 1 /* Construct */);
50060
50162
  }
50061
- if ((sigs && sigs.length) || getPropertyOfType(type, "default" /* Default */)) {
50163
+ if ((sigs && sigs.length) || getPropertyOfType(type, "default" /* Default */, /*skipObjectFunctionPropertyAugment*/ true)) {
50062
50164
  var moduleType = getTypeWithSyntheticDefaultImportType(type, symbol, moduleSymbol, reference);
50063
50165
  return cloneTypeAsModuleType(symbol, moduleType, referenceParent);
50064
50166
  }
@@ -52262,8 +52364,8 @@ var ts;
52262
52364
  }
52263
52365
  else {
52264
52366
  if (parent && getExportsOfSymbol(parent)) {
52265
- var exports_1 = getExportsOfSymbol(parent);
52266
- ts.forEachEntry(exports_1, function (ex, name) {
52367
+ var exports_2 = getExportsOfSymbol(parent);
52368
+ ts.forEachEntry(exports_2, function (ex, name) {
52267
52369
  if (getSymbolIfSameReference(ex, symbol) && !isLateBoundName(name) && name !== "export=" /* ExportEquals */) {
52268
52370
  symbolName = ts.unescapeLeadingUnderscores(name);
52269
52371
  return true;
@@ -57374,6 +57476,11 @@ var ts;
57374
57476
  return simplified !== type ? simplified : getConstraintOfType(type);
57375
57477
  }
57376
57478
  function getConstraintFromIndexedAccess(type) {
57479
+ if (isMappedTypeGenericIndexedAccess(type)) {
57480
+ // For indexed access types of the form { [P in K]: E }[X], where K is non-generic and X is generic,
57481
+ // we substitute an instantiation of E where P is replaced with X.
57482
+ return substituteIndexedMappedType(type.objectType, type.indexType);
57483
+ }
57377
57484
  var indexConstraint = getSimplifiedTypeOrConstraint(type.indexType);
57378
57485
  if (indexConstraint && indexConstraint !== type.indexType) {
57379
57486
  var indexedAccess = getIndexedAccessTypeOrUndefined(type.objectType, indexConstraint, type.accessFlags);
@@ -57578,6 +57685,11 @@ var ts;
57578
57685
  return constraint ? getStringMappingType(t.symbol, constraint) : stringType;
57579
57686
  }
57580
57687
  if (t.flags & 8388608 /* IndexedAccess */) {
57688
+ if (isMappedTypeGenericIndexedAccess(t)) {
57689
+ // For indexed access types of the form { [P in K]: E }[X], where K is non-generic and X is generic,
57690
+ // we substitute an instantiation of E where P is replaced with X.
57691
+ return getBaseConstraint(substituteIndexedMappedType(t.objectType, t.indexType));
57692
+ }
57581
57693
  var baseObjectType = getBaseConstraint(t.objectType);
57582
57694
  var baseIndexType = getBaseConstraint(t.indexType);
57583
57695
  var baseIndexedAccess = baseObjectType && baseIndexType && getIndexedAccessTypeOrUndefined(baseObjectType, baseIndexType, t.accessFlags);
@@ -57662,13 +57774,7 @@ var ts;
57662
57774
  * type itself.
57663
57775
  */
57664
57776
  function getApparentType(type) {
57665
- // We obtain the base constraint for all instantiable types, except indexed access types of the form
57666
- // { [P in K]: E }[X], where K is non-generic and X is generic. For those types, we instead substitute an
57667
- // instantiation of E where P is replaced with X. We do this because getBaseConstraintOfType directly
57668
- // lowers to an instantiation where X's constraint is substituted for X, which isn't always desirable.
57669
- var t = !(type.flags & 465829888 /* Instantiable */) ? type :
57670
- isMappedTypeGenericIndexedAccess(type) ? substituteIndexedMappedType(type.objectType, type.indexType) :
57671
- getBaseConstraintOfType(type) || unknownType;
57777
+ var t = !(type.flags & 465829888 /* Instantiable */) ? type : getBaseConstraintOfType(type) || unknownType;
57672
57778
  return ts.getObjectFlags(t) & 32 /* Mapped */ ? getApparentTypeOfMappedType(t) :
57673
57779
  t.flags & 2097152 /* Intersection */ ? getApparentTypeOfIntersectionType(t) :
57674
57780
  t.flags & 402653316 /* StringLike */ ? globalStringType :
@@ -64332,6 +64438,17 @@ var ts;
64332
64438
  resetErrorInfo(saveErrorInfo);
64333
64439
  return result;
64334
64440
  }
64441
+ if (isMappedTypeGenericIndexedAccess(source)) {
64442
+ // For an indexed access type { [P in K]: E}[X], above we have already explored an instantiation of E with X
64443
+ // substituted for P. We also want to explore type { [P in K]: E }[C], where C is the constraint of X.
64444
+ var indexConstraint = getConstraintOfType(source.indexType);
64445
+ if (indexConstraint) {
64446
+ if (result = isRelatedTo(getIndexedAccessType(source.objectType, indexConstraint), target, 1 /* Source */, reportErrors)) {
64447
+ resetErrorInfo(saveErrorInfo);
64448
+ return result;
64449
+ }
64450
+ }
64451
+ }
64335
64452
  }
64336
64453
  }
64337
64454
  else if (source.flags & 4194304 /* Index */) {
@@ -83450,9 +83567,9 @@ var ts;
83450
83567
  }
83451
83568
  }
83452
83569
  // Checks for export * conflicts
83453
- var exports_2 = getExportsOfModule(moduleSymbol);
83454
- if (exports_2) {
83455
- exports_2.forEach(function (_a, id) {
83570
+ var exports_3 = getExportsOfModule(moduleSymbol);
83571
+ if (exports_3) {
83572
+ exports_3.forEach(function (_a, id) {
83456
83573
  var declarations = _a.declarations, flags = _a.flags;
83457
83574
  if (id === "__export") {
83458
83575
  return;
@@ -90676,6 +90793,7 @@ var ts;
90676
90793
  case 176 /* TypePredicate */:
90677
90794
  case 133 /* BooleanKeyword */:
90678
90795
  return factory.createIdentifier("Boolean");
90796
+ case 197 /* TemplateLiteralType */:
90679
90797
  case 149 /* StringKeyword */:
90680
90798
  return factory.createIdentifier("String");
90681
90799
  case 147 /* ObjectKeyword */:
@@ -93008,6 +93126,11 @@ var ts;
93008
93126
  ts.setSourceMapRange(statement, ts.moveRangePastModifiers(property));
93009
93127
  ts.setCommentRange(statement, property);
93010
93128
  ts.setOriginalNode(statement, property);
93129
+ // `setOriginalNode` *copies* the `emitNode` from `property`, so now both
93130
+ // `statement` and `expression` have a copy of the synthesized comments.
93131
+ // Drop the comments from expression to avoid printing them twice.
93132
+ ts.setSyntheticLeadingComments(expression, undefined);
93133
+ ts.setSyntheticTrailingComments(expression, undefined);
93011
93134
  statements.push(statement);
93012
93135
  }
93013
93136
  }
@@ -119348,28 +119471,37 @@ var ts;
119348
119471
  useCaseSensitiveFileNames: (_a = host.useCaseSensitiveFileNames) === null || _a === void 0 ? void 0 : _a.call(host),
119349
119472
  };
119350
119473
  }
119351
- function updateModuleSpecifier(compilerOptions, importingSourceFileName, toFileName, host, oldImportSpecifier) {
119352
- var res = getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, getPreferencesForUpdate(compilerOptions, oldImportSpecifier, importingSourceFileName, host), {});
119474
+ // `importingSourceFile` and `importingSourceFileName`? Why not just use `importingSourceFile.path`?
119475
+ // Because when this is called by the file renamer, `importingSourceFile` is the file being renamed,
119476
+ // while `importingSourceFileName` its *new* name. We need a source file just to get its
119477
+ // `impliedNodeFormat` and to detect certain preferences from existing import module specifiers.
119478
+ function updateModuleSpecifier(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, oldImportSpecifier) {
119479
+ var res = getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, getPreferencesForUpdate(compilerOptions, oldImportSpecifier, importingSourceFileName, host), {});
119353
119480
  if (res === oldImportSpecifier)
119354
119481
  return undefined;
119355
119482
  return res;
119356
119483
  }
119357
119484
  moduleSpecifiers_1.updateModuleSpecifier = updateModuleSpecifier;
119358
- // Note: importingSourceFile is just for usesJsExtensionOnImports
119485
+ // `importingSourceFile` and `importingSourceFileName`? Why not just use `importingSourceFile.path`?
119486
+ // Because when this is called by the declaration emitter, `importingSourceFile` is the implementation
119487
+ // file, but `importingSourceFileName` and `toFileName` refer to declaration files (the former to the
119488
+ // one currently being produced; the latter to the one being imported). We need an implementation file
119489
+ // just to get its `impliedNodeFormat` and to detect certain preferences from existing import module
119490
+ // specifiers.
119359
119491
  function getModuleSpecifier(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host) {
119360
- return getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, getPreferences(host, {}, compilerOptions, importingSourceFile), {});
119492
+ return getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, getPreferences(host, {}, compilerOptions, importingSourceFile), {});
119361
119493
  }
119362
119494
  moduleSpecifiers_1.getModuleSpecifier = getModuleSpecifier;
119363
- function getNodeModulesPackageName(compilerOptions, importingSourceFileName, nodeModulesFileName, host, preferences) {
119364
- var info = getInfo(importingSourceFileName, host);
119365
- var modulePaths = getAllModulePaths(importingSourceFileName, nodeModulesFileName, host, preferences);
119366
- return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, host, compilerOptions, /*packageNameOnly*/ true); });
119495
+ function getNodeModulesPackageName(compilerOptions, importingSourceFile, nodeModulesFileName, host, preferences) {
119496
+ var info = getInfo(importingSourceFile.path, host);
119497
+ var modulePaths = getAllModulePaths(importingSourceFile.path, nodeModulesFileName, host, preferences);
119498
+ return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, /*packageNameOnly*/ true); });
119367
119499
  }
119368
119500
  moduleSpecifiers_1.getNodeModulesPackageName = getNodeModulesPackageName;
119369
- function getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, preferences, userPreferences) {
119501
+ function getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, preferences, userPreferences) {
119370
119502
  var info = getInfo(importingSourceFileName, host);
119371
119503
  var modulePaths = getAllModulePaths(importingSourceFileName, toFileName, host, userPreferences);
119372
- return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, host, compilerOptions); }) ||
119504
+ return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions); }) ||
119373
119505
  getLocalModuleSpecifier(toFileName, info, compilerOptions, host, preferences);
119374
119506
  }
119375
119507
  function tryGetModuleSpecifiersFromCache(moduleSymbol, importingSourceFile, host, userPreferences) {
@@ -119436,7 +119568,7 @@ var ts;
119436
119568
  var relativeSpecifiers;
119437
119569
  for (var _i = 0, modulePaths_1 = modulePaths; _i < modulePaths_1.length; _i++) {
119438
119570
  var modulePath = modulePaths_1[_i];
119439
- var specifier = tryGetModuleNameAsNodeModule(modulePath, info, host, compilerOptions);
119571
+ var specifier = tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions);
119440
119572
  nodeModulesSpecifiers = ts.append(nodeModulesSpecifiers, specifier);
119441
119573
  if (specifier && modulePath.isRedirect) {
119442
119574
  // If we got a specifier for a redirect, it was a bare package specifier (e.g. "@foo/bar",
@@ -119828,7 +119960,7 @@ var ts;
119828
119960
  ? removeExtensionAndIndexPostFix(relativePath, ending, compilerOptions)
119829
119961
  : ts.removeFileExtension(relativePath);
119830
119962
  }
119831
- function tryGetModuleNameAsNodeModule(_a, _b, host, options, packageNameOnly) {
119963
+ function tryGetModuleNameAsNodeModule(_a, _b, importingSourceFile, host, options, packageNameOnly) {
119832
119964
  var path = _a.path, isRedirect = _a.isRedirect;
119833
119965
  var getCanonicalFileName = _b.getCanonicalFileName, sourceDirectory = _b.sourceDirectory;
119834
119966
  if (!host.fileExists || !host.readFile) {
@@ -119891,11 +120023,19 @@ var ts;
119891
120023
  var moduleFileToTry = path;
119892
120024
  if (host.fileExists(packageJsonPath)) {
119893
120025
  var packageJsonContent = JSON.parse(host.readFile(packageJsonPath));
119894
- // TODO: Inject `require` or `import` condition based on the intended import mode
119895
120026
  if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) {
119896
- var fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string" ? tryGetModuleNameFromExports(options, path, packageRootPath, packageJsonContent.name, packageJsonContent.exports, ["node", "types"]) : undefined;
120027
+ // `conditions` *could* be made to go against `importingSourceFile.impliedNodeFormat` if something wanted to generate
120028
+ // an ImportEqualsDeclaration in an ESM-implied file or an ImportCall in a CJS-implied file. But since this function is
120029
+ // usually called to conjure an import out of thin air, we don't have an existing usage to call `getModeForUsageAtIndex`
120030
+ // with, so for now we just stick with the mode of the file.
120031
+ var conditions = ["node", importingSourceFile.impliedNodeFormat === ts.ModuleKind.ESNext ? "import" : "require", "types"];
120032
+ var fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string"
120033
+ ? tryGetModuleNameFromExports(options, path, packageRootPath, ts.getPackageNameFromTypesPackageName(packageJsonContent.name), packageJsonContent.exports, conditions)
120034
+ : undefined;
119897
120035
  if (fromExports) {
119898
- var withJsExtension = !ts.hasTSFileExtension(fromExports.moduleFileToTry) ? fromExports : { moduleFileToTry: ts.removeFileExtension(fromExports.moduleFileToTry) + tryGetJSExtensionForFile(fromExports.moduleFileToTry, options) };
120036
+ var withJsExtension = !ts.hasTSFileExtension(fromExports.moduleFileToTry)
120037
+ ? fromExports
120038
+ : { moduleFileToTry: ts.removeFileExtension(fromExports.moduleFileToTry) + tryGetJSExtensionForFile(fromExports.moduleFileToTry, options) };
119899
120039
  return __assign(__assign({}, withJsExtension), { verbatimFromExports: true });
119900
120040
  }
119901
120041
  if (packageJsonContent.exports) {
@@ -120001,8 +120141,8 @@ var ts;
120001
120141
  }
120002
120142
  function getPathRelativeToRootDirs(path, rootDirs, getCanonicalFileName) {
120003
120143
  return ts.firstDefined(rootDirs, function (rootDir) {
120004
- var relativePath = getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName); // TODO: GH#18217
120005
- return isPathRelativeToParent(relativePath) ? undefined : relativePath;
120144
+ var relativePath = getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName);
120145
+ return relativePath !== undefined && isPathRelativeToParent(relativePath) ? undefined : relativePath;
120006
120146
  });
120007
120147
  }
120008
120148
  function removeExtensionAndIndexPostFix(fileName, ending, options) {
@@ -126631,7 +126771,7 @@ var ts;
126631
126771
  if (!ts.stringContains(importedFileName, "node_modules")) {
126632
126772
  return undefined;
126633
126773
  }
126634
- var specifier = ts.moduleSpecifiers.getNodeModulesPackageName(host.getCompilationSettings(), fromFile.path, importedFileName, moduleSpecifierResolutionHost, preferences);
126774
+ var specifier = ts.moduleSpecifiers.getNodeModulesPackageName(host.getCompilationSettings(), fromFile, importedFileName, moduleSpecifierResolutionHost, preferences);
126635
126775
  if (!specifier) {
126636
126776
  return undefined;
126637
126777
  }
@@ -136277,7 +136417,7 @@ var ts;
136277
136417
  : getSourceFileToImport(importedModuleSymbol, importLiteral, sourceFile, program, host, oldToNew);
136278
136418
  // Need an update if the imported file moved, or the importing file moved and was using a relative path.
136279
136419
  return toImport !== undefined && (toImport.updated || (importingSourceFileMoved && ts.pathIsRelative(importLiteral.text)))
136280
- ? ts.moduleSpecifiers.updateModuleSpecifier(program.getCompilerOptions(), getCanonicalFileName(newImportFromPath), toImport.newFileName, ts.createModuleSpecifierResolutionHost(program, host), importLiteral.text)
136420
+ ? ts.moduleSpecifiers.updateModuleSpecifier(program.getCompilerOptions(), sourceFile, getCanonicalFileName(newImportFromPath), toImport.newFileName, ts.createModuleSpecifierResolutionHost(program, host), importLiteral.text)
136281
136421
  : undefined;
136282
136422
  });
136283
136423
  };
@@ -137922,6 +138062,9 @@ var ts;
137922
138062
  // We use 1 NavNode to represent 'A.B.C', but there are multiple source nodes.
137923
138063
  // Only merge module nodes that have the same chain. Don't merge 'A.B.C' with 'A'!
137924
138064
  function areSameModule(a, b) {
138065
+ if (!a.body || !b.body) {
138066
+ return a.body === b.body;
138067
+ }
137925
138068
  return a.body.kind === b.body.kind && (a.body.kind !== 260 /* ModuleDeclaration */ || areSameModule(a.body, b.body));
137926
138069
  }
137927
138070
  /** Merge source into target. Source should be thrown away after this is called. */
@@ -155136,7 +155279,7 @@ var ts;
155136
155279
  defaultToNamedAction.kind,
155137
155280
  namedToDefaultAction.kind
155138
155281
  ],
155139
- getAvailableActions: function (context) {
155282
+ getAvailableActions: function getRefactorActionsToConvertBetweenNamedAndDefaultExports(context) {
155140
155283
  var info = getInfo(context, context.triggerReason === "invoked");
155141
155284
  if (!info)
155142
155285
  return ts.emptyArray;
@@ -155154,7 +155297,7 @@ var ts;
155154
155297
  }
155155
155298
  return ts.emptyArray;
155156
155299
  },
155157
- getEditsForAction: function (context, actionName) {
155300
+ getEditsForAction: function getRefactorEditsToConvertBetweenNamedAndDefaultExports(context, actionName) {
155158
155301
  ts.Debug.assert(actionName === defaultToNamedAction.name || actionName === namedToDefaultAction.name, "Unexpected action name");
155159
155302
  var info = getInfo(context);
155160
155303
  ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected applicable refactor info");
@@ -155382,7 +155525,7 @@ var ts;
155382
155525
  namespaceToNamedAction.kind,
155383
155526
  namedToNamespaceAction.kind
155384
155527
  ],
155385
- getAvailableActions: function (context) {
155528
+ getAvailableActions: function getRefactorActionsToConvertBetweenNamedAndNamespacedImports(context) {
155386
155529
  var info = getImportToConvert(context, context.triggerReason === "invoked");
155387
155530
  if (!info)
155388
155531
  return ts.emptyArray;
@@ -155401,7 +155544,7 @@ var ts;
155401
155544
  }
155402
155545
  return ts.emptyArray;
155403
155546
  },
155404
- getEditsForAction: function (context, actionName) {
155547
+ getEditsForAction: function getRefactorEditsToConvertBetweenNamedAndNamespacedImports(context, actionName) {
155405
155548
  ts.Debug.assert(actionName === namespaceToNamedAction.name || actionName === namedToNamespaceAction.name, "Unexpected action name");
155406
155549
  var info = getImportToConvert(context);
155407
155550
  ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected applicable refactor info");
@@ -155567,10 +155710,10 @@ var ts;
155567
155710
  };
155568
155711
  refactor.registerRefactor(refactorName, {
155569
155712
  kinds: [toOptionalChainAction.kind],
155570
- getAvailableActions: getAvailableActions,
155571
- getEditsForAction: getEditsForAction
155713
+ getEditsForAction: getRefactorEditsToConvertToOptionalChain,
155714
+ getAvailableActions: getRefactorActionsToConvertToOptionalChain,
155572
155715
  });
155573
- function getAvailableActions(context) {
155716
+ function getRefactorActionsToConvertToOptionalChain(context) {
155574
155717
  var info = getInfo(context, context.triggerReason === "invoked");
155575
155718
  if (!info)
155576
155719
  return ts.emptyArray;
@@ -155590,7 +155733,7 @@ var ts;
155590
155733
  }
155591
155734
  return ts.emptyArray;
155592
155735
  }
155593
- function getEditsForAction(context, actionName) {
155736
+ function getRefactorEditsToConvertToOptionalChain(context, actionName) {
155594
155737
  var info = getInfo(context);
155595
155738
  ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected applicable refactor info");
155596
155739
  var edits = ts.textChanges.ChangeTracker.with(context, function (t) {
@@ -155833,10 +155976,10 @@ var ts;
155833
155976
  };
155834
155977
  refactor.registerRefactor(refactorName, {
155835
155978
  kinds: [functionOverloadAction.kind],
155836
- getEditsForAction: getEditsForAction,
155837
- getAvailableActions: getAvailableActions
155979
+ getEditsForAction: getRefactorEditsToConvertOverloadsToOneSignature,
155980
+ getAvailableActions: getRefactorActionsToConvertOverloadsToOneSignature
155838
155981
  });
155839
- function getAvailableActions(context) {
155982
+ function getRefactorActionsToConvertOverloadsToOneSignature(context) {
155840
155983
  var file = context.file, startPosition = context.startPosition, program = context.program;
155841
155984
  var info = getConvertableOverloadListAtPosition(file, startPosition, program);
155842
155985
  if (!info)
@@ -155847,7 +155990,7 @@ var ts;
155847
155990
  actions: [functionOverloadAction]
155848
155991
  }];
155849
155992
  }
155850
- function getEditsForAction(context) {
155993
+ function getRefactorEditsToConvertOverloadsToOneSignature(context) {
155851
155994
  var file = context.file, startPosition = context.startPosition, program = context.program;
155852
155995
  var signatureDecls = getConvertableOverloadListAtPosition(file, startPosition, program);
155853
155996
  if (!signatureDecls)
@@ -156003,14 +156146,14 @@ var ts;
156003
156146
  extractConstantAction.kind,
156004
156147
  extractFunctionAction.kind
156005
156148
  ],
156006
- getAvailableActions: getAvailableActions,
156007
- getEditsForAction: getEditsForAction
156149
+ getEditsForAction: getRefactorEditsToExtractSymbol,
156150
+ getAvailableActions: getRefactorActionsToExtractSymbol,
156008
156151
  });
156009
156152
  /**
156010
156153
  * Compute the associated code actions
156011
156154
  * Exported for tests.
156012
156155
  */
156013
- function getAvailableActions(context) {
156156
+ function getRefactorActionsToExtractSymbol(context) {
156014
156157
  var requestedRefactor = context.kind;
156015
156158
  var rangeToExtract = getRangeToExtract(context.file, ts.getRefactorContextSpan(context), context.triggerReason === "invoked");
156016
156159
  var targetRange = rangeToExtract.targetRange;
@@ -156139,9 +156282,9 @@ var ts;
156139
156282
  return error;
156140
156283
  }
156141
156284
  }
156142
- extractSymbol.getAvailableActions = getAvailableActions;
156285
+ extractSymbol.getRefactorActionsToExtractSymbol = getRefactorActionsToExtractSymbol;
156143
156286
  /* Exported for tests */
156144
- function getEditsForAction(context, actionName) {
156287
+ function getRefactorEditsToExtractSymbol(context, actionName) {
156145
156288
  var rangeToExtract = getRangeToExtract(context.file, ts.getRefactorContextSpan(context));
156146
156289
  var targetRange = rangeToExtract.targetRange; // TODO:GH#18217
156147
156290
  var parsedFunctionIndexMatch = /^function_scope_(\d+)$/.exec(actionName);
@@ -156158,7 +156301,7 @@ var ts;
156158
156301
  }
156159
156302
  ts.Debug.fail("Unrecognized action name");
156160
156303
  }
156161
- extractSymbol.getEditsForAction = getEditsForAction;
156304
+ extractSymbol.getRefactorEditsToExtractSymbol = getRefactorEditsToExtractSymbol;
156162
156305
  // Move these into diagnostic messages if they become user-facing
156163
156306
  var Messages;
156164
156307
  (function (Messages) {
@@ -157709,7 +157852,7 @@ var ts;
157709
157852
  extractToInterfaceAction.kind,
157710
157853
  extractToTypeDefAction.kind
157711
157854
  ],
157712
- getAvailableActions: function (context) {
157855
+ getAvailableActions: function getRefactorActionsToExtractType(context) {
157713
157856
  var info = getRangeToExtract(context, context.triggerReason === "invoked");
157714
157857
  if (!info)
157715
157858
  return ts.emptyArray;
@@ -157734,7 +157877,7 @@ var ts;
157734
157877
  }
157735
157878
  return ts.emptyArray;
157736
157879
  },
157737
- getEditsForAction: function (context, actionName) {
157880
+ getEditsForAction: function getRefactorEditsToExtractType(context, actionName) {
157738
157881
  var file = context.file;
157739
157882
  var info = getRangeToExtract(context);
157740
157883
  ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected to find a range to extract");
@@ -157902,7 +158045,7 @@ var ts;
157902
158045
  };
157903
158046
  refactor.registerRefactor(actionName, {
157904
158047
  kinds: [generateGetSetAction.kind],
157905
- getEditsForAction: function (context, actionName) {
158048
+ getEditsForAction: function getRefactorActionsToGenerateGetAndSetAccessors(context, actionName) {
157906
158049
  if (!context.endPosition)
157907
158050
  return undefined;
157908
158051
  var info = ts.codefix.getAccessorConvertiblePropertyAtPosition(context.file, context.program, context.startPosition, context.endPosition);
@@ -157981,7 +158124,7 @@ var ts;
157981
158124
  };
157982
158125
  refactor.registerRefactor(refactorName, {
157983
158126
  kinds: [moveToNewFileAction.kind],
157984
- getAvailableActions: function (context) {
158127
+ getAvailableActions: function getRefactorActionsToMoveToNewFile(context) {
157985
158128
  var statements = getStatementsToMove(context);
157986
158129
  if (context.preferences.allowTextChangesInNewFiles && statements) {
157987
158130
  return [{ name: refactorName, description: description, actions: [moveToNewFileAction] }];
@@ -157992,7 +158135,7 @@ var ts;
157992
158135
  }
157993
158136
  return ts.emptyArray;
157994
158137
  },
157995
- getEditsForAction: function (context, actionName) {
158138
+ getEditsForAction: function getRefactorEditsToMoveToNewFile(context, actionName) {
157996
158139
  ts.Debug.assert(actionName === refactorName, "Wrong refactor invoked");
157997
158140
  var statements = ts.Debug.checkDefined(getStatementsToMove(context));
157998
158141
  var edits = ts.textChanges.ChangeTracker.with(context, function (t) { return doChange(context.file, context.program, statements, t, context.host, context.preferences); });
@@ -158723,10 +158866,10 @@ var ts;
158723
158866
  };
158724
158867
  refactor.registerRefactor(refactorName, {
158725
158868
  kinds: [removeBracesAction.kind],
158726
- getEditsForAction: getEditsForAction,
158727
- getAvailableActions: getAvailableActions
158869
+ getEditsForAction: getRefactorEditsToRemoveFunctionBraces,
158870
+ getAvailableActions: getRefactorActionsToRemoveFunctionBraces
158728
158871
  });
158729
- function getAvailableActions(context) {
158872
+ function getRefactorActionsToRemoveFunctionBraces(context) {
158730
158873
  var file = context.file, startPosition = context.startPosition, triggerReason = context.triggerReason;
158731
158874
  var info = getConvertibleArrowFunctionAtPosition(file, startPosition, triggerReason === "invoked");
158732
158875
  if (!info)
@@ -158752,7 +158895,7 @@ var ts;
158752
158895
  }
158753
158896
  return ts.emptyArray;
158754
158897
  }
158755
- function getEditsForAction(context, actionName) {
158898
+ function getRefactorEditsToRemoveFunctionBraces(context, actionName) {
158756
158899
  var file = context.file, startPosition = context.startPosition;
158757
158900
  var info = getConvertibleArrowFunctionAtPosition(file, startPosition);
158758
158901
  ts.Debug.assert(info && !refactor.isRefactorErrorInfo(info), "Expected applicable refactor info");
@@ -158826,10 +158969,10 @@ var ts;
158826
158969
  };
158827
158970
  refactor.registerRefactor(refactorName, {
158828
158971
  kinds: [toDestructuredAction.kind],
158829
- getEditsForAction: getEditsForAction,
158830
- getAvailableActions: getAvailableActions
158972
+ getEditsForAction: getRefactorEditsToConvertParametersToDestructuredObject,
158973
+ getAvailableActions: getRefactorActionsToConvertParametersToDestructuredObject
158831
158974
  });
158832
- function getAvailableActions(context) {
158975
+ function getRefactorActionsToConvertParametersToDestructuredObject(context) {
158833
158976
  var file = context.file, startPosition = context.startPosition;
158834
158977
  var isJSFile = ts.isSourceFileJS(file);
158835
158978
  if (isJSFile)
@@ -158843,7 +158986,7 @@ var ts;
158843
158986
  actions: [toDestructuredAction]
158844
158987
  }];
158845
158988
  }
158846
- function getEditsForAction(context, actionName) {
158989
+ function getRefactorEditsToConvertParametersToDestructuredObject(context, actionName) {
158847
158990
  ts.Debug.assert(actionName === refactorName, "Unexpected action name");
158848
158991
  var file = context.file, startPosition = context.startPosition, program = context.program, cancellationToken = context.cancellationToken, host = context.host;
158849
158992
  var functionDeclaration = getFunctionDeclarationAtPosition(file, startPosition, program.getTypeChecker());
@@ -159353,10 +159496,10 @@ var ts;
159353
159496
  };
159354
159497
  refactor.registerRefactor(refactorName, {
159355
159498
  kinds: [convertStringAction.kind],
159356
- getEditsForAction: getEditsForAction,
159357
- getAvailableActions: getAvailableActions
159499
+ getEditsForAction: getRefactorEditsToConvertToTemplateString,
159500
+ getAvailableActions: getRefactorActionsToConvertToTemplateString
159358
159501
  });
159359
- function getAvailableActions(context) {
159502
+ function getRefactorActionsToConvertToTemplateString(context) {
159360
159503
  var file = context.file, startPosition = context.startPosition;
159361
159504
  var node = getNodeOrParentOfParentheses(file, startPosition);
159362
159505
  var maybeBinary = getParentBinaryExpression(node);
@@ -159382,7 +159525,7 @@ var ts;
159382
159525
  }
159383
159526
  return node;
159384
159527
  }
159385
- function getEditsForAction(context, actionName) {
159528
+ function getRefactorEditsToConvertToTemplateString(context, actionName) {
159386
159529
  var file = context.file, startPosition = context.startPosition;
159387
159530
  var node = getNodeOrParentOfParentheses(file, startPosition);
159388
159531
  switch (actionName) {
@@ -159596,10 +159739,10 @@ var ts;
159596
159739
  toNamedFunctionAction.kind,
159597
159740
  toArrowFunctionAction.kind
159598
159741
  ],
159599
- getEditsForAction: getEditsForAction,
159600
- getAvailableActions: getAvailableActions
159742
+ getEditsForAction: getRefactorEditsToConvertFunctionExpressions,
159743
+ getAvailableActions: getRefactorActionsToConvertFunctionExpressions
159601
159744
  });
159602
- function getAvailableActions(context) {
159745
+ function getRefactorActionsToConvertFunctionExpressions(context) {
159603
159746
  var file = context.file, startPosition = context.startPosition, program = context.program, kind = context.kind;
159604
159747
  var info = getFunctionInfo(file, startPosition, program);
159605
159748
  if (!info)
@@ -159643,7 +159786,7 @@ var ts;
159643
159786
  errors : possibleActions
159644
159787
  }];
159645
159788
  }
159646
- function getEditsForAction(context, actionName) {
159789
+ function getRefactorEditsToConvertFunctionExpressions(context, actionName) {
159647
159790
  var file = context.file, startPosition = context.startPosition, program = context.program;
159648
159791
  var info = getFunctionInfo(file, startPosition, program);
159649
159792
  if (!info)
@@ -159803,10 +159946,10 @@ var ts;
159803
159946
  };
159804
159947
  refactor.registerRefactor(refactorName, {
159805
159948
  kinds: [inferReturnTypeAction.kind],
159806
- getEditsForAction: getEditsForAction,
159807
- getAvailableActions: getAvailableActions
159949
+ getEditsForAction: getRefactorEditsToInferReturnType,
159950
+ getAvailableActions: getRefactorActionsToInferReturnType
159808
159951
  });
159809
- function getEditsForAction(context) {
159952
+ function getRefactorEditsToInferReturnType(context) {
159810
159953
  var info = getInfo(context);
159811
159954
  if (info && !refactor.isRefactorErrorInfo(info)) {
159812
159955
  var edits = ts.textChanges.ChangeTracker.with(context, function (t) { return doChange(context.file, t, info.declaration, info.returnTypeNode); });
@@ -159814,7 +159957,7 @@ var ts;
159814
159957
  }
159815
159958
  return undefined;
159816
159959
  }
159817
- function getAvailableActions(context) {
159960
+ function getRefactorActionsToInferReturnType(context) {
159818
159961
  var info = getInfo(context);
159819
159962
  if (!info)
159820
159963
  return ts.emptyArray;