typescript 4.7.0-dev.20220505 → 4.8.0-dev.20220508

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.
@@ -85,11 +85,11 @@ var ts;
85
85
  (function (ts) {
86
86
  // WARNING: The script `configurePrerelease.ts` uses a regexp to parse out these values.
87
87
  // If changing the text in this section, be sure to test `configurePrerelease` too.
88
- ts.versionMajorMinor = "4.7";
88
+ ts.versionMajorMinor = "4.8";
89
89
  // The following is baselined as a literal template type without intervention
90
90
  /** The version of the TypeScript compiler release */
91
91
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
92
- ts.version = ts.versionMajorMinor + ".0-dev.20220505";
92
+ ts.version = ts.versionMajorMinor + ".0-dev.20220508";
93
93
  /* @internal */
94
94
  var Comparison;
95
95
  (function (Comparison) {
@@ -8398,6 +8398,8 @@ var ts;
8398
8398
  Construct_signatures_with_no_arguments_have_incompatible_return_types_0_and_1: diag(2205, ts.DiagnosticCategory.Error, "Construct_signatures_with_no_arguments_have_incompatible_return_types_0_and_1_2205", "Construct signatures with no arguments have incompatible return types '{0}' and '{1}'.", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ true),
8399
8399
  The_type_modifier_cannot_be_used_on_a_named_import_when_import_type_is_used_on_its_import_statement: diag(2206, ts.DiagnosticCategory.Error, "The_type_modifier_cannot_be_used_on_a_named_import_when_import_type_is_used_on_its_import_statement_2206", "The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement."),
8400
8400
  The_type_modifier_cannot_be_used_on_a_named_export_when_export_type_is_used_on_its_export_statement: diag(2207, ts.DiagnosticCategory.Error, "The_type_modifier_cannot_be_used_on_a_named_export_when_export_type_is_used_on_its_export_statement_2207", "The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement."),
8401
+ The_project_root_is_ambiguous_but_is_required_to_resolve_export_map_entry_0_in_file_1_Supply_the_rootDir_compiler_option_to_disambiguate: diag(2209, ts.DiagnosticCategory.Error, "The_project_root_is_ambiguous_but_is_required_to_resolve_export_map_entry_0_in_file_1_Supply_the_roo_2209", "The project root is ambiguous, but is required to resolve export map entry '{0}' in file '{1}'. Supply the `rootDir` compiler option to disambiguate."),
8402
+ The_project_root_is_ambiguous_but_is_required_to_resolve_import_map_entry_0_in_file_1_Supply_the_rootDir_compiler_option_to_disambiguate: diag(2210, ts.DiagnosticCategory.Error, "The_project_root_is_ambiguous_but_is_required_to_resolve_import_map_entry_0_in_file_1_Supply_the_roo_2210", "The project root is ambiguous, but is required to resolve import map entry '{0}' in file '{1}'. Supply the `rootDir` compiler option to disambiguate."),
8401
8403
  Duplicate_identifier_0: diag(2300, ts.DiagnosticCategory.Error, "Duplicate_identifier_0_2300", "Duplicate identifier '{0}'."),
8402
8404
  Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: diag(2301, ts.DiagnosticCategory.Error, "Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor_2301", "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor."),
8403
8405
  Static_members_cannot_reference_class_type_parameters: diag(2302, ts.DiagnosticCategory.Error, "Static_members_cannot_reference_class_type_parameters_2302", "Static members cannot reference class type parameters."),
@@ -8987,6 +8989,7 @@ var ts;
8987
8989
  This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0: diag(4122, ts.DiagnosticCategory.Error, "This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base__4122", "This member cannot have a JSDoc comment with an '@override' tag because it is not declared in the base class '{0}'."),
8988
8990
  This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0_Did_you_mean_1: diag(4123, ts.DiagnosticCategory.Error, "This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base__4123", "This member cannot have a JSDoc comment with an 'override' tag because it is not declared in the base class '{0}'. Did you mean '{1}'?"),
8989
8991
  Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(4124, ts.DiagnosticCategory.Error, "Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_w_4124", "Compiler option '{0}' of value '{1}' is unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."),
8992
+ Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(4125, ts.DiagnosticCategory.Error, "Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_wi_4125", "Resolution mode assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."),
8990
8993
  The_current_host_does_not_support_the_0_option: diag(5001, ts.DiagnosticCategory.Error, "The_current_host_does_not_support_the_0_option_5001", "The current host does not support the '{0}' option."),
8991
8994
  Cannot_find_the_common_subdirectory_path_for_the_input_files: diag(5009, ts.DiagnosticCategory.Error, "Cannot_find_the_common_subdirectory_path_for_the_input_files_5009", "Cannot find the common subdirectory path for the input files."),
8992
8995
  File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0: diag(5010, ts.DiagnosticCategory.Error, "File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0_5010", "File specification cannot end in a recursive directory wildcard ('**'): '{0}'."),
@@ -17993,6 +17996,10 @@ var ts;
17993
17996
  return indentStrings[1].length;
17994
17997
  }
17995
17998
  ts.getIndentSize = getIndentSize;
17999
+ function isNightly() {
18000
+ return ts.stringContains(ts.version, "-dev") || ts.stringContains(ts.version, "-insiders");
18001
+ }
18002
+ ts.isNightly = isNightly;
17996
18003
  function createTextWriter(newLine) {
17997
18004
  var output;
17998
18005
  var indent;
@@ -18223,6 +18230,16 @@ var ts;
18223
18230
  ".d.ts" /* Dts */;
18224
18231
  }
18225
18232
  ts.getDeclarationEmitExtensionForPath = getDeclarationEmitExtensionForPath;
18233
+ /**
18234
+ * This function is an inverse of `getDeclarationEmitExtensionForPath`.
18235
+ */
18236
+ function getPossibleOriginalInputExtensionForExtension(path) {
18237
+ return ts.fileExtensionIsOneOf(path, [".d.mts" /* Dmts */, ".mjs" /* Mjs */, ".mts" /* Mts */]) ? [".mts" /* Mts */, ".mjs" /* Mjs */] :
18238
+ ts.fileExtensionIsOneOf(path, [".d.cts" /* Dcts */, ".cjs" /* Cjs */, ".cts" /* Cts */]) ? [".cts" /* Cts */, ".cjs" /* Cjs */] :
18239
+ ts.fileExtensionIsOneOf(path, [".json.d.ts"]) ? [".json" /* Json */] :
18240
+ [".tsx" /* Tsx */, ".ts" /* Ts */, ".jsx" /* Jsx */, ".js" /* Js */];
18241
+ }
18242
+ ts.getPossibleOriginalInputExtensionForExtension = getPossibleOriginalInputExtensionForExtension;
18226
18243
  function outFile(options) {
18227
18244
  return options.outFile || options.out;
18228
18245
  }
@@ -32830,6 +32847,7 @@ var ts;
32830
32847
  var startPos = scanner.getStartPos();
32831
32848
  var result = parseListElement(kind, parseElement);
32832
32849
  if (!result) {
32850
+ parsingContext = saveParsingContext;
32833
32851
  return undefined;
32834
32852
  }
32835
32853
  list.push(result);
@@ -38944,6 +38962,7 @@ var ts;
38944
38962
  ["es2021.intl", "lib.es2021.intl.d.ts"],
38945
38963
  ["es2022.array", "lib.es2022.array.d.ts"],
38946
38964
  ["es2022.error", "lib.es2022.error.d.ts"],
38965
+ ["es2022.intl", "lib.es2022.intl.d.ts"],
38947
38966
  ["es2022.object", "lib.es2022.object.d.ts"],
38948
38967
  ["es2022.string", "lib.es2022.string.d.ts"],
38949
38968
  ["esnext.array", "lib.es2022.array.d.ts"],
@@ -42142,7 +42161,7 @@ var ts;
42142
42161
  ts.Debug.assert(ts.extensionIsTS(resolved.extension));
42143
42162
  return { fileName: resolved.path, packageId: resolved.packageId };
42144
42163
  }
42145
- function createResolvedModuleWithFailedLookupLocations(resolved, isExternalLibraryImport, failedLookupLocations, resultFromCache) {
42164
+ function createResolvedModuleWithFailedLookupLocations(resolved, isExternalLibraryImport, failedLookupLocations, diagnostics, resultFromCache) {
42146
42165
  var _a;
42147
42166
  if (resultFromCache) {
42148
42167
  (_a = resultFromCache.failedLookupLocations).push.apply(_a, failedLookupLocations);
@@ -42150,7 +42169,8 @@ var ts;
42150
42169
  }
42151
42170
  return {
42152
42171
  resolvedModule: resolved && { resolvedFileName: resolved.path, originalPath: resolved.originalPath === true ? undefined : resolved.originalPath, extension: resolved.extension, isExternalLibraryImport: isExternalLibraryImport, packageId: resolved.packageId },
42153
- failedLookupLocations: failedLookupLocations
42172
+ failedLookupLocations: failedLookupLocations,
42173
+ resolutionDiagnostics: diagnostics
42154
42174
  };
42155
42175
  }
42156
42176
  function readPackageJsonField(jsonContent, fieldName, typeOfTag, state) {
@@ -42351,7 +42371,18 @@ var ts;
42351
42371
  features |= NodeResolutionFeatures.EsmMode;
42352
42372
  }
42353
42373
  var conditions = features & NodeResolutionFeatures.Exports ? features & NodeResolutionFeatures.EsmMode ? ["node", "import", "types"] : ["node", "require", "types"] : [];
42354
- var moduleResolutionState = { compilerOptions: options, host: host, traceEnabled: traceEnabled, failedLookupLocations: failedLookupLocations, packageJsonInfoCache: cache, features: features, conditions: conditions };
42374
+ var diagnostics = [];
42375
+ var moduleResolutionState = {
42376
+ compilerOptions: options,
42377
+ host: host,
42378
+ traceEnabled: traceEnabled,
42379
+ failedLookupLocations: failedLookupLocations,
42380
+ packageJsonInfoCache: cache,
42381
+ features: features,
42382
+ conditions: conditions,
42383
+ requestContainingDirectory: containingDirectory,
42384
+ reportDiagnostic: function (diag) { return void diagnostics.push(diag); },
42385
+ };
42355
42386
  var resolved = primaryLookup();
42356
42387
  var primary = true;
42357
42388
  if (!resolved) {
@@ -42370,7 +42401,7 @@ var ts;
42370
42401
  isExternalLibraryImport: pathContainsNodeModules(fileName),
42371
42402
  };
42372
42403
  }
42373
- result = { resolvedTypeReferenceDirective: resolvedTypeReferenceDirective, failedLookupLocations: failedLookupLocations };
42404
+ result = { resolvedTypeReferenceDirective: resolvedTypeReferenceDirective, failedLookupLocations: failedLookupLocations, resolutionDiagnostics: diagnostics };
42374
42405
  perFolderCache === null || perFolderCache === void 0 ? void 0 : perFolderCache.set(typeReferenceDirectiveName, /*mode*/ resolutionMode, result);
42375
42406
  if (traceEnabled)
42376
42407
  traceResult(result);
@@ -42453,6 +42484,8 @@ var ts;
42453
42484
  packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
42454
42485
  conditions: ts.emptyArray,
42455
42486
  features: NodeResolutionFeatures.None,
42487
+ requestContainingDirectory: containingDirectory,
42488
+ reportDiagnostic: ts.noop
42456
42489
  };
42457
42490
  return ts.forEachAncestorDirectory(containingDirectory, function (ancestorDirectory) {
42458
42491
  if (ts.getBaseFileName(ancestorDirectory) !== "node_modules") {
@@ -43104,6 +43137,7 @@ var ts;
43104
43137
  if (compilerOptions.noDtsResolution) {
43105
43138
  conditions.pop();
43106
43139
  }
43140
+ var diagnostics = [];
43107
43141
  var state = {
43108
43142
  compilerOptions: compilerOptions,
43109
43143
  host: host,
@@ -43112,9 +43146,11 @@ var ts;
43112
43146
  packageJsonInfoCache: cache,
43113
43147
  features: features,
43114
43148
  conditions: conditions,
43149
+ requestContainingDirectory: containingDirectory,
43150
+ reportDiagnostic: function (diag) { return void diagnostics.push(diag); },
43115
43151
  };
43116
43152
  var result = ts.forEach(extensions, function (ext) { return tryResolve(ext); });
43117
- return createResolvedModuleWithFailedLookupLocations((_a = result === null || result === void 0 ? void 0 : result.value) === null || _a === void 0 ? void 0 : _a.resolved, (_b = result === null || result === void 0 ? void 0 : result.value) === null || _b === void 0 ? void 0 : _b.isExternalLibraryImport, failedLookupLocations, state.resultFromCache);
43153
+ return createResolvedModuleWithFailedLookupLocations((_a = result === null || result === void 0 ? void 0 : result.value) === null || _a === void 0 ? void 0 : _a.resolved, (_b = result === null || result === void 0 ? void 0 : result.value) === null || _b === void 0 ? void 0 : _b.isExternalLibraryImport, failedLookupLocations, diagnostics, state.resultFromCache);
43118
43154
  function tryResolve(extensions) {
43119
43155
  var loader = function (extensions, candidate, onlyRecordFailures, state) { return nodeLoadModuleByRelativeName(extensions, candidate, onlyRecordFailures, state, /*considerPackageJson*/ true); };
43120
43156
  var resolved = tryLoadModuleUsingOptionalResolutionSettings(extensions, moduleName, containingDirectory, loader, state);
@@ -43287,9 +43323,9 @@ var ts;
43287
43323
  }
43288
43324
  }
43289
43325
  function loadJSOrExactTSFileName(extensions, candidate, onlyRecordFailures, state) {
43290
- if ((extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) && ts.isDeclarationFileName(candidate)) {
43326
+ if ((extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) && ts.fileExtensionIsOneOf(candidate, ts.supportedTSExtensionsFlat)) {
43291
43327
  var result = tryFile(candidate, onlyRecordFailures, state);
43292
- return result !== undefined ? { path: candidate, ext: ts.forEach(ts.supportedDeclarationExtensions, function (e) { return ts.fileExtensionIs(candidate, e) ? e : undefined; }) } : undefined;
43328
+ return result !== undefined ? { path: candidate, ext: ts.tryExtractTSExtension(candidate) } : undefined;
43293
43329
  }
43294
43330
  return loadModuleFromFileNoImplicitExtensions(extensions, candidate, onlyRecordFailures, state);
43295
43331
  }
@@ -43412,6 +43448,8 @@ var ts;
43412
43448
  packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
43413
43449
  conditions: ["node", "require", "types"],
43414
43450
  features: features,
43451
+ requestContainingDirectory: packageJsonInfo.packageDirectory,
43452
+ reportDiagnostic: ts.noop
43415
43453
  };
43416
43454
  var requireResolution = loadNodeModuleFromDirectoryWorker(extensions, packageJsonInfo.packageDirectory,
43417
43455
  /*onlyRecordFailures*/ false, requireState, packageJsonInfo.packageJsonContent, packageJsonInfo.versionPaths);
@@ -43498,6 +43536,8 @@ var ts;
43498
43536
  packageJsonInfoCache: packageJsonInfoCache,
43499
43537
  features: 0,
43500
43538
  conditions: [],
43539
+ requestContainingDirectory: undefined,
43540
+ reportDiagnostic: ts.noop
43501
43541
  };
43502
43542
  var parts = ts.getPathComponents(fileName);
43503
43543
  parts.pop();
@@ -43789,7 +43829,6 @@ var ts;
43789
43829
  function getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, moduleName, scope, isImports) {
43790
43830
  return loadModuleFromTargetImportOrExport;
43791
43831
  function loadModuleFromTargetImportOrExport(target, subpath, pattern) {
43792
- var _a, _b;
43793
43832
  if (typeof target === "string") {
43794
43833
  if (!pattern && subpath.length > 0 && !ts.endsWith(target, "/")) {
43795
43834
  if (state.traceEnabled) {
@@ -43826,13 +43865,16 @@ var ts;
43826
43865
  }
43827
43866
  return toSearchResult(/*value*/ undefined);
43828
43867
  }
43829
- var finalPath = ts.getNormalizedAbsolutePath(pattern ? resolvedTarget.replace(/\*/g, subpath) : resolvedTarget + subpath, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a));
43868
+ var finalPath = toAbsolutePath(pattern ? resolvedTarget.replace(/\*/g, subpath) : resolvedTarget + subpath);
43869
+ var inputLink = tryLoadInputFileForPath(finalPath, subpath, ts.combinePaths(scope.packageDirectory, "package.json"), isImports);
43870
+ if (inputLink)
43871
+ return inputLink;
43830
43872
  return toSearchResult(withPackageId(scope, loadJSOrExactTSFileName(extensions, finalPath, /*onlyRecordFailures*/ false, state)));
43831
43873
  }
43832
43874
  else if (typeof target === "object" && target !== null) { // eslint-disable-line no-null/no-null
43833
43875
  if (!Array.isArray(target)) {
43834
- for (var _i = 0, _c = ts.getOwnKeys(target); _i < _c.length; _i++) {
43835
- var key = _c[_i];
43876
+ for (var _i = 0, _a = ts.getOwnKeys(target); _i < _a.length; _i++) {
43877
+ var key = _a[_i];
43836
43878
  if (key === "default" || state.conditions.indexOf(key) >= 0 || isApplicableVersionedTypesKey(state.conditions, key)) {
43837
43879
  var subTarget = target[key];
43838
43880
  var result = loadModuleFromTargetImportOrExport(subTarget, subpath, pattern);
@@ -43850,8 +43892,8 @@ var ts;
43850
43892
  }
43851
43893
  return toSearchResult(/*value*/ undefined);
43852
43894
  }
43853
- for (var _d = 0, target_2 = target; _d < target_2.length; _d++) {
43854
- var elem = target_2[_d];
43895
+ for (var _b = 0, target_2 = target; _b < target_2.length; _b++) {
43896
+ var elem = target_2[_b];
43855
43897
  var result = loadModuleFromTargetImportOrExport(elem, subpath, pattern);
43856
43898
  if (result) {
43857
43899
  return result;
@@ -43869,6 +43911,128 @@ var ts;
43869
43911
  trace(state.host, ts.Diagnostics.package_json_scope_0_has_invalid_type_for_target_of_specifier_1, scope.packageDirectory, moduleName);
43870
43912
  }
43871
43913
  return toSearchResult(/*value*/ undefined);
43914
+ function toAbsolutePath(path) {
43915
+ var _a, _b;
43916
+ if (path === undefined)
43917
+ return path;
43918
+ return ts.hostGetCanonicalFileName({ useCaseSensitiveFileNames: useCaseSensitiveFileNames })(ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)));
43919
+ }
43920
+ function combineDirectoryPath(root, dir) {
43921
+ return ts.ensureTrailingDirectorySeparator(ts.combinePaths(root, dir));
43922
+ }
43923
+ function useCaseSensitiveFileNames() {
43924
+ return !state.host.useCaseSensitiveFileNames ? true :
43925
+ typeof state.host.useCaseSensitiveFileNames === "boolean" ? state.host.useCaseSensitiveFileNames :
43926
+ state.host.useCaseSensitiveFileNames();
43927
+ }
43928
+ function tryLoadInputFileForPath(finalPath, entry, packagePath, isImports) {
43929
+ var _a, _b, _c, _d;
43930
+ // Replace any references to outputs for files in the program with the input files to support package self-names used with outDir
43931
+ // PROBLEM: We don't know how to calculate the output paths yet, because the "common source directory" we use as the base of the file structure
43932
+ // we reproduce into the output directory is based on the set of input files, which we're still in the process of traversing and resolving!
43933
+ // _Given that_, we have to guess what the base of the output directory is (obviously the user wrote the export map, so has some idea what it is!).
43934
+ // We are going to probe _so many_ possible paths. We limit where we'll do this to try to reduce the possibilities of false positive lookups.
43935
+ if ((extensions === Extensions.TypeScript || extensions === Extensions.JavaScript || extensions === Extensions.Json)
43936
+ && (state.compilerOptions.declarationDir || state.compilerOptions.outDir)
43937
+ && finalPath.indexOf("/node_modules/") === -1
43938
+ && (state.compilerOptions.configFile ? ts.startsWith(toAbsolutePath(state.compilerOptions.configFile.fileName), scope.packageDirectory) : true)) {
43939
+ // So that all means we'll only try these guesses for files outside `node_modules` in a directory where the `package.json` and `tsconfig.json` are siblings.
43940
+ // Even with all that, we still don't know if the root of the output file structure will be (relative to the package file)
43941
+ // `.`, `./src` or any other deeper directory structure. (If project references are used, it's definitely `.` by fiat, so that should be pretty common.)
43942
+ var getCanonicalFileName = ts.hostGetCanonicalFileName({ useCaseSensitiveFileNames: useCaseSensitiveFileNames });
43943
+ var commonSourceDirGuesses = [];
43944
+ // A `rootDir` compiler option strongly indicates the root location
43945
+ // A `composite` project is using project references and has it's common src dir set to `.`, so it shouldn't need to check any other locations
43946
+ if (state.compilerOptions.rootDir || (state.compilerOptions.composite && state.compilerOptions.configFilePath)) {
43947
+ var commonDir = toAbsolutePath(ts.getCommonSourceDirectory(state.compilerOptions, function () { return []; }, ((_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)) || "", getCanonicalFileName));
43948
+ commonSourceDirGuesses.push(commonDir);
43949
+ }
43950
+ else if (state.requestContainingDirectory) {
43951
+ // However without either of those set we're in the dark. Let's say you have
43952
+ //
43953
+ // ./tools/index.ts
43954
+ // ./src/index.ts
43955
+ // ./dist/index.js
43956
+ // ./package.json <-- references ./dist/index.js
43957
+ // ./tsconfig.json <-- loads ./src/index.ts
43958
+ //
43959
+ // How do we know `./src` is the common src dir, and not `./tools`, given only the `./dist` out dir and `./dist/index.js` filename?
43960
+ // Answer: We... don't. We know we're looking for an `index.ts` input file, but we have _no clue_ which subfolder it's supposed to be loaded from
43961
+ // without more context.
43962
+ // But we do have more context! Just a tiny bit more! We're resolving an import _for some other input file_! And that input file, too
43963
+ // must be inside the common source directory! So we propagate that tidbit of info all the way to here via state.requestContainingDirectory
43964
+ var requestingFile_1 = toAbsolutePath(ts.combinePaths(state.requestContainingDirectory, "index.ts"));
43965
+ // And we can try every folder above the common folder for the request folder and the config/package base directory
43966
+ // This technically can be wrong - we may load ./src/index.ts when ./src/sub/index.ts was right because we don't
43967
+ // know if only `./src/sub` files were loaded by the program; but this has the best chance to be right of just about anything
43968
+ // else we have. And, given that we're about to load `./src/index.ts` because we choose it as likely correct, there will then
43969
+ // be a file outside of `./src/sub` in the program (the file we resolved to), making us de-facto right. So this fallback lookup
43970
+ // logic may influence what files are pulled in by self-names, which in turn influences the output path shape, but it's all
43971
+ // internally consistent so the paths should be stable so long as we prefer the "most general" (meaning: top-most-level directory) possible results first.
43972
+ var commonDir = toAbsolutePath(ts.getCommonSourceDirectory(state.compilerOptions, function () { return [requestingFile_1, toAbsolutePath(packagePath)]; }, ((_d = (_c = state.host).getCurrentDirectory) === null || _d === void 0 ? void 0 : _d.call(_c)) || "", getCanonicalFileName));
43973
+ commonSourceDirGuesses.push(commonDir);
43974
+ var fragment = ts.ensureTrailingDirectorySeparator(commonDir);
43975
+ while (fragment && fragment.length > 1) {
43976
+ var parts = ts.getPathComponents(fragment);
43977
+ parts.pop(); // remove a directory
43978
+ var commonDir_1 = ts.getPathFromPathComponents(parts);
43979
+ commonSourceDirGuesses.unshift(commonDir_1);
43980
+ fragment = ts.ensureTrailingDirectorySeparator(commonDir_1);
43981
+ }
43982
+ }
43983
+ if (commonSourceDirGuesses.length > 1) {
43984
+ state.reportDiagnostic(ts.createCompilerDiagnostic(isImports
43985
+ ? ts.Diagnostics.The_project_root_is_ambiguous_but_is_required_to_resolve_import_map_entry_0_in_file_1_Supply_the_rootDir_compiler_option_to_disambiguate
43986
+ : ts.Diagnostics.The_project_root_is_ambiguous_but_is_required_to_resolve_export_map_entry_0_in_file_1_Supply_the_rootDir_compiler_option_to_disambiguate, entry === "" ? "." : entry, // replace empty string with `.` - the reverse of the operation done when entries are built - so main entrypoint errors don't look weird
43987
+ packagePath));
43988
+ }
43989
+ for (var _i = 0, commonSourceDirGuesses_1 = commonSourceDirGuesses; _i < commonSourceDirGuesses_1.length; _i++) {
43990
+ var commonSourceDirGuess = commonSourceDirGuesses_1[_i];
43991
+ var candidateDirectories = getOutputDirectoriesForBaseDirectory(commonSourceDirGuess);
43992
+ for (var _e = 0, candidateDirectories_1 = candidateDirectories; _e < candidateDirectories_1.length; _e++) {
43993
+ var candidateDir = candidateDirectories_1[_e];
43994
+ if (ts.startsWith(finalPath, candidateDir)) {
43995
+ // The matched export is looking up something in either the out declaration or js dir, now map the written path back into the source dir and source extension
43996
+ var pathFragment = finalPath.slice(candidateDir.length + 1); // +1 to also remove directory seperator
43997
+ var possibleInputBase = ts.combinePaths(commonSourceDirGuess, pathFragment);
43998
+ var jsAndDtsExtensions = [".mjs" /* Mjs */, ".cjs" /* Cjs */, ".js" /* Js */, ".json" /* Json */, ".d.mts" /* Dmts */, ".d.cts" /* Dcts */, ".d.ts" /* Dts */];
43999
+ for (var _f = 0, jsAndDtsExtensions_1 = jsAndDtsExtensions; _f < jsAndDtsExtensions_1.length; _f++) {
44000
+ var ext = jsAndDtsExtensions_1[_f];
44001
+ if (ts.fileExtensionIs(possibleInputBase, ext)) {
44002
+ var inputExts = ts.getPossibleOriginalInputExtensionForExtension(possibleInputBase);
44003
+ for (var _g = 0, inputExts_1 = inputExts; _g < inputExts_1.length; _g++) {
44004
+ var possibleExt = inputExts_1[_g];
44005
+ var possibleInputWithInputExtension = ts.changeAnyExtension(possibleInputBase, possibleExt, ext, !useCaseSensitiveFileNames());
44006
+ if ((extensions === Extensions.TypeScript && ts.hasJSFileExtension(possibleInputWithInputExtension)) ||
44007
+ (extensions === Extensions.JavaScript && ts.hasTSFileExtension(possibleInputWithInputExtension))) {
44008
+ continue;
44009
+ }
44010
+ if (state.host.fileExists(possibleInputWithInputExtension)) {
44011
+ return toSearchResult(withPackageId(scope, loadJSOrExactTSFileName(extensions, possibleInputWithInputExtension, /*onlyRecordFailures*/ false, state)));
44012
+ }
44013
+ }
44014
+ }
44015
+ }
44016
+ }
44017
+ }
44018
+ }
44019
+ }
44020
+ return undefined;
44021
+ function getOutputDirectoriesForBaseDirectory(commonSourceDirGuess) {
44022
+ var _a, _b;
44023
+ // Config file ouput paths are processed to be relative to the host's current directory, while
44024
+ // otherwise the paths are resolved relative to the common source dir the compiler puts together
44025
+ var currentDir = state.compilerOptions.configFile ? ((_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)) || "" : commonSourceDirGuess;
44026
+ var candidateDirectories = [];
44027
+ if (state.compilerOptions.declarationDir) {
44028
+ candidateDirectories.push(toAbsolutePath(combineDirectoryPath(currentDir, state.compilerOptions.declarationDir)));
44029
+ }
44030
+ if (state.compilerOptions.outDir && state.compilerOptions.outDir !== state.compilerOptions.declarationDir) {
44031
+ candidateDirectories.push(toAbsolutePath(combineDirectoryPath(currentDir, state.compilerOptions.outDir)));
44032
+ }
44033
+ return candidateDirectories;
44034
+ }
44035
+ }
43872
44036
  }
43873
44037
  }
43874
44038
  /* @internal */
@@ -44059,11 +44223,12 @@ var ts;
44059
44223
  function classicNameResolver(moduleName, containingFile, compilerOptions, host, cache, redirectedReference) {
44060
44224
  var traceEnabled = isTraceEnabled(compilerOptions, host);
44061
44225
  var failedLookupLocations = [];
44062
- var state = { compilerOptions: compilerOptions, host: host, traceEnabled: traceEnabled, failedLookupLocations: failedLookupLocations, packageJsonInfoCache: cache, features: NodeResolutionFeatures.None, conditions: [] };
44063
44226
  var containingDirectory = ts.getDirectoryPath(containingFile);
44227
+ var diagnostics = [];
44228
+ var state = { compilerOptions: compilerOptions, host: host, traceEnabled: traceEnabled, failedLookupLocations: failedLookupLocations, packageJsonInfoCache: cache, features: NodeResolutionFeatures.None, conditions: [], requestContainingDirectory: containingDirectory, reportDiagnostic: function (diag) { return void diagnostics.push(diag); } };
44064
44229
  var resolved = tryResolve(Extensions.TypeScript) || tryResolve(Extensions.JavaScript);
44065
44230
  // No originalPath because classic resolution doesn't resolve realPath
44066
- return createResolvedModuleWithFailedLookupLocations(resolved && resolved.value, /*isExternalLibraryImport*/ false, failedLookupLocations, state.resultFromCache);
44231
+ return createResolvedModuleWithFailedLookupLocations(resolved && resolved.value, /*isExternalLibraryImport*/ false, failedLookupLocations, diagnostics, state.resultFromCache);
44067
44232
  function tryResolve(extensions) {
44068
44233
  var resolvedUsingSettings = tryLoadModuleUsingOptionalResolutionSettings(extensions, moduleName, containingDirectory, loadModuleFromFileNoPackageId, state);
44069
44234
  if (resolvedUsingSettings) {
@@ -44106,9 +44271,10 @@ var ts;
44106
44271
  trace(host, ts.Diagnostics.Auto_discovery_for_typings_is_enabled_in_project_0_Running_extra_resolution_pass_for_module_1_using_cache_location_2, projectName, moduleName, globalCache);
44107
44272
  }
44108
44273
  var failedLookupLocations = [];
44109
- var state = { compilerOptions: compilerOptions, host: host, traceEnabled: traceEnabled, failedLookupLocations: failedLookupLocations, packageJsonInfoCache: packageJsonInfoCache, features: NodeResolutionFeatures.None, conditions: [] };
44274
+ var diagnostics = [];
44275
+ var state = { compilerOptions: compilerOptions, host: host, traceEnabled: traceEnabled, failedLookupLocations: failedLookupLocations, packageJsonInfoCache: packageJsonInfoCache, features: NodeResolutionFeatures.None, conditions: [], requestContainingDirectory: undefined, reportDiagnostic: function (diag) { return void diagnostics.push(diag); } };
44110
44276
  var resolved = loadModuleFromImmediateNodeModulesDirectory(Extensions.DtsOnly, moduleName, globalCache, state, /*typesScopeOnly*/ false, /*cache*/ undefined, /*redirectedReference*/ undefined);
44111
- return createResolvedModuleWithFailedLookupLocations(resolved, /*isExternalLibraryImport*/ true, failedLookupLocations, state.resultFromCache);
44277
+ return createResolvedModuleWithFailedLookupLocations(resolved, /*isExternalLibraryImport*/ true, failedLookupLocations, diagnostics, state.resultFromCache);
44112
44278
  }
44113
44279
  ts.loadModuleFromGlobalCache = loadModuleFromGlobalCache;
44114
44280
  /**
@@ -57972,7 +58138,8 @@ var ts;
57972
58138
  if (symbol === globalThisSymbol) {
57973
58139
  var varsOnly_1 = new ts.Map();
57974
58140
  members.forEach(function (p) {
57975
- if (!(p.flags & 418 /* BlockScoped */)) {
58141
+ var _a;
58142
+ if (!(p.flags & 418 /* BlockScoped */) && !(p.flags & 512 /* ValueModule */ && ((_a = p.declarations) === null || _a === void 0 ? void 0 : _a.length) && ts.every(p.declarations, ts.isAmbientModule))) {
57976
58143
  varsOnly_1.set(p.escapedName, p);
57977
58144
  }
57978
58145
  });
@@ -84823,6 +84990,9 @@ var ts;
84823
84990
  var validForTypeAssertions = ts.isExclusivelyTypeOnlyImportOrExport(declaration);
84824
84991
  var override = ts.getResolutionModeOverrideForClause(declaration.assertClause, validForTypeAssertions ? grammarErrorOnNode : undefined);
84825
84992
  if (validForTypeAssertions && override) {
84993
+ if (!ts.isNightly()) {
84994
+ grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next);
84995
+ }
84826
84996
  if (ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.Node16 && ts.getEmitModuleResolutionKind(compilerOptions) !== ts.ModuleResolutionKind.NodeNext) {
84827
84997
  return grammarErrorOnNode(declaration.assertClause, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node16_or_nodenext);
84828
84998
  }
@@ -86163,7 +86333,7 @@ var ts;
86163
86333
  if (ts.isDeclaration(node)) {
86164
86334
  // In this case, we call getSymbolOfNode instead of getSymbolAtLocation because it is a declaration
86165
86335
  var symbol = getSymbolOfNode(node);
86166
- return getTypeOfSymbol(symbol);
86336
+ return symbol ? getTypeOfSymbol(symbol) : errorType;
86167
86337
  }
86168
86338
  if (isDeclarationNameOrImportPropertyName(node)) {
86169
86339
  var symbol = getSymbolAtLocation(node);
@@ -108221,34 +108391,44 @@ var ts;
108221
108391
  if (!decl.importClause) {
108222
108392
  // import "mod" - possibly needed for side effects? (global interface patches, module augmentations, etc)
108223
108393
  return factory.updateImportDeclaration(decl,
108224
- /*decorators*/ undefined, decl.modifiers, decl.importClause, rewriteModuleSpecifier(decl, decl.moduleSpecifier), ts.getResolutionModeOverrideForClause(decl.assertClause) ? decl.assertClause : undefined);
108394
+ /*decorators*/ undefined, decl.modifiers, decl.importClause, rewriteModuleSpecifier(decl, decl.moduleSpecifier), getResolutionModeOverrideForClauseInNightly(decl.assertClause));
108225
108395
  }
108226
108396
  // The `importClause` visibility corresponds to the default's visibility.
108227
108397
  var visibleDefaultBinding = decl.importClause && decl.importClause.name && resolver.isDeclarationVisible(decl.importClause) ? decl.importClause.name : undefined;
108228
108398
  if (!decl.importClause.namedBindings) {
108229
108399
  // No named bindings (either namespace or list), meaning the import is just default or should be elided
108230
108400
  return visibleDefaultBinding && factory.updateImportDeclaration(decl, /*decorators*/ undefined, decl.modifiers, factory.updateImportClause(decl.importClause, decl.importClause.isTypeOnly, visibleDefaultBinding,
108231
- /*namedBindings*/ undefined), rewriteModuleSpecifier(decl, decl.moduleSpecifier), ts.getResolutionModeOverrideForClause(decl.assertClause) ? decl.assertClause : undefined);
108401
+ /*namedBindings*/ undefined), rewriteModuleSpecifier(decl, decl.moduleSpecifier), getResolutionModeOverrideForClauseInNightly(decl.assertClause));
108232
108402
  }
