typescript 5.5.0-dev.20240411 → 5.5.0-dev.20240413

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.5";
21
- var version = `${versionMajorMinor}.0-dev.20240411`;
21
+ var version = `${versionMajorMinor}.0-dev.20240413`;
22
22
 
23
23
  // src/compiler/core.ts
24
24
  var emptyArray = [];
@@ -4307,7 +4307,7 @@ function createDirectoryWatcherSupportingRecursive({
4307
4307
  const filePathComparer = getStringComparer(!useCaseSensitiveFileNames2);
4308
4308
  const toCanonicalFilePath = createGetCanonicalFileName(useCaseSensitiveFileNames2);
4309
4309
  return (dirName, callback, recursive, options) => recursive ? createDirectoryWatcher(dirName, options, callback) : watchDirectory(dirName, callback, recursive, options);
4310
- function createDirectoryWatcher(dirName, options, callback) {
4310
+ function createDirectoryWatcher(dirName, options, callback, link) {
4311
4311
  const dirPath = toCanonicalFilePath(dirName);
4312
4312
  let directoryWatcher = cache.get(dirPath);
4313
4313
  if (directoryWatcher) {
@@ -4317,10 +4317,12 @@ function createDirectoryWatcherSupportingRecursive({
4317
4317
  watcher: watchDirectory(
4318
4318
  dirName,
4319
4319
  (fileName) => {
4320
+ var _a;
4320
4321
  if (isIgnoredPath(fileName, options))
4321
4322
  return;
4322
4323
  if (options == null ? void 0 : options.synchronousWatchDirectory) {
4323
- invokeCallbacks(dirPath, fileName);
4324
+ if (!((_a = cache.get(dirPath)) == null ? void 0 : _a.targetWatcher))
4325
+ invokeCallbacks(dirName, dirPath, fileName);
4324
4326
  updateChildWatches(dirName, dirPath, options);
4325
4327
  } else {
4326
4328
  nonSyncUpdateChildWatches(dirName, dirPath, fileName, options);
@@ -4331,11 +4333,15 @@ function createDirectoryWatcherSupportingRecursive({
4331
4333
  options
4332
4334
  ),
4333
4335
  refCount: 1,
4334
- childWatches: emptyArray
4336
+ childWatches: emptyArray,
4337
+ targetWatcher: void 0,
4338
+ links: void 0
4335
4339
  };
4336
4340
  cache.set(dirPath, directoryWatcher);
4337
4341
  updateChildWatches(dirName, dirPath, options);
4338
4342
  }
4343
+ if (link)
4344
+ (directoryWatcher.links ?? (directoryWatcher.links = /* @__PURE__ */ new Set())).add(link);
4339
4345
  const callbackToAdd = callback && { dirName, callback };
4340
4346
  if (callbackToAdd) {
4341
4347
  callbackCache.add(dirPath, callbackToAdd);
@@ -4343,19 +4349,25 @@ function createDirectoryWatcherSupportingRecursive({
4343
4349
  return {
4344
4350
  dirName,
4345
4351
  close: () => {
4352
+ var _a;
4346
4353
  const directoryWatcher2 = Debug.checkDefined(cache.get(dirPath));
4347
4354
  if (callbackToAdd)
4348
4355
  callbackCache.remove(dirPath, callbackToAdd);
4356
+ if (link)
4357
+ (_a = directoryWatcher2.links) == null ? void 0 : _a.delete(link);
4349
4358
  directoryWatcher2.refCount--;
4350
4359
  if (directoryWatcher2.refCount)
4351
4360
  return;
4352
4361
  cache.delete(dirPath);
4362
+ directoryWatcher2.links = void 0;
4353
4363
  closeFileWatcherOf(directoryWatcher2);
4364
+ closeTargetWatcher(directoryWatcher2);
4354
4365
  directoryWatcher2.childWatches.forEach(closeFileWatcher);
4355
4366
  }
4356
4367
  };
4357
4368
  }
4358
- function invokeCallbacks(dirPath, fileNameOrInvokeMap, fileNames) {
4369
+ function invokeCallbacks(dirName, dirPath, fileNameOrInvokeMap, fileNames) {
4370
+ var _a, _b;
4359
4371
  let fileName;
4360
4372
  let invokeMap;
4361
4373
  if (isString(fileNameOrInvokeMap)) {
@@ -4383,6 +4395,14 @@ function createDirectoryWatcherSupportingRecursive({
4383
4395
  }
4384
4396
  }
4385
4397
  });
4398
+ (_b = (_a = cache.get(dirPath)) == null ? void 0 : _a.links) == null ? void 0 : _b.forEach((link) => {
4399
+ const toPathInLink = (fileName2) => combinePaths(link, getRelativePathFromDirectory(dirName, fileName2, toCanonicalFilePath));
4400
+ if (invokeMap) {
4401
+ invokeCallbacks(link, toCanonicalFilePath(link), invokeMap, fileNames == null ? void 0 : fileNames.map(toPathInLink));
4402
+ } else {
4403
+ invokeCallbacks(link, toCanonicalFilePath(link), toPathInLink(fileName));
4404
+ }
4405
+ });
4386
4406
  }
4387
4407
  function nonSyncUpdateChildWatches(dirName, dirPath, fileName, options) {
4388
4408
  const parentWatcher = cache.get(dirPath);
@@ -4390,7 +4410,8 @@ function createDirectoryWatcherSupportingRecursive({
4390
4410
  scheduleUpdateChildWatches(dirName, dirPath, fileName, options);
4391
4411
  return;
4392
4412
  }
4393
- invokeCallbacks(dirPath, fileName);
4413
+ invokeCallbacks(dirName, dirPath, fileName);
4414
+ closeTargetWatcher(parentWatcher);
4394
4415
  removeChildWatches(parentWatcher);
4395
4416
  }
4396
4417
  function scheduleUpdateChildWatches(dirName, dirPath, fileName, options) {
@@ -4407,6 +4428,7 @@ function createDirectoryWatcherSupportingRecursive({
4407
4428
  timerToUpdateChildWatches = setTimeout2(onTimerToUpdateChildWatches, 1e3, "timerToUpdateChildWatches");
4408
4429
  }
4409
4430
  function onTimerToUpdateChildWatches() {
4431
+ var _a;
4410
4432
  timerToUpdateChildWatches = void 0;
4411
4433
  sysLog(`sysLog:: onTimerToUpdateChildWatches:: ${cacheToUpdateChildWatches.size}`);
4412
4434
  const start = timestamp();
@@ -4417,7 +4439,8 @@ function createDirectoryWatcherSupportingRecursive({
4417
4439
  const { value: [dirPath, { dirName, options, fileNames }] } = result;
4418
4440
  cacheToUpdateChildWatches.delete(dirPath);
4419
4441
  const hasChanges = updateChildWatches(dirName, dirPath, options);
4420
- invokeCallbacks(dirPath, invokeMap, hasChanges ? void 0 : fileNames);
4442
+ if (!((_a = cache.get(dirPath)) == null ? void 0 : _a.targetWatcher))
4443
+ invokeCallbacks(dirName, dirPath, invokeMap, hasChanges ? void 0 : fileNames);
4421
4444
  }
4422
4445
  sysLog(`sysLog:: invokingWatchers:: Elapsed:: ${timestamp() - start}ms:: ${cacheToUpdateChildWatches.size}`);
4423
4446
  callbackCache.forEach((callbacks, rootDirName) => {
@@ -4445,22 +4468,46 @@ function createDirectoryWatcherSupportingRecursive({
4445
4468
  removeChildWatches(cache.get(toCanonicalFilePath(childWatcher.dirName)));
4446
4469
  }
4447
4470
  }
4471
+ function closeTargetWatcher(watcher) {
4472
+ if (watcher == null ? void 0 : watcher.targetWatcher) {
4473
+ watcher.targetWatcher.close();
4474
+ watcher.targetWatcher = void 0;
4475
+ }
4476
+ }
4448
4477
  function updateChildWatches(parentDir, parentDirPath, options) {
4449
4478
  const parentWatcher = cache.get(parentDirPath);
4450
4479
  if (!parentWatcher)
4451
4480
  return false;
4481
+ const target = normalizePath(realpath(parentDir));
4482
+ let hasChanges;
4452
4483
  let newChildWatches;
4453
- const hasChanges = enumerateInsertsAndDeletes(
4454
- fileSystemEntryExists(parentDir, 1 /* Directory */) ? mapDefined(getAccessibleSortedChildDirectories(parentDir), (child) => {
4455
- const childFullName = getNormalizedAbsolutePath(child, parentDir);
4456
- return !isIgnoredPath(childFullName, options) && filePathComparer(childFullName, normalizePath(realpath(childFullName))) === 0 /* EqualTo */ ? childFullName : void 0;
4457
- }) : emptyArray,
4458
- parentWatcher.childWatches,
4459
- (child, childWatcher) => filePathComparer(child, childWatcher.dirName),
4460
- createAndAddChildDirectoryWatcher,
4461
- closeFileWatcher,
4462
- addChildDirectoryWatcher
4463
- );
4484
+ if (filePathComparer(target, parentDir) === 0 /* EqualTo */) {
4485
+ hasChanges = enumerateInsertsAndDeletes(
4486
+ fileSystemEntryExists(parentDir, 1 /* Directory */) ? mapDefined(getAccessibleSortedChildDirectories(parentDir), (child) => {
4487
+ const childFullName = getNormalizedAbsolutePath(child, parentDir);
4488
+ return !isIgnoredPath(childFullName, options) && filePathComparer(childFullName, normalizePath(realpath(childFullName))) === 0 /* EqualTo */ ? childFullName : void 0;
4489
+ }) : emptyArray,
4490
+ parentWatcher.childWatches,
4491
+ (child, childWatcher) => filePathComparer(child, childWatcher.dirName),
4492
+ createAndAddChildDirectoryWatcher,
4493
+ closeFileWatcher,
4494
+ addChildDirectoryWatcher
4495
+ );
4496
+ } else if (parentWatcher.targetWatcher && filePathComparer(target, parentWatcher.targetWatcher.dirName) === 0 /* EqualTo */) {
4497
+ hasChanges = false;
4498
+ Debug.assert(parentWatcher.childWatches === emptyArray);
4499
+ } else {
4500
+ closeTargetWatcher(parentWatcher);
4501
+ parentWatcher.targetWatcher = createDirectoryWatcher(
4502
+ target,
4503
+ options,
4504
+ /*callback*/
4505
+ void 0,
4506
+ parentDir
4507
+ );
4508
+ parentWatcher.childWatches.forEach(closeFileWatcher);
4509
+ hasChanges = true;
4510
+ }
4464
4511
  parentWatcher.childWatches = newChildWatches || emptyArray;
4465
4512
  return hasChanges;
4466
4513
  function createAndAddChildDirectoryWatcher(childName) {
@@ -5955,6 +6002,7 @@ var Diagnostics = {
5955
6002
  _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 }'."),
5956
6003
  _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."),
5957
6004
  _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 }'."),
6005
+ 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'."),
5958
6006
  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."),
5959
6007
  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."),
5960
6008
  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."),
@@ -10060,6 +10108,8 @@ function getDefaultLibFileName(options) {
10060
10108
  switch (getEmitScriptTarget(options)) {
10061
10109
  case 99 /* ESNext */:
10062
10110
  return "lib.esnext.full.d.ts";
10111
+ case 10 /* ES2023 */:
10112
+ return "lib.es2023.full.d.ts";
10063
10113
  case 9 /* ES2022 */:
10064
10114
  return "lib.es2022.full.d.ts";
10065
10115
  case 8 /* ES2021 */:
@@ -12644,6 +12694,9 @@ function getErrorSpanForNode(sourceFile, node) {
12644
12694
  }
12645
12695
  return createTextSpanFromBounds(pos, errorNode.end);
12646
12696
  }
12697
+ function isGlobalSourceFile(node) {
12698
+ return node.kind === 307 /* SourceFile */ && !isExternalOrCommonJsModule(node);
12699
+ }
12647
12700
  function isExternalOrCommonJsModule(file) {
12648
12701
  return (file.externalModuleIndicator || file.commonJsModuleIndicator) !== void 0;
12649
12702
  }
@@ -13704,6 +13757,23 @@ function isFunctionSymbol(symbol) {
13704
13757
  const decl = symbol.valueDeclaration;
13705
13758
  return decl.kind === 262 /* FunctionDeclaration */ || isVariableDeclaration(decl) && decl.initializer && isFunctionLike(decl.initializer);
13706
13759
  }
13760
+ function canHaveModuleSpecifier(node) {
13761
+ switch (node == null ? void 0 : node.kind) {
13762
+ case 260 /* VariableDeclaration */:
13763
+ case 208 /* BindingElement */:
13764
+ case 272 /* ImportDeclaration */:
13765
+ case 278 /* ExportDeclaration */:
13766
+ case 271 /* ImportEqualsDeclaration */:
13767
+ case 273 /* ImportClause */:
13768
+ case 280 /* NamespaceExport */:
13769
+ case 274 /* NamespaceImport */:
13770
+ case 281 /* ExportSpecifier */:
13771
+ case 276 /* ImportSpecifier */:
13772
+ case 205 /* ImportType */:
13773
+ return true;
13774
+ }
13775
+ return false;
13776
+ }
13707
13777
  function tryGetModuleSpecifierFromDeclaration(node) {
13708
13778
  var _a, _b;
13709
13779
  switch (node.kind) {
@@ -16378,8 +16448,8 @@ function walkTreeForJSXTags(node) {
16378
16448
  function isFileModuleFromUsingJSXTag(file) {
16379
16449
  return !file.isDeclarationFile ? walkTreeForJSXTags(file) : void 0;
16380
16450
  }
16381
- function isFileForcedToBeModuleByFormat(file) {
16382
- return (file.impliedNodeFormat === 99 /* ESNext */ || fileExtensionIsOneOf(file.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */, ".mjs" /* Mjs */, ".mts" /* Mts */])) && !file.isDeclarationFile ? true : void 0;
16451
+ function isFileForcedToBeModuleByFormat(file, options) {
16452
+ return (getImpliedNodeFormatForEmitWorker(file, options) === 99 /* ESNext */ || fileExtensionIsOneOf(file.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */, ".mjs" /* Mjs */, ".mts" /* Mts */])) && !file.isDeclarationFile ? true : void 0;
16383
16453
  }
16384
16454
  function getSetExternalModuleIndicator(options) {
16385
16455
  switch (getEmitModuleDetectionKind(options)) {
@@ -16398,10 +16468,14 @@ function getSetExternalModuleIndicator(options) {
16398
16468
  }
16399
16469
  checks.push(isFileForcedToBeModuleByFormat);
16400
16470
  const combined = or(...checks);
16401
- const callback = (file) => void (file.externalModuleIndicator = combined(file));
16471
+ const callback = (file) => void (file.externalModuleIndicator = combined(file, options));
16402
16472
  return callback;
16403
16473
  }
16404
16474
  }
16475
+ function importSyntaxAffectsModuleResolution(options) {
16476
+ const moduleResolution = getEmitModuleResolutionKind(options);
16477
+ return 3 /* Node16 */ <= moduleResolution && moduleResolution <= 99 /* NodeNext */ || getResolvePackageJsonExports(options) || getResolvePackageJsonImports(options);
16478
+ }
16405
16479
  function createComputedCompilerOptions(options) {
16406
16480
  return options;
16407
16481
  }
@@ -17820,6 +17894,380 @@ function createEvaluator({ evaluateElementAccessExpression, evaluateEntityNameEx
17820
17894
  }
17821
17895
  return evaluate;
17822
17896
  }
17897
+ function isConstAssertion(location) {
17898
+ return isAssertionExpression(location) && isConstTypeReference(location.type) || isJSDocTypeTag(location) && isConstTypeReference(location.typeExpression);
17899
+ }
17900
+ function findConstructorDeclaration(node) {
17901
+ const members = node.members;
17902
+ for (const member of members) {
17903
+ if (member.kind === 176 /* Constructor */ && nodeIsPresent(member.body)) {
17904
+ return member;
17905
+ }
17906
+ }
17907
+ }
17908
+ function createNameResolver({
17909
+ compilerOptions,
17910
+ requireSymbol,
17911
+ argumentsSymbol,
17912
+ error,
17913
+ getSymbolOfDeclaration,
17914
+ globals,
17915
+ lookup,
17916
+ setRequiresScopeChangeCache = returnUndefined,
17917
+ getRequiresScopeChangeCache = returnUndefined,
17918
+ onPropertyWithInvalidInitializer = returnFalse,
17919
+ onFailedToResolveSymbol = returnUndefined,
17920
+ onSuccessfullyResolvedSymbol = returnUndefined
17921
+ }) {
17922
+ var isolatedModulesLikeFlagName = compilerOptions.verbatimModuleSyntax ? "verbatimModuleSyntax" : "isolatedModules";
17923
+ var emitStandardClassFields = getEmitStandardClassFields(compilerOptions);
17924
+ var emptySymbols = createSymbolTable();
17925
+ return resolveNameHelper;
17926
+ function resolveNameHelper(location, nameArg, meaning, nameNotFoundMessage, isUse, excludeGlobals) {
17927
+ var _a, _b, _c;
17928
+ const originalLocation = location;
17929
+ let result;
17930
+ let lastLocation;
17931
+ let lastSelfReferenceLocation;
17932
+ let propertyWithInvalidInitializer;
17933
+ let associatedDeclarationForContainingInitializerOrBindingName;
17934
+ let withinDeferredContext = false;
17935
+ let grandparent;
17936
+ const name = isString(nameArg) ? nameArg : nameArg.escapedText;
17937
+ loop:
17938
+ while (location) {
17939
+ if (name === "const" && isConstAssertion(location)) {
17940
+ return void 0;
17941
+ }
17942
+ if (isModuleOrEnumDeclaration(location) && lastLocation && location.name === lastLocation) {
17943
+ lastLocation = location;
17944
+ location = location.parent;
17945
+ }
17946
+ if (canHaveLocals(location) && location.locals && !isGlobalSourceFile(location)) {
17947
+ if (result = lookup(location.locals, name, meaning)) {
17948
+ let useResult = true;
17949
+ if (isFunctionLike(location) && lastLocation && lastLocation !== location.body) {
17950
+ if (meaning & result.flags & 788968 /* Type */ && lastLocation.kind !== 320 /* JSDoc */) {
17951
+ useResult = result.flags & 262144 /* TypeParameter */ ? lastLocation === location.type || lastLocation.kind === 169 /* Parameter */ || lastLocation.kind === 341 /* JSDocParameterTag */ || lastLocation.kind === 342 /* JSDocReturnTag */ || lastLocation.kind === 168 /* TypeParameter */ : false;
17952
+ }
17953
+ if (meaning & result.flags & 3 /* Variable */) {
17954
+ if (useOuterVariableScopeInParameter(result, location, lastLocation)) {
17955
+ useResult = false;
17956
+ } else if (result.flags & 1 /* FunctionScopedVariable */) {
17957
+ useResult = lastLocation.kind === 169 /* Parameter */ || lastLocation === location.type && !!findAncestor(result.valueDeclaration, isParameter);
17958
+ }
17959
+ }
17960
+ } else if (location.kind === 194 /* ConditionalType */) {
17961
+ useResult = lastLocation === location.trueType;
17962
+ }
17963
+ if (useResult) {
17964
+ break loop;
17965
+ } else {
17966
+ result = void 0;
17967
+ }
17968
+ }
17969
+ }
17970
+ withinDeferredContext = withinDeferredContext || getIsDeferredContext(location, lastLocation);
17971
+ switch (location.kind) {
17972
+ case 307 /* SourceFile */:
17973
+ if (!isExternalOrCommonJsModule(location))
17974
+ break;
17975
+ case 267 /* ModuleDeclaration */:
17976
+ const moduleExports = ((_a = getSymbolOfDeclaration(location)) == null ? void 0 : _a.exports) || emptySymbols;
17977
+ if (location.kind === 307 /* SourceFile */ || isModuleDeclaration(location) && location.flags & 33554432 /* Ambient */ && !isGlobalScopeAugmentation(location)) {
17978
+ if (result = moduleExports.get("default" /* Default */)) {
17979
+ const localSymbol = getLocalSymbolForExportDefault(result);
17980
+ if (localSymbol && result.flags & meaning && localSymbol.escapedName === name) {
17981
+ break loop;
17982
+ }
17983
+ result = void 0;
17984
+ }
17985
+ const moduleExport = moduleExports.get(name);
17986
+ if (moduleExport && moduleExport.flags === 2097152 /* Alias */ && (getDeclarationOfKind(moduleExport, 281 /* ExportSpecifier */) || getDeclarationOfKind(moduleExport, 280 /* NamespaceExport */))) {
17987
+ break;
17988
+ }
17989
+ }
17990
+ if (name !== "default" /* Default */ && (result = lookup(moduleExports, name, meaning & 2623475 /* ModuleMember */))) {
17991
+ if (isSourceFile(location) && location.commonJsModuleIndicator && !((_b = result.declarations) == null ? void 0 : _b.some(isJSDocTypeAlias))) {
17992
+ result = void 0;
17993
+ } else {
17994
+ break loop;
17995
+ }
17996
+ }
17997
+ break;
17998
+ case 266 /* EnumDeclaration */:
17999
+ if (result = lookup(((_c = getSymbolOfDeclaration(location)) == null ? void 0 : _c.exports) || emptySymbols, name, meaning & 8 /* EnumMember */)) {
18000
+ if (nameNotFoundMessage && getIsolatedModules(compilerOptions) && !(location.flags & 33554432 /* Ambient */) && getSourceFileOfNode(location) !== getSourceFileOfNode(result.valueDeclaration)) {
18001
+ error(
18002
+ originalLocation,
18003
+ Diagnostics.Cannot_access_0_from_another_file_without_qualification_when_1_is_enabled_Use_2_instead,
18004
+ unescapeLeadingUnderscores(name),
18005
+ isolatedModulesLikeFlagName,
18006
+ `${unescapeLeadingUnderscores(getSymbolOfDeclaration(location).escapedName)}.${unescapeLeadingUnderscores(name)}`
18007
+ );
18008
+ }
18009
+ break loop;
18010
+ }
18011
+ break;
18012
+ case 172 /* PropertyDeclaration */:
18013
+ if (!isStatic(location)) {
18014
+ const ctor = findConstructorDeclaration(location.parent);
18015
+ if (ctor && ctor.locals) {
18016
+ if (lookup(ctor.locals, name, meaning & 111551 /* Value */)) {
18017
+ Debug.assertNode(location, isPropertyDeclaration);
18018
+ propertyWithInvalidInitializer = location;
18019
+ }
18020
+ }
18021
+ }
18022
+ break;
18023
+ case 263 /* ClassDeclaration */:
18024
+ case 231 /* ClassExpression */:
18025
+ case 264 /* InterfaceDeclaration */:
18026
+ if (result = lookup(getSymbolOfDeclaration(location).members || emptySymbols, name, meaning & 788968 /* Type */)) {
18027
+ if (!isTypeParameterSymbolDeclaredInContainer(result, location)) {
18028
+ result = void 0;
18029
+ break;
18030
+ }
18031
+ if (lastLocation && isStatic(lastLocation)) {
18032
+ if (nameNotFoundMessage) {
18033
+ error(originalLocation, Diagnostics.Static_members_cannot_reference_class_type_parameters);
18034
+ }
18035
+ return void 0;
18036
+ }
18037
+ break loop;
18038
+ }
18039
+ if (isClassExpression(location) && meaning & 32 /* Class */) {
18040
+ const className = location.name;
18041
+ if (className && name === className.escapedText) {
18042
+ result = location.symbol;
18043
+ break loop;
18044
+ }
18045
+ }
18046
+ break;
18047
+ case 233 /* ExpressionWithTypeArguments */:
18048
+ if (lastLocation === location.expression && location.parent.token === 96 /* ExtendsKeyword */) {
18049
+ const container = location.parent.parent;
18050
+ if (isClassLike(container) && (result = lookup(getSymbolOfDeclaration(container).members, name, meaning & 788968 /* Type */))) {
18051
+ if (nameNotFoundMessage) {
18052
+ error(originalLocation, Diagnostics.Base_class_expressions_cannot_reference_class_type_parameters);
18053
+ }
18054
+ return void 0;
18055
+ }
18056
+ }
18057
+ break;
18058
+ case 167 /* ComputedPropertyName */:
18059
+ grandparent = location.parent.parent;
18060
+ if (isClassLike(grandparent) || grandparent.kind === 264 /* InterfaceDeclaration */) {
18061
+ if (result = lookup(getSymbolOfDeclaration(grandparent).members, name, meaning & 788968 /* Type */)) {
18062
+ if (nameNotFoundMessage) {
18063
+ error(originalLocation, Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type);
18064
+ }
18065
+ return void 0;
18066
+ }
18067
+ }
18068
+ break;
18069
+ case 219 /* ArrowFunction */:
18070
+ if (getEmitScriptTarget(compilerOptions) >= 2 /* ES2015 */) {
18071
+ break;
18072
+ }
18073
+ case 174 /* MethodDeclaration */:
18074
+ case 176 /* Constructor */:
18075
+ case 177 /* GetAccessor */:
18076
+ case 178 /* SetAccessor */:
18077
+ case 262 /* FunctionDeclaration */:
18078
+ if (meaning & 3 /* Variable */ && name === "arguments") {
18079
+ result = argumentsSymbol;
18080
+ break loop;
18081
+ }
18082
+ break;
18083
+ case 218 /* FunctionExpression */:
18084
+ if (meaning & 3 /* Variable */ && name === "arguments") {
18085
+ result = argumentsSymbol;
18086
+ break loop;
18087
+ }
18088
+ if (meaning & 16 /* Function */) {
18089
+ const functionName = location.name;
18090
+ if (functionName && name === functionName.escapedText) {
18091
+ result = location.symbol;
18092
+ break loop;
18093
+ }
18094
+ }
18095
+ break;
18096
+ case 170 /* Decorator */:
18097
+ if (location.parent && location.parent.kind === 169 /* Parameter */) {
18098
+ location = location.parent;
18099
+ }
18100
+ if (location.parent && (isClassElement(location.parent) || location.parent.kind === 263 /* ClassDeclaration */)) {
18101
+ location = location.parent;
18102
+ }
18103
+ break;
18104
+ case 346 /* JSDocTypedefTag */:
18105
+ case 338 /* JSDocCallbackTag */:
18106
+ case 340 /* JSDocEnumTag */:
18107
+ case 351 /* JSDocImportTag */:
18108
+ const root = getJSDocRoot(location);
18109
+ if (root) {
18110
+ location = root.parent;
18111
+ }
18112
+ break;
18113
+ case 169 /* Parameter */:
18114
+ if (lastLocation && (lastLocation === location.initializer || lastLocation === location.name && isBindingPattern(lastLocation))) {
18115
+ if (!associatedDeclarationForContainingInitializerOrBindingName) {
18116
+ associatedDeclarationForContainingInitializerOrBindingName = location;
18117
+ }
18118
+ }
18119
+ break;
18120
+ case 208 /* BindingElement */:
18121
+ if (lastLocation && (lastLocation === location.initializer || lastLocation === location.name && isBindingPattern(lastLocation))) {
18122
+ if (isParameterDeclaration(location) && !associatedDeclarationForContainingInitializerOrBindingName) {
18123
+ associatedDeclarationForContainingInitializerOrBindingName = location;
18124
+ }
18125
+ }
18126
+ break;
18127
+ case 195 /* InferType */:
18128
+ if (meaning & 262144 /* TypeParameter */) {
18129
+ const parameterName = location.typeParameter.name;
18130
+ if (parameterName && name === parameterName.escapedText) {
18131
+ result = location.typeParameter.symbol;
18132
+ break loop;
18133
+ }
18134
+ }
18135
+ break;
18136
+ case 281 /* ExportSpecifier */:
18137
+ if (lastLocation && lastLocation === location.propertyName && location.parent.parent.moduleSpecifier) {
18138
+ location = location.parent.parent.parent;
18139
+ }
18140
+ break;
18141
+ }
18142
+ if (isSelfReferenceLocation(location)) {
18143
+ lastSelfReferenceLocation = location;
18144
+ }
18145
+ lastLocation = location;
18146
+ location = isJSDocTemplateTag(location) ? getEffectiveContainerForJSDocTemplateTag(location) || location.parent : isJSDocParameterTag(location) || isJSDocReturnTag(location) ? getHostSignatureFromJSDoc(location) || location.parent : location.parent;
18147
+ }
18148
+ if (isUse && result && (!lastSelfReferenceLocation || result !== lastSelfReferenceLocation.symbol)) {
18149
+ result.isReferenced |= meaning;
18150
+ }
18151
+ if (!result) {
18152
+ if (lastLocation) {
18153
+ Debug.assertNode(lastLocation, isSourceFile);
18154
+ if (lastLocation.commonJsModuleIndicator && name === "exports" && meaning & lastLocation.symbol.flags) {
18155
+ return lastLocation.symbol;
18156
+ }
18157
+ }
18158
+ if (!excludeGlobals) {
18159
+ result = lookup(globals, name, meaning);
18160
+ }
18161
+ }
18162
+ if (!result) {
18163
+ if (originalLocation && isInJSFile(originalLocation) && originalLocation.parent) {
18164
+ if (isRequireCall(
18165
+ originalLocation.parent,
18166
+ /*requireStringLiteralLikeArgument*/
18167
+ false
18168
+ )) {
18169
+ return requireSymbol;
18170
+ }
18171
+ }
18172
+ }
18173
+ if (nameNotFoundMessage) {
18174
+ if (propertyWithInvalidInitializer && onPropertyWithInvalidInitializer(originalLocation, name, propertyWithInvalidInitializer, result)) {
18175
+ return void 0;
18176
+ }
18177
+ if (!result) {
18178
+ onFailedToResolveSymbol(originalLocation, nameArg, meaning, nameNotFoundMessage);
18179
+ } else {
18180
+ onSuccessfullyResolvedSymbol(originalLocation, result, meaning, lastLocation, associatedDeclarationForContainingInitializerOrBindingName, withinDeferredContext);
18181
+ }
18182
+ }
18183
+ return result;
18184
+ }
18185
+ function useOuterVariableScopeInParameter(result, location, lastLocation) {
18186
+ const target = getEmitScriptTarget(compilerOptions);
18187
+ const functionLocation = location;
18188
+ if (isParameter(lastLocation) && functionLocation.body && result.valueDeclaration && result.valueDeclaration.pos >= functionLocation.body.pos && result.valueDeclaration.end <= functionLocation.body.end) {
18189
+ if (target >= 2 /* ES2015 */) {
18190
+ let declarationRequiresScopeChange = getRequiresScopeChangeCache(functionLocation);
18191
+ if (declarationRequiresScopeChange === void 0) {
18192
+ declarationRequiresScopeChange = forEach(functionLocation.parameters, requiresScopeChange) || false;
18193
+ setRequiresScopeChangeCache(functionLocation, declarationRequiresScopeChange);
18194
+ }
18195
+ return !declarationRequiresScopeChange;
18196
+ }
18197
+ }
18198
+ return false;
18199
+ function requiresScopeChange(node) {
18200
+ return requiresScopeChangeWorker(node.name) || !!node.initializer && requiresScopeChangeWorker(node.initializer);
18201
+ }
18202
+ function requiresScopeChangeWorker(node) {
18203
+ switch (node.kind) {
18204
+ case 219 /* ArrowFunction */:
18205
+ case 218 /* FunctionExpression */:
18206
+ case 262 /* FunctionDeclaration */:
18207
+ case 176 /* Constructor */:
18208
+ return false;
18209
+ case 174 /* MethodDeclaration */:
18210
+ case 177 /* GetAccessor */:
18211
+ case 178 /* SetAccessor */:
18212
+ case 303 /* PropertyAssignment */:
18213
+ return requiresScopeChangeWorker(node.name);
18214
+ case 172 /* PropertyDeclaration */:
18215
+ if (hasStaticModifier(node)) {
18216
+ return !emitStandardClassFields;
18217
+ }
18218
+ return requiresScopeChangeWorker(node.name);
18219
+ default:
18220
+ if (isNullishCoalesce(node) || isOptionalChain(node)) {
18221
+ return target < 7 /* ES2020 */;
18222
+ }
18223
+ if (isBindingElement(node) && node.dotDotDotToken && isObjectBindingPattern(node.parent)) {
18224
+ return target < 4 /* ES2017 */;
18225
+ }
18226
+ if (isTypeNode(node))
18227
+ return false;
18228
+ return forEachChild(node, requiresScopeChangeWorker) || false;
18229
+ }
18230
+ }
18231
+ }
18232
+ function getIsDeferredContext(location, lastLocation) {
18233
+ if (location.kind !== 219 /* ArrowFunction */ && location.kind !== 218 /* FunctionExpression */) {
18234
+ return isTypeQueryNode(location) || (isFunctionLikeDeclaration(location) || location.kind === 172 /* PropertyDeclaration */ && !isStatic(location)) && (!lastLocation || lastLocation !== location.name);
18235
+ }
18236
+ if (lastLocation && lastLocation === location.name) {
18237
+ return false;
18238
+ }
18239
+ if (location.asteriskToken || hasSyntacticModifier(location, 1024 /* Async */)) {
18240
+ return true;
18241
+ }
18242
+ return !getImmediatelyInvokedFunctionExpression(location);
18243
+ }
18244
+ function isSelfReferenceLocation(node) {
18245
+ switch (node.kind) {
18246
+ case 262 /* FunctionDeclaration */:
18247
+ case 263 /* ClassDeclaration */:
18248
+ case 264 /* InterfaceDeclaration */:
18249
+ case 266 /* EnumDeclaration */:
18250
+ case 265 /* TypeAliasDeclaration */:
18251
+ case 267 /* ModuleDeclaration */:
18252
+ return true;
18253
+ default:
18254
+ return false;
18255
+ }
18256
+ }
18257
+ function isTypeParameterSymbolDeclaredInContainer(symbol, container) {
18258
+ if (symbol.declarations) {
18259
+ for (const decl of symbol.declarations) {
18260
+ if (decl.kind === 168 /* TypeParameter */) {
18261
+ const parent = isJSDocTemplateTag(decl.parent) ? getJSDocHost(decl.parent) : decl.parent;
18262
+ if (parent === container) {
18263
+ return !(isJSDocTemplateTag(decl.parent) && find(decl.parent.parent.tags, isJSDocTypeAlias));
18264
+ }
18265
+ }
18266
+ }
18267
+ }
18268
+ return false;
18269
+ }
18270
+ }
17823
18271
 
17824
18272
  // src/compiler/factory/baseNodeFactory.ts
17825
18273
  function createBaseNodeFactory() {
@@ -25171,7 +25619,7 @@ function createExternalHelpersImportDeclarationIfNeeded(nodeFactory, helperFacto
25171
25619
  if (compilerOptions.importHelpers && isEffectiveExternalModule(sourceFile, compilerOptions)) {
25172
25620
  let namedBindings;
25173
25621
  const moduleKind = getEmitModuleKind(compilerOptions);
25174
- if (moduleKind >= 5 /* ES2015 */ && moduleKind <= 99 /* ESNext */ || sourceFile.impliedNodeFormat === 99 /* ESNext */) {
25622
+ if (moduleKind >= 5 /* ES2015 */ && moduleKind <= 99 /* ESNext */ || getImpliedNodeFormatForEmitWorker(sourceFile, compilerOptions) === 99 /* ESNext */) {
25175
25623
  const helpers = getEmitHelpers(sourceFile);
25176
25624
  if (helpers) {
25177
25625
  const helperNames = [];
@@ -25236,8 +25684,7 @@ function getOrCreateExternalHelpersModuleNameIfNeeded(factory2, node, compilerOp
25236
25684
  if (externalHelpersModuleName) {
25237
25685
  return externalHelpersModuleName;
25238
25686
  }
25239
- const moduleKind = getEmitModuleKind(compilerOptions);
25240
- let create = (hasExportStarsToExportValues || getESModuleInterop(compilerOptions) && hasImportStarOrImportDefault) && moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || node.impliedNodeFormat === 1 /* CommonJS */);
25687
+ let create = (hasExportStarsToExportValues || getESModuleInterop(compilerOptions) && hasImportStarOrImportDefault) && getEmitModuleFormatOfFileWorker(node, compilerOptions) < 4 /* System */;
25241
25688
  if (!create) {
25242
25689
  const helpers = getEmitHelpers(node);
25243
25690
  if (helpers) {
@@ -34253,6 +34700,7 @@ var targetOptionDeclaration = {
34253
34700
  es2020: 7 /* ES2020 */,
34254
34701
  es2021: 8 /* ES2021 */,
34255
34702
  es2022: 9 /* ES2022 */,
34703
+ es2023: 10 /* ES2023 */,
34256
34704
  esnext: 99 /* ESNext */
34257
34705
  })),
34258
34706
  affectsSourceFile: true,
@@ -42631,13 +43079,15 @@ function createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignatu
42631
43079
  }
42632
43080
 
42633
43081
  // src/compiler/moduleSpecifiers.ts
42634
- function getModuleSpecifierPreferences({ importModuleSpecifierPreference, importModuleSpecifierEnding }, compilerOptions, importingSourceFile, oldImportSpecifier) {
43082
+ function getModuleSpecifierPreferences({ importModuleSpecifierPreference, importModuleSpecifierEnding }, host, compilerOptions, importingSourceFile, oldImportSpecifier) {
42635
43083
  const filePreferredEnding = getPreferredEnding();
42636
43084
  return {
42637
43085
  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 */,
42638
43086
  getAllowedEndingsInPreferredOrder: (syntaxImpliedNodeFormat) => {
42639
- const preferredEnding = syntaxImpliedNodeFormat !== importingSourceFile.impliedNodeFormat ? getPreferredEnding(syntaxImpliedNodeFormat) : filePreferredEnding;
42640
- if ((syntaxImpliedNodeFormat ?? importingSourceFile.impliedNodeFormat) === 99 /* ESNext */) {
43087
+ const impliedNodeFormat = getDefaultResolutionModeForFile(importingSourceFile, host, compilerOptions);
43088
+ const preferredEnding = syntaxImpliedNodeFormat !== impliedNodeFormat ? getPreferredEnding(syntaxImpliedNodeFormat) : filePreferredEnding;
43089
+ const moduleResolution = getEmitModuleResolutionKind(compilerOptions);
43090
+ if ((syntaxImpliedNodeFormat ?? impliedNodeFormat) === 99 /* ESNext */ && 3 /* Node16 */ <= moduleResolution && moduleResolution <= 99 /* NodeNext */) {
42641
43091
  if (shouldAllowImportingTsExtension(compilerOptions, importingSourceFile.fileName)) {
42642
43092
  return [3 /* TsExtension */, 2 /* JsExtension */];
42643
43093
  }
@@ -42670,7 +43120,7 @@ function getModuleSpecifierPreferences({ importModuleSpecifierPreference, import
42670
43120
  }
42671
43121
  return getModuleSpecifierEndingPreference(
42672
43122
  importModuleSpecifierEnding,
42673
- resolutionMode ?? importingSourceFile.impliedNodeFormat,
43123
+ resolutionMode ?? getDefaultResolutionModeForFile(importingSourceFile, host, compilerOptions),
42674
43124
  compilerOptions,
42675
43125
  isFullSourceFile(importingSourceFile) ? importingSourceFile : void 0
42676
43126
  );
@@ -42731,14 +43181,17 @@ function getModuleSpecifiersWithCacheInfo(moduleSymbol, checker, compilerOptions
42731
43181
  }
42732
43182
  function computeModuleSpecifiers(modulePaths, compilerOptions, importingSourceFile, host, userPreferences, options = {}, forAutoImport) {
42733
43183
  const info = getInfo(importingSourceFile.fileName, host);
42734
- const preferences = getModuleSpecifierPreferences(userPreferences, compilerOptions, importingSourceFile);
43184
+ const preferences = getModuleSpecifierPreferences(userPreferences, host, compilerOptions, importingSourceFile);
42735
43185
  const existingSpecifier = isFullSourceFile(importingSourceFile) && forEach(modulePaths, (modulePath) => forEach(
42736
43186
  host.getFileIncludeReasons().get(toPath(modulePath.path, host.getCurrentDirectory(), info.getCanonicalFileName)),
42737
43187
  (reason) => {
42738
43188
  if (reason.kind !== 3 /* Import */ || reason.file !== importingSourceFile.path)
42739
43189
  return void 0;
42740
- if (importingSourceFile.impliedNodeFormat && importingSourceFile.impliedNodeFormat !== getModeForResolutionAtIndex(importingSourceFile, reason.index, compilerOptions))
43190
+ const existingMode = host.getModeForResolutionAtIndex(importingSourceFile, reason.index);
43191
+ const targetMode = options.overrideImportMode ?? host.getDefaultResolutionModeForFile(importingSourceFile);
43192
+ if (existingMode !== targetMode && existingMode !== void 0 && targetMode !== void 0) {
42741
43193
  return void 0;
43194
+ }
42742
43195
  const specifier = getModuleNameStringLiteralAt(importingSourceFile, reason.index).text;
42743
43196
  return preferences.relativePreference !== 1 /* NonRelative */ || !pathIsRelative(specifier) ? specifier : void 0;
42744
43197
  }
@@ -43233,7 +43686,7 @@ function tryGetModuleNameAsNodeModule({ path, isRedirect }, { getCanonicalFileNa
43233
43686
  if (!parts) {
43234
43687
  return void 0;
43235
43688
  }
43236
- const preferences = getModuleSpecifierPreferences(userPreferences, options, importingSourceFile);
43689
+ const preferences = getModuleSpecifierPreferences(userPreferences, host, options, importingSourceFile);
43237
43690
  const allowedEndings = preferences.getAllowedEndingsInPreferredOrder();
43238
43691
  let moduleSpecifier = path;
43239
43692
  let isPackageRootPath = false;
@@ -43284,7 +43737,7 @@ function tryGetModuleNameAsNodeModule({ path, isRedirect }, { getCanonicalFileNa
43284
43737
  const cachedPackageJson = (_b = (_a = host.getPackageJsonInfoCache) == null ? void 0 : _a.call(host)) == null ? void 0 : _b.getPackageJsonInfo(packageJsonPath);
43285
43738
  if (isPackageJsonInfo(cachedPackageJson) || cachedPackageJson === void 0 && host.fileExists(packageJsonPath)) {
43286
43739
  const packageJsonContent = (cachedPackageJson == null ? void 0 : cachedPackageJson.contents.packageJsonContent) || tryParseJson(host.readFile(packageJsonPath));
43287
- const importMode = overrideMode || importingSourceFile.impliedNodeFormat;
43740
+ const importMode = overrideMode || getDefaultResolutionModeForFile(importingSourceFile, host, options);
43288
43741
  if (getResolvePackageJsonExports(options)) {
43289
43742
  const nodeModulesDirectoryName2 = packageRootPath.substring(parts.topLevelPackageNameIndex + 1);
43290
43743
  const packageName2 = getPackageNameFromTypesPackageName(nodeModulesDirectoryName2);
@@ -43436,6 +43889,9 @@ function getRelativePathIfInSameVolume(path, directoryPath, getCanonicalFileName
43436
43889
  function isPathRelativeToParent(path) {
43437
43890
  return startsWith(path, "..");
43438
43891
  }
43892
+ function getDefaultResolutionModeForFile(file, host, compilerOptions) {
43893
+ return isFullSourceFile(file) ? host.getDefaultResolutionModeForFile(file) : getDefaultResolutionModeForFileWorker(file, compilerOptions);
43894
+ }
43439
43895
 
43440
43896
  // src/compiler/checker.ts
43441
43897
  var ambientModuleSymbolRegex = /^".+"$/;
@@ -43646,6 +44102,31 @@ function createTypeChecker(host) {
43646
44102
  var lastGetCombinedNodeFlagsResult = 0 /* None */;
43647
44103
  var lastGetCombinedModifierFlagsNode;
43648
44104
  var lastGetCombinedModifierFlagsResult = 0 /* None */;
44105
+ var resolveName = createNameResolver({
44106
+ compilerOptions,
44107
+ requireSymbol,
44108
+ argumentsSymbol,
44109
+ globals,
44110
+ getSymbolOfDeclaration,
44111
+ error,
44112
+ getRequiresScopeChangeCache,
44113
+ setRequiresScopeChangeCache,
44114
+ lookup: getSymbol,
44115
+ onPropertyWithInvalidInitializer: checkAndReportErrorForInvalidInitializer,
44116
+ onFailedToResolveSymbol,
44117
+ onSuccessfullyResolvedSymbol
44118
+ });
44119
+ var resolveNameForSymbolSuggestion = createNameResolver({
44120
+ compilerOptions,
44121
+ requireSymbol,
44122
+ argumentsSymbol,
44123
+ globals,
44124
+ getSymbolOfDeclaration,
44125
+ error,
44126
+ getRequiresScopeChangeCache,
44127
+ setRequiresScopeChangeCache,
44128
+ lookup: getSuggestionForSymbolNameLookup
44129
+ });
43649
44130
  const checker = {
43650
44131
  getNodeCount: () => reduceLeft(host.getSourceFiles(), (n, s) => n + s.nodeCount, 0),
43651
44132
  getIdentifierCount: () => reduceLeft(host.getSourceFiles(), (n, s) => n + s.identifierCount, 0),
@@ -43951,8 +44432,6 @@ function createTypeChecker(host) {
43951
44432
  meaning,
43952
44433
  /*nameNotFoundMessage*/
43953
44434
  void 0,
43954
- /*nameArg*/
43955
- void 0,
43956
44435
  /*isUse*/
43957
44436
  false,
43958
44437
  excludeGlobals
@@ -44982,9 +45461,6 @@ function createTypeChecker(host) {
44982
45461
  const nodeId = getNodeId(node);
44983
45462
  return nodeLinks[nodeId] || (nodeLinks[nodeId] = new NodeLinks());
44984
45463
  }
44985
- function isGlobalSourceFile(node) {
44986
- return node.kind === 307 /* SourceFile */ && !isExternalOrCommonJsModule(node);
44987
- }
44988
45464
  function getSymbol(symbols, name, meaning) {
44989
45465
  if (meaning) {
44990
45466
  const symbol = getMergedSymbol(symbols.get(name));
@@ -45160,417 +45636,120 @@ function createTypeChecker(host) {
45160
45636
  return ancestorChangingReferenceScope === void 0;
45161
45637
  }
45162
45638
  }
45163
- function useOuterVariableScopeInParameter(result, location, lastLocation) {
45164
- const target = getEmitScriptTarget(compilerOptions);
45165
- const functionLocation = location;
45166
- if (isParameter(lastLocation) && functionLocation.body && result.valueDeclaration && result.valueDeclaration.pos >= functionLocation.body.pos && result.valueDeclaration.end <= functionLocation.body.end) {
45167
- if (target >= 2 /* ES2015 */) {
45168
- const links = getNodeLinks(functionLocation);
45169
- if (links.declarationRequiresScopeChange === void 0) {
45170
- links.declarationRequiresScopeChange = forEach(functionLocation.parameters, requiresScopeChange) || false;
45171
- }
45172
- return !links.declarationRequiresScopeChange;
45639
+ function getRequiresScopeChangeCache(node) {
45640
+ return getNodeLinks(node).declarationRequiresScopeChange;
45641
+ }
45642
+ function setRequiresScopeChangeCache(node, value) {
45643
+ getNodeLinks(node).declarationRequiresScopeChange = value;
45644
+ }
45645
+ function checkAndReportErrorForInvalidInitializer(errorLocation, name, propertyWithInvalidInitializer, result) {
45646
+ if (!emitStandardClassFields) {
45647
+ if (errorLocation && !result && checkAndReportErrorForMissingPrefix(errorLocation, name, name)) {
45648
+ return true;
45173
45649
  }
45650
+ error(
45651
+ errorLocation,
45652
+ errorLocation && propertyWithInvalidInitializer.type && textRangeContainsPositionInclusive(propertyWithInvalidInitializer.type, errorLocation.pos) ? Diagnostics.Type_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor : Diagnostics.Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor,
45653
+ declarationNameToString(propertyWithInvalidInitializer.name),
45654
+ diagnosticName(name)
45655
+ );
45656
+ return true;
45174
45657
  }
45175
45658
  return false;
45176
- function requiresScopeChange(node) {
45177
- return requiresScopeChangeWorker(node.name) || !!node.initializer && requiresScopeChangeWorker(node.initializer);
45178
- }
45179
- function requiresScopeChangeWorker(node) {
45180
- switch (node.kind) {
45181
- case 219 /* ArrowFunction */:
45182
- case 218 /* FunctionExpression */:
45183
- case 262 /* FunctionDeclaration */:
45184
- case 176 /* Constructor */:
45185
- return false;
45186
- case 174 /* MethodDeclaration */:
45187
- case 177 /* GetAccessor */:
45188
- case 178 /* SetAccessor */:
45189
- case 303 /* PropertyAssignment */:
45190
- return requiresScopeChangeWorker(node.name);
45191
- case 172 /* PropertyDeclaration */:
45192
- if (hasStaticModifier(node)) {
45193
- return !emitStandardClassFields;
45194
- }
45195
- return requiresScopeChangeWorker(node.name);
45196
- default:
45197
- if (isNullishCoalesce(node) || isOptionalChain(node)) {
45198
- return target < 7 /* ES2020 */;
45199
- }
45200
- if (isBindingElement(node) && node.dotDotDotToken && isObjectBindingPattern(node.parent)) {
45201
- return target < 4 /* ES2017 */;
45202
- }
45203
- if (isTypeNode(node))
45204
- return false;
45205
- return forEachChild(node, requiresScopeChangeWorker) || false;
45206
- }
45207
- }
45208
- }
45209
- function isConstAssertion(location) {
45210
- return isAssertionExpression(location) && isConstTypeReference(location.type) || isJSDocTypeTag(location) && isConstTypeReference(location.typeExpression);
45211
45659
  }
45212
- function resolveName(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals = false, getSpellingSuggestions = true) {
45213
- return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSpellingSuggestions, getSymbol);
45214
- }
45215
- function resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSpellingSuggestions, lookup) {
45216
- var _a, _b, _c;
45217
- const originalLocation = location;
45218
- let result;
45219
- let lastLocation;
45220
- let lastSelfReferenceLocation;
45221
- let propertyWithInvalidInitializer;
45222
- let associatedDeclarationForContainingInitializerOrBindingName;
45223
- let withinDeferredContext = false;
45224
- const errorLocation = location;
45225
- let grandparent;
45226
- let isInExternalModule = false;
45227
- loop:
45228
- while (location) {
45229
- if (name === "const" && isConstAssertion(location)) {
45230
- return void 0;
45231
- }
45232
- if (isModuleOrEnumDeclaration(location) && lastLocation && location.name === lastLocation) {
45233
- lastLocation = location;
45234
- location = location.parent;
45235
- }
45236
- if (canHaveLocals(location) && location.locals && !isGlobalSourceFile(location)) {
45237
- if (result = lookup(location.locals, name, meaning)) {
45238
- let useResult = true;
45239
- if (isFunctionLike(location) && lastLocation && lastLocation !== location.body) {
45240
- if (meaning & result.flags & 788968 /* Type */ && lastLocation.kind !== 320 /* JSDoc */) {
45241
- useResult = result.flags & 262144 /* TypeParameter */ ? lastLocation === location.type || lastLocation.kind === 169 /* Parameter */ || lastLocation.kind === 341 /* JSDocParameterTag */ || lastLocation.kind === 342 /* JSDocReturnTag */ || lastLocation.kind === 168 /* TypeParameter */ : false;
45242
- }
45243
- if (meaning & result.flags & 3 /* Variable */) {
45244
- if (useOuterVariableScopeInParameter(result, location, lastLocation)) {
45245
- useResult = false;
45246
- } else if (result.flags & 1 /* FunctionScopedVariable */) {
45247
- useResult = lastLocation.kind === 169 /* Parameter */ || lastLocation === location.type && !!findAncestor(result.valueDeclaration, isParameter);
45248
- }
45249
- }
45250
- } else if (location.kind === 194 /* ConditionalType */) {
45251
- useResult = lastLocation === location.trueType;
45252
- }
45253
- if (useResult) {
45254
- break loop;
45255
- } else {
45256
- result = void 0;
45660
+ function onFailedToResolveSymbol(errorLocation, nameArg, meaning, nameNotFoundMessage) {
45661
+ const name = isString(nameArg) ? nameArg : nameArg.escapedText;
45662
+ addLazyDiagnostic(() => {
45663
+ if (!errorLocation || errorLocation.parent.kind !== 324 /* JSDocLink */ && !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && !checkAndReportErrorForExtendingInterface(errorLocation) && !checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) && !checkAndReportErrorForExportingPrimitiveType(errorLocation, name) && !checkAndReportErrorForUsingNamespaceAsTypeOrValue(errorLocation, name, meaning) && !checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning) && !checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
45664
+ let suggestion;
45665
+ let suggestedLib;
45666
+ if (nameArg) {
45667
+ suggestedLib = getSuggestedLibForNonExistentName(nameArg);
45668
+ if (suggestedLib) {
45669
+ error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg), suggestedLib);
45670
+ }
45671
+ }
45672
+ if (!suggestedLib && suggestionCount < maximumSuggestionCount) {
45673
+ suggestion = getSuggestedSymbolForNonexistentSymbol(errorLocation, name, meaning);
45674
+ const isGlobalScopeAugmentationDeclaration = (suggestion == null ? void 0 : suggestion.valueDeclaration) && isAmbientModule(suggestion.valueDeclaration) && isGlobalScopeAugmentation(suggestion.valueDeclaration);
45675
+ if (isGlobalScopeAugmentationDeclaration) {
45676
+ suggestion = void 0;
45677
+ }
45678
+ if (suggestion) {
45679
+ const suggestionName = symbolToString(suggestion);
45680
+ const isUncheckedJS = isUncheckedJSSuggestion(
45681
+ errorLocation,
45682
+ suggestion,
45683
+ /*excludeClasses*/
45684
+ false
45685
+ );
45686
+ const message = meaning === 1920 /* Namespace */ || nameArg && typeof nameArg !== "string" && nodeIsSynthesized(nameArg) ? Diagnostics.Cannot_find_namespace_0_Did_you_mean_1 : isUncheckedJS ? Diagnostics.Could_not_find_name_0_Did_you_mean_1 : Diagnostics.Cannot_find_name_0_Did_you_mean_1;
45687
+ const diagnostic = createError(errorLocation, message, diagnosticName(nameArg), suggestionName);
45688
+ addErrorOrSuggestion(!isUncheckedJS, diagnostic);
45689
+ if (suggestion.valueDeclaration) {
45690
+ addRelatedInfo(
45691
+ diagnostic,
45692
+ createDiagnosticForNode(suggestion.valueDeclaration, Diagnostics._0_is_declared_here, suggestionName)
45693
+ );
45257
45694
  }
45258
45695
  }
45259
45696
  }
45260
- withinDeferredContext = withinDeferredContext || getIsDeferredContext(location, lastLocation);
45261
- switch (location.kind) {
45262
- case 307 /* SourceFile */:
45263
- if (!isExternalOrCommonJsModule(location))
45264
- break;
45265
- isInExternalModule = true;
45266
- case 267 /* ModuleDeclaration */:
45267
- const moduleExports = ((_a = getSymbolOfDeclaration(location)) == null ? void 0 : _a.exports) || emptySymbols;
45268
- if (location.kind === 307 /* SourceFile */ || isModuleDeclaration(location) && location.flags & 33554432 /* Ambient */ && !isGlobalScopeAugmentation(location)) {
45269
- if (result = moduleExports.get("default" /* Default */)) {
45270
- const localSymbol = getLocalSymbolForExportDefault(result);
45271
- if (localSymbol && result.flags & meaning && localSymbol.escapedName === name) {
45272
- break loop;
45273
- }
45274
- result = void 0;
45275
- }
45276
- const moduleExport = moduleExports.get(name);
45277
- if (moduleExport && moduleExport.flags === 2097152 /* Alias */ && (getDeclarationOfKind(moduleExport, 281 /* ExportSpecifier */) || getDeclarationOfKind(moduleExport, 280 /* NamespaceExport */))) {
45278
- break;
45279
- }
45280
- }
45281
- if (name !== "default" /* Default */ && (result = lookup(moduleExports, name, meaning & 2623475 /* ModuleMember */))) {
45282
- if (isSourceFile(location) && location.commonJsModuleIndicator && !((_b = result.declarations) == null ? void 0 : _b.some(isJSDocTypeAlias))) {
45283
- result = void 0;
45284
- } else {
45285
- break loop;
45286
- }
45287
- }
45288
- break;
45289
- case 266 /* EnumDeclaration */:
45290
- if (result = lookup(((_c = getSymbolOfDeclaration(location)) == null ? void 0 : _c.exports) || emptySymbols, name, meaning & 8 /* EnumMember */)) {
45291
- if (nameNotFoundMessage && getIsolatedModules(compilerOptions) && !(location.flags & 33554432 /* Ambient */) && getSourceFileOfNode(location) !== getSourceFileOfNode(result.valueDeclaration)) {
45292
- error(
45293
- errorLocation,
45294
- Diagnostics.Cannot_access_0_from_another_file_without_qualification_when_1_is_enabled_Use_2_instead,
45295
- unescapeLeadingUnderscores(name),
45296
- isolatedModulesLikeFlagName,
45297
- `${unescapeLeadingUnderscores(getSymbolOfNode(location).escapedName)}.${unescapeLeadingUnderscores(name)}`
45298
- );
45299
- }
45300
- break loop;
45301
- }
45302
- break;
45303
- case 172 /* PropertyDeclaration */:
45304
- if (!isStatic(location)) {
45305
- const ctor = findConstructorDeclaration(location.parent);
45306
- if (ctor && ctor.locals) {
45307
- if (lookup(ctor.locals, name, meaning & 111551 /* Value */)) {
45308
- Debug.assertNode(location, isPropertyDeclaration);
45309
- propertyWithInvalidInitializer = location;
45310
- }
45311
- }
45312
- }
45313
- break;
45314
- case 263 /* ClassDeclaration */:
45315
- case 231 /* ClassExpression */:
45316
- case 264 /* InterfaceDeclaration */:
45317
- if (result = lookup(getSymbolOfDeclaration(location).members || emptySymbols, name, meaning & 788968 /* Type */)) {
45318
- if (!isTypeParameterSymbolDeclaredInContainer(result, location)) {
45319
- result = void 0;
45320
- break;
45321
- }
45322
- if (lastLocation && isStatic(lastLocation)) {
45323
- if (nameNotFoundMessage) {
45324
- error(errorLocation, Diagnostics.Static_members_cannot_reference_class_type_parameters);
45325
- }
45326
- return void 0;
45327
- }
45328
- break loop;
45329
- }
45330
- if (isClassExpression(location) && meaning & 32 /* Class */) {
45331
- const className = location.name;
45332
- if (className && name === className.escapedText) {
45333
- result = location.symbol;
45334
- break loop;
45335
- }
45336
- }
45337
- break;
45338
- case 233 /* ExpressionWithTypeArguments */:
45339
- if (lastLocation === location.expression && location.parent.token === 96 /* ExtendsKeyword */) {
45340
- const container = location.parent.parent;
45341
- if (isClassLike(container) && (result = lookup(getSymbolOfDeclaration(container).members, name, meaning & 788968 /* Type */))) {
45342
- if (nameNotFoundMessage) {
45343
- error(errorLocation, Diagnostics.Base_class_expressions_cannot_reference_class_type_parameters);
45344
- }
45345
- return void 0;
45346
- }
45347
- }
45348
- break;
45349
- case 167 /* ComputedPropertyName */:
45350
- grandparent = location.parent.parent;
45351
- if (isClassLike(grandparent) || grandparent.kind === 264 /* InterfaceDeclaration */) {
45352
- if (result = lookup(getSymbolOfDeclaration(grandparent).members, name, meaning & 788968 /* Type */)) {
45353
- if (nameNotFoundMessage) {
45354
- error(errorLocation, Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type);
45355
- }
45356
- return void 0;
45357
- }
45358
- }
45359
- break;
45360
- case 219 /* ArrowFunction */:
45361
- if (getEmitScriptTarget(compilerOptions) >= 2 /* ES2015 */) {
45362
- break;
45363
- }
45364
- case 174 /* MethodDeclaration */:
45365
- case 176 /* Constructor */:
45366
- case 177 /* GetAccessor */:
45367
- case 178 /* SetAccessor */:
45368
- case 262 /* FunctionDeclaration */:
45369
- if (meaning & 3 /* Variable */ && name === "arguments") {
45370
- result = argumentsSymbol;
45371
- break loop;
45372
- }
45373
- break;
45374
- case 218 /* FunctionExpression */:
45375
- if (meaning & 3 /* Variable */ && name === "arguments") {
45376
- result = argumentsSymbol;
45377
- break loop;
45378
- }
45379
- if (meaning & 16 /* Function */) {
45380
- const functionName = location.name;
45381
- if (functionName && name === functionName.escapedText) {
45382
- result = location.symbol;
45383
- break loop;
45384
- }
45385
- }
45386
- break;
45387
- case 170 /* Decorator */:
45388
- if (location.parent && location.parent.kind === 169 /* Parameter */) {
45389
- location = location.parent;
45390
- }
45391
- if (location.parent && (isClassElement(location.parent) || location.parent.kind === 263 /* ClassDeclaration */)) {
45392
- location = location.parent;
45393
- }
45394
- break;
45395
- case 346 /* JSDocTypedefTag */:
45396
- case 338 /* JSDocCallbackTag */:
45397
- case 340 /* JSDocEnumTag */:
45398
- case 351 /* JSDocImportTag */:
45399
- const root = getJSDocRoot(location);
45400
- if (root) {
45401
- location = root.parent;
45402
- }
45403
- break;
45404
- case 169 /* Parameter */:
45405
- if (lastLocation && (lastLocation === location.initializer || lastLocation === location.name && isBindingPattern(lastLocation))) {
45406
- if (!associatedDeclarationForContainingInitializerOrBindingName) {
45407
- associatedDeclarationForContainingInitializerOrBindingName = location;
45408
- }
45409
- }
45410
- break;
45411
- case 208 /* BindingElement */:
45412
- if (lastLocation && (lastLocation === location.initializer || lastLocation === location.name && isBindingPattern(lastLocation))) {
45413
- if (isParameterDeclaration(location) && !associatedDeclarationForContainingInitializerOrBindingName) {
45414
- associatedDeclarationForContainingInitializerOrBindingName = location;
45415
- }
45416
- }
45417
- break;
45418
- case 195 /* InferType */:
45419
- if (meaning & 262144 /* TypeParameter */) {
45420
- const parameterName = location.typeParameter.name;
45421
- if (parameterName && name === parameterName.escapedText) {
45422
- result = location.typeParameter.symbol;
45423
- break loop;
45424
- }
45425
- }
45426
- break;
45427
- case 281 /* ExportSpecifier */:
45428
- if (lastLocation && lastLocation === location.propertyName && location.parent.parent.moduleSpecifier) {
45429
- location = location.parent.parent.parent;
45430
- }
45431
- break;
45697
+ if (!suggestion && !suggestedLib && nameArg) {
45698
+ error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg));
45432
45699
  }
45433
- if (isSelfReferenceLocation(location)) {
45434
- lastSelfReferenceLocation = location;
45435
- }
45436
- lastLocation = location;
45437
- location = isJSDocTemplateTag(location) ? getEffectiveContainerForJSDocTemplateTag(location) || location.parent : isJSDocParameterTag(location) || isJSDocReturnTag(location) ? getHostSignatureFromJSDoc(location) || location.parent : location.parent;
45438
- }
45439
- if (isUse && result && (!lastSelfReferenceLocation || result !== lastSelfReferenceLocation.symbol)) {
45440
- result.isReferenced |= meaning;
45441
- }
45442
- if (!result) {
45443
- if (lastLocation) {
45444
- Debug.assertNode(lastLocation, isSourceFile);
45445
- if (lastLocation.commonJsModuleIndicator && name === "exports" && meaning & lastLocation.symbol.flags) {
45446
- return lastLocation.symbol;
45447
- }
45448
- }
45449
- if (!excludeGlobals) {
45450
- result = lookup(globals, name, meaning);
45700
+ suggestionCount++;
45451
45701
  }
45452
- }
45453
- if (!result) {
45454
- if (originalLocation && isInJSFile(originalLocation) && originalLocation.parent) {
45455
- if (isRequireCall(
45456
- originalLocation.parent,
45457
- /*requireStringLiteralLikeArgument*/
45458
- false
45459
- )) {
45460
- return requireSymbol;
45702
+ });
45703
+ }
45704
+ function onSuccessfullyResolvedSymbol(errorLocation, result, meaning, lastLocation, associatedDeclarationForContainingInitializerOrBindingName, withinDeferredContext) {
45705
+ addLazyDiagnostic(() => {
45706
+ var _a;
45707
+ const name = result.escapedName;
45708
+ const isInExternalModule = lastLocation && isSourceFile(lastLocation) && isExternalOrCommonJsModule(lastLocation);
45709
+ if (errorLocation && (meaning & 2 /* BlockScopedVariable */ || (meaning & 32 /* Class */ || meaning & 384 /* Enum */) && (meaning & 111551 /* Value */) === 111551 /* Value */)) {
45710
+ const exportOrLocalSymbol = getExportSymbolOfValueSymbolIfExported(result);
45711
+ if (exportOrLocalSymbol.flags & 2 /* BlockScopedVariable */ || exportOrLocalSymbol.flags & 32 /* Class */ || exportOrLocalSymbol.flags & 384 /* Enum */) {
45712
+ checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation);
45713
+ }
45714
+ }
45715
+ if (isInExternalModule && (meaning & 111551 /* Value */) === 111551 /* Value */ && !(errorLocation.flags & 16777216 /* JSDoc */)) {
45716
+ const merged = getMergedSymbol(result);
45717
+ if (length(merged.declarations) && every(merged.declarations, (d) => isNamespaceExportDeclaration(d) || isSourceFile(d) && !!d.symbol.globalExports)) {
45718
+ errorOrSuggestion(!compilerOptions.allowUmdGlobalAccess, errorLocation, Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, unescapeLeadingUnderscores(name));
45719
+ }
45720
+ }
45721
+ if (associatedDeclarationForContainingInitializerOrBindingName && !withinDeferredContext && (meaning & 111551 /* Value */) === 111551 /* Value */) {
45722
+ const candidate = getMergedSymbol(getLateBoundSymbol(result));
45723
+ const root = getRootDeclaration(associatedDeclarationForContainingInitializerOrBindingName);
45724
+ if (candidate === getSymbolOfDeclaration(associatedDeclarationForContainingInitializerOrBindingName)) {
45725
+ error(errorLocation, Diagnostics.Parameter_0_cannot_reference_itself, declarationNameToString(associatedDeclarationForContainingInitializerOrBindingName.name));
45726
+ } else if (candidate.valueDeclaration && candidate.valueDeclaration.pos > associatedDeclarationForContainingInitializerOrBindingName.pos && root.parent.locals && getSymbol(root.parent.locals, candidate.escapedName, meaning) === candidate) {
45727
+ error(errorLocation, Diagnostics.Parameter_0_cannot_reference_identifier_1_declared_after_it, declarationNameToString(associatedDeclarationForContainingInitializerOrBindingName.name), declarationNameToString(errorLocation));
45728
+ }
45729
+ }
45730
+ if (errorLocation && meaning & 111551 /* Value */ && result.flags & 2097152 /* Alias */ && !(result.flags & 111551 /* Value */) && !isValidTypeOnlyAliasUseSite(errorLocation)) {
45731
+ const typeOnlyDeclaration = getTypeOnlyAliasDeclaration(result, 111551 /* Value */);
45732
+ if (typeOnlyDeclaration) {
45733
+ const message = typeOnlyDeclaration.kind === 281 /* ExportSpecifier */ || typeOnlyDeclaration.kind === 278 /* ExportDeclaration */ || typeOnlyDeclaration.kind === 280 /* NamespaceExport */ ? Diagnostics._0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type : Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type;
45734
+ const unescapedName = unescapeLeadingUnderscores(name);
45735
+ addTypeOnlyDeclarationRelatedInfo(
45736
+ error(errorLocation, message, unescapedName),
45737
+ typeOnlyDeclaration,
45738
+ unescapedName
45739
+ );
45461
45740
  }
45462
45741
  }
45463
- }
45464
- function checkAndReportErrorForInvalidInitializer() {
45465
- if (propertyWithInvalidInitializer && !emitStandardClassFields) {
45466
- error(
45467
- errorLocation,
45468
- errorLocation && propertyWithInvalidInitializer.type && textRangeContainsPositionInclusive(propertyWithInvalidInitializer.type, errorLocation.pos) ? Diagnostics.Type_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor : Diagnostics.Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor,
45469
- declarationNameToString(propertyWithInvalidInitializer.name),
45470
- diagnosticName(nameArg)
45471
- );
45472
- return true;
45473
- }
45474
- return false;
45475
- }
45476
- if (!result) {
45477
- if (nameNotFoundMessage) {
45478
- addLazyDiagnostic(() => {
45479
- if (!errorLocation || errorLocation.parent.kind !== 324 /* JSDocLink */ && !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && // TODO: GH#18217
45480
- !checkAndReportErrorForInvalidInitializer() && !checkAndReportErrorForExtendingInterface(errorLocation) && !checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) && !checkAndReportErrorForExportingPrimitiveType(errorLocation, name) && !checkAndReportErrorForUsingNamespaceAsTypeOrValue(errorLocation, name, meaning) && !checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning) && !checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
45481
- let suggestion;
45482
- let suggestedLib;
45483
- if (nameArg) {
45484
- suggestedLib = getSuggestedLibForNonExistentName(nameArg);
45485
- if (suggestedLib) {
45486
- error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg), suggestedLib);
45487
- }
45488
- }
45489
- if (!suggestedLib && getSpellingSuggestions && suggestionCount < maximumSuggestionCount) {
45490
- suggestion = getSuggestedSymbolForNonexistentSymbol(originalLocation, name, meaning);
45491
- const isGlobalScopeAugmentationDeclaration = (suggestion == null ? void 0 : suggestion.valueDeclaration) && isAmbientModule(suggestion.valueDeclaration) && isGlobalScopeAugmentation(suggestion.valueDeclaration);
45492
- if (isGlobalScopeAugmentationDeclaration) {
45493
- suggestion = void 0;
45494
- }
45495
- if (suggestion) {
45496
- const suggestionName = symbolToString(suggestion);
45497
- const isUncheckedJS = isUncheckedJSSuggestion(
45498
- originalLocation,
45499
- suggestion,
45500
- /*excludeClasses*/
45501
- false
45502
- );
45503
- const message = meaning === 1920 /* Namespace */ || nameArg && typeof nameArg !== "string" && nodeIsSynthesized(nameArg) ? Diagnostics.Cannot_find_namespace_0_Did_you_mean_1 : isUncheckedJS ? Diagnostics.Could_not_find_name_0_Did_you_mean_1 : Diagnostics.Cannot_find_name_0_Did_you_mean_1;
45504
- const diagnostic = createError(errorLocation, message, diagnosticName(nameArg), suggestionName);
45505
- addErrorOrSuggestion(!isUncheckedJS, diagnostic);
45506
- if (suggestion.valueDeclaration) {
45507
- addRelatedInfo(
45508
- diagnostic,
45509
- createDiagnosticForNode(suggestion.valueDeclaration, Diagnostics._0_is_declared_here, suggestionName)
45510
- );
45511
- }
45512
- }
45513
- }
45514
- if (!suggestion && !suggestedLib && nameArg) {
45515
- error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg));
45516
- }
45517
- suggestionCount++;
45518
- }
45519
- });
45520
- }
45521
- return void 0;
45522
- } else if (nameNotFoundMessage && checkAndReportErrorForInvalidInitializer()) {
45523
- return void 0;
45524
- }
45525
- if (nameNotFoundMessage) {
45526
- addLazyDiagnostic(() => {
45527
- var _a2;
45528
- if (errorLocation && (meaning & 2 /* BlockScopedVariable */ || (meaning & 32 /* Class */ || meaning & 384 /* Enum */) && (meaning & 111551 /* Value */) === 111551 /* Value */)) {
45529
- const exportOrLocalSymbol = getExportSymbolOfValueSymbolIfExported(result);
45530
- if (exportOrLocalSymbol.flags & 2 /* BlockScopedVariable */ || exportOrLocalSymbol.flags & 32 /* Class */ || exportOrLocalSymbol.flags & 384 /* Enum */) {
45531
- checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation);
45532
- }
45533
- }
45534
- if (result && isInExternalModule && (meaning & 111551 /* Value */) === 111551 /* Value */ && !(originalLocation.flags & 16777216 /* JSDoc */)) {
45535
- const merged = getMergedSymbol(result);
45536
- if (length(merged.declarations) && every(merged.declarations, (d) => isNamespaceExportDeclaration(d) || isSourceFile(d) && !!d.symbol.globalExports)) {
45537
- errorOrSuggestion(!compilerOptions.allowUmdGlobalAccess, errorLocation, Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, unescapeLeadingUnderscores(name));
45538
- }
45539
- }
45540
- if (result && associatedDeclarationForContainingInitializerOrBindingName && !withinDeferredContext && (meaning & 111551 /* Value */) === 111551 /* Value */) {
45541
- const candidate = getMergedSymbol(getLateBoundSymbol(result));
45542
- const root = getRootDeclaration(associatedDeclarationForContainingInitializerOrBindingName);
45543
- if (candidate === getSymbolOfDeclaration(associatedDeclarationForContainingInitializerOrBindingName)) {
45544
- error(errorLocation, Diagnostics.Parameter_0_cannot_reference_itself, declarationNameToString(associatedDeclarationForContainingInitializerOrBindingName.name));
45545
- } else if (candidate.valueDeclaration && candidate.valueDeclaration.pos > associatedDeclarationForContainingInitializerOrBindingName.pos && root.parent.locals && lookup(root.parent.locals, candidate.escapedName, meaning) === candidate) {
45546
- error(errorLocation, Diagnostics.Parameter_0_cannot_reference_identifier_1_declared_after_it, declarationNameToString(associatedDeclarationForContainingInitializerOrBindingName.name), declarationNameToString(errorLocation));
45742
+ if (compilerOptions.isolatedModules && result && isInExternalModule && (meaning & 111551 /* Value */) === 111551 /* Value */) {
45743
+ const isGlobal = getSymbol(globals, name, meaning) === result;
45744
+ const nonValueSymbol = isGlobal && isSourceFile(lastLocation) && lastLocation.locals && getSymbol(lastLocation.locals, name, ~111551 /* Value */);
45745
+ if (nonValueSymbol) {
45746
+ const importDecl = (_a = nonValueSymbol.declarations) == null ? void 0 : _a.find((d) => d.kind === 276 /* ImportSpecifier */ || d.kind === 273 /* ImportClause */ || d.kind === 274 /* NamespaceImport */ || d.kind === 271 /* ImportEqualsDeclaration */);
45747
+ if (importDecl && !isTypeOnlyImportDeclaration(importDecl)) {
45748
+ error(importDecl, Diagnostics.Import_0_conflicts_with_global_value_used_in_this_file_so_must_be_declared_with_a_type_only_import_when_isolatedModules_is_enabled, unescapeLeadingUnderscores(name));
45547
45749
  }
45548
45750
  }
45549
- if (result && errorLocation && meaning & 111551 /* Value */ && result.flags & 2097152 /* Alias */ && !(result.flags & 111551 /* Value */) && !isValidTypeOnlyAliasUseSite(errorLocation)) {
45550
- const typeOnlyDeclaration = getTypeOnlyAliasDeclaration(result, 111551 /* Value */);
45551
- if (typeOnlyDeclaration) {
45552
- const message = typeOnlyDeclaration.kind === 281 /* ExportSpecifier */ || typeOnlyDeclaration.kind === 278 /* ExportDeclaration */ || typeOnlyDeclaration.kind === 280 /* NamespaceExport */ ? Diagnostics._0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type : Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type;
45553
- const unescapedName = unescapeLeadingUnderscores(name);
45554
- addTypeOnlyDeclarationRelatedInfo(
45555
- error(errorLocation, message, unescapedName),
45556
- typeOnlyDeclaration,
45557
- unescapedName
45558
- );
45559
- }
45560
- }
45561
- if (compilerOptions.isolatedModules && result && isInExternalModule && (meaning & 111551 /* Value */) === 111551 /* Value */) {
45562
- const isGlobal = lookup(globals, name, meaning) === result;
45563
- const nonValueSymbol = isGlobal && isSourceFile(lastLocation) && lastLocation.locals && lookup(lastLocation.locals, name, ~111551 /* Value */);
45564
- if (nonValueSymbol) {
45565
- const importDecl = (_a2 = nonValueSymbol.declarations) == null ? void 0 : _a2.find((d) => d.kind === 276 /* ImportSpecifier */ || d.kind === 273 /* ImportClause */ || d.kind === 274 /* NamespaceImport */ || d.kind === 271 /* ImportEqualsDeclaration */);
45566
- if (importDecl && !isTypeOnlyImportDeclaration(importDecl)) {
45567
- error(importDecl, Diagnostics.Import_0_conflicts_with_global_value_used_in_this_file_so_must_be_declared_with_a_type_only_import_when_isolatedModules_is_enabled, unescapeLeadingUnderscores(name));
45568
- }
45569
- }
45570
- }
45571
- });
45572
- }
45573
- return result;
45751
+ }
45752
+ });
45574
45753
  }
45575
45754
  function addTypeOnlyDeclarationRelatedInfo(diagnostic, typeOnlyDeclaration, unescapedName) {
45576
45755
  if (!typeOnlyDeclaration)
@@ -45584,47 +45763,9 @@ function createTypeChecker(host) {
45584
45763
  )
45585
45764
  );
45586
45765
  }
45587
- function getIsDeferredContext(location, lastLocation) {
45588
- if (location.kind !== 219 /* ArrowFunction */ && location.kind !== 218 /* FunctionExpression */) {
45589
- return isTypeQueryNode(location) || (isFunctionLikeDeclaration(location) || location.kind === 172 /* PropertyDeclaration */ && !isStatic(location)) && (!lastLocation || lastLocation !== location.name);
45590
- }
45591
- if (lastLocation && lastLocation === location.name) {
45592
- return false;
45593
- }
45594
- if (location.asteriskToken || hasSyntacticModifier(location, 1024 /* Async */)) {
45595
- return true;
45596
- }
45597
- return !getImmediatelyInvokedFunctionExpression(location);
45598
- }
45599
- function isSelfReferenceLocation(node) {
45600
- switch (node.kind) {
45601
- case 262 /* FunctionDeclaration */:
45602
- case 263 /* ClassDeclaration */:
45603
- case 264 /* InterfaceDeclaration */:
45604
- case 266 /* EnumDeclaration */:
45605
- case 265 /* TypeAliasDeclaration */:
45606
- case 267 /* ModuleDeclaration */:
45607
- return true;
45608
- default:
45609
- return false;
45610
- }
45611
- }
45612
45766
  function diagnosticName(nameArg) {
45613
45767
  return isString(nameArg) ? unescapeLeadingUnderscores(nameArg) : declarationNameToString(nameArg);
45614
45768
  }
45615
- function isTypeParameterSymbolDeclaredInContainer(symbol, container) {
45616
- if (symbol.declarations) {
45617
- for (const decl of symbol.declarations) {
45618
- if (decl.kind === 168 /* TypeParameter */) {
45619
- const parent = isJSDocTemplateTag(decl.parent) ? getJSDocHost(decl.parent) : decl.parent;
45620
- if (parent === container) {
45621
- return !(isJSDocTemplateTag(decl.parent) && find(decl.parent.parent.tags, isJSDocTypeAlias));
45622
- }
45623
- }
45624
- }
45625
- }
45626
- return false;
45627
- }
45628
45769
  function checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) {
45629
45770
  if (!isIdentifier(errorLocation) || errorLocation.escapedText !== name || isTypeReferenceIdentifier(errorLocation) || isInTypeQuery(errorLocation)) {
45630
45771
  return false;
@@ -45695,8 +45836,6 @@ function createTypeChecker(host) {
45695
45836
  788968 /* Type */ & ~namespaceMeaning,
45696
45837
  /*nameNotFoundMessage*/
45697
45838
  void 0,
45698
- /*nameArg*/
45699
- void 0,
45700
45839
  /*isUse*/
45701
45840
  false
45702
45841
  ));
@@ -45730,8 +45869,6 @@ function createTypeChecker(host) {
45730
45869
  ~788968 /* Type */ & 111551 /* Value */,
45731
45870
  /*nameNotFoundMessage*/
45732
45871
  void 0,
45733
- /*nameArg*/
45734
- void 0,
45735
45872
  /*isUse*/
45736
45873
  false
45737
45874
  ));
@@ -45777,8 +45914,6 @@ function createTypeChecker(host) {
45777
45914
  788968 /* Type */ & ~111551 /* Value */,
45778
45915
  /*nameNotFoundMessage*/
45779
45916
  void 0,
45780
- /*nameArg*/
45781
- void 0,
45782
45917
  /*isUse*/
45783
45918
  false
45784
45919
  ));
@@ -45830,8 +45965,6 @@ function createTypeChecker(host) {
45830
45965
  1024 /* NamespaceModule */,
45831
45966
  /*nameNotFoundMessage*/
45832
45967
  void 0,
45833
- /*nameArg*/
45834
- void 0,
45835
45968
  /*isUse*/
45836
45969
  false
45837
45970
  ));
@@ -45850,8 +45983,6 @@ function createTypeChecker(host) {
45850
45983
  1536 /* Module */,
45851
45984
  /*nameNotFoundMessage*/
45852
45985
  void 0,
45853
- /*nameArg*/
45854
- void 0,
45855
45986
  /*isUse*/
45856
45987
  false
45857
45988
  ));
@@ -45982,22 +46113,28 @@ function createTypeChecker(host) {
45982
46113
  function isSyntacticDefault(node) {
45983
46114
  return isExportAssignment(node) && !node.isExportEquals || hasSyntacticModifier(node, 2048 /* Default */) || isExportSpecifier(node) || isNamespaceExport(node);
45984
46115
  }
45985
- function getUsageModeForExpression(usage) {
45986
- return isStringLiteralLike(usage) ? host.getModeForUsageLocation(getSourceFileOfNode(usage), usage) : void 0;
46116
+ function getEmitSyntaxForModuleSpecifierExpression(usage) {
46117
+ return isStringLiteralLike(usage) ? host.getEmitSyntaxForUsageLocation(getSourceFileOfNode(usage), usage) : void 0;
45987
46118
  }
45988
46119
  function isESMFormatImportImportingCommonjsFormatFile(usageMode, targetMode) {
45989
46120
  return usageMode === 99 /* ESNext */ && targetMode === 1 /* CommonJS */;
45990
46121
  }
45991
- function isOnlyImportedAsDefault(usage) {
45992
- const usageMode = getUsageModeForExpression(usage);
45993
- return usageMode === 99 /* ESNext */ && endsWith(usage.text, ".json" /* Json */);
46122
+ function isOnlyImportableAsDefault(usage) {
46123
+ if (100 /* Node16 */ <= moduleKind && moduleKind <= 199 /* NodeNext */) {
46124
+ const usageMode = getEmitSyntaxForModuleSpecifierExpression(usage);
46125
+ return usageMode === 99 /* ESNext */ && endsWith(usage.text, ".json" /* Json */);
46126
+ }
46127
+ return false;
45994
46128
  }
45995
46129
  function canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, usage) {
45996
- const usageMode = file && getUsageModeForExpression(usage);
45997
- if (file && usageMode !== void 0 && 100 /* Node16 */ <= moduleKind && moduleKind <= 199 /* NodeNext */) {
45998
- const result = isESMFormatImportImportingCommonjsFormatFile(usageMode, file.impliedNodeFormat);
45999
- if (usageMode === 99 /* ESNext */ || result) {
46000
- return result;
46130
+ const usageMode = file && getEmitSyntaxForModuleSpecifierExpression(usage);
46131
+ if (file && usageMode !== void 0) {
46132
+ const targetMode = host.getImpliedNodeFormatForEmit(file);
46133
+ if (usageMode === 99 /* ESNext */ && targetMode === 1 /* CommonJS */ && 100 /* Node16 */ <= moduleKind && moduleKind <= 199 /* NodeNext */) {
46134
+ return true;
46135
+ }
46136
+ if (usageMode === 99 /* ESNext */ && targetMode === 99 /* ESNext */) {
46137
+ return false;
46001
46138
  }
46002
46139
  }
46003
46140
  if (!allowSyntheticDefaultImports) {
@@ -46056,7 +46193,7 @@ function createTypeChecker(host) {
46056
46193
  if (!specifier) {
46057
46194
  return exportDefaultSymbol;
46058
46195
  }
46059
- const hasDefaultOnly = isOnlyImportedAsDefault(specifier);
46196
+ const hasDefaultOnly = isOnlyImportableAsDefault(specifier);
46060
46197
  const hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, specifier);
46061
46198
  if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) {
46062
46199
  if (hasExportAssignmentSymbol(moduleSymbol) && !allowSyntheticDefaultImports) {
@@ -46260,7 +46397,7 @@ function createTypeChecker(host) {
46260
46397
  let symbolFromModule = getExportOfModule(targetSymbol, name, specifier, dontResolveAlias);
46261
46398
  if (symbolFromModule === void 0 && name.escapedText === "default" /* Default */) {
46262
46399
  const file = (_a = moduleSymbol.declarations) == null ? void 0 : _a.find(isSourceFile);
46263
- if (isOnlyImportedAsDefault(moduleSpecifier) || canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, moduleSpecifier)) {
46400
+ if (isOnlyImportableAsDefault(moduleSpecifier) || canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, moduleSpecifier)) {
46264
46401
  symbolFromModule = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias);
46265
46402
  }
46266
46403
  }
@@ -46667,11 +46804,10 @@ function createTypeChecker(host) {
46667
46804
  let left = getFirstIdentifier(node);
46668
46805
  let symbol = resolveName(
46669
46806
  left,
46670
- left.escapedText,
46807
+ left,
46671
46808
  111551 /* Value */,
46672
46809
  /*nameNotFoundMessage*/
46673
46810
  void 0,
46674
- left,
46675
46811
  /*isUse*/
46676
46812
  true
46677
46813
  );
@@ -46699,10 +46835,9 @@ function createTypeChecker(host) {
46699
46835
  const symbolFromJSPrototype = isInJSFile(name) && !nodeIsSynthesized(name) ? resolveEntityNameFromAssignmentDeclaration(name, meaning) : void 0;
46700
46836
  symbol = getMergedSymbol(resolveName(
46701
46837
  location || name,
46702
- name.escapedText,
46838
+ name,
46703
46839
  meaning,
46704
46840
  ignoreErrors || symbolFromJSPrototype ? void 0 : message,
46705
- name,
46706
46841
  /*isUse*/
46707
46842
  true,
46708
46843
  /*excludeGlobals*/
@@ -46798,11 +46933,10 @@ function createTypeChecker(host) {
46798
46933
  if (secondaryLocation) {
46799
46934
  return resolveName(
46800
46935
  secondaryLocation,
46801
- name.escapedText,
46936
+ name,
46802
46937
  meaning,
46803
46938
  /*nameNotFoundMessage*/
46804
46939
  void 0,
46805
- name,
46806
46940
  /*isUse*/
46807
46941
  true
46808
46942
  );
@@ -46893,7 +47027,7 @@ function createTypeChecker(host) {
46893
47027
  /*requireStringLiteralLikeArgument*/
46894
47028
  true
46895
47029
  ) ? 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);
46896
- const mode = contextSpecifier && isStringLiteralLike(contextSpecifier) ? host.getModeForUsageLocation(currentSourceFile, contextSpecifier) : currentSourceFile.impliedNodeFormat;
47030
+ const mode = contextSpecifier && isStringLiteralLike(contextSpecifier) ? host.getModeForUsageLocation(currentSourceFile, contextSpecifier) : host.getDefaultResolutionModeForFile(currentSourceFile);
46897
47031
  const moduleResolutionKind = getEmitModuleResolutionKind(compilerOptions);
46898
47032
  const resolvedModule = (_g = host.getResolvedModule(currentSourceFile, moduleReference, mode)) == null ? void 0 : _g.resolvedModule;
46899
47033
  const resolutionDiagnostic = resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule, currentSourceFile);
@@ -47138,7 +47272,7 @@ function createTypeChecker(host) {
47138
47272
  return cloneTypeAsModuleType(symbol, defaultOnlyType, referenceParent);
47139
47273
  }
47140
47274
  const targetFile = (_a = moduleSymbol == null ? void 0 : moduleSymbol.declarations) == null ? void 0 : _a.find(isSourceFile);
47141
- const isEsmCjsRef = targetFile && isESMFormatImportImportingCommonjsFormatFile(getUsageModeForExpression(reference), targetFile.impliedNodeFormat);
47275
+ const isEsmCjsRef = targetFile && isESMFormatImportImportingCommonjsFormatFile(getEmitSyntaxForModuleSpecifierExpression(reference), host.getImpliedNodeFormatForEmit(targetFile));
47142
47276
  if (getESModuleInterop(compilerOptions) || isEsmCjsRef) {
47143
47277
  let sigs = getSignaturesOfStructuredType(type, 0 /* Call */);
47144
47278
  if (!sigs || !sigs.length) {
@@ -47500,14 +47634,6 @@ function createTypeChecker(host) {
47500
47634
  function symbolIsValue(symbol, includeTypeOnlyMembers) {
47501
47635
  return !!(symbol.flags & 111551 /* Value */ || symbol.flags & 2097152 /* Alias */ && getSymbolFlags(symbol, !includeTypeOnlyMembers) & 111551 /* Value */);
47502
47636
  }
47503
- function findConstructorDeclaration(node) {
47504
- const members = node.members;
47505
- for (const member of members) {
47506
- if (member.kind === 176 /* Constructor */ && nodeIsPresent(member.body)) {
47507
- return member;
47508
- }
47509
- }
47510
- }
47511
47637
  function createType(flags) {
47512
47638
  var _a;
47513
47639
  const result = new Type7(checker, flags);
@@ -47989,8 +48115,6 @@ function createTypeChecker(host) {
47989
48115
  meaning,
47990
48116
  /*nameNotFoundMessage*/
47991
48117
  void 0,
47992
- /*nameArg*/
47993
- void 0,
47994
48118
  /*isUse*/
47995
48119
  false
47996
48120
  );
@@ -49561,8 +49685,6 @@ function createTypeChecker(host) {
49561
49685
  111551 /* Value */ | 1048576 /* ExportValue */,
49562
49686
  /*nameNotFoundMessage*/
49563
49687
  void 0,
49564
- /*nameArg*/
49565
- void 0,
49566
49688
  /*isUse*/
49567
49689
  true
49568
49690
  );
@@ -49703,14 +49825,16 @@ function createTypeChecker(host) {
49703
49825
  return symbol.escapedName.substring(1, symbol.escapedName.length - 1);
49704
49826
  }
49705
49827
  }
49706
- if (!context.enclosingDeclaration || !context.tracker.moduleResolverHost) {
49828
+ if (!context.enclosingFile || !context.tracker.moduleResolverHost) {
49707
49829
  if (ambientModuleSymbolRegex.test(symbol.escapedName)) {
49708
49830
  return symbol.escapedName.substring(1, symbol.escapedName.length - 1);
49709
49831
  }
49710
49832
  return getSourceFileOfNode(getNonAugmentationDeclaration(symbol)).fileName;
49711
49833
  }
49712
- const contextFile = getSourceFileOfNode(getOriginalNode(context.enclosingDeclaration));
49713
- const resolutionMode = overrideImportMode || (contextFile == null ? void 0 : contextFile.impliedNodeFormat);
49834
+ const enclosingDeclaration = getOriginalNode(context.enclosingDeclaration);
49835
+ const originalModuleSpecifier = canHaveModuleSpecifier(enclosingDeclaration) ? tryGetModuleSpecifierFromDeclaration(enclosingDeclaration) : void 0;
49836
+ const contextFile = context.enclosingFile;
49837
+ const resolutionMode = overrideImportMode || originalModuleSpecifier && host.getModeForUsageLocation(contextFile, originalModuleSpecifier) || contextFile && host.getDefaultResolutionModeForFile(contextFile);
49714
49838
  const cacheKey = createModeAwareCacheKey(contextFile.path, resolutionMode);
49715
49839
  const links = getSymbolLinks(symbol);
49716
49840
  let specifier = links.specifierCache && links.specifierCache.get(cacheKey);
@@ -49886,7 +50010,6 @@ function createTypeChecker(host) {
49886
50010
  788968 /* Type */,
49887
50011
  /*nameNotFoundMessage*/
49888
50012
  void 0,
49889
- escapedName,
49890
50013
  /*isUse*/
49891
50014
  false
49892
50015
  );
@@ -50447,22 +50570,16 @@ function createTypeChecker(host) {
50447
50570
  return p.name && isIdentifier(p.name) && p.name.escapedText === "this" ? "this" : getEffectiveDotDotDotForParameter(p) ? `args` : `arg${index}`;
50448
50571
  }
50449
50572
  function rewriteModuleSpecifier(parent, lit) {
50450
- if (context.bundled) {
50451
- if (context.tracker && context.tracker.moduleResolverHost) {
50452
- const targetFile = getExternalModuleFileFromDeclaration(parent);
50453
- if (targetFile) {
50454
- const getCanonicalFileName = createGetCanonicalFileName(!!host.useCaseSensitiveFileNames);
50455
- const resolverHost = {
50456
- getCanonicalFileName,
50457
- getCurrentDirectory: () => context.tracker.moduleResolverHost.getCurrentDirectory(),
50458
- getCommonSourceDirectory: () => context.tracker.moduleResolverHost.getCommonSourceDirectory()
50459
- };
50460
- const newName = getResolvedExternalModuleName(resolverHost, targetFile);
50461
- return factory.createStringLiteral(newName);
50573
+ if (context.bundled || context.enclosingFile !== getSourceFileOfNode(lit)) {
50574
+ const targetFile = getExternalModuleFileFromDeclaration(parent);
50575
+ if (targetFile) {
50576
+ const newName = getSpecifierForModuleSymbol(targetFile.symbol, context);
50577
+ if (newName !== lit.text) {
50578
+ return setOriginalNode(factory.createStringLiteral(newName), lit);
50462
50579
  }
50463
50580
  }
50464
50581
  }
50465
- return lit;
50582
+ return visitNode(lit, visitExistingNodeTreeSymbols, isStringLiteral);
50466
50583
  }
50467
50584
  }
50468
50585
  }
@@ -52218,11 +52335,10 @@ function createTypeChecker(host) {
52218
52335
  if (node.parent && node.parent.kind === 277 /* ExportAssignment */) {
52219
52336
  exportSymbol = resolveName(
52220
52337
  node,
52221
- node.escapedText,
52338
+ node,
52222
52339
  111551 /* Value */ | 788968 /* Type */ | 1920 /* Namespace */ | 2097152 /* Alias */,
52223
52340
  /*nameNotFoundMessage*/
52224
52341
  void 0,
52225
- node,
52226
52342
  /*isUse*/
52227
52343
  false
52228
52344
  );
@@ -52255,8 +52371,6 @@ function createTypeChecker(host) {
52255
52371
  111551 /* Value */ | 788968 /* Type */ | 1920 /* Namespace */,
52256
52372
  /*nameNotFoundMessage*/
52257
52373
  void 0,
52258
- /*nameArg*/
52259
- void 0,
52260
52374
  /*isUse*/
52261
52375
  false
52262
52376
  );
@@ -56076,8 +56190,6 @@ function createTypeChecker(host) {
56076
56190
  111551 /* Value */,
56077
56191
  /*nameNotFoundMessage*/
56078
56192
  void 0,
56079
- /*nameArg*/
56080
- void 0,
56081
56193
  /*isUse*/
56082
56194
  false
56083
56195
  );
@@ -57111,12 +57223,9 @@ function createTypeChecker(host) {
57111
57223
  name,
57112
57224
  meaning,
57113
57225
  diagnostic,
57114
- name,
57115
57226
  /*isUse*/
57116
57227
  false,
57117
57228
  /*excludeGlobals*/
57118
- false,
57119
- /*getSpellingSuggestions*/
57120
57229
  false
57121
57230
  );
57122
57231
  }
@@ -64501,7 +64610,6 @@ function createTypeChecker(host) {
64501
64610
  788968 /* Type */,
64502
64611
  /*nameNotFoundMessage*/
64503
64612
  void 0,
64504
- param.name.escapedText,
64505
64613
  /*isUse*/
64506
64614
  true
64507
64615
  ) || originalKeywordKind && isTypeNodeKind(originalKeywordKind))) {
@@ -65723,10 +65831,9 @@ function createTypeChecker(host) {
65723
65831
  if (!links.resolvedSymbol) {
65724
65832
  links.resolvedSymbol = !nodeIsMissing(node) && resolveName(
65725
65833
  node,
65726
- node.escapedText,
65834
+ node,
65727
65835
  111551 /* Value */ | 1048576 /* ExportValue */,
65728
65836
  getCannotFindNameDiagnosticForName(node),
65729
- node,
65730
65837
  !isWriteOnlyAccess(node),
65731
65838
  /*excludeGlobals*/
65732
65839
  false
@@ -68962,7 +69069,6 @@ function createTypeChecker(host) {
68962
69069
  111551 /* Value */,
68963
69070
  /*nameNotFoundMessage*/
68964
69071
  void 0,
68965
- id.escapedText,
68966
69072
  /*isUse*/
68967
69073
  true
68968
69074
  );
@@ -69012,8 +69118,6 @@ function createTypeChecker(host) {
69012
69118
  111551 /* Value */,
69013
69119
  /*nameNotFoundMessage*/
69014
69120
  void 0,
69015
- /*nameArg*/
69016
- void 0,
69017
69121
  /*isUse*/
69018
69122
  true,
69019
69123
  /*excludeGlobals*/
@@ -70390,7 +70494,6 @@ function createTypeChecker(host) {
70390
70494
  1920 /* Namespace */,
70391
70495
  /*nameNotFoundMessage*/
70392
70496
  void 0,
70393
- namespaceName,
70394
70497
  /*isUse*/
70395
70498
  false
70396
70499
  );
@@ -70605,7 +70708,6 @@ function createTypeChecker(host) {
70605
70708
  jsxFactoryNamespace,
70606
70709
  111551 /* Value */,
70607
70710
  jsxFactoryRefErr,
70608
- jsxFactoryNamespace,
70609
70711
  /*isUse*/
70610
70712
  true
70611
70713
  );
@@ -70625,7 +70727,6 @@ function createTypeChecker(host) {
70625
70727
  localJsxNamespace,
70626
70728
  111551 /* Value */,
70627
70729
  jsxFactoryRefErr,
70628
- localJsxNamespace,
70629
70730
  /*isUse*/
70630
70731
  true
70631
70732
  );
@@ -71346,38 +71447,34 @@ function createTypeChecker(host) {
71346
71447
  const suggestion = getSuggestedSymbolForNonexistentProperty(name, containingType);
71347
71448
  return suggestion && symbolName(suggestion);
71348
71449
  }
71450
+ function getSuggestionForSymbolNameLookup(symbols, name, meaning) {
71451
+ const symbol = getSymbol(symbols, name, meaning);
71452
+ if (symbol)
71453
+ return symbol;
71454
+ let candidates;
71455
+ if (symbols === globals) {
71456
+ const primitives = mapDefined(
71457
+ ["string", "number", "boolean", "object", "bigint", "symbol"],
71458
+ (s) => symbols.has(s.charAt(0).toUpperCase() + s.slice(1)) ? createSymbol(524288 /* TypeAlias */, s) : void 0
71459
+ );
71460
+ candidates = primitives.concat(arrayFrom(symbols.values()));
71461
+ } else {
71462
+ candidates = arrayFrom(symbols.values());
71463
+ }
71464
+ return getSpellingSuggestionForName(unescapeLeadingUnderscores(name), candidates, meaning);
71465
+ }
71349
71466
  function getSuggestedSymbolForNonexistentSymbol(location, outerName, meaning) {
71350
71467
  Debug.assert(outerName !== void 0, "outername should always be defined");
71351
- const result = resolveNameHelper(
71468
+ const result = resolveNameForSymbolSuggestion(
71352
71469
  location,
71353
71470
  outerName,
71354
71471
  meaning,
71355
71472
  /*nameNotFoundMessage*/
71356
71473
  void 0,
71357
- outerName,
71358
71474
  /*isUse*/
71359
71475
  false,
71360
71476
  /*excludeGlobals*/
71361
- false,
71362
- /*getSpellingSuggestions*/
71363
- true,
71364
- (symbols, name, meaning2) => {
71365
- Debug.assertEqual(outerName, name, "name should equal outerName");
71366
- const symbol = getSymbol(symbols, name, meaning2);
71367
- if (symbol)
71368
- return symbol;
71369
- let candidates;
71370
- if (symbols === globals) {
71371
- const primitives = mapDefined(
71372
- ["string", "number", "boolean", "object", "bigint", "symbol"],
71373
- (s) => symbols.has(s.charAt(0).toUpperCase() + s.slice(1)) ? createSymbol(524288 /* TypeAlias */, s) : void 0
71374
- );
71375
- candidates = primitives.concat(arrayFrom(symbols.values()));
71376
- } else {
71377
- candidates = arrayFrom(symbols.values());
71378
- }
71379
- return getSpellingSuggestionForName(unescapeLeadingUnderscores(name), candidates, meaning2);
71380
- }
71477
+ false
71381
71478
  );
71382
71479
  return result;
71383
71480
  }
@@ -72234,8 +72331,6 @@ function createTypeChecker(host) {
72234
72331
  111551 /* Value */,
72235
72332
  /*nameNotFoundMessage*/
72236
72333
  void 0,
72237
- /*nameArg*/
72238
- void 0,
72239
72334
  /*isUse*/
72240
72335
  false
72241
72336
  );
@@ -72575,6 +72670,7 @@ function createTypeChecker(host) {
72575
72670
  candidateForTypeArgumentError = oldCandidateForTypeArgumentError;
72576
72671
  }
72577
72672
  function chooseOverload(candidates2, relation, isSingleNonGenericCandidate2, signatureHelpTrailingComma2 = false) {
72673
+ var _a, _b;
72578
72674
  candidatesForArgumentError = void 0;
72579
72675
  candidateForArgumentArityError = void 0;
72580
72676
  candidateForTypeArgumentError = void 0;
@@ -72609,7 +72705,9 @@ function createTypeChecker(host) {
72609
72705
  let checkCandidate;
72610
72706
  let inferenceContext;
72611
72707
  if (candidate.typeParameters) {
72612
- if (candidate.declaration && findAncestor(node, (a) => a === candidate.declaration)) {
72708
+ const paramLocation = (_b = (_a = candidate.typeParameters[0].symbol.declarations) == null ? void 0 : _a[0]) == null ? void 0 : _b.parent;
72709
+ const candidateParameterContext = paramLocation || (candidate.declaration && isConstructorDeclaration(candidate.declaration) ? candidate.declaration.parent : candidate.declaration);
72710
+ if (candidateParameterContext && findAncestor(node, (a) => a === candidateParameterContext)) {
72613
72711
  candidate = getImplementationSignature(candidate);
72614
72712
  }
72615
72713
  let typeArgumentTypes;
@@ -73499,8 +73597,6 @@ function createTypeChecker(host) {
73499
73597
  111551 /* Value */,
73500
73598
  /*nameNotFoundMessage*/
73501
73599
  void 0,
73502
- /*nameArg*/
73503
- void 0,
73504
73600
  /*isUse*/
73505
73601
  false
73506
73602
  );
@@ -73557,7 +73653,7 @@ function createTypeChecker(host) {
73557
73653
  return createAnonymousType(anonymousSymbol, memberTable, emptyArray, emptyArray, emptyArray);
73558
73654
  }
73559
73655
  function getTypeWithSyntheticDefaultOnly(type, symbol, originalSymbol, moduleSpecifier) {
73560
- const hasDefaultOnly = isOnlyImportedAsDefault(moduleSpecifier);
73656
+ const hasDefaultOnly = isOnlyImportableAsDefault(moduleSpecifier);
73561
73657
  if (hasDefaultOnly && type && !isErrorType(type)) {
73562
73658
  const synthType = type;
73563
73659
  if (!synthType.defaultOnlyType) {
@@ -73618,8 +73714,6 @@ function createTypeChecker(host) {
73618
73714
  111551 /* Value */,
73619
73715
  /*nameNotFoundMessage*/
73620
73716
  void 0,
73621
- /*nameArg*/
73622
- void 0,
73623
73717
  /*isUse*/
73624
73718
  true
73625
73719
  );
@@ -75955,7 +76049,6 @@ function createTypeChecker(host) {
75955
76049
  788968 /* Type */,
75956
76050
  /*nameNotFoundMessage*/
75957
76051
  void 0,
75958
- name,
75959
76052
  /*isUse*/
75960
76053
  false
75961
76054
  );
@@ -78243,8 +78336,6 @@ function createTypeChecker(host) {
78243
78336
  meaning,
78244
78337
  /*nameNotFoundMessage*/
78245
78338
  void 0,
78246
- /*nameArg*/
78247
- void 0,
78248
78339
  /*isUse*/
78249
78340
  true
78250
78341
  );
@@ -78899,7 +78990,7 @@ function createTypeChecker(host) {
78899
78990
  });
78900
78991
  }
78901
78992
  function checkCollisionWithRequireExportsInGeneratedCode(node, name) {
78902
- if (moduleKind >= 5 /* ES2015 */ && !(moduleKind >= 100 /* Node16 */ && getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) {
78993
+ if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) >= 5 /* ES2015 */) {
78903
78994
  return;
78904
78995
  }
78905
78996
  if (!name || !needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) {
@@ -78996,8 +79087,6 @@ function createTypeChecker(host) {
78996
79087
  3 /* Variable */,
78997
79088
  /*nameNotFoundMessage*/
78998
79089
  void 0,
78999
- /*nameArg*/
79000
- void 0,
79001
79090
  /*isUse*/
79002
79091
  false
79003
79092
  );
@@ -80330,7 +80419,7 @@ function createTypeChecker(host) {
80330
80419
  }
80331
80420
  }
80332
80421
  function checkClassNameCollisionWithObject(name) {
80333
- if (languageVersion >= 1 /* ES5 */ && name.escapedText === "Object" && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(name).impliedNodeFormat === 1 /* CommonJS */)) {
80422
+ if (languageVersion >= 1 /* ES5 */ && name.escapedText === "Object" && host.getEmitModuleFormatOfFile(getSourceFileOfNode(name)) < 5 /* ES2015 */) {
80334
80423
  error(name, Diagnostics.Class_name_cannot_be_Object_when_targeting_ES5_with_module_0, ModuleKind[moduleKind]);
80335
80424
  }
80336
80425
  }
@@ -81400,7 +81489,7 @@ function createTypeChecker(host) {
81400
81489
  getNodeLinks(node).flags |= 2048 /* LexicalModuleMergesWithClass */;
81401
81490
  }
81402
81491
  }
81403
- if (compilerOptions.verbatimModuleSyntax && node.parent.kind === 307 /* SourceFile */ && (moduleKind === 1 /* CommonJS */ || node.parent.impliedNodeFormat === 1 /* CommonJS */)) {
81492
+ if (compilerOptions.verbatimModuleSyntax && node.parent.kind === 307 /* SourceFile */ && host.getEmitModuleFormatOfFile(node.parent) === 1 /* CommonJS */) {
81404
81493
  const exportModifier = (_b = node.modifiers) == null ? void 0 : _b.find((m) => m.kind === 95 /* ExportKeyword */);
81405
81494
  if (exportModifier) {
81406
81495
  error(exportModifier, Diagnostics.A_top_level_export_modifier_cannot_be_used_on_value_declarations_in_a_CommonJS_module_when_verbatimModuleSyntax_is_enabled);
@@ -81610,8 +81699,10 @@ function createTypeChecker(host) {
81610
81699
  }
81611
81700
  }
81612
81701
  }
81613
- if (compilerOptions.verbatimModuleSyntax && node.kind !== 271 /* ImportEqualsDeclaration */ && !isInJSFile(node) && (moduleKind === 1 /* CommonJS */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) {
81702
+ if (compilerOptions.verbatimModuleSyntax && node.kind !== 271 /* ImportEqualsDeclaration */ && !isInJSFile(node) && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === 1 /* CommonJS */) {
81614
81703
  error(node, Diagnostics.ESM_syntax_is_not_allowed_in_a_CommonJS_module_when_verbatimModuleSyntax_is_enabled);
81704
+ } else if (moduleKind === 200 /* Preserve */ && node.kind !== 271 /* ImportEqualsDeclaration */ && node.kind !== 260 /* VariableDeclaration */ && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === 1 /* CommonJS */) {
81705
+ error(node, Diagnostics.ESM_syntax_is_not_allowed_in_a_CommonJS_module_when_module_is_set_to_preserve);
81615
81706
  }
81616
81707
  }
81617
81708
  if (isImportSpecifier(node)) {
@@ -81653,7 +81744,7 @@ function createTypeChecker(host) {
81653
81744
  function checkImportBinding(node) {
81654
81745
  checkCollisionsForDeclarationName(node, node.name);
81655
81746
  checkAliasSymbol(node);
81656
- if (node.kind === 276 /* ImportSpecifier */ && idText(node.propertyName || node.name) === "default" && getESModuleInterop(compilerOptions) && moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) {
81747
+ if (node.kind === 276 /* ImportSpecifier */ && idText(node.propertyName || node.name) === "default" && getESModuleInterop(compilerOptions) && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */) {
81657
81748
  checkExternalEmitHelpers(node, 131072 /* ImportDefault */);
81658
81749
  }
81659
81750
  }
@@ -81674,7 +81765,7 @@ function createTypeChecker(host) {
81674
81765
  if (validForTypeAttributes && override) {
81675
81766
  return;
81676
81767
  }
81677
- const mode = moduleKind === 199 /* NodeNext */ && declaration.moduleSpecifier && getUsageModeForExpression(declaration.moduleSpecifier);
81768
+ const mode = moduleKind === 199 /* NodeNext */ && declaration.moduleSpecifier && getEmitSyntaxForModuleSpecifierExpression(declaration.moduleSpecifier);
81678
81769
  if (mode !== 99 /* ESNext */ && moduleKind !== 99 /* ESNext */ && moduleKind !== 200 /* Preserve */) {
81679
81770
  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;
81680
81771
  return grammarErrorOnNode(node, message);
@@ -81707,7 +81798,7 @@ function createTypeChecker(host) {
81707
81798
  if (importClause.namedBindings) {
81708
81799
  if (importClause.namedBindings.kind === 274 /* NamespaceImport */) {
81709
81800
  checkImportBinding(importClause.namedBindings);
81710
- if (moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */) && getESModuleInterop(compilerOptions)) {
81801
+ if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */ && getESModuleInterop(compilerOptions)) {
81711
81802
  checkExternalEmitHelpers(node, 65536 /* ImportStar */);
81712
81803
  }
81713
81804
  } else {
@@ -81749,7 +81840,7 @@ function createTypeChecker(host) {
81749
81840
  grammarErrorOnNode(node, Diagnostics.An_import_alias_cannot_use_import_type);
81750
81841
  }
81751
81842
  } else {
81752
- if (moduleKind >= 5 /* ES2015 */ && moduleKind !== 200 /* Preserve */ && getSourceFileOfNode(node).impliedNodeFormat === void 0 && !node.isTypeOnly && !(node.flags & 33554432 /* Ambient */)) {
81843
+ if (5 /* ES2015 */ <= moduleKind && moduleKind <= 99 /* ESNext */ && !node.isTypeOnly && !(node.flags & 33554432 /* Ambient */)) {
81753
81844
  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);
81754
81845
  }
81755
81846
  }
@@ -81778,7 +81869,7 @@ function createTypeChecker(host) {
81778
81869
  } else if (node.exportClause) {
81779
81870
  checkAliasSymbol(node.exportClause);
81780
81871
  }
81781
- if (moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) {
81872
+ if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */) {
81782
81873
  if (node.exportClause) {
81783
81874
  if (getESModuleInterop(compilerOptions)) {
81784
81875
  checkExternalEmitHelpers(node, 65536 /* ImportStar */);
@@ -81822,8 +81913,6 @@ function createTypeChecker(host) {
81822
81913
  111551 /* Value */ | 788968 /* Type */ | 1920 /* Namespace */ | 2097152 /* Alias */,
81823
81914
  /*nameNotFoundMessage*/
81824
81915
  void 0,
81825
- /*nameArg*/
81826
- void 0,
81827
81916
  /*isUse*/
81828
81917
  true
81829
81918
  );
@@ -81839,7 +81928,7 @@ function createTypeChecker(host) {
81839
81928
  }
81840
81929
  }
81841
81930
  } else {
81842
- if (getESModuleInterop(compilerOptions) && moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */) && idText(node.propertyName || node.name) === "default") {
81931
+ if (getESModuleInterop(compilerOptions) && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */ && idText(node.propertyName || node.name) === "default") {
81843
81932
  checkExternalEmitHelpers(node, 131072 /* ImportDefault */);
81844
81933
  }
81845
81934
  }
@@ -81865,7 +81954,7 @@ function createTypeChecker(host) {
81865
81954
  if (typeAnnotationNode) {
81866
81955
  checkTypeAssignableTo(checkExpressionCached(node.expression), getTypeFromTypeNode(typeAnnotationNode), node.expression);
81867
81956
  }
81868
- const isIllegalExportDefaultInCJS = !node.isExportEquals && !(node.flags & 33554432 /* Ambient */) && compilerOptions.verbatimModuleSyntax && (moduleKind === 1 /* CommonJS */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */);
81957
+ const isIllegalExportDefaultInCJS = !node.isExportEquals && !(node.flags & 33554432 /* Ambient */) && compilerOptions.verbatimModuleSyntax && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === 1 /* CommonJS */;
81869
81958
  if (node.expression.kind === 80 /* Identifier */) {
81870
81959
  const id = node.expression;
81871
81960
  const sym = getExportSymbolOfValueSymbolIfExported(resolveEntityName(
@@ -81945,7 +82034,7 @@ function createTypeChecker(host) {
81945
82034
  grammarErrorOnNode(node.expression, Diagnostics.The_expression_of_an_export_assignment_must_be_an_identifier_or_qualified_name_in_an_ambient_context);
81946
82035
  }
81947
82036
  if (node.isExportEquals) {
81948
- 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 */)) {
82037
+ 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 */)) {
81949
82038
  grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_export_default_or_another_module_format_instead);
81950
82039
  } else if (moduleKind === 4 /* System */ && !(node.flags & 33554432 /* Ambient */)) {
81951
82040
  grammarErrorOnNode(node, Diagnostics.Export_assignment_is_not_supported_when_module_flag_is_system);
@@ -83240,8 +83329,6 @@ function createTypeChecker(host) {
83240
83329
  111551 /* Value */,
83241
83330
  /*nameNotFoundMessage*/
83242
83331
  void 0,
83243
- /*nameArg*/
83244
- void 0,
83245
83332
  /*isUse*/
83246
83333
  false
83247
83334
  )) {
@@ -83633,8 +83720,6 @@ function createTypeChecker(host) {
83633
83720
  111551 /* Value */ | 1048576 /* ExportValue */ | 2097152 /* Alias */,
83634
83721
  /*nameNotFoundMessage*/
83635
83722
  void 0,
83636
- /*nameArg*/
83637
- void 0,
83638
83723
  /*isUse*/
83639
83724
  true
83640
83725
  );
@@ -83650,13 +83735,9 @@ function createTypeChecker(host) {
83650
83735
  111551 /* Value */ | 1048576 /* ExportValue */ | 2097152 /* Alias */,
83651
83736
  /*nameNotFoundMessage*/
83652
83737
  void 0,
83653
- /*nameArg*/
83654
- void 0,
83655
83738
  /*isUse*/
83656
83739
  true,
83657
83740
  /*excludeGlobals*/
83658
- void 0,
83659
- /*getSpellingSuggestions*/
83660
83741
  void 0
83661
83742
  );
83662
83743
  }
@@ -84334,7 +84415,7 @@ function createTypeChecker(host) {
84334
84415
  break;
84335
84416
  case 95 /* ExportKeyword */:
84336
84417
  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
84337
- node.kind !== 267 /* ModuleDeclaration */ && node.parent.kind === 307 /* SourceFile */ && (moduleKind === 1 /* CommonJS */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) {
84418
+ node.kind !== 267 /* ModuleDeclaration */ && node.parent.kind === 307 /* SourceFile */ && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === 1 /* CommonJS */) {
84338
84419
  return grammarErrorOnNode(modifier, Diagnostics.A_top_level_export_modifier_cannot_be_used_on_value_declarations_in_a_CommonJS_module_when_verbatimModuleSyntax_is_enabled);
84339
84420
  }
84340
84421
  if (flags & 32 /* Export */) {
@@ -85245,7 +85326,7 @@ function createTypeChecker(host) {
85245
85326
  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;
85246
85327
  return grammarErrorOnNode(node.exclamationToken, message);
85247
85328
  }
85248
- if ((moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */) && moduleKind !== 4 /* System */ && !(node.parent.parent.flags & 33554432 /* Ambient */) && hasSyntacticModifier(node.parent.parent, 32 /* Export */)) {
85329
+ if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */ && !(node.parent.parent.flags & 33554432 /* Ambient */) && hasSyntacticModifier(node.parent.parent, 32 /* Export */)) {
85249
85330
  checkESModuleMarker(node.name);
85250
85331
  }
85251
85332
  return !!blockScopeKind && checkGrammarNameInLetOrConstDeclarations(node.name);
@@ -85732,7 +85813,9 @@ function createBasicNodeBuilderModuleSpecifierResolutionHost(host) {
85732
85813
  isSourceOfProjectReferenceRedirect: (fileName) => host.isSourceOfProjectReferenceRedirect(fileName),
85733
85814
  fileExists: (fileName) => host.fileExists(fileName),
85734
85815
  getFileIncludeReasons: () => host.getFileIncludeReasons(),
85735
- readFile: host.readFile ? (fileName) => host.readFile(fileName) : void 0
85816
+ readFile: host.readFile ? (fileName) => host.readFile(fileName) : void 0,
85817
+ getDefaultResolutionModeForFile: (file) => host.getDefaultResolutionModeForFile(file),
85818
+ getModeForResolutionAtIndex: (file, index) => host.getModeForResolutionAtIndex(file, index)
85736
85819
  };
85737
85820
  }
85738
85821
  var SymbolTrackerImpl = class _SymbolTrackerImpl {
@@ -104978,6 +105061,9 @@ function transformModule(context) {
104978
105061
  return updated;
104979
105062
  }
104980
105063
  function shouldEmitUnderscoreUnderscoreESModule() {
105064
+ if (hasJSFileExtension(currentSourceFile.fileName) && currentSourceFile.commonJsModuleIndicator && (!currentSourceFile.externalModuleIndicator || currentSourceFile.externalModuleIndicator === true)) {
105065
+ return false;
105066
+ }
104981
105067
  if (!currentModuleInfo.exportEquals && isExternalModule(currentSourceFile)) {
104982
105068
  return true;
104983
105069
  }
@@ -105456,7 +105542,7 @@ function transformModule(context) {
105456
105542
  case 354 /* PartiallyEmittedExpression */:
105457
105543
  return visitPartiallyEmittedExpression(node, valueIsDiscarded);
105458
105544
  case 213 /* CallExpression */:
105459
- if (isImportCall(node) && currentSourceFile.impliedNodeFormat === void 0) {
105545
+ if (isImportCall(node) && host.shouldTransformImportCall(currentSourceFile)) {
105460
105546
  return visitImportCallExpression(node);
105461
105547
  }
105462
105548
  break;
@@ -108457,8 +108543,8 @@ function transformECMAScriptModule(context) {
108457
108543
  }
108458
108544
  }
108459
108545
 
108460
- // src/compiler/transformers/module/node.ts
108461
- function transformNodeModule(context) {
108546
+ // src/compiler/transformers/module/impliedNodeFormatDependent.ts
108547
+ function transformImpliedNodeFormatDependentModule(context) {
108462
108548
  const previousOnSubstituteNode = context.onSubstituteNode;
108463
108549
  const previousOnEmitNode = context.onEmitNode;
108464
108550
  const esmTransform = transformECMAScriptModule(context);
@@ -108469,6 +108555,7 @@ function transformNodeModule(context) {
108469
108555
  const cjsTransform = transformModule(context);
108470
108556
  const cjsOnSubstituteNode = context.onSubstituteNode;
108471
108557
  const cjsOnEmitNode = context.onEmitNode;
108558
+ const getEmitModuleFormatOfFile = (file) => context.getEmitHost().getEmitModuleFormatOfFile(file);
108472
108559
  context.onSubstituteNode = onSubstituteNode;
108473
108560
  context.onEmitNode = onEmitNode;
108474
108561
  context.enableSubstitution(307 /* SourceFile */);
@@ -108483,7 +108570,7 @@ function transformNodeModule(context) {
108483
108570
  if (!currentSourceFile) {
108484
108571
  return previousOnSubstituteNode(hint, node);
108485
108572
  }
108486
- if (currentSourceFile.impliedNodeFormat === 99 /* ESNext */) {
108573
+ if (getEmitModuleFormatOfFile(currentSourceFile) >= 5 /* ES2015 */) {
108487
108574
  return esmOnSubstituteNode(hint, node);
108488
108575
  }
108489
108576
  return cjsOnSubstituteNode(hint, node);
@@ -108496,13 +108583,13 @@ function transformNodeModule(context) {
108496
108583
  if (!currentSourceFile) {
108497
108584
  return previousOnEmitNode(hint, node, emitCallback);
108498
108585
  }
108499
- if (currentSourceFile.impliedNodeFormat === 99 /* ESNext */) {
108586
+ if (getEmitModuleFormatOfFile(currentSourceFile) >= 5 /* ES2015 */) {
108500
108587
  return esmOnEmitNode(hint, node, emitCallback);
108501
108588
  }
108502
108589
  return cjsOnEmitNode(hint, node, emitCallback);
108503
108590
  }
108504
108591
  function getModuleTransformForFile(file) {
108505
- return file.impliedNodeFormat === 99 /* ESNext */ ? esmTransform : cjsTransform;
108592
+ return getEmitModuleFormatOfFile(file) >= 5 /* ES2015 */ ? esmTransform : cjsTransform;
108506
108593
  }
108507
108594
  function transformSourceFile(node) {
108508
108595
  if (node.isDeclarationFile) {
@@ -110405,17 +110492,18 @@ function isProcessedComponent(node) {
110405
110492
  // src/compiler/transformer.ts
110406
110493
  function getModuleTransformer(moduleKind) {
110407
110494
  switch (moduleKind) {
110495
+ case 200 /* Preserve */:
110496
+ return transformECMAScriptModule;
110408
110497
  case 99 /* ESNext */:
110409
110498
  case 7 /* ES2022 */:
110410
110499
  case 6 /* ES2020 */:
110411
110500
  case 5 /* ES2015 */:
110412
- case 200 /* Preserve */:
110413
- return transformECMAScriptModule;
110414
- case 4 /* System */:
110415
- return transformSystemModule;
110416
110501
  case 100 /* Node16 */:
110417
110502
  case 199 /* NodeNext */:
110418
- return transformNodeModule;
110503
+ case 1 /* CommonJS */:
110504
+ return transformImpliedNodeFormatDependentModule;
110505
+ case 4 /* System */:
110506
+ return transformSystemModule;
110419
110507
  default:
110420
110508
  return transformModule;
110421
110509
  }
@@ -111139,6 +111227,7 @@ function emitFiles(resolver, host, targetSourceFile, { scriptTransformers, decla
111139
111227
  newLine: compilerOptions.newLine,
111140
111228
  noEmitHelpers: compilerOptions.noEmitHelpers,
111141
111229
  module: getEmitModuleKind(compilerOptions),
111230
+ moduleResolution: getEmitModuleResolutionKind(compilerOptions),
111142
111231
  target: getEmitScriptTarget(compilerOptions),
111143
111232
  sourceMap: compilerOptions.sourceMap,
111144
111233
  inlineSourceMap: compilerOptions.inlineSourceMap,
@@ -111201,6 +111290,7 @@ function emitFiles(resolver, host, targetSourceFile, { scriptTransformers, decla
111201
111290
  newLine: compilerOptions.newLine,
111202
111291
  noEmitHelpers: true,
111203
111292
  module: compilerOptions.module,
111293
+ moduleResolution: compilerOptions.moduleResolution,
111204
111294
  target: compilerOptions.target,
111205
111295
  sourceMap: !forceDtsEmit && compilerOptions.declarationMap,
111206
111296
  inlineSourceMap: compilerOptions.inlineSourceMap,
@@ -116710,9 +116800,6 @@ function flattenDiagnosticMessageText(diag2, newLine, indent2 = 0) {
116710
116800
  function getModeForFileReference(ref, containingFileMode) {
116711
116801
  return (isString(ref) ? containingFileMode : ref.resolutionMode) || containingFileMode;
116712
116802
  }
116713
- function getModeForResolutionAtIndex(file, index, compilerOptions) {
116714
- return getModeForUsageLocationWorker(file, getModuleNameStringLiteralAt(file, index), compilerOptions);
116715
- }
116716
116803
  function isExclusivelyTypeOnlyImportOrExport(decl) {
116717
116804
  var _a;
116718
116805
  if (isExportDeclaration(decl)) {
@@ -116727,7 +116814,6 @@ function getModeForUsageLocation(file, usage, compilerOptions) {
116727
116814
  return getModeForUsageLocationWorker(file, usage, compilerOptions);
116728
116815
  }
116729
116816
  function getModeForUsageLocationWorker(file, usage, compilerOptions) {
116730
- var _a;
116731
116817
  if (isImportDeclaration(usage.parent) || isExportDeclaration(usage.parent)) {
116732
116818
  const isTypeOnly = isExclusivelyTypeOnlyImportOrExport(usage.parent);
116733
116819
  if (isTypeOnly) {
@@ -116743,20 +116829,28 @@ function getModeForUsageLocationWorker(file, usage, compilerOptions) {
116743
116829
  return override;
116744
116830
  }
116745
116831
  }
116746
- if (compilerOptions && getEmitModuleKind(compilerOptions) === 200 /* Preserve */) {
116747
- return usage.parent.parent && isImportEqualsDeclaration(usage.parent.parent) || isRequireCall(
116748
- usage.parent,
116749
- /*requireStringLiteralLikeArgument*/
116750
- false
116751
- ) ? 1 /* CommonJS */ : 99 /* ESNext */;
116832
+ if (compilerOptions && importSyntaxAffectsModuleResolution(compilerOptions)) {
116833
+ return getEmitSyntaxForUsageLocationWorker(file, usage, compilerOptions);
116752
116834
  }
116753
- if (file.impliedNodeFormat === void 0)
116835
+ }
116836
+ function getEmitSyntaxForUsageLocationWorker(file, usage, compilerOptions) {
116837
+ var _a;
116838
+ if (!compilerOptions) {
116754
116839
  return void 0;
116755
- if (file.impliedNodeFormat !== 99 /* ESNext */) {
116756
- return isImportCall(walkUpParenthesizedExpressions(usage.parent)) ? 99 /* ESNext */ : 1 /* CommonJS */;
116757
116840
  }
116758
116841
  const exprParentParent = (_a = walkUpParenthesizedExpressions(usage.parent)) == null ? void 0 : _a.parent;
116759
- return exprParentParent && isImportEqualsDeclaration(exprParentParent) ? 1 /* CommonJS */ : 99 /* ESNext */;
116842
+ if (exprParentParent && isImportEqualsDeclaration(exprParentParent) || isRequireCall(
116843
+ usage.parent,
116844
+ /*requireStringLiteralLikeArgument*/
116845
+ false
116846
+ )) {
116847
+ return 1 /* CommonJS */;
116848
+ }
116849
+ if (isImportCall(walkUpParenthesizedExpressions(usage.parent))) {
116850
+ return shouldTransformImportCallWorker(file, compilerOptions) ? 1 /* CommonJS */ : 99 /* ESNext */;
116851
+ }
116852
+ const fileEmitMode = getEmitModuleFormatOfFileWorker(file, compilerOptions);
116853
+ return fileEmitMode === 1 /* CommonJS */ ? 1 /* CommonJS */ : emitModuleKindIsNonNodeESM(fileEmitMode) || fileEmitMode === 200 /* Preserve */ ? 99 /* ESNext */ : void 0;
116760
116854
  }
116761
116855
  function getResolutionModeOverride(node, grammarErrorOnNode) {
116762
116856
  if (!node)
@@ -116816,7 +116910,7 @@ function getTypeReferenceResolutionName(entry) {
116816
116910
  }
116817
116911
  var typeReferenceResolutionNameAndModeGetter = {
116818
116912
  getName: getTypeReferenceResolutionName,
116819
- getMode: (entry, file) => getModeForFileReference(entry, file == null ? void 0 : file.impliedNodeFormat)
116913
+ getMode: (entry, file, compilerOptions) => getModeForFileReference(entry, file && getDefaultResolutionModeForFileWorker(file, compilerOptions))
116820
116914
  };
116821
116915
  function createTypeReferenceResolutionLoader(containingFile, redirectedReference, options, host, cache) {
116822
116916
  return {
@@ -117000,13 +117094,7 @@ function getConfigFileParsingDiagnostics(configFileParseResult) {
117000
117094
  return configFileParseResult.options.configFile ? [...configFileParseResult.options.configFile.parseDiagnostics, ...configFileParseResult.errors] : configFileParseResult.errors;
117001
117095
  }
117002
117096
  function getImpliedNodeFormatForFileWorker(fileName, packageJsonInfoCache, host, options) {
117003
- switch (getEmitModuleResolutionKind(options)) {
117004
- case 3 /* Node16 */:
117005
- case 99 /* NodeNext */:
117006
- return fileExtensionIsOneOf(fileName, [".d.mts" /* Dmts */, ".mts" /* Mts */, ".mjs" /* Mjs */]) ? 99 /* ESNext */ : fileExtensionIsOneOf(fileName, [".d.cts" /* Dcts */, ".cts" /* Cts */, ".cjs" /* Cjs */]) ? 1 /* CommonJS */ : fileExtensionIsOneOf(fileName, [".d.ts" /* Dts */, ".ts" /* Ts */, ".tsx" /* Tsx */, ".js" /* Js */, ".jsx" /* Jsx */]) ? lookupFromPackageJson() : void 0;
117007
- default:
117008
- return void 0;
117009
- }
117097
+ return fileExtensionIsOneOf(fileName, [".d.mts" /* Dmts */, ".mts" /* Mts */, ".mjs" /* Mjs */]) ? 99 /* ESNext */ : fileExtensionIsOneOf(fileName, [".d.cts" /* Dcts */, ".cts" /* Cts */, ".cjs" /* Cjs */]) ? 1 /* CommonJS */ : fileExtensionIsOneOf(fileName, [".d.ts" /* Dts */, ".ts" /* Ts */, ".tsx" /* Tsx */, ".js" /* Js */, ".jsx" /* Jsx */]) ? lookupFromPackageJson() : void 0;
117010
117098
  function lookupFromPackageJson() {
117011
117099
  const state = getTemporaryModuleResolutionState(packageJsonInfoCache, host, options);
117012
117100
  const packageJsonLocations = [];
@@ -117456,7 +117544,8 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
117456
117544
  isSourceFileFromExternalLibrary,
117457
117545
  isSourceFileDefaultLibrary,
117458
117546
  getModeForUsageLocation: getModeForUsageLocation2,
117459
- getModeForResolutionAtIndex: getModeForResolutionAtIndex2,
117547
+ getEmitSyntaxForUsageLocation,
117548
+ getModeForResolutionAtIndex,
117460
117549
  getSourceFileFromReference,
117461
117550
  getLibFileFromReference,
117462
117551
  sourceFileToPackageName,
@@ -117483,6 +117572,11 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
117483
117572
  forEachResolvedProjectReference: forEachResolvedProjectReference2,
117484
117573
  isSourceOfProjectReferenceRedirect,
117485
117574
  getRedirectReferenceForResolutionFromSourceOfProject,
117575
+ getCompilerOptionsForFile,
117576
+ getDefaultResolutionModeForFile: getDefaultResolutionModeForFile2,
117577
+ getEmitModuleFormatOfFile,
117578
+ getImpliedNodeFormatForEmit,
117579
+ shouldTransformImportCall,
117486
117580
  emitBuildInfo,
117487
117581
  fileExists,
117488
117582
  readFile,
@@ -118046,6 +118140,10 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
118046
118140
  getSymlinkCache,
118047
118141
  writeFile: writeFileCallback || writeFile2,
118048
118142
  isEmitBlocked,
118143
+ shouldTransformImportCall,
118144
+ getEmitModuleFormatOfFile,
118145
+ getDefaultResolutionModeForFile: getDefaultResolutionModeForFile2,
118146
+ getModeForResolutionAtIndex,
118049
118147
  readFile: (f) => host.readFile(f),
118050
118148
  fileExists: (f) => {
118051
118149
  const path = toPath3(f);
@@ -119081,10 +119179,14 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
119081
119179
  const resolvedTypeReferenceDirective = resolutions[index];
119082
119180
  const fileName = toFileNameLowerCase(ref.fileName);
119083
119181
  resolutionsInFile.set(fileName, getModeForFileReference(ref, file.impliedNodeFormat), resolvedTypeReferenceDirective);
119084
- const mode = ref.resolutionMode || file.impliedNodeFormat;
119182
+ const mode = ref.resolutionMode || getDefaultResolutionModeForFile2(file);
119085
119183
  processTypeReferenceDirective(fileName, mode, resolvedTypeReferenceDirective, { kind: 5 /* TypeReferenceDirective */, file: file.path, index });
119086
119184
  }
119087
119185
  }
119186
+ function getCompilerOptionsForFile(file) {
119187
+ var _a2;
119188
+ return ((_a2 = getRedirectReferenceForResolution(file)) == null ? void 0 : _a2.commandLine.options) || options;
119189
+ }
119088
119190
  function processTypeReferenceDirective(typeReferenceDirective, mode, resolution, reason) {
119089
119191
  var _a2, _b2;
119090
119192
  (_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 });
@@ -119232,13 +119334,12 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
119232
119334
  return host.getCanonicalFileName(fileName);
119233
119335
  }
119234
119336
  function processImportedModules(file) {
119235
- var _a2;
119236
119337
  collectExternalModuleReferences(file);
119237
119338
  if (file.imports.length || file.moduleAugmentations.length) {
119238
119339
  const moduleNames = getModuleNames(file);
119239
119340
  const resolutions = (resolvedModulesProcessing == null ? void 0 : resolvedModulesProcessing.get(file.path)) || resolveModuleNamesReusingOldState(moduleNames, file);
119240
119341
  Debug.assert(resolutions.length === moduleNames.length);
119241
- const optionsForFile = ((_a2 = getRedirectReferenceForResolution(file)) == null ? void 0 : _a2.commandLine.options) || options;
119342
+ const optionsForFile = getCompilerOptionsForFile(file);
119242
119343
  const resolutionsInFile = createModeAwareCache();
119243
119344
  (resolvedModules ?? (resolvedModules = /* @__PURE__ */ new Map())).set(file.path, resolutionsInFile);
119244
119345
  for (let index = 0; index < moduleNames.length; index++) {
@@ -119774,7 +119875,8 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
119774
119875
  fileIncludeReasons = void 0;
119775
119876
  const location = locationReason && getReferencedFileLocation(program, locationReason);
119776
119877
  const fileIncludeReasonDetails = fileIncludeReasons && chainDiagnosticMessages(fileIncludeReasons, Diagnostics.The_file_is_in_the_program_because_Colon);
119777
- const redirectInfo = file && explainIfFileIsRedirectAndImpliedFormat(file);
119878
+ const optionsForFile = file && getCompilerOptionsForFile(file) || options;
119879
+ const redirectInfo = file && explainIfFileIsRedirectAndImpliedFormat(file, optionsForFile);
119778
119880
  const chain = chainDiagnosticMessages(redirectInfo ? fileIncludeReasonDetails ? [fileIncludeReasonDetails, ...redirectInfo] : redirectInfo : fileIncludeReasonDetails, diagnostic, ...args || emptyArray);
119779
119881
  return location && isReferenceFileLocation(location) ? createFileDiagnosticFromMessageChain(location.file, location.pos, location.end - location.pos, chain, relatedInfo) : createCompilerDiagnosticFromMessageChain(chain, relatedInfo);
119780
119882
  function processReason(reason) {
@@ -120075,13 +120177,53 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config
120075
120177
  return symlinks;
120076
120178
  }
120077
120179
  function getModeForUsageLocation2(file, usage) {
120078
- var _a2;
120079
- const optionsForFile = ((_a2 = getRedirectReferenceForResolution(file)) == null ? void 0 : _a2.commandLine.options) || options;
120080
- return getModeForUsageLocationWorker(file, usage, optionsForFile);
120180
+ return getModeForUsageLocationWorker(file, usage, getCompilerOptionsForFile(file));
120081
120181
  }
120082
- function getModeForResolutionAtIndex2(file, index) {
120182
+ function getEmitSyntaxForUsageLocation(file, usage) {
120183
+ return getEmitSyntaxForUsageLocationWorker(file, usage, getCompilerOptionsForFile(file));
120184
+ }
120185
+ function getModeForResolutionAtIndex(file, index) {
120083
120186
  return getModeForUsageLocation2(file, getModuleNameStringLiteralAt(file, index));
120084
120187
  }
120188
+ function getDefaultResolutionModeForFile2(sourceFile) {
120189
+ return getDefaultResolutionModeForFileWorker(sourceFile, getCompilerOptionsForFile(sourceFile));
120190
+ }
120191
+ function getImpliedNodeFormatForEmit(sourceFile) {
120192
+ return getImpliedNodeFormatForEmitWorker(sourceFile, getCompilerOptionsForFile(sourceFile));
120193
+ }
120194
+ function getEmitModuleFormatOfFile(sourceFile) {
120195
+ return getEmitModuleFormatOfFileWorker(sourceFile, getCompilerOptionsForFile(sourceFile));
120196
+ }
120197
+ function shouldTransformImportCall(sourceFile) {
120198
+ return shouldTransformImportCallWorker(sourceFile, getCompilerOptionsForFile(sourceFile));
120199
+ }
120200
+ }
120201
+ function shouldTransformImportCallWorker(sourceFile, options) {
120202
+ const moduleKind = getEmitModuleKind(options);
120203
+ if (100 /* Node16 */ <= moduleKind && moduleKind <= 199 /* NodeNext */ || moduleKind === 200 /* Preserve */) {
120204
+ return false;
120205
+ }
120206
+ return getEmitModuleFormatOfFileWorker(sourceFile, options) < 5 /* ES2015 */;
120207
+ }
120208
+ function getEmitModuleFormatOfFileWorker(sourceFile, options) {
120209
+ return getImpliedNodeFormatForEmitWorker(sourceFile, options) ?? getEmitModuleKind(options);
120210
+ }
120211
+ function getImpliedNodeFormatForEmitWorker(sourceFile, options) {
120212
+ var _a, _b;
120213
+ const moduleKind = getEmitModuleKind(options);
120214
+ if (100 /* Node16 */ <= moduleKind && moduleKind <= 199 /* NodeNext */) {
120215
+ return sourceFile.impliedNodeFormat;
120216
+ }
120217
+ if (sourceFile.impliedNodeFormat === 1 /* CommonJS */ && (((_a = sourceFile.packageJsonScope) == null ? void 0 : _a.contents.packageJsonContent.type) === "commonjs" || fileExtensionIsOneOf(sourceFile.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */]))) {
120218
+ return 1 /* CommonJS */;
120219
+ }
120220
+ if (sourceFile.impliedNodeFormat === 99 /* ESNext */ && (((_b = sourceFile.packageJsonScope) == null ? void 0 : _b.contents.packageJsonContent.type) === "module" || fileExtensionIsOneOf(sourceFile.fileName, [".mjs" /* Mjs */, ".mts" /* Mts */]))) {
120221
+ return 99 /* ESNext */;
120222
+ }
120223
+ return void 0;
120224
+ }
120225
+ function getDefaultResolutionModeForFileWorker(sourceFile, options) {
120226
+ return importSyntaxAffectsModuleResolution(options) ? getImpliedNodeFormatForEmitWorker(sourceFile, options) : void 0;
120085
120227
  }
120086
120228
  function updateHostForUseSourceOfProjectReferenceRedirect(host) {
120087
120229
  let setOfDeclarationDirectories;
@@ -122054,9 +122196,15 @@ function getDirectoryToWatchFailedLookupLocation(failedLookupLocation, failedLoo
122054
122196
  const nodeModulesIndex = failedLookupPathComponents.indexOf("node_modules");
122055
122197
  if (nodeModulesIndex !== -1 && nodeModulesIndex + 1 <= perceivedOsRootLength + 1)
122056
122198
  return void 0;
122199
+ const lastNodeModulesIndex = failedLookupPathComponents.lastIndexOf("node_modules");
122057
122200
  if (isInDirectoryPath(rootPathComponents, failedLookupPathComponents)) {
122058
122201
  if (failedLookupPathComponents.length > rootPathComponents.length + 1) {
122059
- return getDirectoryOfFailedLookupWatch(failedLookupComponents, failedLookupPathComponents, Math.max(rootPathComponents.length + 1, perceivedOsRootLength + 1));
122202
+ return getDirectoryOfFailedLookupWatch(
122203
+ failedLookupComponents,
122204
+ failedLookupPathComponents,
122205
+ Math.max(rootPathComponents.length + 1, perceivedOsRootLength + 1),
122206
+ lastNodeModulesIndex
122207
+ );
122060
122208
  } else {
122061
122209
  return {
122062
122210
  dir: rootDir,
@@ -122071,12 +122219,18 @@ function getDirectoryToWatchFailedLookupLocation(failedLookupLocation, failedLoo
122071
122219
  failedLookupPathComponents.length - 1,
122072
122220
  perceivedOsRootLength,
122073
122221
  nodeModulesIndex,
122074
- rootPathComponents
122222
+ rootPathComponents,
122223
+ lastNodeModulesIndex
122075
122224
  );
122076
122225
  }
122077
- function getDirectoryToWatchFromFailedLookupLocationDirectory(dirComponents, dirPathComponents, dirPathComponentsLength, perceivedOsRootLength, nodeModulesIndex, rootPathComponents) {
122226
+ function getDirectoryToWatchFromFailedLookupLocationDirectory(dirComponents, dirPathComponents, dirPathComponentsLength, perceivedOsRootLength, nodeModulesIndex, rootPathComponents, lastNodeModulesIndex) {
122078
122227
  if (nodeModulesIndex !== -1) {
122079
- return getDirectoryOfFailedLookupWatch(dirComponents, dirPathComponents, nodeModulesIndex + 1);
122228
+ return getDirectoryOfFailedLookupWatch(
122229
+ dirComponents,
122230
+ dirPathComponents,
122231
+ nodeModulesIndex + 1,
122232
+ lastNodeModulesIndex
122233
+ );
122080
122234
  }
122081
122235
  let nonRecursive = true;
122082
122236
  let length2 = dirPathComponentsLength;
@@ -122087,13 +122241,29 @@ function getDirectoryToWatchFromFailedLookupLocationDirectory(dirComponents, dir
122087
122241
  break;
122088
122242
  }
122089
122243
  }
122090
- return getDirectoryOfFailedLookupWatch(dirComponents, dirPathComponents, length2, nonRecursive);
122244
+ return getDirectoryOfFailedLookupWatch(
122245
+ dirComponents,
122246
+ dirPathComponents,
122247
+ length2,
122248
+ lastNodeModulesIndex,
122249
+ nonRecursive
122250
+ );
122091
122251
  }
122092
- function getDirectoryOfFailedLookupWatch(dirComponents, dirPathComponents, length2, nonRecursive) {
122252
+ function getDirectoryOfFailedLookupWatch(dirComponents, dirPathComponents, length2, lastNodeModulesIndex, nonRecursive) {
122253
+ let packageDirLength;
122254
+ if (lastNodeModulesIndex !== -1 && lastNodeModulesIndex + 1 >= length2 && lastNodeModulesIndex + 2 < dirPathComponents.length) {
122255
+ if (!startsWith(dirPathComponents[lastNodeModulesIndex + 1], "@")) {
122256
+ packageDirLength = lastNodeModulesIndex + 2;
122257
+ } else if (lastNodeModulesIndex + 3 < dirPathComponents.length) {
122258
+ packageDirLength = lastNodeModulesIndex + 3;
122259
+ }
122260
+ }
122093
122261
  return {
122094
122262
  dir: getPathFromPathComponents(dirComponents, length2),
122095
122263
  dirPath: getPathFromPathComponents(dirPathComponents, length2),
122096
- nonRecursive
122264
+ nonRecursive,
122265
+ packageDir: packageDirLength !== void 0 ? getPathFromPathComponents(dirComponents, packageDirLength) : void 0,
122266
+ packageDirPath: packageDirLength !== void 0 ? getPathFromPathComponents(dirPathComponents, packageDirLength) : void 0
122097
122267
  };
122098
122268
  }
122099
122269
  function getDirectoryToWatchFailedLookupLocationFromTypeRoot(typeRoot, typeRootPath, rootPath, rootPathComponents, getCurrentDirectory, filterCustomPath) {
@@ -122108,7 +122278,8 @@ function getDirectoryToWatchFailedLookupLocationFromTypeRoot(typeRoot, typeRootP
122108
122278
  typeRootPathComponents.length,
122109
122279
  perceivedOsRootLengthForWatching(typeRootPathComponents, typeRootPathComponents.length),
122110
122280
  typeRootPathComponents.indexOf("node_modules"),
122111
- rootPathComponents
122281
+ rootPathComponents,
122282
+ typeRootPathComponents.lastIndexOf("node_modules")
122112
122283
  );
122113
122284
  return toWatch && filterCustomPath(toWatch.dirPath) ? toWatch.dirPath : void 0;
122114
122285
  }
@@ -122204,6 +122375,9 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
122204
122375
  const rootDir = getRootDirectoryOfResolutionCache(rootDirForResolution, getCurrentDirectory);
122205
122376
  const rootPath = resolutionHost.toPath(rootDir);
122206
122377
  const rootPathComponents = getPathComponents(rootPath);
122378
+ const isSymlinkCache = /* @__PURE__ */ new Map();
122379
+ const packageDirWatchers = /* @__PURE__ */ new Map();
122380
+ const dirPathToSymlinkPackageRefCount = /* @__PURE__ */ new Map();
122207
122381
  const typeRootsWatches = /* @__PURE__ */ new Map();
122208
122382
  return {
122209
122383
  rootDirForResolution,
@@ -122215,6 +122389,8 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
122215
122389
  resolutionsWithOnlyAffectingLocations,
122216
122390
  directoryWatchesOfFailedLookups,
122217
122391
  fileWatchesOfAffectingLocations,
122392
+ packageDirWatchers,
122393
+ dirPathToSymlinkPackageRefCount,
122218
122394
  watchFailedLookupLocationsOfExternalModuleResolutions,
122219
122395
  getModuleResolutionCache: () => moduleResolutionCache,
122220
122396
  startRecordingFilesWithChangedResolutions,
@@ -122249,6 +122425,9 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
122249
122425
  function clear2() {
122250
122426
  clearMap(directoryWatchesOfFailedLookups, closeFileWatcherOf);
122251
122427
  clearMap(fileWatchesOfAffectingLocations, closeFileWatcherOf);
122428
+ isSymlinkCache.clear();
122429
+ packageDirWatchers.clear();
122430
+ dirPathToSymlinkPackageRefCount.clear();
122252
122431
  nonRelativeExternalModuleResolutions.clear();
122253
122432
  closeTypeRootsWatch();
122254
122433
  resolvedModuleNames.clear();
@@ -122315,6 +122494,7 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
122315
122494
  libraryResolutionCache.clearAllExceptPackageJsonInfoCache();
122316
122495
  nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
122317
122496
  nonRelativeExternalModuleResolutions.clear();
122497
+ isSymlinkCache.clear();
122318
122498
  }
122319
122499
  function cleanupLibResolutionWatching(newProgram) {
122320
122500
  resolvedLibraries.forEach((resolution, libFileName) => {
@@ -122367,11 +122547,18 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
122367
122547
  }
122368
122548
  directoryWatchesOfFailedLookups.forEach(closeDirectoryWatchesOfFailedLookup);
122369
122549
  fileWatchesOfAffectingLocations.forEach(closeFileWatcherOfAffectingLocation);
122550
+ packageDirWatchers.forEach(closePackageDirWatcher);
122370
122551
  hasChangedAutomaticTypeDirectiveNames = false;
122371
122552
  moduleResolutionCache.isReadonly = true;
122372
122553
  typeReferenceDirectiveResolutionCache.isReadonly = true;
122373
122554
  libraryResolutionCache.isReadonly = true;
122374
122555
  moduleResolutionCache.getPackageJsonInfoCache().isReadonly = true;
122556
+ isSymlinkCache.clear();
122557
+ }
122558
+ function closePackageDirWatcher(watcher, packageDirPath) {
122559
+ if (watcher.dirPathToWatcher.size === 0) {
122560
+ packageDirWatchers.delete(packageDirPath);
122561
+ }
122375
122562
  }
122376
122563
  function closeDirectoryWatchesOfFailedLookup(watcher, path) {
122377
122564
  if (watcher.refCount === 0) {
@@ -122621,12 +122808,13 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
122621
122808
  getCurrentDirectory
122622
122809
  );
122623
122810
  if (toWatch) {
122624
- const { dir, dirPath, nonRecursive } = toWatch;
122811
+ const { dir, dirPath, nonRecursive, packageDir, packageDirPath } = toWatch;
122625
122812
  if (dirPath === rootPath) {
122626
122813
  Debug.assert(nonRecursive);
122814
+ Debug.assert(!packageDir);
122627
122815
  setAtRoot = true;
122628
122816
  } else {
122629
- setDirectoryWatcher(dir, dirPath, nonRecursive);
122817
+ setDirectoryWatcher(dir, dirPath, packageDir, packageDirPath, nonRecursive);
122630
122818
  }
122631
122819
  }
122632
122820
  return setAtRoot;
@@ -122650,6 +122838,10 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
122650
122838
  setDirectoryWatcher(
122651
122839
  rootDir,
122652
122840
  rootPath,
122841
+ /*packageDir*/
122842
+ void 0,
122843
+ /*packageDirPath*/
122844
+ void 0,
122653
122845
  /*nonRecursive*/
122654
122846
  true
122655
122847
  );
@@ -122750,14 +122942,68 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
122750
122942
  ));
122751
122943
  }
122752
122944
  }
122753
- function setDirectoryWatcher(dir, dirPath, nonRecursive) {
122754
- const dirWatcher = directoryWatchesOfFailedLookups.get(dirPath);
122945
+ function createDirectoryWatcherForPackageDir(dir, dirPath, packageDir, packageDirPath, nonRecursive) {
122946
+ Debug.assert(!nonRecursive);
122947
+ let isSymlink = isSymlinkCache.get(packageDirPath);
122948
+ let packageDirWatcher = packageDirWatchers.get(packageDirPath);
122949
+ if (isSymlink === void 0) {
122950
+ const realPath2 = resolutionHost.realpath(packageDir);
122951
+ isSymlink = realPath2 !== packageDir && resolutionHost.toPath(realPath2) !== packageDirPath;
122952
+ isSymlinkCache.set(packageDirPath, isSymlink);
122953
+ if (!packageDirWatcher) {
122954
+ packageDirWatchers.set(
122955
+ packageDirPath,
122956
+ packageDirWatcher = {
122957
+ dirPathToWatcher: /* @__PURE__ */ new Map(),
122958
+ isSymlink
122959
+ }
122960
+ );
122961
+ } else if (packageDirWatcher.isSymlink !== isSymlink) {
122962
+ packageDirWatcher.dirPathToWatcher.forEach((watcher) => {
122963
+ removeDirectoryWatcher(
122964
+ packageDirWatcher.isSymlink ? packageDirPath : dirPath,
122965
+ /*syncDirWatcherRemove*/
122966
+ false
122967
+ );
122968
+ watcher.watcher = createDirPathToWatcher();
122969
+ });
122970
+ packageDirWatcher.isSymlink = isSymlink;
122971
+ }
122972
+ } else {
122973
+ Debug.assertIsDefined(packageDirWatcher);
122974
+ Debug.assert(isSymlink === packageDirWatcher.isSymlink);
122975
+ }
122976
+ const forDirPath = packageDirWatcher.dirPathToWatcher.get(dirPath);
122977
+ if (forDirPath) {
122978
+ forDirPath.refCount++;
122979
+ } else {
122980
+ packageDirWatcher.dirPathToWatcher.set(dirPath, {
122981
+ watcher: createDirPathToWatcher(),
122982
+ refCount: 1
122983
+ });
122984
+ if (isSymlink)
122985
+ dirPathToSymlinkPackageRefCount.set(dirPath, (dirPathToSymlinkPackageRefCount.get(dirPath) ?? 0) + 1);
122986
+ }
122987
+ function createDirPathToWatcher() {
122988
+ return isSymlink ? createOrAddRefToDirectoryWatchOfFailedLookups(packageDir, packageDirPath, nonRecursive) : createOrAddRefToDirectoryWatchOfFailedLookups(dir, dirPath, nonRecursive);
122989
+ }
122990
+ }
122991
+ function setDirectoryWatcher(dir, dirPath, packageDir, packageDirPath, nonRecursive) {
122992
+ if (!packageDirPath || !resolutionHost.realpath) {
122993
+ createOrAddRefToDirectoryWatchOfFailedLookups(dir, dirPath, nonRecursive);
122994
+ } else {
122995
+ createDirectoryWatcherForPackageDir(dir, dirPath, packageDir, packageDirPath, nonRecursive);
122996
+ }
122997
+ }
122998
+ function createOrAddRefToDirectoryWatchOfFailedLookups(dir, dirPath, nonRecursive) {
122999
+ let dirWatcher = directoryWatchesOfFailedLookups.get(dirPath);
122755
123000
  if (dirWatcher) {
122756
123001
  Debug.assert(!!nonRecursive === !!dirWatcher.nonRecursive);
122757
123002
  dirWatcher.refCount++;
122758
123003
  } else {
122759
- directoryWatchesOfFailedLookups.set(dirPath, { watcher: createDirectoryWatcher(dir, dirPath, nonRecursive), refCount: 1, nonRecursive });
123004
+ directoryWatchesOfFailedLookups.set(dirPath, dirWatcher = { watcher: createDirectoryWatcher(dir, dirPath, nonRecursive), refCount: 1, nonRecursive });
122760
123005
  }
123006
+ return dirWatcher;
122761
123007
  }
122762
123008
  function stopWatchFailedLookupLocation(failedLookupLocation, removeAtRoot, syncDirWatcherRemove) {
122763
123009
  const failedLookupLocationPath = resolutionHost.toPath(failedLookupLocation);
@@ -122770,9 +123016,27 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
122770
123016
  getCurrentDirectory
122771
123017
  );
122772
123018
  if (toWatch) {
122773
- const { dirPath } = toWatch;
123019
+ const { dirPath, packageDirPath } = toWatch;
122774
123020
  if (dirPath === rootPath) {
122775
123021
  removeAtRoot = true;
123022
+ } else if (packageDirPath && resolutionHost.realpath) {
123023
+ const packageDirWatcher = packageDirWatchers.get(packageDirPath);
123024
+ const forDirPath = packageDirWatcher.dirPathToWatcher.get(dirPath);
123025
+ forDirPath.refCount--;
123026
+ if (forDirPath.refCount === 0) {
123027
+ removeDirectoryWatcher(packageDirWatcher.isSymlink ? packageDirPath : dirPath, syncDirWatcherRemove);
123028
+ packageDirWatcher.dirPathToWatcher.delete(dirPath);
123029
+ if (packageDirWatcher.isSymlink) {
123030
+ const refCount = dirPathToSymlinkPackageRefCount.get(dirPath) - 1;
123031
+ if (refCount === 0) {
123032
+ dirPathToSymlinkPackageRefCount.delete(dirPath);
123033
+ } else {
123034
+ dirPathToSymlinkPackageRefCount.set(dirPath, refCount);
123035
+ }
123036
+ }
123037
+ if (syncDirWatcherRemove)
123038
+ closePackageDirWatcher(packageDirWatcher, packageDirPath);
123039
+ }
122776
123040
  } else {
122777
123041
  removeDirectoryWatcher(dirPath, syncDirWatcherRemove);
122778
123042
  }
@@ -122994,7 +123258,7 @@ function createResolutionCache(resolutionHost, rootDirForResolution, logChangesW
122994
123258
  rootPath,
122995
123259
  rootPathComponents,
122996
123260
  getCurrentDirectory,
122997
- (dirPath2) => directoryWatchesOfFailedLookups.has(dirPath2)
123261
+ (dirPath2) => directoryWatchesOfFailedLookups.has(dirPath2) || dirPathToSymlinkPackageRefCount.has(dirPath2)
122998
123262
  );
122999
123263
  if (dirPath) {
123000
123264
  scheduleInvalidateResolutionOfFailedLookupLocation(fileOrDirectoryPath, dirPath === fileOrDirectoryPath);
@@ -123200,10 +123464,10 @@ function explainFiles(program, write) {
123200
123464
  for (const file of program.getSourceFiles()) {
123201
123465
  write(`${toFileName(file, relativeFileName)}`);
123202
123466
  (_a = reasons.get(file.path)) == null ? void 0 : _a.forEach((reason) => write(` ${fileIncludeReasonToDiagnostics(program, reason, relativeFileName).messageText}`));
123203
- (_b = explainIfFileIsRedirectAndImpliedFormat(file, relativeFileName)) == null ? void 0 : _b.forEach((d) => write(` ${d.messageText}`));
123467
+ (_b = explainIfFileIsRedirectAndImpliedFormat(file, program.getCompilerOptionsForFile(file), relativeFileName)) == null ? void 0 : _b.forEach((d) => write(` ${d.messageText}`));
123204
123468
  }
123205
123469
  }
123206
- function explainIfFileIsRedirectAndImpliedFormat(file, fileNameConvertor) {
123470
+ function explainIfFileIsRedirectAndImpliedFormat(file, options, fileNameConvertor) {
123207
123471
  var _a;
123208
123472
  let result;
123209
123473
  if (file.path !== file.resolvedPath) {
@@ -123223,7 +123487,7 @@ function explainIfFileIsRedirectAndImpliedFormat(file, fileNameConvertor) {
123223
123487
  ));
123224
123488
  }
123225
123489
  if (isExternalOrCommonJsModule(file)) {
123226
- switch (file.impliedNodeFormat) {
123490
+ switch (getImpliedNodeFormatForEmitWorker(file, options)) {
123227
123491
  case 99 /* ESNext */:
123228
123492
  if (file.packageJsonScope) {
123229
123493
  (result ?? (result = [])).push(chainDiagnosticMessages(