@typescript-deploys/pr-build 5.6.0-pr-59285-2 → 5.6.0-pr-59352-2

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-insiders.20240715`;
21
+ var version = `${versionMajorMinor}.0-insiders.20240719`;
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
  }
@@ -14460,7 +14499,7 @@ function isInExpressionContext(node) {
14460
14499
  case 233 /* ExpressionWithTypeArguments */:
14461
14500
  return parent.expression === node && !isPartOfTypeNode(parent);
14462
14501
  case 304 /* ShorthandPropertyAssignment */:
14463
- return (parent.objectAssignmentInitializer ?? parent.name) === node;
14502
+ return parent.objectAssignmentInitializer === node;
14464
14503
  case 238 /* SatisfiesExpression */:
14465
14504
  return node === parent.expression;
14466
14505
  default:
@@ -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) {
@@ -67751,6 +67796,9 @@ function createTypeChecker(host) {
67751
67796
  function recombineUnknownType(type) {
67752
67797
  return type === unknownUnionType ? unknownType : type;
67753
67798
  }
67799
+ function getUnknownIfMaybeUnknown(type) {
67800
+ return strictNullChecks && type.flags & 465829888 /* Instantiable */ ? getBaseConstraintOfType(type) || unknownType : type;
67801
+ }
67754
67802
  function getTypeWithDefault(type, defaultExpression) {
67755
67803
  return defaultExpression ? getUnionType([getNonUndefinedType(type), getTypeOfExpression(defaultExpression)]) : type;
67756
67804
  }
@@ -69583,7 +69631,7 @@ function createTypeChecker(host) {
69583
69631
  if (!canCollectSymbolAliasAccessabilityData) {
69584
69632
  return;
69585
69633
  }
69586
- if (location.flags & 33554432 /* Ambient */) {
69634
+ if (location.flags & 33554432 /* Ambient */ && !isPropertySignature(location) && !isPropertyDeclaration(location)) {
69587
69635
  return;
69588
69636
  }
69589
69637
  switch (hint) {
@@ -72574,7 +72622,7 @@ function createTypeChecker(host) {
72574
72622
  checkGrammarJsxElement(node);
72575
72623
  }
72576
72624
  checkJsxPreconditions(node);
72577
- markLinkedReferences(node, 4 /* Jsx */);
72625
+ markJsxAliasReferenced(node);
72578
72626
  if (isNodeOpeningLikeElement) {
72579
72627
  const jsxOpeningLikeNode = node;
72580
72628
  const sig = getResolvedSignature(jsxOpeningLikeNode);
@@ -75505,7 +75553,7 @@ function createTypeChecker(host) {
75505
75553
  return createAnonymousType(anonymousSymbol, memberTable, emptyArray, emptyArray, emptyArray);
75506
75554
  }
75507
75555
  function getTypeWithSyntheticDefaultOnly(type, symbol, originalSymbol, moduleSpecifier) {
75508
- const hasDefaultOnly = isOnlyImportedAsDefault(moduleSpecifier);
75556
+ const hasDefaultOnly = isOnlyImportableAsDefault(moduleSpecifier);
75509
75557
  if (hasDefaultOnly && type && !isErrorType(type)) {
75510
75558
  const synthType = type;
75511
75559
  if (!synthType.defaultOnlyType) {
@@ -75831,14 +75879,45 @@ function createTypeChecker(host) {
75831
75879
  !!declaration && (hasInitializer(declaration) || isOptionalDeclaration(declaration))
75832
75880
  );
75833
75881
  }
75834
- function getTupleElementLabel(d, index, restParameterName = "arg") {
75882
+ function getTupleElementLabelFromBindingElement(node, index, elementFlags) {
75883
+ switch (node.name.kind) {
75884
+ case 80 /* Identifier */: {
75885
+ const name = node.name.escapedText;
75886
+ if (node.dotDotDotToken) {
75887
+ return elementFlags & 12 /* Variable */ ? name : `${name}_${index}`;
75888
+ } else {
75889
+ return elementFlags & 3 /* Fixed */ ? name : `${name}_n`;
75890
+ }
75891
+ }
75892
+ case 207 /* ArrayBindingPattern */: {
75893
+ if (node.dotDotDotToken) {
75894
+ const elements = node.name.elements;
75895
+ const lastElement = tryCast(lastOrUndefined(elements), isBindingElement);
75896
+ const elementCount = elements.length - ((lastElement == null ? void 0 : lastElement.dotDotDotToken) ? 1 : 0);
75897
+ if (index < elementCount) {
75898
+ const element = elements[index];
75899
+ if (isBindingElement(element)) {
75900
+ return getTupleElementLabelFromBindingElement(element, index, elementFlags);
75901
+ }
75902
+ } else if (lastElement == null ? void 0 : lastElement.dotDotDotToken) {
75903
+ return getTupleElementLabelFromBindingElement(lastElement, index - elementCount, elementFlags);
75904
+ }
75905
+ }
75906
+ break;
75907
+ }
75908
+ }
75909
+ return `arg_${index}`;
75910
+ }
75911
+ function getTupleElementLabel(d, index = 0, elementFlags = 3 /* Fixed */, restSymbol) {
75835
75912
  if (!d) {
75836
- return `${restParameterName}_${index}`;
75913
+ const restParameter = tryCast(restSymbol == null ? void 0 : restSymbol.valueDeclaration, isParameter);
75914
+ return restParameter ? getTupleElementLabelFromBindingElement(restParameter, index, elementFlags) : `${(restSymbol == null ? void 0 : restSymbol.escapedName) ?? "arg"}_${index}`;
75837
75915
  }
75838
75916
  Debug.assert(isIdentifier(d.name));
75839
75917
  return d.name.escapedText;
75840
75918
  }
75841
75919
  function getParameterNameAtPosition(signature, pos, overrideRestType) {
75920
+ var _a;
75842
75921
  const paramCount = signature.parameters.length - (signatureHasRestParameter(signature) ? 1 : 0);
75843
75922
  if (pos < paramCount) {
75844
75923
  return signature.parameters[pos].escapedName;
@@ -75846,9 +75925,11 @@ function createTypeChecker(host) {
75846
75925
  const restParameter = signature.parameters[paramCount] || unknownSymbol;
75847
75926
  const restType = overrideRestType || getTypeOfSymbol(restParameter);
75848
75927
  if (isTupleType(restType)) {
75849
- const associatedNames = restType.target.labeledElementDeclarations;
75928
+ const tupleType = restType.target;
75850
75929
  const index = pos - paramCount;
75851
- return getTupleElementLabel(associatedNames == null ? void 0 : associatedNames[index], index, restParameter.escapedName);
75930
+ const associatedName = (_a = tupleType.labeledElementDeclarations) == null ? void 0 : _a[index];
75931
+ const elementFlags = tupleType.elementFlags[index];
75932
+ return getTupleElementLabel(associatedName, index, elementFlags, restParameter);
75852
75933
  }
75853
75934
  return restParameter.escapedName;
75854
75935
  }
@@ -77786,8 +77867,8 @@ function createTypeChecker(host) {
77786
77867
  case 33 /* LessThanEqualsToken */:
77787
77868
  case 34 /* GreaterThanEqualsToken */:
77788
77869
  if (checkForDisallowedESSymbolOperand(operator)) {
77789
- leftType = getBaseTypeOfLiteralTypeForComparison(checkNonNullType(leftType, left));
77790
- rightType = getBaseTypeOfLiteralTypeForComparison(checkNonNullType(rightType, right));
77870
+ leftType = getBaseTypeOfLiteralTypeForComparison(checkNonNullType(getUnknownIfMaybeUnknown(leftType), left));
77871
+ rightType = getBaseTypeOfLiteralTypeForComparison(checkNonNullType(getUnknownIfMaybeUnknown(rightType), right));
77791
77872
  reportOperatorErrorUnless((left2, right2) => {
77792
77873
  if (isTypeAny(left2) || isTypeAny(right2)) {
77793
77874
  return true;
@@ -80779,7 +80860,7 @@ function createTypeChecker(host) {
80779
80860
  });
80780
80861
  }
80781
80862
  function checkCollisionWithRequireExportsInGeneratedCode(node, name) {
80782
- if (moduleKind >= 5 /* ES2015 */ && !(moduleKind >= 100 /* Node16 */ && getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) {
80863
+ if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) >= 5 /* ES2015 */) {
80783
80864
  return;
80784
80865
  }
80785
80866
  if (!name || !needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) {
@@ -82200,7 +82281,7 @@ function createTypeChecker(host) {
82200
82281
  }
82201
82282
  }
82202
82283
  function checkClassNameCollisionWithObject(name) {
82203
- if (languageVersion >= 1 /* ES5 */ && name.escapedText === "Object" && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(name).impliedNodeFormat === 1 /* CommonJS */)) {
82284
+ if (languageVersion >= 1 /* ES5 */ && name.escapedText === "Object" && host.getEmitModuleFormatOfFile(getSourceFileOfNode(name)) < 5 /* ES2015 */) {
82204
82285
  error(name, Diagnostics.Class_name_cannot_be_Object_when_targeting_ES5_with_module_0, ModuleKind[moduleKind]);
82205
82286
  }
82206
82287
  }
@@ -83280,7 +83361,7 @@ function createTypeChecker(host) {
83280
83361
  getNodeLinks(node).flags |= 2048 /* LexicalModuleMergesWithClass */;
83281
83362
  }
83282
83363
  }
83283
- if (compilerOptions.verbatimModuleSyntax && node.parent.kind === 307 /* SourceFile */ && (moduleKind === 1 /* CommonJS */ || node.parent.impliedNodeFormat === 1 /* CommonJS */)) {
83364
+ if (compilerOptions.verbatimModuleSyntax && node.parent.kind === 307 /* SourceFile */ && host.getEmitModuleFormatOfFile(node.parent) === 1 /* CommonJS */) {
83284
83365
  const exportModifier = (_b = node.modifiers) == null ? void 0 : _b.find((m) => m.kind === 95 /* ExportKeyword */);
83285
83366
  if (exportModifier) {
83286
83367
  error(exportModifier, Diagnostics.A_top_level_export_modifier_cannot_be_used_on_value_declarations_in_a_CommonJS_module_when_verbatimModuleSyntax_is_enabled);
@@ -83500,8 +83581,10 @@ function createTypeChecker(host) {
83500
83581
  }
83501
83582
  }
83502
83583
  }
83503
- if (compilerOptions.verbatimModuleSyntax && node.kind !== 271 /* ImportEqualsDeclaration */ && !isInJSFile(node) && (moduleKind === 1 /* CommonJS */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) {
83584
+ if (compilerOptions.verbatimModuleSyntax && node.kind !== 271 /* ImportEqualsDeclaration */ && !isInJSFile(node) && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === 1 /* CommonJS */) {
83504
83585
  error(node, Diagnostics.ESM_syntax_is_not_allowed_in_a_CommonJS_module_when_verbatimModuleSyntax_is_enabled);
83586
+ } else if (moduleKind === 200 /* Preserve */ && node.kind !== 271 /* ImportEqualsDeclaration */ && node.kind !== 260 /* VariableDeclaration */ && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === 1 /* CommonJS */) {
83587
+ error(node, Diagnostics.ESM_syntax_is_not_allowed_in_a_CommonJS_module_when_module_is_set_to_preserve);
83505
83588
  }
83506
83589
  }
83507
83590
  if (isImportSpecifier(node)) {
@@ -83542,7 +83625,7 @@ function createTypeChecker(host) {
83542
83625
  checkAliasSymbol(node);
83543
83626
  if (node.kind === 276 /* ImportSpecifier */) {
83544
83627
  checkModuleExportName(node.propertyName);
83545
- if (moduleExportNameIsDefault(node.propertyName || node.name) && getESModuleInterop(compilerOptions) && moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) {
83628
+ if (moduleExportNameIsDefault(node.propertyName || node.name) && getESModuleInterop(compilerOptions) && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */) {
83546
83629
  checkExternalEmitHelpers(node, 131072 /* ImportDefault */);
83547
83630
  }
83548
83631
  }
@@ -83564,7 +83647,7 @@ function createTypeChecker(host) {
83564
83647
  if (validForTypeAttributes && override) {
83565
83648
  return;
83566
83649
  }
83567
- const mode = moduleKind === 199 /* NodeNext */ && declaration.moduleSpecifier && getUsageModeForExpression(declaration.moduleSpecifier);
83650
+ const mode = moduleKind === 199 /* NodeNext */ && declaration.moduleSpecifier && getEmitSyntaxForModuleSpecifierExpression(declaration.moduleSpecifier);
83568
83651
  if (mode !== 99 /* ESNext */ && moduleKind !== 99 /* ESNext */ && moduleKind !== 200 /* Preserve */) {
83569
83652
  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
83653
  return grammarErrorOnNode(node, message);
@@ -83597,7 +83680,7 @@ function createTypeChecker(host) {
83597
83680
  if (importClause.namedBindings) {
83598
83681
  if (importClause.namedBindings.kind === 274 /* NamespaceImport */) {
83599
83682
  checkImportBinding(importClause.namedBindings);
83600
- if (moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */) && getESModuleInterop(compilerOptions)) {
83683
+ if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */ && getESModuleInterop(compilerOptions)) {
83601
83684
  checkExternalEmitHelpers(node, 65536 /* ImportStar */);
83602
83685
  }
83603
83686
  } else {
@@ -83637,7 +83720,7 @@ function createTypeChecker(host) {
83637
83720
  grammarErrorOnNode(node, Diagnostics.An_import_alias_cannot_use_import_type);
83638
83721
  }
83639
83722
  } else {
83640
- if (moduleKind >= 5 /* ES2015 */ && moduleKind !== 200 /* Preserve */ && getSourceFileOfNode(node).impliedNodeFormat === void 0 && !node.isTypeOnly && !(node.flags & 33554432 /* Ambient */)) {
83723
+ if (5 /* ES2015 */ <= moduleKind && moduleKind <= 99 /* ESNext */ && !node.isTypeOnly && !(node.flags & 33554432 /* Ambient */)) {
83641
83724
  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
83725
  }
83643
83726
  }
@@ -83667,7 +83750,7 @@ function createTypeChecker(host) {
83667
83750
  checkAliasSymbol(node.exportClause);
83668
83751
  checkModuleExportName(node.exportClause.name);
83669
83752
  }
83670
- if (moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) {
83753
+ if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */) {
83671
83754
  if (node.exportClause) {
83672
83755
  if (getESModuleInterop(compilerOptions)) {
83673
83756
  checkExternalEmitHelpers(node, 65536 /* ImportStar */);
@@ -83726,7 +83809,7 @@ function createTypeChecker(host) {
83726
83809
  markLinkedReferences(node, 7 /* ExportSpecifier */);
83727
83810
  }
83728
83811
  } else {
83729
- if (getESModuleInterop(compilerOptions) && moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */) && moduleExportNameIsDefault(node.propertyName || node.name)) {
83812
+ if (getESModuleInterop(compilerOptions) && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */ && moduleExportNameIsDefault(node.propertyName || node.name)) {
83730
83813
  checkExternalEmitHelpers(node, 131072 /* ImportDefault */);
83731
83814
  }
83732
83815
  }
@@ -83752,7 +83835,7 @@ function createTypeChecker(host) {
83752
83835
  if (typeAnnotationNode) {
83753
83836
  checkTypeAssignableTo(checkExpressionCached(node.expression), getTypeFromTypeNode(typeAnnotationNode), node.expression);
83754
83837
  }
83755
- const isIllegalExportDefaultInCJS = !node.isExportEquals && !(node.flags & 33554432 /* Ambient */) && compilerOptions.verbatimModuleSyntax && (moduleKind === 1 /* CommonJS */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */);
83838
+ const isIllegalExportDefaultInCJS = !node.isExportEquals && !(node.flags & 33554432 /* Ambient */) && compilerOptions.verbatimModuleSyntax && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === 1 /* CommonJS */;
83756
83839
  if (node.expression.kind === 80 /* Identifier */) {
83757
83840
  const id = node.expression;
83758
83841
  const sym = getExportSymbolOfValueSymbolIfExported(resolveEntityName(
@@ -83832,7 +83915,7 @@ function createTypeChecker(host) {
83832
83915
  grammarErrorOnNode(node.expression, Diagnostics.The_expression_of_an_export_assignment_must_be_an_identifier_or_qualified_name_in_an_ambient_context);
83833
83916
  }
83834
83917
  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 */)) {
83918
+ 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
83919
  grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_export_default_or_another_module_format_instead);
83837
83920
  } else if (moduleKind === 4 /* System */ && !(node.flags & 33554432 /* Ambient */)) {
83838
83921
  grammarErrorOnNode(node, Diagnostics.Export_assignment_is_not_supported_when_module_flag_is_system);
@@ -85423,10 +85506,13 @@ function createTypeChecker(host) {
85423
85506
  function checkChildIdentifiers(node2) {
85424
85507
  forEachNodeRecursively(node2, checkIdentifiers);
85425
85508
  }
85509
+ function isExpressionNodeOrShorthandPropertyAssignmentName(node2) {
85510
+ return isExpressionNode(node2) || isShorthandPropertyAssignment(node2.parent) && (node2.parent.objectAssignmentInitializer ?? node2.parent.name) === node2;
85511
+ }
85426
85512
  function checkSingleIdentifier(node2) {
85427
85513
  const nodeLinks2 = getNodeLinks(node2);
85428
85514
  nodeLinks2.calculatedFlags |= 536870912 /* ConstructorReference */ | 16384 /* CapturedBlockScopedBinding */ | 32768 /* BlockScopedBindingInLoop */;
85429
- if (isIdentifier(node2) && isExpressionNode(node2) && !(isPropertyAccessExpression(node2.parent) && node2.parent.name === node2)) {
85515
+ if (isIdentifier(node2) && isExpressionNodeOrShorthandPropertyAssignmentName(node2) && !(isPropertyAccessExpression(node2.parent) && node2.parent.name === node2)) {
85430
85516
  const s = getResolvedSymbol(node2);
85431
85517
  if (s && s !== unknownSymbol) {
85432
85518
  checkIdentifierCalculateNodeCheckFlags(node2, s);
@@ -86374,7 +86460,7 @@ function createTypeChecker(host) {
86374
86460
  break;
86375
86461
  case 95 /* ExportKeyword */:
86376
86462
  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
86377
- node.kind !== 267 /* ModuleDeclaration */ && node.parent.kind === 307 /* SourceFile */ && (moduleKind === 1 /* CommonJS */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) {
86463
+ node.kind !== 267 /* ModuleDeclaration */ && node.parent.kind === 307 /* SourceFile */ && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === 1 /* CommonJS */) {
86378
86464
  return grammarErrorOnNode(modifier, Diagnostics.A_top_level_export_modifier_cannot_be_used_on_value_declarations_in_a_CommonJS_module_when_verbatimModuleSyntax_is_enabled);
86379
86465
  }
86380
86466
  if (flags & 32 /* Export */) {
@@ -87284,7 +87370,7 @@ function createTypeChecker(host) {
87284
87370
  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;
87285
87371
  return grammarErrorOnNode(node.exclamationToken, message);
87286
87372
  }
87287
- if ((moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */) && moduleKind !== 4 /* System */ && !(node.parent.parent.flags & 33554432 /* Ambient */) && hasSyntacticModifier(node.parent.parent, 32 /* Export */)) {
87373
+ if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */ && !(node.parent.parent.flags & 33554432 /* Ambient */) && hasSyntacticModifier(node.parent.parent, 32 /* Export */)) {
87288
87374
  checkESModuleMarker(node.name);
87289
87375
  }
87290
87376
  return !!blockScopeKind && checkGrammarNameInLetOrConstDeclarations(node.name);
@@ -87785,7 +87871,9 @@ function createBasicNodeBuilderModuleSpecifierResolutionHost(host) {
87785
87871
  isSourceOfProjectReferenceRedirect: (fileName) => host.isSourceOfProjectReferenceRedirect(fileName),
87786
87872
  fileExists: (fileName) => host.fileExists(fileName),
87787
87873
  getFileIncludeReasons: () => host.getFileIncludeReasons(),
87788
- readFile: host.readFile ? (fileName) => host.readFile(fileName) : void 0
87874
+ readFile: host.readFile ? (fileName) => host.readFile(fileName) : void 0,
87875
+ getDefaultResolutionModeForFile: (file) => host.getDefaultResolutionModeForFile(file),
87876
+ getModeForResolutionAtIndex: (file, index) => host.getModeForResolutionAtIndex(file, index)
87789
87877
  };
87790
87878
  }
87791
87879
  var SymbolTrackerImpl = class _SymbolTrackerImpl {
@@ -107456,7 +107544,7 @@ function transformModule(context) {
107456
107544
  case 354 /* PartiallyEmittedExpression */:
107457
107545
  return visitPartiallyEmittedExpression(node, valueIsDiscarded);
107458
107546
  case 213 /* CallExpression */:
107459
- if (isImportCall(node) && currentSourceFile.impliedNodeFormat === void 0) {
107547
+ if (isImportCall(node) && host.shouldTransformImportCall(currentSourceFile)) {
107460
107548
  return visitImportCallExpression(node);
107461
107549
  }
107462
107550
  break;
@@ -110452,8 +110540,8 @@ function transformECMAScriptModule(context) {
110452
110540
  }
110453
110541
  }
110454
110542
 
110455
- // src/compiler/transformers/module/node.ts
110456
- function transformNodeModule(context) {
110543
+ // src/compiler/transformers/module/impliedNodeFormatDependent.ts
110544
+ function transformImpliedNodeFormatDependentModule(context) {
110457
110545
  const previousOnSubstituteNode = context.onSubstituteNode;
110458
110546
  const previousOnEmitNode = context.onEmitNode;
110459
110547
  const esmTransform = transformECMAScriptModule(context);
@@ -110464,6 +110552,7 @@ function transformNodeModule(context) {
110464
110552
  const cjsTransform = transformModule(context);
110465
110553
  const cjsOnSubstituteNode = context.onSubstituteNode;
110466
110554
  const cjsOnEmitNode = context.onEmitNode;
110555
+ const getEmitModuleFormatOfFile = (file) => context.getEmitHost().getEmitModuleFormatOfFile(file);
110467
110556
  context.onSubstituteNode = onSubstituteNode;
110468
110557
  context.onEmitNode = onEmitNode;
110469
110558
  context.enableSubstitution(307 /* SourceFile */);
@@ -110478,7 +110567,7 @@ function transformNodeModule(context) {
110478
110567
  if (!currentSourceFile) {
110479
110568
  return previousOnSubstituteNode(hint, node);
110480
110569
  }
110481
- if (currentSourceFile.impliedNodeFormat === 99 /* ESNext */) {
110570
+ if (getEmitModuleFormatOfFile(currentSourceFile) >= 5 /* ES2015 */) {
110482
110571
  return esmOnSubstituteNode(hint, node);
110483
110572
  }
110484
110573
  return cjsOnSubstituteNode(hint, node);
@@ -110491,13 +110580,13 @@ function transformNodeModule(context) {
110491
110580
  if (!currentSourceFile) {
110492
110581
  return previousOnEmitNode(hint, node, emitCallback);
110493
110582
  }
110494
- if (currentSourceFile.impliedNodeFormat === 99 /* ESNext */) {
110583
+ if (getEmitModuleFormatOfFile(currentSourceFile) >= 5 /* ES2015 */) {
110495
110584
  return esmOnEmitNode(hint, node, emitCallback);
110496
110585
  }
110497
110586
  return cjsOnEmitNode(hint, node, emitCallback);
110498
110587
  }
110499
110588
  function getModuleTransformForFile(file) {
110500
- return file.impliedNodeFormat === 99 /* ESNext */ ? esmTransform : cjsTransform;
110589
+ return getEmitModuleFormatOfFile(file) >= 5 /* ES2015 */ ? esmTransform : cjsTransform;
110501
110590
  }
110502
110591
  function transformSourceFile(node) {
110503
110592
  if (node.isDeclarationFile) {
@@ -112622,17 +112711,18 @@ function isProcessedComponent(node) {
112622
112711
  // src/compiler/transformer.ts
112623
112712
  function getModuleTransformer(moduleKind) {
112624
112713
  switch (moduleKind) {
112714
+ case 200 /* Preserve */:
112715
+ return transformECMAScriptModule;
112625
112716
  case 99 /* ESNext */:
112626
112717
  case 7 /* ES2022 */:
112627
112718
  case 6 /* ES2020 */:
112628
112719
  case 5 /* ES2015 */:
112629
- case 200 /* Preserve */:
112630
- return transformECMAScriptModule;
112631
- case 4 /* System */:
112632
- return transformSystemModule;
112633
112720
  case 100 /* Node16 */:
112634
112721
  case 199 /* NodeNext */:
112635
- return transformNodeModule;
112722
+ case 1 /* CommonJS */:
112723
+ return transformImpliedNodeFormatDependentModule;
112724
+ case 4 /* System */:
112725
+ return transformSystemModule;
112636
112726
  default:
112637
112727
  return transformModule;
112638
112728
  }
@@ -113349,6 +113439,7 @@ function emitFiles(resolver, host, targetSourceFile, { scriptTransformers, decla
113349
113439
  newLine: compilerOptions.newLine,
113350
113440
  noEmitHelpers: compilerOptions.noEmitHelpers,
113351
113441
  module: getEmitModuleKind(compilerOptions),
113442
+ moduleResolution: getEmitModuleResolutionKind(compilerOptions),
113352
113443
  target: getEmitScriptTarget(compilerOptions),
113353
113444
  sourceMap: compilerOptions.sourceMap,
113354
113445
  inlineSourceMap: compilerOptions.inlineSourceMap,
@@ -113411,8 +113502,9 @@ function emitFiles(resolver, host, targetSourceFile, { scriptTransformers, decla
113411
113502
  newLine: compilerOptions.newLine,
113412
113503
  noEmitHelpers: true,
113413
113504
  module: compilerOptions.module,
113505
+ moduleResolution: compilerOptions.moduleResolution,
113414
113506
  target: compilerOptions.target,
113415
- sourceMap: !forceDtsEmit && compilerOptions.declarationMap,
113507
+ sourceMap: emitOnly !== 2 /* BuilderSignature */ && compilerOptions.declarationMap,
113416
113508
  inlineSourceMap: compilerOptions.inlineSourceMap,
113417
113509
  extendedDiagnostics: compilerOptions.extendedDiagnostics,
113418
113510
  onlyPrintJsDocStyle: true,
@@ -118873,9 +118965,6 @@ function flattenDiagnosticMessageText(diag2, newLine, indent2 = 0) {
118873
118965
  function getModeForFileReference(ref, containingFileMode) {
118874
118966
  return (isString(ref) ? containingFileMode : ref.resolutionMode) || containingFileMode;
118875
118967
  }
118876
- function getModeForResolutionAtIndex(file, index, compilerOptions) {
118877
- return getModeForUsageLocationWorker(file, getModuleNameStringLiteralAt(file, index), compilerOptions);
118878
- }
118879
118968
  function isExclusivelyTypeOnlyImportOrExport(decl) {
118880
118969
  var _a;
118881
118970
  if (isExportDeclaration(decl)) {
@@ -118890,7 +118979,6 @@ function getModeForUsageLocation(file, usage, compilerOptions) {
118890
118979
  return getModeForUsageLocationWorker(file, usage, compilerOptions);
118891
118980
  }
118892
118981
  function getModeForUsageLocationWorker(file, usage, compilerOptions) {
118893
- var _a;
118894
118982
  if (isImportDeclaration(usage.parent) || isExportDeclaration(usage.parent) || isJSDocImportTag(usage.parent)) {
118895
118983
  const isTypeOnly = isExclusivelyTypeOnlyImportOrExport(usage.parent);
118896
118984
  if (isTypeOnly) {
@@ -118906,19 +118994,28 @@ function getModeForUsageLocationWorker(file, usage, compilerOptions) {
118906
118994
  return override;
118907
118995
  }
118908
118996
  }
118909
- if (compilerOptions && getEmitModuleKind(compilerOptions) === 200 /* Preserve */) {
118910
- return usage.parent.parent && isImportEqualsDeclaration(usage.parent.parent) || isRequireCall(
118911
- usage.parent,
118912
- /*requireStringLiteralLikeArgument*/
118913
- false
118914
- ) ? 1 /* CommonJS */ : 99 /* ESNext */;
118997
+ if (compilerOptions && importSyntaxAffectsModuleResolution(compilerOptions)) {
118998
+ return getEmitSyntaxForUsageLocationWorker(file, usage, compilerOptions);
118915
118999
  }
118916
- if (file.impliedNodeFormat === void 0) return void 0;
118917
- if (file.impliedNodeFormat !== 99 /* ESNext */) {
118918
- return isImportCall(walkUpParenthesizedExpressions(usage.parent)) ? 99 /* ESNext */ : 1 /* CommonJS */;
119000
+ }
119001
+ function getEmitSyntaxForUsageLocationWorker(file, usage, compilerOptions) {
119002
+ var _a;
119003
+ if (!compilerOptions) {
119004
+ return void 0;
118919
119005
  }
118920
119006
  const exprParentParent = (_a = walkUpParenthesizedExpressions(usage.parent)) == null ? void 0 : _a.parent;
118921
- return exprParentParent && isImportEqualsDeclaration(exprParentParent) ? 1 /* CommonJS */ : 99 /* ESNext */;
119007
+ if (exprParentParent && isImportEqualsDeclaration(exprParentParent) || isRequireCall(
119008
+ usage.parent,
119009
+ /*requireStringLiteralLikeArgument*/
119010
+ false
119011
+ )) {
119012
+ return 1 /* CommonJS */;
119013
+ }
119014
+ if (isImportCall(walkUpParenthesizedExpressions(usage.parent))) {
119015
+ return shouldTransformImportCallWorker(file, compilerOptions) ? 1 /* CommonJS */ : 99 /* ESNext */;
119016
+ }
119017
+ const fileEmitMode = getEmitModuleFormatOfFileWorker(file, compilerOptions);
119018
+ return fileEmitMode === 1 /* CommonJS */ ? 1 /* CommonJS */ : emitModuleKindIsNonNodeESM(fileEmitMode) || fileEmitMode === 200 /* Preserve */ ? 99 /* ESNext */ : void 0;
118922
119019
  }
118923
119020
  function getResolutionModeOverride(node, grammarErrorOnNode) {
118924
119021
  if (!node) return void 0;
@@ -118975,7 +119072,7 @@ function getTypeReferenceResolutionName(entry) {
118975
119072
  }
118976
119073
  var typeReferenceResolutionNameAndModeGetter = {
118977
119074
  getName: getTypeReferenceResolutionName,
118978
- getMode: (entry, file) => getModeForFileReference(entry, file == null ? void 0 : file.impliedNodeFormat)
119075
+ getMode: (entry, file, compilerOptions) => getModeForFileReference(entry, file && getDefaultResolutionModeForFileWorker(file, compilerOptions))
118979
119076
  };
118980
119077
  function createTypeReferenceResolutionLoader(containingFile, redirectedReference, options, host, cache) {
118981
119078
  return {
@@ -119157,7 +119254,7 @@ function getImpliedNodeFormatForFileWorker(fileName, packageJsonInfoCache, host,
119157
119254
  const packageJsonLocations = [];
119158
119255
  state.failedLookupLocations = packageJsonLocations;
119159
119256
  state.affectingLocations = packageJsonLocations;
119160
- const packageJsonScope = getPackageScopeForPath(fileName, state);
119257
+ const packageJsonScope = getPackageScopeForPath(getDirectoryPath(fileName), state);
119161
119258
  const impliedNodeFormat = (packageJsonScope == null ? void 0 : packageJsonScope.contents.packageJsonContent.type) === "module" ? 99 /* ESNext */ : 1 /* CommonJS */;
119162
119259
  return { impliedNodeFormat, packageJsonLocations, packageJsonScope };
119163
119260
  }
@@ -119611,7 +119708,8 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
119611
119708
  isSourceFileFromExternalLibrary,
119612
119709
  isSourceFileDefaultLibrary,
119613
119710
  getModeForUsageLocation: getModeForUsageLocation2,
119614
- getModeForResolutionAtIndex: getModeForResolutionAtIndex2,
119711
+ getEmitSyntaxForUsageLocation,
119712
+ getModeForResolutionAtIndex,
119615
119713
  getSourceFileFromReference,
119616
119714
  getLibFileFromReference,
119617
119715
  sourceFileToPackageName,
@@ -119639,6 +119737,11 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
119639
119737
  forEachResolvedProjectReference: forEachResolvedProjectReference2,
119640
119738
  isSourceOfProjectReferenceRedirect,
119641
119739
  getRedirectReferenceForResolutionFromSourceOfProject,
119740
+ getCompilerOptionsForFile,
119741
+ getDefaultResolutionModeForFile: getDefaultResolutionModeForFile2,
119742
+ getEmitModuleFormatOfFile,
119743
+ getImpliedNodeFormatForEmit,
119744
+ shouldTransformImportCall,
119642
119745
  emitBuildInfo,
119643
119746
  fileExists,
119644
119747
  readFile,
@@ -120193,6 +120296,10 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
120193
120296
  getSymlinkCache,
120194
120297
  writeFile: writeFileCallback || writeFile2,
120195
120298
  isEmitBlocked,
120299
+ shouldTransformImportCall,
120300
+ getEmitModuleFormatOfFile,
120301
+ getDefaultResolutionModeForFile: getDefaultResolutionModeForFile2,
120302
+ getModeForResolutionAtIndex,
120196
120303
  readFile: (f) => host.readFile(f),
120197
120304
  fileExists: (f) => {
120198
120305
  const path = toPath3(f);
@@ -121272,10 +121379,14 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
121272
121379
  const resolvedTypeReferenceDirective = resolutions[index];
121273
121380
  const fileName = ref.fileName;
121274
121381
  resolutionsInFile.set(fileName, getModeForFileReference(ref, file.impliedNodeFormat), resolvedTypeReferenceDirective);
121275
- const mode = ref.resolutionMode || file.impliedNodeFormat;
121382
+ const mode = ref.resolutionMode || getDefaultResolutionModeForFile2(file);
121276
121383
  processTypeReferenceDirective(fileName, mode, resolvedTypeReferenceDirective, { kind: 5 /* TypeReferenceDirective */, file: file.path, index });
121277
121384
  }
121278
121385
  }
121386
+ function getCompilerOptionsForFile(file) {
121387
+ var _a2;
121388
+ return ((_a2 = getRedirectReferenceForResolution(file)) == null ? void 0 : _a2.commandLine.options) || options;
121389
+ }
121279
121390
  function processTypeReferenceDirective(typeReferenceDirective, mode, resolution, reason) {
121280
121391
  var _a2, _b2;
121281
121392
  (_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 });
@@ -121376,13 +121487,12 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
121376
121487
  return host.getCanonicalFileName(fileName);
121377
121488
  }
121378
121489
  function processImportedModules(file) {
121379
- var _a2;
121380
121490
  collectExternalModuleReferences(file);
121381
121491
  if (file.imports.length || file.moduleAugmentations.length) {
121382
121492
  const moduleNames = getModuleNames(file);
121383
121493
  const resolutions = (resolvedModulesProcessing == null ? void 0 : resolvedModulesProcessing.get(file.path)) || resolveModuleNamesReusingOldState(moduleNames, file);
121384
121494
  Debug.assert(resolutions.length === moduleNames.length);
121385
- const optionsForFile = ((_a2 = getRedirectReferenceForResolution(file)) == null ? void 0 : _a2.commandLine.options) || options;
121495
+ const optionsForFile = getCompilerOptionsForFile(file);
121386
121496
  const resolutionsInFile = createModeAwareCache();
121387
121497
  (resolvedModules ?? (resolvedModules = /* @__PURE__ */ new Map())).set(file.path, resolutionsInFile);
121388
121498
  for (let index = 0; index < moduleNames.length; index++) {
@@ -121931,7 +122041,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
121931
122041
  redirectInfo = cachedChain.redirectInfo;
121932
122042
  } else {
121933
122043
  reasons == null ? void 0 : reasons.forEach(processReason);
121934
- redirectInfo = file && explainIfFileIsRedirectAndImpliedFormat(file);
122044
+ redirectInfo = file && explainIfFileIsRedirectAndImpliedFormat(file, getCompilerOptionsForFile(file));
121935
122045
  }
121936
122046
  if (fileProcessingReason) processReason(fileProcessingReason);
121937
122047
  const processedExtraReason = (seenReasons == null ? void 0 : seenReasons.size) !== (reasons == null ? void 0 : reasons.length);
@@ -122289,13 +122399,53 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
122289
122399
  return symlinks;
122290
122400
  }
122291
122401
  function getModeForUsageLocation2(file, usage) {
122292
- var _a2;
122293
- const optionsForFile = ((_a2 = getRedirectReferenceForResolution(file)) == null ? void 0 : _a2.commandLine.options) || options;
122294
- return getModeForUsageLocationWorker(file, usage, optionsForFile);
122402
+ return getModeForUsageLocationWorker(file, usage, getCompilerOptionsForFile(file));
122295
122403
  }
122296
- function getModeForResolutionAtIndex2(file, index) {
122404
+ function getEmitSyntaxForUsageLocation(file, usage) {
122405
+ return getEmitSyntaxForUsageLocationWorker(file, usage, getCompilerOptionsForFile(file));
122406
+ }
122407
+ function getModeForResolutionAtIndex(file, index) {
122297
122408
  return getModeForUsageLocation2(file, getModuleNameStringLiteralAt(file, index));
122298
122409
  }
122410
+ function getDefaultResolutionModeForFile2(sourceFile) {
122411
+ return getDefaultResolutionModeForFileWorker(sourceFile, getCompilerOptionsForFile(sourceFile));
122412
+ }
122413
+ function getImpliedNodeFormatForEmit(sourceFile) {
122414
+ return getImpliedNodeFormatForEmitWorker(sourceFile, getCompilerOptionsForFile(sourceFile));
122415
+ }
122416
+ function getEmitModuleFormatOfFile(sourceFile) {
122417
+ return getEmitModuleFormatOfFileWorker(sourceFile, getCompilerOptionsForFile(sourceFile));
122418
+ }
122419
+ function shouldTransformImportCall(sourceFile) {
122420
+ return shouldTransformImportCallWorker(sourceFile, getCompilerOptionsForFile(sourceFile));
122421
+ }
122422
+ }
122423
+ function shouldTransformImportCallWorker(sourceFile, options) {
122424
+ const moduleKind = getEmitModuleKind(options);
122425
+ if (100 /* Node16 */ <= moduleKind && moduleKind <= 199 /* NodeNext */ || moduleKind === 200 /* Preserve */) {
122426
+ return false;
122427
+ }
122428
+ return getEmitModuleFormatOfFileWorker(sourceFile, options) < 5 /* ES2015 */;
122429
+ }
122430
+ function getEmitModuleFormatOfFileWorker(sourceFile, options) {
122431
+ return getImpliedNodeFormatForEmitWorker(sourceFile, options) ?? getEmitModuleKind(options);
122432
+ }
122433
+ function getImpliedNodeFormatForEmitWorker(sourceFile, options) {
122434
+ var _a, _b;
122435
+ const moduleKind = getEmitModuleKind(options);
122436
+ if (100 /* Node16 */ <= moduleKind && moduleKind <= 199 /* NodeNext */) {
122437
+ return sourceFile.impliedNodeFormat;
122438
+ }
122439
+ if (sourceFile.impliedNodeFormat === 1 /* CommonJS */ && (((_a = sourceFile.packageJsonScope) == null ? void 0 : _a.contents.packageJsonContent.type) === "commonjs" || fileExtensionIsOneOf(sourceFile.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */]))) {
122440
+ return 1 /* CommonJS */;
122441
+ }
122442
+ if (sourceFile.impliedNodeFormat === 99 /* ESNext */ && (((_b = sourceFile.packageJsonScope) == null ? void 0 : _b.contents.packageJsonContent.type) === "module" || fileExtensionIsOneOf(sourceFile.fileName, [".mjs" /* Mjs */, ".mts" /* Mts */]))) {
122443
+ return 99 /* ESNext */;
122444
+ }
122445
+ return void 0;
122446
+ }
122447
+ function getDefaultResolutionModeForFileWorker(sourceFile, options) {
122448
+ return importSyntaxAffectsModuleResolution(options) ? getImpliedNodeFormatForEmitWorker(sourceFile, options) : void 0;
122299
122449
  }
122300
122450
  function updateHostForUseSourceOfProjectReferenceRedirect(host) {
122301
122451
  let setOfDeclarationDirectories;
@@ -122750,8 +122900,7 @@ var BuilderState;
122750
122900
  );
122751
122901
  },
122752
122902
  cancellationToken,
122753
- /*emitOnly*/
122754
- true,
122903
+ 2 /* BuilderSignature */,
122755
122904
  /*customTransformers*/
122756
122905
  void 0,
122757
122906
  /*forceDtsEmit*/
@@ -123072,7 +123221,12 @@ function repopulateDiagnostics(diagnostics, newProgram) {
123072
123221
  }
123073
123222
  function convertOrRepopulateDiagnosticMessageChain(chain, sourceFile, newProgram, repopulateInfo) {
123074
123223
  const info = repopulateInfo(chain);
123075
- if (info) {
123224
+ if (info === true) {
123225
+ return {
123226
+ ...createModeMismatchDetails(sourceFile),
123227
+ next: convertOrRepopulateDiagnosticMessageChainArray(chain.next, sourceFile, newProgram, repopulateInfo)
123228
+ };
123229
+ } else if (info) {
123076
123230
  return {
123077
123231
  ...createModuleNotFoundChain(sourceFile, newProgram, info.moduleReference, info.mode, info.packageName || info.moduleReference),
123078
123232
  next: convertOrRepopulateDiagnosticMessageChainArray(chain.next, sourceFile, newProgram, repopulateInfo)
@@ -124803,7 +124957,7 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
124803
124957
  cleanupLibResolutionWatching(newProgram);
124804
124958
  newProgram == null ? void 0 : newProgram.getSourceFiles().forEach((newFile) => {
124805
124959
  var _a;
124806
- const expected = isExternalOrCommonJsModule(newFile) ? ((_a = newFile.packageJsonLocations) == null ? void 0 : _a.length) ?? 0 : 0;
124960
+ const expected = ((_a = newFile.packageJsonLocations) == null ? void 0 : _a.length) ?? 0;
124807
124961
  const existing = impliedFormatPackageJsons.get(newFile.resolvedPath) ?? emptyArray;
124808
124962
  for (let i = existing.length; i < expected; i++) {
124809
124963
  createFileWatcherOfAffectingLocation(
@@ -125695,10 +125849,10 @@ function explainFiles(program, write) {
125695
125849
  for (const file of program.getSourceFiles()) {
125696
125850
  write(`${toFileName(file, relativeFileName)}`);
125697
125851
  (_a = reasons.get(file.path)) == null ? void 0 : _a.forEach((reason) => write(` ${fileIncludeReasonToDiagnostics(program, reason, relativeFileName).messageText}`));
125698
- (_b = explainIfFileIsRedirectAndImpliedFormat(file, relativeFileName)) == null ? void 0 : _b.forEach((d) => write(` ${d.messageText}`));
125852
+ (_b = explainIfFileIsRedirectAndImpliedFormat(file, program.getCompilerOptionsForFile(file), relativeFileName)) == null ? void 0 : _b.forEach((d) => write(` ${d.messageText}`));
125699
125853
  }
125700
125854
  }
125701
- function explainIfFileIsRedirectAndImpliedFormat(file, fileNameConvertor) {
125855
+ function explainIfFileIsRedirectAndImpliedFormat(file, options, fileNameConvertor) {
125702
125856
  var _a;
125703
125857
  let result;
125704
125858
  if (file.path !== file.resolvedPath) {
@@ -125718,7 +125872,7 @@ function explainIfFileIsRedirectAndImpliedFormat(file, fileNameConvertor) {
125718
125872
  ));
125719
125873
  }
125720
125874
  if (isExternalOrCommonJsModule(file)) {
125721
- switch (file.impliedNodeFormat) {
125875
+ switch (getImpliedNodeFormatForEmitWorker(file, options)) {
125722
125876
  case 99 /* ESNext */:
125723
125877
  if (file.packageJsonScope) {
125724
125878
  (result ?? (result = [])).push(chainDiagnosticMessages(