108233
108403
  if (decl.importClause.namedBindings.kind === 268 /* NamespaceImport */) {
108234
108404
  // Namespace import (optionally with visible default)
108235
108405
  var namedBindings = resolver.isDeclarationVisible(decl.importClause.namedBindings) ? decl.importClause.namedBindings : /*namedBindings*/ undefined;
108236
- return visibleDefaultBinding || namedBindings ? factory.updateImportDeclaration(decl, /*decorators*/ undefined, decl.modifiers, factory.updateImportClause(decl.importClause, decl.importClause.isTypeOnly, visibleDefaultBinding, namedBindings), rewriteModuleSpecifier(decl, decl.moduleSpecifier), ts.getResolutionModeOverrideForClause(decl.assertClause) ? decl.assertClause : undefined) : undefined;
108406
+ return visibleDefaultBinding || namedBindings ? factory.updateImportDeclaration(decl, /*decorators*/ undefined, decl.modifiers, factory.updateImportClause(decl.importClause, decl.importClause.isTypeOnly, visibleDefaultBinding, namedBindings), rewriteModuleSpecifier(decl, decl.moduleSpecifier), getResolutionModeOverrideForClauseInNightly(decl.assertClause)) : undefined;
108237
108407
  }
108238
108408
  // Named imports (optionally with visible default)
