typescript 5.6.0-dev.20240716 → 5.6.0-dev.20240718

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/tsc.js CHANGED
@@ -18,7 +18,7 @@ and limitations under the License.
18
18
 
19
19
  // src/compiler/corePublic.ts
20
20
  var versionMajorMinor = "5.6";
21
- var version = `${versionMajorMinor}.0-dev.20240716`;
21
+ var version = `${versionMajorMinor}.0-dev.20240718`;
22
22
 
23
23
  // src/compiler/core.ts
24
24
  var emptyArray = [];
@@ -2515,10 +2515,12 @@ function tryGetPerformance() {
2515
2515
  if (isNodeLikeSystem()) {
2516
2516
  try {
2517
2517
  const { performance: performance2 } = require("perf_hooks");
2518
- return {
2519
- shouldWriteNativeEvents: false,
2520
- performance: performance2
2521
- };
2518
+ if (performance2) {
2519
+ return {
2520
+ shouldWriteNativeEvents: false,
2521
+ performance: performance2
2522
+ };
2523
+ }
2522
2524
  } catch {
2523
2525
  }
2524
2526
  }
@@ -5912,6 +5914,7 @@ var Diagnostics = {
5912
5914
  _0_resolves_to_a_type_only_declaration_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enabled_Consider_using_export_type_0_as_default: diag(1290, 1 /* Error */, "_0_resolves_to_a_type_only_declaration_and_must_be_marked_type_only_in_this_file_before_re_exporting_1290", "'{0}' resolves to a type-only declaration and must be marked type-only in this file before re-exporting when '{1}' is enabled. Consider using 'export type { {0} as default }'."),
5913
5915
  _0_resolves_to_a_type_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enabled_Consider_using_import_type_where_0_is_imported: diag(1291, 1 /* Error */, "_0_resolves_to_a_type_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enable_1291", "'{0}' resolves to a type and must be marked type-only in this file before re-exporting when '{1}' is enabled. Consider using 'import type' where '{0}' is imported."),
5914
5916
  _0_resolves_to_a_type_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enabled_Consider_using_export_type_0_as_default: diag(1292, 1 /* Error */, "_0_resolves_to_a_type_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enable_1292", "'{0}' resolves to a type and must be marked type-only in this file before re-exporting when '{1}' is enabled. Consider using 'export type { {0} as default }'."),
5917
+ ESM_syntax_is_not_allowed_in_a_CommonJS_module_when_module_is_set_to_preserve: diag(1293, 1 /* Error */, "ESM_syntax_is_not_allowed_in_a_CommonJS_module_when_module_is_set_to_preserve_1293", "ESM syntax is not allowed in a CommonJS module when 'module' is set to 'preserve'."),
5915
5918
  with_statements_are_not_allowed_in_an_async_function_block: diag(1300, 1 /* Error */, "with_statements_are_not_allowed_in_an_async_function_block_1300", "'with' statements are not allowed in an async function block."),
5916
5919
  await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules: diag(1308, 1 /* Error */, "await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules_1308", "'await' expressions are only allowed within async functions and at the top levels of modules."),
5917
5920
  The_current_file_is_a_CommonJS_module_and_cannot_use_await_at_the_top_level: diag(1309, 1 /* Error */, "The_current_file_is_a_CommonJS_module_and_cannot_use_await_at_the_top_level_1309", "The current file is a CommonJS module and cannot use 'await' at the top level."),
@@ -6120,6 +6123,7 @@ var Diagnostics = {
6120
6123
  This_character_cannot_be_escaped_in_a_regular_expression: diag(1535, 1 /* Error */, "This_character_cannot_be_escaped_in_a_regular_expression_1535", "This character cannot be escaped in a regular expression."),
6121
6124
  Octal_escape_sequences_and_backreferences_are_not_allowed_in_a_character_class_If_this_was_intended_as_an_escape_sequence_use_the_syntax_0_instead: diag(1536, 1 /* Error */, "Octal_escape_sequences_and_backreferences_are_not_allowed_in_a_character_class_If_this_was_intended__1536", "Octal escape sequences and backreferences are not allowed in a character class. If this was intended as an escape sequence, use the syntax '{0}' instead."),
6122
6125
  Decimal_escape_sequences_and_backreferences_are_not_allowed_in_a_character_class: diag(1537, 1 /* Error */, "Decimal_escape_sequences_and_backreferences_are_not_allowed_in_a_character_class_1537", "Decimal escape sequences and backreferences are not allowed in a character class."),
6126
+ Unicode_escape_sequences_are_only_available_when_the_Unicode_u_flag_or_the_Unicode_Sets_v_flag_is_set: diag(1538, 1 /* Error */, "Unicode_escape_sequences_are_only_available_when_the_Unicode_u_flag_or_the_Unicode_Sets_v_flag_is_se_1538", "Unicode escape sequences are only available when the Unicode (u) flag or the Unicode Sets (v) flag is set."),
6123
6127
  The_types_of_0_are_incompatible_between_these_types: diag(2200, 1 /* Error */, "The_types_of_0_are_incompatible_between_these_types_2200", "The types of '{0}' are incompatible between these types."),
6124
6128
  The_types_returned_by_0_are_incompatible_between_these_types: diag(2201, 1 /* Error */, "The_types_returned_by_0_are_incompatible_between_these_types_2201", "The types returned by '{0}' are incompatible between these types."),
6125
6129
  Call_signature_return_types_0_and_1_are_incompatible: diag(
@@ -8967,9 +8971,16 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
8967
8971
  case 34 /* doubleQuote */:
8968
8972
  return '"';
8969
8973
  case 117 /* u */:
8970
- if (flags & 17 /* ScanExtendedUnicodeEscape */ && pos < end && charCodeUnchecked(pos) === 123 /* openBrace */) {
8974
+ if (pos < end && charCodeUnchecked(pos) === 123 /* openBrace */) {
8971
8975
  pos -= 2;
8972
- return scanExtendedUnicodeEscape(!!(flags & 6 /* ReportInvalidEscapeErrors */));
8976
+ const result = scanExtendedUnicodeEscape(!!(flags & 6 /* ReportInvalidEscapeErrors */));
8977
+ if (!(flags & 17 /* AllowExtendedUnicodeEscape */)) {
8978
+ tokenFlags |= 2048 /* ContainsInvalidEscape */;
8979
+ if (flags & 6 /* ReportInvalidEscapeErrors */) {
8980
+ error(Diagnostics.Unicode_escape_sequences_are_only_available_when_the_Unicode_u_flag_or_the_Unicode_Sets_v_flag_is_set, start2, pos - start2);
8981
+ }
8982
+ }
8983
+ return result;
8973
8984
  }
8974
8985
  for (; pos < start2 + 6; pos++) {
8975
8986
  if (!(pos < end && isHexDigit(charCodeUnchecked(pos)))) {
@@ -8987,7 +8998,7 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
8987
8998
  const nextStart = pos;
8988
8999
  let nextPos = pos + 2;
8989
9000
  for (; nextPos < nextStart + 6; nextPos++) {
8990
- if (!isHexDigit(charCodeUnchecked(pos))) {
9001
+ if (!isHexDigit(charCodeUnchecked(nextPos))) {
8991
9002
  return escapedValueString;
8992
9003
  }
8993
9004
  }
@@ -10615,7 +10626,7 @@ function createScanner(languageVersion, skipTrivia2, languageVariant = 0 /* Stan
10615
10626
  return value;
10616
10627
  }
10617
10628
  function scanSourceCharacter() {
10618
- const size = anyUnicodeMode ? charSize(charCodeChecked(pos)) : 1;
10629
+ const size = anyUnicodeMode ? charSize(codePointChecked(pos)) : 1;
10619
10630
  pos += size;
10620
10631
  return size > 0 ? text.substring(pos - size, pos) : "";
10621
10632
  }
@@ -12585,6 +12596,34 @@ function createModuleNotFoundChain(sourceFile, host, moduleReference, mode, pack
12585
12596
  if (result) result.repopulateInfo = () => ({ moduleReference, mode, packageName: packageName === moduleReference ? void 0 : packageName });
12586
12597
  return result;
12587
12598
  }
12599
+ function createModeMismatchDetails(currentSourceFile) {
12600
+ const ext = tryGetExtensionFromPath2(currentSourceFile.fileName);
12601
+ const scope = currentSourceFile.packageJsonScope;
12602
+ const targetExt = ext === ".ts" /* Ts */ ? ".mts" /* Mts */ : ext === ".js" /* Js */ ? ".mjs" /* Mjs */ : void 0;
12603
+ const result = scope && !scope.contents.packageJsonContent.type ? targetExt ? chainDiagnosticMessages(
12604
+ /*details*/
12605
+ void 0,
12606
+ Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_add_the_field_type_Colon_module_to_1,
12607
+ targetExt,
12608
+ combinePaths(scope.packageDirectory, "package.json")
12609
+ ) : chainDiagnosticMessages(
12610
+ /*details*/
12611
+ void 0,
12612
+ Diagnostics.To_convert_this_file_to_an_ECMAScript_module_add_the_field_type_Colon_module_to_0,
12613
+ combinePaths(scope.packageDirectory, "package.json")
12614
+ ) : targetExt ? chainDiagnosticMessages(
12615
+ /*details*/
12616
+ void 0,
12617
+ Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_create_a_local_package_json_file_with_type_Colon_module,
12618
+ targetExt
12619
+ ) : chainDiagnosticMessages(
12620
+ /*details*/
12621
+ void 0,
12622
+ Diagnostics.To_convert_this_file_to_an_ECMAScript_module_create_a_local_package_json_file_with_type_Colon_module
12623
+ );
12624
+ result.repopulateInfo = () => true;
12625
+ return result;
12626
+ }
12588
12627
  function packageIdIsEqual(a, b) {
12589
12628
  return a === b || !!a && !!b && a.name === b.name && a.subModuleName === b.subModuleName && a.version === b.version && a.peerDependencies === b.peerDependencies;
12590
12629
  }
@@ -14796,6 +14835,23 @@ function isFunctionSymbol(symbol) {
14796
14835
  const decl = symbol.valueDeclaration;
14797
14836
  return decl.kind === 262 /* FunctionDeclaration */ || isVariableDeclaration(decl) && decl.initializer && isFunctionLike(decl.initializer);
14798
14837
  }
14838
+ function canHaveModuleSpecifier(node) {
14839
+ switch (node == null ? void 0 : node.kind) {
14840
+ case 260 /* VariableDeclaration */:
14841
+ case 208 /* BindingElement */:
14842
+ case 272 /* ImportDeclaration */:
14843
+ case 278 /* ExportDeclaration */:
14844
+ case 271 /* ImportEqualsDeclaration */:
14845
+ case 273 /* ImportClause */:
14846
+ case 280 /* NamespaceExport */:
14847
+ case 274 /* NamespaceImport */:
14848
+ case 281 /* ExportSpecifier */:
14849
+ case 276 /* ImportSpecifier */:
14850
+ case 205 /* ImportType */:
14851
+ return true;
14852
+ }
14853
+ return false;
14854
+ }
14799
14855
  function tryGetModuleSpecifierFromDeclaration(node) {
14800
14856
  var _a, _b;
14801
14857
  switch (node.kind) {
@@ -17513,8 +17569,8 @@ function walkTreeForJSXTags(node) {
17513
17569
  function isFileModuleFromUsingJSXTag(file) {
17514
17570
  return !file.isDeclarationFile ? walkTreeForJSXTags(file) : void 0;
17515
17571
  }
17516
- function isFileForcedToBeModuleByFormat(file) {
17517
- return (file.impliedNodeFormat === 99 /* ESNext */ || fileExtensionIsOneOf(file.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */, ".mjs" /* Mjs */, ".mts" /* Mts */])) && !file.isDeclarationFile ? true : void 0;
17572
+ function isFileForcedToBeModuleByFormat(file, options) {
17573
+ return (getImpliedNodeFormatForEmitWorker(file, options) === 99 /* ESNext */ || fileExtensionIsOneOf(file.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */, ".mjs" /* Mjs */, ".mts" /* Mts */])) && !file.isDeclarationFile ? true : void 0;
17518
17574
  }
17519
17575
  function getSetExternalModuleIndicator(options) {
17520
17576
  switch (getEmitModuleDetectionKind(options)) {
@@ -17533,10 +17589,14 @@ function getSetExternalModuleIndicator(options) {
17533
17589
  }
17534
17590
  checks.push(isFileForcedToBeModuleByFormat);
17535
17591
  const combined = or(...checks);
17536
- const callback = (file) => void (file.externalModuleIndicator = combined(file));
17592
+ const callback = (file) => void (file.externalModuleIndicator = combined(file, options));
17537
17593
  return callback;
17538
17594
  }
17539
17595
  }
17596
+ function importSyntaxAffectsModuleResolution(options) {
17597
+ const moduleResolution = getEmitModuleResolutionKind(options);
17598
+ return 3 /* Node16 */ <= moduleResolution && moduleResolution <= 99 /* NodeNext */ || getResolvePackageJsonExports(options) || getResolvePackageJsonImports(options);
17599
+ }
17540
17600
  function createComputedCompilerOptions(options) {
17541
17601
  return options;
17542
17602
  }
@@ -26736,7 +26796,7 @@ function createExternalHelpersImportDeclarationIfNeeded(nodeFactory, helperFacto
26736
26796
  if (compilerOptions.importHelpers && isEffectiveExternalModule(sourceFile, compilerOptions)) {
26737
26797
  let namedBindings;
26738
26798
  const moduleKind = getEmitModuleKind(compilerOptions);
26739
- if (moduleKind >= 5 /* ES2015 */ && moduleKind <= 99 /* ESNext */ || sourceFile.impliedNodeFormat === 99 /* ESNext */) {
26799
+ if (moduleKind >= 5 /* ES2015 */ && moduleKind <= 99 /* ESNext */ || getImpliedNodeFormatForEmitWorker(sourceFile, compilerOptions) === 99 /* ESNext */) {
26740
26800
  const helpers = getEmitHelpers(sourceFile);
26741
26801
  if (helpers) {
26742
26802
  const helperNames = [];
@@ -26801,8 +26861,7 @@ function getOrCreateExternalHelpersModuleNameIfNeeded(factory2, node, compilerOp
26801
26861
  if (externalHelpersModuleName) {
26802
26862
  return externalHelpersModuleName;
26803
26863
  }
26804
- const moduleKind = getEmitModuleKind(compilerOptions);
26805
- let create = (hasExportStarsToExportValues || getESModuleInterop(compilerOptions) && hasImportStarOrImportDefault) && moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || node.impliedNodeFormat === 1 /* CommonJS */);
26864
+ let create = (hasExportStarsToExportValues || getESModuleInterop(compilerOptions) && hasImportStarOrImportDefault) && getEmitModuleFormatOfFileWorker(node, compilerOptions) < 4 /* System */;
26806
26865
  if (!create) {
26807
26866
  const helpers = getEmitHelpers(node);
26808
26867
  if (helpers) {
@@ -35756,7 +35815,6 @@ var commonOptionsWithBuild = [
35756
35815
  affectsBuildInfo: true,
35757
35816
  showInSimplifiedHelpView: true,
35758
35817
  category: Diagnostics.Emit,
35759
- transpileOptionValue: void 0,
35760
35818
  defaultValueDescription: false,
35761
35819
  description: Diagnostics.Create_sourcemaps_for_d_ts_files
35762
35820
  },
@@ -40133,22 +40191,16 @@ function getTemporaryModuleResolutionState(packageJsonInfoCache, host, options)
40133
40191
  resolvedPackageDirectory: false
40134
40192
  };
40135
40193
  }
40136
- function getPackageScopeForPath(fileName, state) {
40137
- const parts = getPathComponents(fileName);
40138
- parts.pop();
40139
- while (parts.length > 0) {
40140
- const pkg = getPackageJsonInfo(
40141
- getPathFromPathComponents(parts),
40194
+ function getPackageScopeForPath(directory, state) {
40195
+ return forEachAncestorDirectory(
40196
+ directory,
40197
+ (dir) => getPackageJsonInfo(
40198
+ dir,
40142
40199
  /*onlyRecordFailures*/
40143
40200
  false,
40144
40201
  state
40145
- );
40146
- if (pkg) {
40147
- return pkg;
40148
- }
40149
- parts.pop();
40150
- }
40151
- return void 0;
40202
+ )
40203
+ );
40152
40204
  }
40153
40205
  function getVersionPathsOfPackageJsonInfo(packageJsonInfo, state) {
40154
40206
  if (packageJsonInfo.contents.versionPaths === void 0) {
@@ -40311,7 +40363,7 @@ function noKeyStartsWithDot(obj) {
40311
40363
  }
40312
40364
  function loadModuleFromSelfNameReference(extensions, moduleName, directory, state, cache, redirectedReference) {
40313
40365
  var _a, _b;
40314
- const directoryPath = getNormalizedAbsolutePath(combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) == null ? void 0 : _b.call(_a));
40366
+ const directoryPath = getNormalizedAbsolutePath(directory, (_b = (_a = state.host).getCurrentDirectory) == null ? void 0 : _b.call(_a));
40315
40367
  const scope = getPackageScopeForPath(directoryPath, state);
40316
40368
  if (!scope || !scope.contents.packageJsonContent.exports) {
40317
40369
  return void 0;
@@ -40407,7 +40459,7 @@ function loadModuleFromImports(extensions, moduleName, directory, state, cache,
40407
40459
  void 0
40408
40460
  );
40409
40461
  }
40410
- const directoryPath = getNormalizedAbsolutePath(combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) == null ? void 0 : _b.call(_a));
40462
+ const directoryPath = getNormalizedAbsolutePath(directory, (_b = (_a = state.host).getCurrentDirectory) == null ? void 0 : _b.call(_a));
40411
40463
  const scope = getPackageScopeForPath(directoryPath, state);
40412
40464
  if (!scope) {
40413
40465
  if (state.traceEnabled) {
@@ -44225,13 +44277,15 @@ function createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignatu
44225
44277
  }
44226
44278
 
44227
44279
  // src/compiler/moduleSpecifiers.ts
44228
- function getModuleSpecifierPreferences({ importModuleSpecifierPreference, importModuleSpecifierEnding }, compilerOptions, importingSourceFile, oldImportSpecifier) {
44280
+ function getModuleSpecifierPreferences({ importModuleSpecifierPreference, importModuleSpecifierEnding }, host, compilerOptions, importingSourceFile, oldImportSpecifier) {
44229
44281
  const filePreferredEnding = getPreferredEnding();
44230
44282
  return {
44231
44283
  relativePreference: oldImportSpecifier !== void 0 ? isExternalModuleNameRelative(oldImportSpecifier) ? 0 /* Relative */ : 1 /* NonRelative */ : importModuleSpecifierPreference === "relative" ? 0 /* Relative */ : importModuleSpecifierPreference === "non-relative" ? 1 /* NonRelative */ : importModuleSpecifierPreference === "project-relative" ? 3 /* ExternalNonRelative */ : 2 /* Shortest */,
44232
44284
  getAllowedEndingsInPreferredOrder: (syntaxImpliedNodeFormat) => {
44233
- const preferredEnding = syntaxImpliedNodeFormat !== importingSourceFile.impliedNodeFormat ? getPreferredEnding(syntaxImpliedNodeFormat) : filePreferredEnding;
44234
- if ((syntaxImpliedNodeFormat ?? importingSourceFile.impliedNodeFormat) === 99 /* ESNext */) {
44285
+ const impliedNodeFormat = getDefaultResolutionModeForFile(importingSourceFile, host, compilerOptions);
44286
+ const preferredEnding = syntaxImpliedNodeFormat !== impliedNodeFormat ? getPreferredEnding(syntaxImpliedNodeFormat) : filePreferredEnding;
44287
+ const moduleResolution = getEmitModuleResolutionKind(compilerOptions);
44288
+ if ((syntaxImpliedNodeFormat ?? impliedNodeFormat) === 99 /* ESNext */ && 3 /* Node16 */ <= moduleResolution && moduleResolution <= 99 /* NodeNext */) {
44235
44289
  if (shouldAllowImportingTsExtension(compilerOptions, importingSourceFile.fileName)) {
44236
44290
  return [3 /* TsExtension */, 2 /* JsExtension */];
44237
44291
  }
@@ -44262,7 +44316,7 @@ function getModuleSpecifierPreferences({ importModuleSpecifierPreference, import
44262
44316
  }
44263
44317
  return getModuleSpecifierEndingPreference(
44264
44318
  importModuleSpecifierEnding,
44265
- resolutionMode ?? importingSourceFile.impliedNodeFormat,
44319
+ resolutionMode ?? getDefaultResolutionModeForFile(importingSourceFile, host, compilerOptions),
44266
44320
  compilerOptions,
44267
44321
  isFullSourceFile(importingSourceFile) ? importingSourceFile : void 0
44268
44322
  );
@@ -44320,12 +44374,16 @@ function getModuleSpecifiersWithCacheInfo(moduleSymbol, checker, compilerOptions
44320
44374
  }
44321
44375
  function computeModuleSpecifiers(modulePaths, compilerOptions, importingSourceFile, host, userPreferences, options = {}, forAutoImport) {
44322
44376
  const info = getInfo(importingSourceFile.fileName, host);
44323
- const preferences = getModuleSpecifierPreferences(userPreferences, compilerOptions, importingSourceFile);
44377
+ const preferences = getModuleSpecifierPreferences(userPreferences, host, compilerOptions, importingSourceFile);
44324
44378
  const existingSpecifier = isFullSourceFile(importingSourceFile) && forEach(modulePaths, (modulePath) => forEach(
44325
44379
  host.getFileIncludeReasons().get(toPath(modulePath.path, host.getCurrentDirectory(), info.getCanonicalFileName)),
44326
44380
  (reason) => {
44327
44381
  if (reason.kind !== 3 /* Import */ || reason.file !== importingSourceFile.path) return void 0;
44328
- if (importingSourceFile.impliedNodeFormat && importingSourceFile.impliedNodeFormat !== getModeForResolutionAtIndex(importingSourceFile, reason.index, compilerOptions)) return void 0;
44382
+ const existingMode = host.getModeForResolutionAtIndex(importingSourceFile, reason.index);
44383
+ const targetMode = options.overrideImportMode ?? host.getDefaultResolutionModeForFile(importingSourceFile);
44384
+ if (existingMode !== targetMode && existingMode !== void 0 && targetMode !== void 0) {
44385
+ return void 0;
44386
+ }
44329
44387
  const specifier = getModuleNameStringLiteralAt(importingSourceFile, reason.index).text;
44330
44388
  return preferences.relativePreference !== 1 /* NonRelative */ || !pathIsRelative(specifier) ? specifier : void 0;
44331
44389
  }
@@ -44518,7 +44576,7 @@ function getAllModulePathsWorker(info, importedFileName, host, compilerOptions,
44518
44576
  if (cache && links && host.readFile && !pathContainsNodeModules(info.importingSourceFileName)) {
44519
44577
  Debug.type(host);
44520
44578
  const state = getTemporaryModuleResolutionState(cache.getPackageJsonInfoCache(), host, {});
44521
- const packageJson = getPackageScopeForPath(info.importingSourceFileName, state);
44579
+ const packageJson = getPackageScopeForPath(getDirectoryPath(info.importingSourceFileName), state);
44522
44580
  if (packageJson) {
44523
44581
  const toResolve = getAllRuntimeDependencies(packageJson.contents.packageJsonContent);
44524
44582
  for (const depName of toResolve || emptyArray) {
@@ -44840,7 +44898,7 @@ function tryGetModuleNameAsNodeModule({ path, isRedirect }, { getCanonicalFileNa
44840
44898
  if (!parts) {
44841
44899
  return void 0;
44842
44900
  }
44843
- const preferences = getModuleSpecifierPreferences(userPreferences, options, importingSourceFile);
44901
+ const preferences = getModuleSpecifierPreferences(userPreferences, host, options, importingSourceFile);
44844
44902
  const allowedEndings = preferences.getAllowedEndingsInPreferredOrder();
44845
44903
  let moduleSpecifier = path;
44846
44904
  let isPackageRootPath = false;
@@ -44890,7 +44948,7 @@ function tryGetModuleNameAsNodeModule({ path, isRedirect }, { getCanonicalFileNa
44890
44948
  const cachedPackageJson = (_b = (_a = host.getPackageJsonInfoCache) == null ? void 0 : _a.call(host)) == null ? void 0 : _b.getPackageJsonInfo(packageJsonPath);
44891
44949
  if (isPackageJsonInfo(cachedPackageJson) || cachedPackageJson === void 0 && host.fileExists(packageJsonPath)) {
44892
44950
  const packageJsonContent = (cachedPackageJson == null ? void 0 : cachedPackageJson.contents.packageJsonContent) || tryParseJson(host.readFile(packageJsonPath));
44893
- const importMode = overrideMode || importingSourceFile.impliedNodeFormat;
44951
+ const importMode = overrideMode || getDefaultResolutionModeForFile(importingSourceFile, host, options);
44894
44952
  if (getResolvePackageJsonExports(options)) {
44895
44953
  const nodeModulesDirectoryName2 = packageRootPath.substring(parts.topLevelPackageNameIndex + 1);
44896
44954
  const packageName2 = getPackageNameFromTypesPackageName(nodeModulesDirectoryName2);
@@ -45040,6 +45098,9 @@ function getRelativePathIfInSameVolume(path, directoryPath, getCanonicalFileName
45040
45098
  function isPathRelativeToParent(path) {
45041
45099
  return startsWith(path, "..");
45042
45100
  }
45101
+ function getDefaultResolutionModeForFile(file, host, compilerOptions) {
45102
+ return isFullSourceFile(file) ? host.getDefaultResolutionModeForFile(file) : getDefaultResolutionModeForFileWorker(file, compilerOptions);
45103
+ }
45043
45104
 
45044
45105
  // src/compiler/checker.ts
45045
45106
  var ambientModuleSymbolRegex = /^".+"$/;
@@ -47260,22 +47321,28 @@ function createTypeChecker(host) {
47260
47321
  function isSyntacticDefault(node) {
47261
47322
  return isExportAssignment(node) && !node.isExportEquals || hasSyntacticModifier(node, 2048 /* Default */) || isExportSpecifier(node) || isNamespaceExport(node);
47262
47323
  }
47263
- function getUsageModeForExpression(usage) {
47264
- return isStringLiteralLike(usage) ? host.getModeForUsageLocation(getSourceFileOfNode(usage), usage) : void 0;
47324
+ function getEmitSyntaxForModuleSpecifierExpression(usage) {
47325
+ return isStringLiteralLike(usage) ? host.getEmitSyntaxForUsageLocation(getSourceFileOfNode(usage), usage) : void 0;
47265
47326
  }
47266
47327
  function isESMFormatImportImportingCommonjsFormatFile(usageMode, targetMode) {
47267
47328
  return usageMode === 99 /* ESNext */ && targetMode === 1 /* CommonJS */;
47268
47329
  }
47269
- function isOnlyImportedAsDefault(usage) {
47270
- const usageMode = getUsageModeForExpression(usage);
47271
- return usageMode === 99 /* ESNext */ && endsWith(usage.text, ".json" /* Json */);
47330
+ function isOnlyImportableAsDefault(usage) {
47331
+ if (100 /* Node16 */ <= moduleKind && moduleKind <= 199 /* NodeNext */) {
47332
+ const usageMode = getEmitSyntaxForModuleSpecifierExpression(usage);
47333
+ return usageMode === 99 /* ESNext */ && endsWith(usage.text, ".json" /* Json */);
47334
+ }
47335
+ return false;
47272
47336
  }
47273
47337
  function canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, usage) {
47274
- const usageMode = file && getUsageModeForExpression(usage);
47275
- if (file && usageMode !== void 0 && 100 /* Node16 */ <= moduleKind && moduleKind <= 199 /* NodeNext */) {
47276
- const result = isESMFormatImportImportingCommonjsFormatFile(usageMode, file.impliedNodeFormat);
47277
- if (usageMode === 99 /* ESNext */ || result) {
47278
- return result;
47338
+ const usageMode = file && getEmitSyntaxForModuleSpecifierExpression(usage);
47339
+ if (file && usageMode !== void 0) {
47340
+ const targetMode = host.getImpliedNodeFormatForEmit(file);
47341
+ if (usageMode === 99 /* ESNext */ && targetMode === 1 /* CommonJS */ && 100 /* Node16 */ <= moduleKind && moduleKind <= 199 /* NodeNext */) {
47342
+ return true;
47343
+ }
47344
+ if (usageMode === 99 /* ESNext */ && targetMode === 99 /* ESNext */) {
47345
+ return false;
47279
47346
  }
47280
47347
  }
47281
47348
  if (!allowSyntheticDefaultImports) {
@@ -47334,7 +47401,7 @@ function createTypeChecker(host) {
47334
47401
  if (!specifier) {
47335
47402
  return exportDefaultSymbol;
47336
47403
  }
47337
- const hasDefaultOnly = isOnlyImportedAsDefault(specifier);
47404
+ const hasDefaultOnly = isOnlyImportableAsDefault(specifier);
47338
47405
  const hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, specifier);
47339
47406
  if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) {
47340
47407
  if (hasExportAssignmentSymbol(moduleSymbol) && !allowSyntheticDefaultImports) {
@@ -47536,7 +47603,7 @@ function createTypeChecker(host) {
47536
47603
  let symbolFromModule = getExportOfModule(targetSymbol, nameText, specifier, dontResolveAlias);
47537
47604
  if (symbolFromModule === void 0 && nameText === "default" /* Default */) {
47538
47605
  const file = (_a = moduleSymbol.declarations) == null ? void 0 : _a.find(isSourceFile);
47539
- if (isOnlyImportedAsDefault(moduleSpecifier) || canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, moduleSpecifier)) {
47606
+ if (isOnlyImportableAsDefault(moduleSpecifier) || canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, moduleSpecifier)) {
47540
47607
  symbolFromModule = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias);
47541
47608
  }
47542
47609
  }
@@ -48140,7 +48207,7 @@ function createTypeChecker(host) {
48140
48207
  /*requireStringLiteralLikeArgument*/
48141
48208
  true
48142
48209
  ) ? location.initializer.arguments[0] : void 0) || ((_c = findAncestor(location, isImportCall)) == null ? void 0 : _c.arguments[0]) || ((_d = findAncestor(location, isImportDeclaration)) == null ? void 0 : _d.moduleSpecifier) || ((_e = findAncestor(location, isExternalModuleImportEqualsDeclaration)) == null ? void 0 : _e.moduleReference.expression) || ((_f = findAncestor(location, isExportDeclaration)) == null ? void 0 : _f.moduleSpecifier);
48143
- const mode = contextSpecifier && isStringLiteralLike(contextSpecifier) ? host.getModeForUsageLocation(currentSourceFile, contextSpecifier) : currentSourceFile.impliedNodeFormat;
48210
+ const mode = contextSpecifier && isStringLiteralLike(contextSpecifier) ? host.getModeForUsageLocation(currentSourceFile, contextSpecifier) : host.getDefaultResolutionModeForFile(currentSourceFile);
48144
48211
  const moduleResolutionKind = getEmitModuleResolutionKind(compilerOptions);
48145
48212
  const resolvedModule = (_g = host.getResolvedModule(currentSourceFile, moduleReference, mode)) == null ? void 0 : _g.resolvedModule;
48146
48213
  const resolutionDiagnostic = errorNode && resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule, currentSourceFile);
@@ -48187,41 +48254,7 @@ function createTypeChecker(host) {
48187
48254
  let diagnosticDetails;
48188
48255
  const ext = tryGetExtensionFromPath2(currentSourceFile.fileName);
48189
48256
  if (ext === ".ts" /* Ts */ || ext === ".js" /* Js */ || ext === ".tsx" /* Tsx */ || ext === ".jsx" /* Jsx */) {
48190
- const scope = currentSourceFile.packageJsonScope;
48191
- const targetExt = ext === ".ts" /* Ts */ ? ".mts" /* Mts */ : ext === ".js" /* Js */ ? ".mjs" /* Mjs */ : void 0;
48192
- if (scope && !scope.contents.packageJsonContent.type) {
48193
- if (targetExt) {
48194
- diagnosticDetails = chainDiagnosticMessages(
48195
- /*details*/
48196
- void 0,
48197
- Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_add_the_field_type_Colon_module_to_1,
48198
- targetExt,
48199
- combinePaths(scope.packageDirectory, "package.json")
48200
- );
48201
- } else {
48202
- diagnosticDetails = chainDiagnosticMessages(
48203
- /*details*/
48204
- void 0,
48205
- Diagnostics.To_convert_this_file_to_an_ECMAScript_module_add_the_field_type_Colon_module_to_0,
48206
- combinePaths(scope.packageDirectory, "package.json")
48207
- );
48208
- }
48209
- } else {
48210
- if (targetExt) {
48211
- diagnosticDetails = chainDiagnosticMessages(
48212
- /*details*/
48213
- void 0,
48214
- Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_create_a_local_package_json_file_with_type_Colon_module,
48215
- targetExt
48216
- );
48217
- } else {
48218
- diagnosticDetails = chainDiagnosticMessages(
48219
- /*details*/
48220
- void 0,
48221
- Diagnostics.To_convert_this_file_to_an_ECMAScript_module_create_a_local_package_json_file_with_type_Colon_module
48222
- );
48223
- }
48224
- }
48257
+ diagnosticDetails = createModeMismatchDetails(currentSourceFile);
48225
48258
  }
48226
48259
  diagnostics.add(createDiagnosticForNodeFromMessageChain(
48227
48260
  getSourceFileOfNode(errorNode),
@@ -48387,7 +48420,7 @@ function createTypeChecker(host) {
48387
48420
  return cloneTypeAsModuleType(symbol, defaultOnlyType, referenceParent);
48388
48421
  }
48389
48422
  const targetFile = (_a = moduleSymbol == null ? void 0 : moduleSymbol.declarations) == null ? void 0 : _a.find(isSourceFile);
48390
- const isEsmCjsRef = targetFile && isESMFormatImportImportingCommonjsFormatFile(getUsageModeForExpression(reference), targetFile.impliedNodeFormat);
48423
+ const isEsmCjsRef = targetFile && isESMFormatImportImportingCommonjsFormatFile(getEmitSyntaxForModuleSpecifierExpression(reference), host.getImpliedNodeFormatForEmit(targetFile));
48391
48424
  if (getESModuleInterop(compilerOptions) || isEsmCjsRef) {
48392
48425
  let sigs = getSignaturesOfStructuredType(type, 0 /* Call */);
48393
48426
  if (!sigs || !sigs.length) {
@@ -51007,8 +51040,10 @@ function createTypeChecker(host) {
51007
51040
  }
51008
51041
  return getSourceFileOfNode(getNonAugmentationDeclaration(symbol)).fileName;
51009
51042
  }
51043
+ const enclosingDeclaration = getOriginalNode(context.enclosingDeclaration);
51044
+ const originalModuleSpecifier = canHaveModuleSpecifier(enclosingDeclaration) ? tryGetModuleSpecifierFromDeclaration(enclosingDeclaration) : void 0;
51010
51045
  const contextFile = context.enclosingFile;
51011
- const resolutionMode = overrideImportMode || (contextFile == null ? void 0 : contextFile.impliedNodeFormat);
51046
+ const resolutionMode = overrideImportMode || originalModuleSpecifier && host.getModeForUsageLocation(contextFile, originalModuleSpecifier) || contextFile && host.getDefaultResolutionModeForFile(contextFile);
51012
51047
  const cacheKey = createModeAwareCacheKey(contextFile.path, resolutionMode);
51013
51048
  const links = getSymbolLinks(symbol);
51014
51049
  let specifier = links.specifierCache && links.specifierCache.get(cacheKey);
@@ -52081,7 +52116,7 @@ function createTypeChecker(host) {
52081
52116
  if (result) {
52082
52117
  if (result.pos !== -1 || result.end !== -1) {
52083
52118
  if (result === nodes) {
52084
- result = factory.createNodeArray(nodes, nodes.hasTrailingComma);
52119
+ result = factory.createNodeArray(nodes.slice(), nodes.hasTrailingComma);
52085
52120
  }
52086
52121
  setTextRangePosEnd(result, -1, -1);
52087
52122
  }
@@ -56057,18 +56092,18 @@ function createTypeChecker(host) {
56057
56092
  function getExpandedParameters(sig, skipUnionExpanding) {
56058
56093
  if (signatureHasRestParameter(sig)) {
56059
56094
  const restIndex = sig.parameters.length - 1;
56060
- const restName = sig.parameters[restIndex].escapedName;
56061
- const restType = getTypeOfSymbol(sig.parameters[restIndex]);
56095
+ const restSymbol = sig.parameters[restIndex];
56096
+ const restType = getTypeOfSymbol(restSymbol);
56062
56097
  if (isTupleType(restType)) {
56063
- return [expandSignatureParametersWithTupleMembers(restType, restIndex, restName)];
56098
+ return [expandSignatureParametersWithTupleMembers(restType, restIndex, restSymbol)];
56064
56099
  } else if (!skipUnionExpanding && restType.flags & 1048576 /* Union */ && every(restType.types, isTupleType)) {
56065
- return map(restType.types, (t) => expandSignatureParametersWithTupleMembers(t, restIndex, restName));
56100
+ return map(restType.types, (t) => expandSignatureParametersWithTupleMembers(t, restIndex, restSymbol));
56066
56101
  }
56067
56102
  }
56068
56103
  return [sig.parameters];
56069
- function expandSignatureParametersWithTupleMembers(restType, restIndex, restName) {
56104
+ function expandSignatureParametersWithTupleMembers(restType, restIndex, restSymbol) {
56070
56105
  const elementTypes = getTypeArguments(restType);
56071
- const associatedNames = getUniqAssociatedNamesFromTupleType(restType, restName);
56106
+ const associatedNames = getUniqAssociatedNamesFromTupleType(restType, restSymbol);
56072
56107
  const restParams = map(elementTypes, (t, i) => {
56073
56108
  const name = associatedNames && associatedNames[i] ? associatedNames[i] : getParameterNameAtPosition(sig, restIndex + i, restType);
56074
56109
  const flags = restType.target.elementFlags[i];
@@ -56079,19 +56114,29 @@ function createTypeChecker(host) {
56079
56114
  });
56080
56115
  return concatenate(sig.parameters.slice(0, restIndex), restParams);
56081
56116
  }
56082
- function getUniqAssociatedNamesFromTupleType(type, restName) {
56083
- const associatedNamesMap = /* @__PURE__ */ new Map();
56084
- return map(type.target.labeledElementDeclarations, (labeledElement, i) => {
56085
- const name = getTupleElementLabel(labeledElement, i, restName);
56086
- const prevCounter = associatedNamesMap.get(name);
56087
- if (prevCounter === void 0) {
56088
- associatedNamesMap.set(name, 1);
56089
- return name;
56090
- } else {
56091
- associatedNamesMap.set(name, prevCounter + 1);
56092
- return `${name}_${prevCounter}`;
56117
+ function getUniqAssociatedNamesFromTupleType(type, restSymbol) {
56118
+ const names = map(type.target.labeledElementDeclarations, (labeledElement, i) => getTupleElementLabel(labeledElement, i, type.target.elementFlags[i], restSymbol));
56119
+ if (names) {
56120
+ const duplicates = [];
56121
+ const uniqueNames = /* @__PURE__ */ new Set();
56122
+ for (let i = 0; i < names.length; i++) {
56123
+ const name = names[i];
56124
+ if (!tryAddToSet(uniqueNames, name)) {
56125
+ duplicates.push(i);
56126
+ }
56093
56127
  }
56094
- });
56128
+ const counters = /* @__PURE__ */ new Map();
56129
+ for (const i of duplicates) {
56130
+ let counter = counters.get(names[i]) ?? 1;
56131
+ let name;
56132
+ while (!tryAddToSet(uniqueNames, name = `${names[i]}_${counter}`)) {
56133
+ counter++;
56134
+ }
56135
+ names[i] = name;
56136
+ counters.set(names[i], counter + 1);
56137
+ }
56138
+ }
56139
+ return names;
56095
56140
  }
56096
56141
  }
56097
56142
  function getDefaultConstructSignatures(classType) {
@@ -69583,7 +69628,7 @@ function createTypeChecker(host) {
69583
69628
  if (!canCollectSymbolAliasAccessabilityData) {
69584
69629
  return;
69585
69630
  }
69586
- if (location.flags & 33554432 /* Ambient */) {
69631
+ if (location.flags & 33554432 /* Ambient */ && !isPropertySignature(location) && !isPropertyDeclaration(location)) {
69587
69632
  return;
69588
69633
  }
69589
69634
  switch (hint) {
@@ -72574,7 +72619,7 @@ function createTypeChecker(host) {
72574
72619
  checkGrammarJsxElement(node);
72575
72620
  }
72576
72621
  checkJsxPreconditions(node);
72577
- markLinkedReferences(node, 4 /* Jsx */);
72622
+ markJsxAliasReferenced(node);
72578
72623
  if (isNodeOpeningLikeElement) {
72579
72624
  const jsxOpeningLikeNode = node;
72580
72625
  const sig = getResolvedSignature(jsxOpeningLikeNode);
@@ -75505,7 +75550,7 @@ function createTypeChecker(host) {
75505
75550
  return createAnonymousType(anonymousSymbol, memberTable, emptyArray, emptyArray, emptyArray);
75506
75551
  }
75507
75552
  function getTypeWithSyntheticDefaultOnly(type, symbol, originalSymbol, moduleSpecifier) {
75508
- const hasDefaultOnly = isOnlyImportedAsDefault(moduleSpecifier);
75553
+ const hasDefaultOnly = isOnlyImportableAsDefault(moduleSpecifier);
75509
75554
  if (hasDefaultOnly && type && !isErrorType(type)) {
75510
75555
  const synthType = type;
75511
75556
  if (!synthType.defaultOnlyType) {
@@ -75831,14 +75876,45 @@ function createTypeChecker(host) {
75831
75876
  !!declaration && (hasInitializer(declaration) || isOptionalDeclaration(declaration))
75832
75877
  );
75833
75878
  }
75834
- function getTupleElementLabel(d, index, restParameterName = "arg") {
75879
+ function getTupleElementLabelFromBindingElement(node, index, elementFlags) {
75880
+ switch (node.name.kind) {
75881
+ case 80 /* Identifier */: {
75882
+ const name = node.name.escapedText;
75883
+ if (node.dotDotDotToken) {
75884
+ return elementFlags & 12 /* Variable */ ? name : `${name}_${index}`;
75885
+ } else {
75886
+ return elementFlags & 3 /* Fixed */ ? name : `${name}_n`;
75887
+ }
75888
+ }
75889
+ case 207 /* ArrayBindingPattern */: {
75890
+ if (node.dotDotDotToken) {
75891
+ const elements = node.name.elements;
75892
+ const lastElement = tryCast(lastOrUndefined(elements), isBindingElement);
75893
+ const elementCount = elements.length - ((lastElement == null ? void 0 : lastElement.dotDotDotToken) ? 1 : 0);
75894
+ if (index < elementCount) {
75895
+ const element = elements[index];
75896
+ if (isBindingElement(element)) {
75897
+ return getTupleElementLabelFromBindingElement(element, index, elementFlags);
75898
+ }
75899
+ } else if (lastElement == null ? void 0 : lastElement.dotDotDotToken) {
75900
+ return getTupleElementLabelFromBindingElement(lastElement, index - elementCount, elementFlags);
75901
+ }
75902
+ }
75903
+ break;
75904
+ }
75905
+ }
75906
+ return `arg_${index}`;
75907
+ }
75908
+ function getTupleElementLabel(d, index = 0, elementFlags = 3 /* Fixed */, restSymbol) {
75835
75909
  if (!d) {
75836
- return `${restParameterName}_${index}`;
75910
+ const restParameter = tryCast(restSymbol == null ? void 0 : restSymbol.valueDeclaration, isParameter);
75911
+ return restParameter ? getTupleElementLabelFromBindingElement(restParameter, index, elementFlags) : `${(restSymbol == null ? void 0 : restSymbol.escapedName) ?? "arg"}_${index}`;
75837
75912
  }
75838
75913
  Debug.assert(isIdentifier(d.name));
75839
75914
  return d.name.escapedText;
75840
75915
  }
75841
75916
  function getParameterNameAtPosition(signature, pos, overrideRestType) {
75917
+ var _a;
75842
75918
  const paramCount = signature.parameters.length - (signatureHasRestParameter(signature) ? 1 : 0);
75843
75919
  if (pos < paramCount) {
75844
75920
  return signature.parameters[pos].escapedName;
@@ -75846,9 +75922,11 @@ function createTypeChecker(host) {
75846
75922
  const restParameter = signature.parameters[paramCount] || unknownSymbol;
75847
75923
  const restType = overrideRestType || getTypeOfSymbol(restParameter);
75848
75924
  if (isTupleType(restType)) {
75849
- const associatedNames = restType.target.labeledElementDeclarations;
75925
+ const tupleType = restType.target;
75850
75926
  const index = pos - paramCount;
75851
- return getTupleElementLabel(associatedNames == null ? void 0 : associatedNames[index], index, restParameter.escapedName);
75927
+ const associatedName = (_a = tupleType.labeledElementDeclarations) == null ? void 0 : _a[index];
75928
+ const elementFlags = tupleType.elementFlags[index];
75929
+ return getTupleElementLabel(associatedName, index, elementFlags, restParameter);
75852
75930
  }
75853
75931
  return restParameter.escapedName;
75854
75932
  }
@@ -80779,7 +80857,7 @@ function createTypeChecker(host) {
80779
80857
  });
80780
80858
  }
80781
80859
  function checkCollisionWithRequireExportsInGeneratedCode(node, name) {
80782
- if (moduleKind >= 5 /* ES2015 */ && !(moduleKind >= 100 /* Node16 */ && getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) {
80860
+ if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) >= 5 /* ES2015 */) {
80783
80861
  return;
80784
80862
  }
80785
80863
  if (!name || !needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) {
@@ -82200,7 +82278,7 @@ function createTypeChecker(host) {
82200
82278
  }
82201
82279
  }
82202
82280
  function checkClassNameCollisionWithObject(name) {
82203
- if (languageVersion >= 1 /* ES5 */ && name.escapedText === "Object" && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(name).impliedNodeFormat === 1 /* CommonJS */)) {
82281
+ if (languageVersion >= 1 /* ES5 */ && name.escapedText === "Object" && host.getEmitModuleFormatOfFile(getSourceFileOfNode(name)) < 5 /* ES2015 */) {
82204
82282
  error(name, Diagnostics.Class_name_cannot_be_Object_when_targeting_ES5_with_module_0, ModuleKind[moduleKind]);
82205
82283
  }
82206
82284
  }
@@ -83280,7 +83358,7 @@ function createTypeChecker(host) {
83280
83358
  getNodeLinks(node).flags |= 2048 /* LexicalModuleMergesWithClass */;
83281
83359
  }
83282
83360
  }
83283
- if (compilerOptions.verbatimModuleSyntax && node.parent.kind === 307 /* SourceFile */ && (moduleKind === 1 /* CommonJS */ || node.parent.impliedNodeFormat === 1 /* CommonJS */)) {
83361
+ if (compilerOptions.verbatimModuleSyntax && node.parent.kind === 307 /* SourceFile */ && host.getEmitModuleFormatOfFile(node.parent) === 1 /* CommonJS */) {
83284
83362
  const exportModifier = (_b = node.modifiers) == null ? void 0 : _b.find((m) => m.kind === 95 /* ExportKeyword */);
83285
83363
  if (exportModifier) {
83286
83364
  error(exportModifier, Diagnostics.A_top_level_export_modifier_cannot_be_used_on_value_declarations_in_a_CommonJS_module_when_verbatimModuleSyntax_is_enabled);
@@ -83500,8 +83578,10 @@ function createTypeChecker(host) {
83500
83578
  }
83501
83579
  }
83502
83580
  }
83503
- if (compilerOptions.verbatimModuleSyntax && node.kind !== 271 /* ImportEqualsDeclaration */ && !isInJSFile(node) && (moduleKind === 1 /* CommonJS */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) {
83581
+ if (compilerOptions.verbatimModuleSyntax && node.kind !== 271 /* ImportEqualsDeclaration */ && !isInJSFile(node) && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === 1 /* CommonJS */) {
83504
83582
  error(node, Diagnostics.ESM_syntax_is_not_allowed_in_a_CommonJS_module_when_verbatimModuleSyntax_is_enabled);
83583
+ } else if (moduleKind === 200 /* Preserve */ && node.kind !== 271 /* ImportEqualsDeclaration */ && node.kind !== 260 /* VariableDeclaration */ && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === 1 /* CommonJS */) {
83584
+ error(node, Diagnostics.ESM_syntax_is_not_allowed_in_a_CommonJS_module_when_module_is_set_to_preserve);
83505
83585
  }
83506
83586
  }
83507
83587
  if (isImportSpecifier(node)) {
@@ -83542,7 +83622,7 @@ function createTypeChecker(host) {
83542
83622
  checkAliasSymbol(node);
83543
83623
  if (node.kind === 276 /* ImportSpecifier */) {
83544
83624
  checkModuleExportName(node.propertyName);
83545
- if (moduleExportNameIsDefault(node.propertyName || node.name) && getESModuleInterop(compilerOptions) && moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) {
83625
+ if (moduleExportNameIsDefault(node.propertyName || node.name) && getESModuleInterop(compilerOptions) && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */) {
83546
83626
  checkExternalEmitHelpers(node, 131072 /* ImportDefault */);
83547
83627
  }
83548
83628
  }
@@ -83564,7 +83644,7 @@ function createTypeChecker(host) {
83564
83644
  if (validForTypeAttributes && override) {
83565
83645
  return;
83566
83646
  }
83567
- const mode = moduleKind === 199 /* NodeNext */ && declaration.moduleSpecifier && getUsageModeForExpression(declaration.moduleSpecifier);
83647
+ const mode = moduleKind === 199 /* NodeNext */ && declaration.moduleSpecifier && getEmitSyntaxForModuleSpecifierExpression(declaration.moduleSpecifier);
83568
83648
  if (mode !== 99 /* ESNext */ && moduleKind !== 99 /* ESNext */ && moduleKind !== 200 /* Preserve */) {
83569
83649
  const message = isImportAttributes2 ? moduleKind === 199 /* NodeNext */ ? Diagnostics.Import_attributes_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls : Diagnostics.Import_attributes_are_only_supported_when_the_module_option_is_set_to_esnext_nodenext_or_preserve : moduleKind === 199 /* NodeNext */ ? Diagnostics.Import_assertions_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls : Diagnostics.Import_assertions_are_only_supported_when_the_module_option_is_set_to_esnext_nodenext_or_preserve;
83570
83650
  return grammarErrorOnNode(node, message);
@@ -83597,7 +83677,7 @@ function createTypeChecker(host) {
83597
83677
  if (importClause.namedBindings) {
83598
83678
  if (importClause.namedBindings.kind === 274 /* NamespaceImport */) {
83599
83679
  checkImportBinding(importClause.namedBindings);
83600
- if (moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */) && getESModuleInterop(compilerOptions)) {
83680
+ if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */ && getESModuleInterop(compilerOptions)) {
83601
83681
  checkExternalEmitHelpers(node, 65536 /* ImportStar */);
83602
83682
  }
83603
83683
  } else {
@@ -83637,7 +83717,7 @@ function createTypeChecker(host) {
83637
83717
  grammarErrorOnNode(node, Diagnostics.An_import_alias_cannot_use_import_type);
83638
83718
  }
83639
83719
  } else {
83640
- if (moduleKind >= 5 /* ES2015 */ && moduleKind !== 200 /* Preserve */ && getSourceFileOfNode(node).impliedNodeFormat === void 0 && !node.isTypeOnly && !(node.flags & 33554432 /* Ambient */)) {
83720
+ if (5 /* ES2015 */ <= moduleKind && moduleKind <= 99 /* ESNext */ && !node.isTypeOnly && !(node.flags & 33554432 /* Ambient */)) {
83641
83721
  grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead);
83642
83722
  }
83643
83723
  }
@@ -83667,7 +83747,7 @@ function createTypeChecker(host) {
83667
83747
  checkAliasSymbol(node.exportClause);
83668
83748
  checkModuleExportName(node.exportClause.name);
83669
83749
  }
83670
- if (moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) {
83750
+ if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */) {
83671
83751
  if (node.exportClause) {
83672
83752
  if (getESModuleInterop(compilerOptions)) {
83673
83753
  checkExternalEmitHelpers(node, 65536 /* ImportStar */);
@@ -83726,7 +83806,7 @@ function createTypeChecker(host) {
83726
83806
  markLinkedReferences(node, 7 /* ExportSpecifier */);
83727
83807
  }
83728
83808
  } else {
83729
- if (getESModuleInterop(compilerOptions) && moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */) && moduleExportNameIsDefault(node.propertyName || node.name)) {
83809
+ if (getESModuleInterop(compilerOptions) && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */ && moduleExportNameIsDefault(node.propertyName || node.name)) {
83730
83810
  checkExternalEmitHelpers(node, 131072 /* ImportDefault */);
83731
83811
  }
83732
83812
  }
@@ -83752,7 +83832,7 @@ function createTypeChecker(host) {
83752
83832
  if (typeAnnotationNode) {
83753
83833
  checkTypeAssignableTo(checkExpressionCached(node.expression), getTypeFromTypeNode(typeAnnotationNode), node.expression);
83754
83834
  }
83755
- const isIllegalExportDefaultInCJS = !node.isExportEquals && !(node.flags & 33554432 /* Ambient */) && compilerOptions.verbatimModuleSyntax && (moduleKind === 1 /* CommonJS */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */);
83835
+ const isIllegalExportDefaultInCJS = !node.isExportEquals && !(node.flags & 33554432 /* Ambient */) && compilerOptions.verbatimModuleSyntax && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === 1 /* CommonJS */;
83756
83836
  if (node.expression.kind === 80 /* Identifier */) {
83757
83837
  const id = node.expression;
83758
83838
  const sym = getExportSymbolOfValueSymbolIfExported(resolveEntityName(
@@ -83832,7 +83912,7 @@ function createTypeChecker(host) {
83832
83912
  grammarErrorOnNode(node.expression, Diagnostics.The_expression_of_an_export_assignment_must_be_an_identifier_or_qualified_name_in_an_ambient_context);
83833
83913
  }
83834
83914
  if (node.isExportEquals) {
83835
- if (moduleKind >= 5 /* ES2015 */ && moduleKind !== 200 /* Preserve */ && (node.flags & 33554432 /* Ambient */ && getSourceFileOfNode(node).impliedNodeFormat === 99 /* ESNext */ || !(node.flags & 33554432 /* Ambient */) && getSourceFileOfNode(node).impliedNodeFormat !== 1 /* CommonJS */)) {
83915
+ if (moduleKind >= 5 /* ES2015 */ && moduleKind !== 200 /* Preserve */ && (node.flags & 33554432 /* Ambient */ && host.getImpliedNodeFormatForEmit(getSourceFileOfNode(node)) === 99 /* ESNext */ || !(node.flags & 33554432 /* Ambient */) && host.getImpliedNodeFormatForEmit(getSourceFileOfNode(node)) !== 1 /* CommonJS */)) {
83836
83916
  grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_export_default_or_another_module_format_instead);
83837
83917
  } else if (moduleKind === 4 /* System */ && !(node.flags & 33554432 /* Ambient */)) {
83838
83918
  grammarErrorOnNode(node, Diagnostics.Export_assignment_is_not_supported_when_module_flag_is_system);
@@ -85423,15 +85503,14 @@ function createTypeChecker(host) {
85423
85503
  function checkChildIdentifiers(node2) {
85424
85504
  forEachNodeRecursively(node2, checkIdentifiers);
85425
85505
  }
85506
+ function isExpressionNodeOrShorthandPropertyAssignmentName(node2) {
85507
+ return isExpressionNode(node2) || isShorthandPropertyAssignment(node2.parent) && (node2.parent.objectAssignmentInitializer ?? node2.parent.name) === node2;
85508
+ }
85426
85509
  function checkSingleIdentifier(node2) {
85427
85510
  const nodeLinks2 = getNodeLinks(node2);
85428
85511
  nodeLinks2.calculatedFlags |= 536870912 /* ConstructorReference */ | 16384 /* CapturedBlockScopedBinding */ | 32768 /* BlockScopedBindingInLoop */;
85429
- if (isIdentifier(node2) && isExpressionNode(node2) && !(isPropertyAccessExpression(node2.parent) && node2.parent.name === node2)) {
85430
- const s = getSymbolAtLocation(
85431
- node2,
85432
- /*ignoreErrors*/
85433
- true
85434
- );
85512
+ if (isIdentifier(node2) && isExpressionNodeOrShorthandPropertyAssignmentName(node2) && !(isPropertyAccessExpression(node2.parent) && node2.parent.name === node2)) {
85513
+ const s = getResolvedSymbol(node2);
85435
85514
  if (s && s !== unknownSymbol) {
85436
85515
  checkIdentifierCalculateNodeCheckFlags(node2, s);
85437
85516
  }
@@ -86378,7 +86457,7 @@ function createTypeChecker(host) {
86378
86457
  break;
86379
86458
  case 95 /* ExportKeyword */:
86380
86459
  if (compilerOptions.verbatimModuleSyntax && !(node.flags & 33554432 /* Ambient */) && node.kind !== 265 /* TypeAliasDeclaration */ && node.kind !== 264 /* InterfaceDeclaration */ && // ModuleDeclaration needs to be checked that it is uninstantiated later
86381
- node.kind !== 267 /* ModuleDeclaration */ && node.parent.kind === 307 /* SourceFile */ && (moduleKind === 1 /* CommonJS */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) {
86460
+ node.kind !== 267 /* ModuleDeclaration */ && node.parent.kind === 307 /* SourceFile */ && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === 1 /* CommonJS */) {
86382
86461
  return grammarErrorOnNode(modifier, Diagnostics.A_top_level_export_modifier_cannot_be_used_on_value_declarations_in_a_CommonJS_module_when_verbatimModuleSyntax_is_enabled);
86383
86462
  }
86384
86463
  if (flags & 32 /* Export */) {
@@ -87288,7 +87367,7 @@ function createTypeChecker(host) {
87288
87367
  const message = node.initializer ? Diagnostics.Declarations_with_initializers_cannot_also_have_definite_assignment_assertions : !node.type ? Diagnostics.Declarations_with_definite_assignment_assertions_must_also_have_type_annotations : Diagnostics.A_definite_assignment_assertion_is_not_permitted_in_this_context;
87289
87368
  return grammarErrorOnNode(node.exclamationToken, message);
87290
87369
  }
87291
- if ((moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */) && moduleKind !== 4 /* System */ && !(node.parent.parent.flags & 33554432 /* Ambient */) && hasSyntacticModifier(node.parent.parent, 32 /* Export */)) {
87370
+ if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */ && !(node.parent.parent.flags & 33554432 /* Ambient */) && hasSyntacticModifier(node.parent.parent, 32 /* Export */)) {
87292
87371
  checkESModuleMarker(node.name);
87293
87372
  }
87294
87373
  return !!blockScopeKind && checkGrammarNameInLetOrConstDeclarations(node.name);
@@ -87789,7 +87868,9 @@ function createBasicNodeBuilderModuleSpecifierResolutionHost(host) {
87789
87868
  isSourceOfProjectReferenceRedirect: (fileName) => host.isSourceOfProjectReferenceRedirect(fileName),
87790
87869
  fileExists: (fileName) => host.fileExists(fileName),
87791
87870
  getFileIncludeReasons: () => host.getFileIncludeReasons(),
87792
- readFile: host.readFile ? (fileName) => host.readFile(fileName) : void 0
87871
+ readFile: host.readFile ? (fileName) => host.readFile(fileName) : void 0,
87872
+ getDefaultResolutionModeForFile: (file) => host.getDefaultResolutionModeForFile(file),
87873
+ getModeForResolutionAtIndex: (file, index) => host.getModeForResolutionAtIndex(file, index)
87793
87874
  };
87794
87875
  }
87795
87876
  var SymbolTrackerImpl = class _SymbolTrackerImpl {
@@ -107460,7 +107541,7 @@ function transformModule(context) {
107460
107541
  case 354 /* PartiallyEmittedExpression */:
107461
107542
  return visitPartiallyEmittedExpression(node, valueIsDiscarded);
107462
107543
  case 213 /* CallExpression */:
107463
- if (isImportCall(node) && currentSourceFile.impliedNodeFormat === void 0) {
107544
+ if (isImportCall(node) && host.shouldTransformImportCall(currentSourceFile)) {
107464
107545
  return visitImportCallExpression(node);
107465
107546
  }
107466
107547
  break;
@@ -110456,8 +110537,8 @@ function transformECMAScriptModule(context) {
110456
110537
  }
110457
110538
  }
110458
110539
 
110459
- // src/compiler/transformers/module/node.ts
110460
- function transformNodeModule(context) {
110540
+ // src/compiler/transformers/module/impliedNodeFormatDependent.ts
110541
+ function transformImpliedNodeFormatDependentModule(context) {
110461
110542
  const previousOnSubstituteNode = context.onSubstituteNode;
110462
110543
  const previousOnEmitNode = context.onEmitNode;
110463
110544
  const esmTransform = transformECMAScriptModule(context);
@@ -110468,6 +110549,7 @@ function transformNodeModule(context) {
110468
110549
  const cjsTransform = transformModule(context);
110469
110550
  const cjsOnSubstituteNode = context.onSubstituteNode;
110470
110551
  const cjsOnEmitNode = context.onEmitNode;
110552
+ const getEmitModuleFormatOfFile = (file) => context.getEmitHost().getEmitModuleFormatOfFile(file);
110471
110553
  context.onSubstituteNode = onSubstituteNode;
110472
110554
  context.onEmitNode = onEmitNode;
110473
110555
  context.enableSubstitution(307 /* SourceFile */);
@@ -110482,7 +110564,7 @@ function transformNodeModule(context) {
110482
110564
  if (!currentSourceFile) {
110483
110565
  return previousOnSubstituteNode(hint, node);
110484
110566
  }
110485
- if (currentSourceFile.impliedNodeFormat === 99 /* ESNext */) {
110567
+ if (getEmitModuleFormatOfFile(currentSourceFile) >= 5 /* ES2015 */) {
110486
110568
  return esmOnSubstituteNode(hint, node);
110487
110569
  }
110488
110570
  return cjsOnSubstituteNode(hint, node);
@@ -110495,13 +110577,13 @@ function transformNodeModule(context) {
110495
110577
  if (!currentSourceFile) {
110496
110578
  return previousOnEmitNode(hint, node, emitCallback);
110497
110579
  }
110498
- if (currentSourceFile.impliedNodeFormat === 99 /* ESNext */) {
110580
+ if (getEmitModuleFormatOfFile(currentSourceFile) >= 5 /* ES2015 */) {
110499
110581
  return esmOnEmitNode(hint, node, emitCallback);
110500
110582
  }
110501
110583
  return cjsOnEmitNode(hint, node, emitCallback);
110502
110584
  }
110503
110585
  function getModuleTransformForFile(file) {
110504
- return file.impliedNodeFormat === 99 /* ESNext */ ? esmTransform : cjsTransform;
110586
+ return getEmitModuleFormatOfFile(file) >= 5 /* ES2015 */ ? esmTransform : cjsTransform;
110505
110587
  }
110506
110588
  function transformSourceFile(node) {
110507
110589
  if (node.isDeclarationFile) {
@@ -112626,17 +112708,18 @@ function isProcessedComponent(node) {
112626
112708
  // src/compiler/transformer.ts
112627
112709
  function getModuleTransformer(moduleKind) {
112628
112710
  switch (moduleKind) {
112711
+ case 200 /* Preserve */:
112712
+ return transformECMAScriptModule;
112629
112713
  case 99 /* ESNext */:
112630
112714
  case 7 /* ES2022 */:
112631
112715
  case 6 /* ES2020 */:
112632
112716
  case 5 /* ES2015 */:
112633
- case 200 /* Preserve */:
112634
- return transformECMAScriptModule;
112635
- case 4 /* System */:
112636
- return transformSystemModule;
112637
112717
  case 100 /* Node16 */:
112638
112718
  case 199 /* NodeNext */:
112639
- return transformNodeModule;
112719
+ case 1 /* CommonJS */:
112720
+ return transformImpliedNodeFormatDependentModule;
112721
+ case 4 /* System */:
112722
+ return transformSystemModule;
112640
112723
  default:
112641
112724
  return transformModule;
112642
112725
  }
@@ -113353,6 +113436,7 @@ function emitFiles(resolver, host, targetSourceFile, { scriptTransformers, decla
113353
113436
  newLine: compilerOptions.newLine,
113354
113437
  noEmitHelpers: compilerOptions.noEmitHelpers,
113355
113438
  module: getEmitModuleKind(compilerOptions),
113439
+ moduleResolution: getEmitModuleResolutionKind(compilerOptions),
113356
113440
  target: getEmitScriptTarget(compilerOptions),
113357
113441
  sourceMap: compilerOptions.sourceMap,
113358
113442
  inlineSourceMap: compilerOptions.inlineSourceMap,
@@ -113415,8 +113499,9 @@ function emitFiles(resolver, host, targetSourceFile, { scriptTransformers, decla
113415
113499
  newLine: compilerOptions.newLine,
113416
113500
  noEmitHelpers: true,
113417
113501
  module: compilerOptions.module,
113502
+ moduleResolution: compilerOptions.moduleResolution,
113418
113503
  target: compilerOptions.target,
113419
- sourceMap: !forceDtsEmit && compilerOptions.declarationMap,
113504
+ sourceMap: emitOnly !== 2 /* BuilderSignature */ && compilerOptions.declarationMap,
113420
113505
  inlineSourceMap: compilerOptions.inlineSourceMap,
113421
113506
  extendedDiagnostics: compilerOptions.extendedDiagnostics,
113422
113507
  onlyPrintJsDocStyle: true,
@@ -118877,9 +118962,6 @@ function flattenDiagnosticMessageText(diag2, newLine, indent2 = 0) {
118877
118962
  function getModeForFileReference(ref, containingFileMode) {
118878
118963
  return (isString(ref) ? containingFileMode : ref.resolutionMode) || containingFileMode;
118879
118964
  }
118880
- function getModeForResolutionAtIndex(file, index, compilerOptions) {
118881
- return getModeForUsageLocationWorker(file, getModuleNameStringLiteralAt(file, index), compilerOptions);
118882
- }
118883
118965
  function isExclusivelyTypeOnlyImportOrExport(decl) {
118884
118966
  var _a;
118885
118967
  if (isExportDeclaration(decl)) {
@@ -118894,7 +118976,6 @@ function getModeForUsageLocation(file, usage, compilerOptions) {
118894
118976
  return getModeForUsageLocationWorker(file, usage, compilerOptions);
118895
118977
  }
118896
118978
  function getModeForUsageLocationWorker(file, usage, compilerOptions) {
118897
- var _a;
118898
118979
  if (isImportDeclaration(usage.parent) || isExportDeclaration(usage.parent) || isJSDocImportTag(usage.parent)) {
118899
118980
  const isTypeOnly = isExclusivelyTypeOnlyImportOrExport(usage.parent);
118900
118981
  if (isTypeOnly) {
@@ -118910,19 +118991,28 @@ function getModeForUsageLocationWorker(file, usage, compilerOptions) {
118910
118991
  return override;
118911
118992
  }
118912
118993
  }
118913
- if (compilerOptions && getEmitModuleKind(compilerOptions) === 200 /* Preserve */) {
118914
- return usage.parent.parent && isImportEqualsDeclaration(usage.parent.parent) || isRequireCall(
118915
- usage.parent,
118916
- /*requireStringLiteralLikeArgument*/
118917
- false
118918
- ) ? 1 /* CommonJS */ : 99 /* ESNext */;
118994
+ if (compilerOptions && importSyntaxAffectsModuleResolution(compilerOptions)) {
118995
+ return getEmitSyntaxForUsageLocationWorker(file, usage, compilerOptions);
118919
118996
  }
118920
- if (file.impliedNodeFormat === void 0) return void 0;
118921
- if (file.impliedNodeFormat !== 99 /* ESNext */) {
118922
- return isImportCall(walkUpParenthesizedExpressions(usage.parent)) ? 99 /* ESNext */ : 1 /* CommonJS */;
118997
+ }
118998
+ function getEmitSyntaxForUsageLocationWorker(file, usage, compilerOptions) {
118999
+ var _a;
119000
+ if (!compilerOptions) {
119001
+ return void 0;
118923
119002
  }
118924
119003
  const exprParentParent = (_a = walkUpParenthesizedExpressions(usage.parent)) == null ? void 0 : _a.parent;
118925
- return exprParentParent && isImportEqualsDeclaration(exprParentParent) ? 1 /* CommonJS */ : 99 /* ESNext */;
119004
+ if (exprParentParent && isImportEqualsDeclaration(exprParentParent) || isRequireCall(
119005
+ usage.parent,
119006
+ /*requireStringLiteralLikeArgument*/
119007
+ false
119008
+ )) {
119009
+ return 1 /* CommonJS */;
119010
+ }
119011
+ if (isImportCall(walkUpParenthesizedExpressions(usage.parent))) {
119012
+ return shouldTransformImportCallWorker(file, compilerOptions) ? 1 /* CommonJS */ : 99 /* ESNext */;
119013
+ }
119014
+ const fileEmitMode = getEmitModuleFormatOfFileWorker(file, compilerOptions);
119015
+ return fileEmitMode === 1 /* CommonJS */ ? 1 /* CommonJS */ : emitModuleKindIsNonNodeESM(fileEmitMode) || fileEmitMode === 200 /* Preserve */ ? 99 /* ESNext */ : void 0;
118926
119016
  }
118927
119017
  function getResolutionModeOverride(node, grammarErrorOnNode) {
118928
119018
  if (!node) return void 0;
@@ -118979,7 +119069,7 @@ function getTypeReferenceResolutionName(entry) {
118979
119069
  }
118980
119070
  var typeReferenceResolutionNameAndModeGetter = {
118981
119071
  getName: getTypeReferenceResolutionName,
118982
- getMode: (entry, file) => getModeForFileReference(entry, file == null ? void 0 : file.impliedNodeFormat)
119072
+ getMode: (entry, file, compilerOptions) => getModeForFileReference(entry, file && getDefaultResolutionModeForFileWorker(file, compilerOptions))
118983
119073
  };
118984
119074
  function createTypeReferenceResolutionLoader(containingFile, redirectedReference, options, host, cache) {
118985
119075
  return {
@@ -119161,7 +119251,7 @@ function getImpliedNodeFormatForFileWorker(fileName, packageJsonInfoCache, host,
119161
119251
  const packageJsonLocations = [];
119162
119252
  state.failedLookupLocations = packageJsonLocations;
119163
119253
  state.affectingLocations = packageJsonLocations;
119164
- const packageJsonScope = getPackageScopeForPath(fileName, state);
119254
+ const packageJsonScope = getPackageScopeForPath(getDirectoryPath(fileName), state);
119165
119255
  const impliedNodeFormat = (packageJsonScope == null ? void 0 : packageJsonScope.contents.packageJsonContent.type) === "module" ? 99 /* ESNext */ : 1 /* CommonJS */;
119166
119256
  return { impliedNodeFormat, packageJsonLocations, packageJsonScope };
119167
119257
  }
@@ -119615,7 +119705,8 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
119615
119705
  isSourceFileFromExternalLibrary,
119616
119706
  isSourceFileDefaultLibrary,
119617
119707
  getModeForUsageLocation: getModeForUsageLocation2,
119618
- getModeForResolutionAtIndex: getModeForResolutionAtIndex2,
119708
+ getEmitSyntaxForUsageLocation,
119709
+ getModeForResolutionAtIndex,
119619
119710
  getSourceFileFromReference,
119620
119711
  getLibFileFromReference,
119621
119712
  sourceFileToPackageName,
@@ -119643,6 +119734,11 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
119643
119734
  forEachResolvedProjectReference: forEachResolvedProjectReference2,
119644
119735
  isSourceOfProjectReferenceRedirect,
119645
119736
  getRedirectReferenceForResolutionFromSourceOfProject,
119737
+ getCompilerOptionsForFile,
119738
+ getDefaultResolutionModeForFile: getDefaultResolutionModeForFile2,
119739
+ getEmitModuleFormatOfFile,
119740
+ getImpliedNodeFormatForEmit,
119741
+ shouldTransformImportCall,
119646
119742
  emitBuildInfo,
119647
119743
  fileExists,
119648
119744
  readFile,
@@ -120197,6 +120293,10 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
120197
120293
  getSymlinkCache,
120198
120294
  writeFile: writeFileCallback || writeFile2,
120199
120295
  isEmitBlocked,
120296
+ shouldTransformImportCall,
120297
+ getEmitModuleFormatOfFile,
120298
+ getDefaultResolutionModeForFile: getDefaultResolutionModeForFile2,
120299
+ getModeForResolutionAtIndex,
120200
120300
  readFile: (f) => host.readFile(f),
120201
120301
  fileExists: (f) => {
120202
120302
  const path = toPath3(f);
@@ -121276,10 +121376,14 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
121276
121376
  const resolvedTypeReferenceDirective = resolutions[index];
121277
121377
  const fileName = ref.fileName;
121278
121378
  resolutionsInFile.set(fileName, getModeForFileReference(ref, file.impliedNodeFormat), resolvedTypeReferenceDirective);
121279
- const mode = ref.resolutionMode || file.impliedNodeFormat;
121379
+ const mode = ref.resolutionMode || getDefaultResolutionModeForFile2(file);
121280
121380
  processTypeReferenceDirective(fileName, mode, resolvedTypeReferenceDirective, { kind: 5 /* TypeReferenceDirective */, file: file.path, index });
121281
121381
  }
121282
121382
  }
121383
+ function getCompilerOptionsForFile(file) {
121384
+ var _a2;
121385
+ return ((_a2 = getRedirectReferenceForResolution(file)) == null ? void 0 : _a2.commandLine.options) || options;
121386
+ }
121283
121387
  function processTypeReferenceDirective(typeReferenceDirective, mode, resolution, reason) {
121284
121388
  var _a2, _b2;
121285
121389
  (_a2 = tracing) == null ? void 0 : _a2.push(tracing.Phase.Program, "processTypeReferenceDirective", { directive: typeReferenceDirective, hasResolved: !!resolution.resolvedTypeReferenceDirective, refKind: reason.kind, refPath: isReferencedFile(reason) ? reason.file : void 0 });
@@ -121380,13 +121484,12 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
121380
121484
  return host.getCanonicalFileName(fileName);
121381
121485
  }
121382
121486
  function processImportedModules(file) {
121383
- var _a2;
121384
121487
  collectExternalModuleReferences(file);
121385
121488
  if (file.imports.length || file.moduleAugmentations.length) {
121386
121489
  const moduleNames = getModuleNames(file);
121387
121490
  const resolutions = (resolvedModulesProcessing == null ? void 0 : resolvedModulesProcessing.get(file.path)) || resolveModuleNamesReusingOldState(moduleNames, file);
121388
121491
  Debug.assert(resolutions.length === moduleNames.length);
121389
- const optionsForFile = ((_a2 = getRedirectReferenceForResolution(file)) == null ? void 0 : _a2.commandLine.options) || options;
121492
+ const optionsForFile = getCompilerOptionsForFile(file);
121390
121493
  const resolutionsInFile = createModeAwareCache();
121391
121494
  (resolvedModules ?? (resolvedModules = /* @__PURE__ */ new Map())).set(file.path, resolutionsInFile);
121392
121495
  for (let index = 0; index < moduleNames.length; index++) {
@@ -121935,7 +122038,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
121935
122038
  redirectInfo = cachedChain.redirectInfo;
121936
122039
  } else {
121937
122040
  reasons == null ? void 0 : reasons.forEach(processReason);
121938
- redirectInfo = file && explainIfFileIsRedirectAndImpliedFormat(file);
122041
+ redirectInfo = file && explainIfFileIsRedirectAndImpliedFormat(file, getCompilerOptionsForFile(file));
121939
122042
  }
121940
122043
  if (fileProcessingReason) processReason(fileProcessingReason);
121941
122044
  const processedExtraReason = (seenReasons == null ? void 0 : seenReasons.size) !== (reasons == null ? void 0 : reasons.length);
@@ -122293,13 +122396,53 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
122293
122396
  return symlinks;
122294
122397
  }
122295
122398
  function getModeForUsageLocation2(file, usage) {
122296
- var _a2;
122297
- const optionsForFile = ((_a2 = getRedirectReferenceForResolution(file)) == null ? void 0 : _a2.commandLine.options) || options;
122298
- return getModeForUsageLocationWorker(file, usage, optionsForFile);
122399
+ return getModeForUsageLocationWorker(file, usage, getCompilerOptionsForFile(file));
122299
122400
  }
122300
- function getModeForResolutionAtIndex2(file, index) {
122401
+ function getEmitSyntaxForUsageLocation(file, usage) {
122402
+ return getEmitSyntaxForUsageLocationWorker(file, usage, getCompilerOptionsForFile(file));
122403
+ }
122404
+ function getModeForResolutionAtIndex(file, index) {
122301
122405
  return getModeForUsageLocation2(file, getModuleNameStringLiteralAt(file, index));
122302
122406
  }
122407
+ function getDefaultResolutionModeForFile2(sourceFile) {
122408
+ return getDefaultResolutionModeForFileWorker(sourceFile, getCompilerOptionsForFile(sourceFile));
122409
+ }
122410
+ function getImpliedNodeFormatForEmit(sourceFile) {
122411
+ return getImpliedNodeFormatForEmitWorker(sourceFile, getCompilerOptionsForFile(sourceFile));
122412
+ }
122413
+ function getEmitModuleFormatOfFile(sourceFile) {
122414
+ return getEmitModuleFormatOfFileWorker(sourceFile, getCompilerOptionsForFile(sourceFile));
122415
+ }
122416
+ function shouldTransformImportCall(sourceFile) {
122417
+ return shouldTransformImportCallWorker(sourceFile, getCompilerOptionsForFile(sourceFile));
122418
+ }
122419
+ }
122420
+ function shouldTransformImportCallWorker(sourceFile, options) {
122421
+ const moduleKind = getEmitModuleKind(options);
122422
+ if (100 /* Node16 */ <= moduleKind && moduleKind <= 199 /* NodeNext */ || moduleKind === 200 /* Preserve */) {
122423
+ return false;
122424
+ }
122425
+ return getEmitModuleFormatOfFileWorker(sourceFile, options) < 5 /* ES2015 */;
122426
+ }
122427
+ function getEmitModuleFormatOfFileWorker(sourceFile, options) {
122428
+ return getImpliedNodeFormatForEmitWorker(sourceFile, options) ?? getEmitModuleKind(options);
122429
+ }
122430
+ function getImpliedNodeFormatForEmitWorker(sourceFile, options) {
122431
+ var _a, _b;
122432
+ const moduleKind = getEmitModuleKind(options);
122433
+ if (100 /* Node16 */ <= moduleKind && moduleKind <= 199 /* NodeNext */) {
122434
+ return sourceFile.impliedNodeFormat;
122435
+ }
122436
+ if (sourceFile.impliedNodeFormat === 1 /* CommonJS */ && (((_a = sourceFile.packageJsonScope) == null ? void 0 : _a.contents.packageJsonContent.type) === "commonjs" || fileExtensionIsOneOf(sourceFile.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */]))) {
122437
+ return 1 /* CommonJS */;
122438
+ }
122439
+ if (sourceFile.impliedNodeFormat === 99 /* ESNext */ && (((_b = sourceFile.packageJsonScope) == null ? void 0 : _b.contents.packageJsonContent.type) === "module" || fileExtensionIsOneOf(sourceFile.fileName, [".mjs" /* Mjs */, ".mts" /* Mts */]))) {
122440
+ return 99 /* ESNext */;
122441
+ }
122442
+ return void 0;
122443
+ }
122444
+ function getDefaultResolutionModeForFileWorker(sourceFile, options) {
122445
+ return importSyntaxAffectsModuleResolution(options) ? getImpliedNodeFormatForEmitWorker(sourceFile, options) : void 0;
122303
122446
  }
122304
122447
  function updateHostForUseSourceOfProjectReferenceRedirect(host) {
122305
122448
  let setOfDeclarationDirectories;
@@ -122754,8 +122897,7 @@ var BuilderState;
122754
122897
  );
122755
122898
  },
122756
122899
  cancellationToken,
122757
- /*emitOnly*/
122758
- true,
122900
+ 2 /* BuilderSignature */,
122759
122901
  /*customTransformers*/
122760
122902
  void 0,
122761
122903
  /*forceDtsEmit*/
@@ -123076,7 +123218,12 @@ function repopulateDiagnostics(diagnostics, newProgram) {
123076
123218
  }
123077
123219
  function convertOrRepopulateDiagnosticMessageChain(chain, sourceFile, newProgram, repopulateInfo) {
123078
123220
  const info = repopulateInfo(chain);
123079
- if (info) {
123221
+ if (info === true) {
123222
+ return {
123223
+ ...createModeMismatchDetails(sourceFile),
123224
+ next: convertOrRepopulateDiagnosticMessageChainArray(chain.next, sourceFile, newProgram, repopulateInfo)
123225
+ };
123226
+ } else if (info) {
123080
123227
  return {
123081
123228
  ...createModuleNotFoundChain(sourceFile, newProgram, info.moduleReference, info.mode, info.packageName || info.moduleReference),
123082
123229
  next: convertOrRepopulateDiagnosticMessageChainArray(chain.next, sourceFile, newProgram, repopulateInfo)
@@ -124807,7 +124954,7 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
124807
124954
  cleanupLibResolutionWatching(newProgram);
124808
124955
  newProgram == null ? void 0 : newProgram.getSourceFiles().forEach((newFile) => {
124809
124956
  var _a;
124810
- const expected = isExternalOrCommonJsModule(newFile) ? ((_a = newFile.packageJsonLocations) == null ? void 0 : _a.length) ?? 0 : 0;
124957
+ const expected = ((_a = newFile.packageJsonLocations) == null ? void 0 : _a.length) ?? 0;
124811
124958
  const existing = impliedFormatPackageJsons.get(newFile.resolvedPath) ?? emptyArray;
124812
124959
  for (let i = existing.length; i < expected; i++) {
124813
124960
  createFileWatcherOfAffectingLocation(
@@ -125699,10 +125846,10 @@ function explainFiles(program, write) {
125699
125846
  for (const file of program.getSourceFiles()) {
125700
125847
  write(`${toFileName(file, relativeFileName)}`);
125701
125848
  (_a = reasons.get(file.path)) == null ? void 0 : _a.forEach((reason) => write(` ${fileIncludeReasonToDiagnostics(program, reason, relativeFileName).messageText}`));
125702
- (_b = explainIfFileIsRedirectAndImpliedFormat(file, relativeFileName)) == null ? void 0 : _b.forEach((d) => write(` ${d.messageText}`));
125849
+ (_b = explainIfFileIsRedirectAndImpliedFormat(file, program.getCompilerOptionsForFile(file), relativeFileName)) == null ? void 0 : _b.forEach((d) => write(` ${d.messageText}`));
125703
125850
  }
125704
125851
  }
125705
- function explainIfFileIsRedirectAndImpliedFormat(file, fileNameConvertor) {
125852
+ function explainIfFileIsRedirectAndImpliedFormat(file, options, fileNameConvertor) {
125706
125853
  var _a;
125707
125854
  let result;
125708
125855
  if (file.path !== file.resolvedPath) {
@@ -125722,7 +125869,7 @@ function explainIfFileIsRedirectAndImpliedFormat(file, fileNameConvertor) {
125722
125869
  ));
125723
125870
  }
125724
125871
  if (isExternalOrCommonJsModule(file)) {
125725
- switch (file.impliedNodeFormat) {
125872
+ switch (getImpliedNodeFormatForEmitWorker(file, options)) {
125726
125873
  case 99 /* ESNext */:
125727
125874
  if (file.packageJsonScope) {
125728
125875
  (result ?? (result = [])).push(chainDiagnosticMessages(