108239
108409
  var bindingList = ts.mapDefined(decl.importClause.namedBindings.elements, function (b) { return resolver.isDeclarationVisible(b) ? b : undefined; });
108240
108410
  if ((bindingList && bindingList.length) || visibleDefaultBinding) {
108241
108411
  return factory.updateImportDeclaration(decl,
108242
- /*decorators*/ undefined, decl.modifiers, factory.updateImportClause(decl.importClause, decl.importClause.isTypeOnly, visibleDefaultBinding, bindingList && bindingList.length ? factory.updateNamedImports(decl.importClause.namedBindings, bindingList) : undefined), rewriteModuleSpecifier(decl, decl.moduleSpecifier), ts.getResolutionModeOverrideForClause(decl.assertClause) ? decl.assertClause : undefined);
108412
+ /*decorators*/ undefined, decl.modifiers, factory.updateImportClause(decl.importClause, decl.importClause.isTypeOnly, visibleDefaultBinding, bindingList && bindingList.length ? factory.updateNamedImports(decl.importClause.namedBindings, bindingList) : undefined), rewriteModuleSpecifier(decl, decl.moduleSpecifier), getResolutionModeOverrideForClauseInNightly(decl.assertClause));
108243
108413
  }
108244
108414
  // Augmentation of export depends on import
108245
108415
  if (resolver.isImportRequiredByAugmentation(decl)) {
108246
108416
  return factory.updateImportDeclaration(decl,
108247
108417
  /*decorators*/ undefined, decl.modifiers,
108248
- /*importClause*/ undefined, rewriteModuleSpecifier(decl, decl.moduleSpecifier), ts.getResolutionModeOverrideForClause(decl.assertClause) ? decl.assertClause : undefined);
108418
+ /*importClause*/ undefined, rewriteModuleSpecifier(decl, decl.moduleSpecifier), getResolutionModeOverrideForClauseInNightly(decl.assertClause));
108249
108419
  }
108250
108420
  // Nothing visible
108251
108421
  }
108422
+ function getResolutionModeOverrideForClauseInNightly(assertClause) {
108423
+ var mode = ts.getResolutionModeOverrideForClause(assertClause);
108424
+ if (mode !== undefined) {
108425
+ if (!ts.isNightly()) {
108426
+ context.addDiagnostic(ts.createDiagnosticForNode(assertClause, ts.Diagnostics.Resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next));
108427
+ }
108428
+ return assertClause;
108429
+ }
108430
+ return undefined;
108431
+ }
108252
108432
  function transformAndReplaceLatePaintedStatements(statements) {
108253
108433
  // This is a `while` loop because `handleSymbolAccessibilityError` can see additional import aliases marked as visible during
108254
108434
  // error handling which must now be included in the output and themselves checked for errors.
@@ -116077,7 +116257,6 @@ var ts;
116077
116257
  ts.Diagnostics.A_rest_parameter_cannot_have_an_initializer.code,
116078
116258
  ts.Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list.code,
116079
116259
  ts.Diagnostics.A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma.code,
116080
- ts.Diagnostics.A_return_statement_can_only_be_used_within_a_function_body.code,
116081
116260
  ts.Diagnostics.A_return_statement_cannot_be_used_inside_a_class_static_block.code,
116082
116261
  ts.Diagnostics.A_set_accessor_cannot_have_rest_parameter.code,
116083
116262
  ts.Diagnostics.A_set_accessor_must_have_exactly_one_parameter.code,
@@ -116464,6 +116643,40 @@ var ts;
116464
116643
  ts.performance.measure("Program", "beforeProgram", "afterProgram");
116465
116644
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
116466
116645
  return program;
116646
+ function addResolutionDiagnostics(list) {
116647
+ if (!list)
116648
+ return;
116649
+ for (var _i = 0, list_3 = list; _i < list_3.length; _i++) {
116650
+ var elem = list_3[_i];
116651
+ programDiagnostics.add(elem);
116652
+ }
116653
+ }
116654
+ function pullDiagnosticsFromCache(names, containingFile) {
116655
+ var _a;
116656
+ if (!moduleResolutionCache)
116657
+ return;
116658
+ var containingFileName = ts.getNormalizedAbsolutePath(containingFile.originalFileName, currentDirectory);
116659
+ var containingFileMode = !ts.isString(containingFile) ? containingFile.impliedNodeFormat : undefined;
116660
+ var containingDir = ts.getDirectoryPath(containingFileName);
116661
+ var redirectedReference = getRedirectReferenceForResolution(containingFile);
116662
+ var i = 0;
116663
+ for (var _i = 0, names_4 = names; _i < names_4.length; _i++) {
116664
+ var n = names_4[_i];
116665
+ // mimics logic done in the resolution cache, should be resilient to upgrading it to use `FileReference`s for non-type-reference modal lookups to make it rely on the index in the list less
116666
+ var mode = typeof n === "string" ? getModeForResolutionAtIndex(containingFile, i) : getModeForFileReference(n, containingFileMode);
116667
+ var name = typeof n === "string" ? n : n.fileName;
116668
+ i++;
116669
+ // only nonrelative names hit the cache, and, at least as of right now, only nonrelative names can issue diagnostics
116670
+ // (Since diagnostics are only issued via import or export map lookup)
116671
+ // This may totally change if/when the issue of output paths not mapping to input files is fixed in a broader context
116672
+ // When it is, how we extract diagnostics from the module name resolver will have the be refined - the current cache
116673
+ // APIs wrapping the underlying resolver make it almost impossible to smuggle the diagnostics out in a generalized way
116674
+ if (ts.isExternalModuleNameRelative(name))
116675
+ continue;
116676
+ var diags = (_a = moduleResolutionCache.getOrCreateCacheForModuleName(name, mode, redirectedReference).get(containingDir)) === null || _a === void 0 ? void 0 : _a.resolutionDiagnostics;
116677
+ addResolutionDiagnostics(diags);
116678
+ }
116679
+ }
116467
116680
  function resolveModuleNamesWorker(moduleNames, containingFile, reusedNames) {
116468
116681
  if (!moduleNames.length)
116469
116682
  return ts.emptyArray;
@@ -116475,6 +116688,7 @@ var ts;
116475
116688
  ts.performance.mark("afterResolveModule");
116476
116689
  ts.performance.measure("ResolveModule", "beforeResolveModule", "afterResolveModule");
116477
116690
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
116691
+ pullDiagnosticsFromCache(moduleNames, containingFile);
116478
116692
  return result;
116479
116693
  }
116480
116694
  function resolveTypeReferenceDirectiveNamesWorker(typeDirectiveNames, containingFile) {
@@ -120911,8 +121125,8 @@ var ts;
120911
121125
  !!redirectedReference;
120912
121126
  var seenNamesInFile = ts.createModeAwareCache();
120913
121127
  var i = 0;
120914
- for (var _i = 0, names_4 = names; _i < names_4.length; _i++) {
120915
- var entry = names_4[_i];
121128
+ for (var _i = 0, names_5 = names; _i < names_5.length; _i++) {
121129
+ var entry = names_5[_i];
120916
121130
  var name = ts.isString(entry) ? entry : entry.fileName.toLowerCase();
120917
121131
  // Imports supply a `containingSourceFile` but no `containingSourceFileMode` - it would be redundant
120918
121132
  // they require calculating the mode for a given import from it's position in the resolution table, since a given
@@ -121522,14 +121736,14 @@ var ts;
121522
121736
  if (options === void 0) { options = {}; }
121523
121737
  var info = getInfo(importingSourceFile.path, host);
121524
121738
  var modulePaths = getAllModulePaths(importingSourceFile.path, nodeModulesFileName, host, preferences, options);
121525
- return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, /*packageNameOnly*/ true, options.overrideImportMode); });
121739
+ return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, preferences, /*packageNameOnly*/ true, options.overrideImportMode); });
121526
121740
  }
121527
121741
  moduleSpecifiers_1.getNodeModulesPackageName = getNodeModulesPackageName;
121528
121742
  function getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, preferences, userPreferences, options) {
121529
121743
  if (options === void 0) { options = {}; }
121530
121744
  var info = getInfo(importingSourceFileName, host);
121531
121745
  var modulePaths = getAllModulePaths(importingSourceFileName, toFileName, host, userPreferences, options);
121532
- return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, /*packageNameOnly*/ undefined, options.overrideImportMode); }) ||
121746
+ return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, userPreferences, /*packageNameOnly*/ undefined, options.overrideImportMode); }) ||
121533
121747
  getLocalModuleSpecifier(toFileName, info, compilerOptions, host, preferences);
121534
121748
  }
121535
121749
  function tryGetModuleSpecifiersFromCache(moduleSymbol, importingSourceFile, host, userPreferences, options) {
@@ -121605,7 +121819,7 @@ var ts;
121605
121819
  var relativeSpecifiers;
121606
121820
  for (var _i = 0, modulePaths_1 = modulePaths; _i < modulePaths_1.length; _i++) {
121607
121821
  var modulePath = modulePaths_1[_i];
121608
- var specifier = tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, /*packageNameOnly*/ undefined, options.overrideImportMode);
121822
+ var specifier = tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, userPreferences, /*packageNameOnly*/ undefined, options.overrideImportMode);
121609
121823
  nodeModulesSpecifiers = ts.append(nodeModulesSpecifiers, specifier);
121610
121824
  if (specifier && modulePath.isRedirect) {
121611
121825
  // If we got a specifier for a redirect, it was a bare package specifier (e.g. "@foo/bar",
@@ -121998,7 +122212,7 @@ var ts;
121998
122212
  ? removeExtensionAndIndexPostFix(relativePath, ending, compilerOptions)
121999
122213
  : ts.removeFileExtension(relativePath);
122000
122214
  }
122001
- function tryGetModuleNameAsNodeModule(_a, _b, importingSourceFile, host, options, packageNameOnly, overrideMode) {
122215
+ function tryGetModuleNameAsNodeModule(_a, _b, importingSourceFile, host, options, userPreferences, packageNameOnly, overrideMode) {
122002
122216
  var path = _a.path, isRedirect = _a.isRedirect;
122003
122217
  var getCanonicalFileName = _b.getCanonicalFileName, sourceDirectory = _b.sourceDirectory;
122004
122218
  if (!host.fileExists || !host.readFile) {
@@ -122012,8 +122226,9 @@ var ts;
122012
122226
  var moduleSpecifier = path;
122013
122227
  var isPackageRootPath = false;
122014
122228
  if (!packageNameOnly) {
122229
+ var preferences = getPreferences(host, userPreferences, options, importingSourceFile);
122015
122230
  var packageRootIndex = parts.packageRootIndex;
122016
- var moduleFileNameForExtensionless = void 0;
122231
+ var moduleFileName = void 0;
122017
122232
  while (true) {
122018
122233
  // If the module could be imported by a directory name, use that directory's name
122019
122234
  var _c = tryDirectoryWithPackageJson(packageRootIndex), moduleFileToTry = _c.moduleFileToTry, packageRootPath = _c.packageRootPath, blockedByExports = _c.blockedByExports, verbatimFromExports = _c.verbatimFromExports;
@@ -122030,12 +122245,12 @@ var ts;
122030
122245
  isPackageRootPath = true;
122031
122246
  break;
122032
122247
  }
122033
- if (!moduleFileNameForExtensionless)
122034
- moduleFileNameForExtensionless = moduleFileToTry;
122248
+ if (!moduleFileName)
122249
+ moduleFileName = moduleFileToTry;
122035
122250
  // try with next level of directory
122036
122251
  packageRootIndex = path.indexOf(ts.directorySeparator, packageRootIndex + 1);
122037
122252
  if (packageRootIndex === -1) {
122038
- moduleSpecifier = getExtensionlessFileName(moduleFileNameForExtensionless);
122253
+ moduleSpecifier = removeExtensionAndIndexPostFix(moduleFileName, preferences.ending, options, host);
122039
122254
  break;
122040
122255
  }
122041
122256
  }
@@ -122093,7 +122308,7 @@ var ts;
122093
122308
  }
122094
122309
  }
122095
122310
  // If the file is the main module, it can be imported by the package name
122096
- var mainFileRelative = packageJsonContent.typings || packageJsonContent.types || packageJsonContent.main;
122311
+ var mainFileRelative = packageJsonContent.typings || packageJsonContent.types || packageJsonContent.main || "index.js";
122097
122312
  if (ts.isString(mainFileRelative)) {
122098
122313
  var mainExportFile = ts.toPath(mainFileRelative, packageRootPath, getCanonicalFileName);
122099
122314
  if (ts.removeFileExtension(mainExportFile) === ts.removeFileExtension(getCanonicalFileName(moduleFileToTry))) {
@@ -122101,17 +122316,14 @@ var ts;
122101
122316
  }
122102
122317
  }
122103
122318
  }
122104
- return { moduleFileToTry: moduleFileToTry };
122105
- }
122106
- function getExtensionlessFileName(path) {
122107
- // We still have a file name - remove the extension
122108
- var fullModulePathWithoutExtension = ts.removeFileExtension(path);
122109
- // If the file is /index, it can be imported by its directory name
122110
- // IFF there is not _also_ a file by the same name
122111
- if (getCanonicalFileName(fullModulePathWithoutExtension.substring(parts.fileNameIndex)) === "/index" && !tryGetAnyFileFromPath(host, fullModulePathWithoutExtension.substring(0, parts.fileNameIndex))) {
122112
- return fullModulePathWithoutExtension.substring(0, parts.fileNameIndex);
122319
+ else {
122320
+ // No package.json exists; an index.js will still resolve as the package name
122321
+ var fileName = getCanonicalFileName(moduleFileToTry.substring(parts.packageRootIndex + 1));
122322
+ if (fileName === "index.d.ts" || fileName === "index.js" || fileName === "index.ts" || fileName === "index.tsx") {
122323
+ return { moduleFileToTry: moduleFileToTry, packageRootPath: packageRootPath };
122324
+ }
122113
122325
  }
122114
- return fullModulePathWithoutExtension;
122326
+ return { moduleFileToTry: moduleFileToTry };
122115
122327
  }
122116
122328
  }
122117
122329
  function tryGetAnyFileFromPath(host, path) {
@@ -122133,7 +122345,7 @@ var ts;
122133
122345
  return relativePath !== undefined && isPathRelativeToParent(relativePath) ? undefined : relativePath;
122134
122346
  });
122135
122347
  }
122136
- function removeExtensionAndIndexPostFix(fileName, ending, options) {
122348
+ function removeExtensionAndIndexPostFix(fileName, ending, options, host) {
122137
122349
  if (ts.fileExtensionIsOneOf(fileName, [".json" /* Json */, ".mjs" /* Mjs */, ".cjs" /* Cjs */]))
122138
122350
  return fileName;
122139
122351
  var noExtension = ts.removeFileExtension(fileName);
@@ -122141,7 +122353,13 @@ var ts;
122141
122353
  return noExtension + getJSExtensionForFile(fileName, options);
122142
122354
  switch (ending) {
122143
122355
  case 0 /* Minimal */:
122144
- return ts.removeSuffix(noExtension, "/index");
122356
+ var withoutIndex = ts.removeSuffix(noExtension, "/index");
122357
+ if (host && withoutIndex !== noExtension && tryGetAnyFileFromPath(host, withoutIndex)) {
122358
+ // Can't remove index if there's a file by the same name as the directory.
122359
+ // Probably more callers should pass `host` so we can determine this?
122360
+ return noExtension;
122361
+ }
122362
+ return withoutIndex;
122145
122363
  case 1 /* Index */:
122146
122364
  return noExtension;
122147
122365
  case 2 /* JsExtension */: