typescript 5.5.0-dev.20240409 → 5.5.0-dev.20240411

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.20240409`;
21
+ var version = `${versionMajorMinor}.0-dev.20240411`;
22
22
 
23
23
  // src/compiler/core.ts
24
24
  var emptyArray = [];
@@ -13397,6 +13397,9 @@ function getExternalModuleRequireArgument(node) {
13397
13397
  function isInternalModuleImportEqualsDeclaration(node) {
13398
13398
  return node.kind === 271 /* ImportEqualsDeclaration */ && node.moduleReference.kind !== 283 /* ExternalModuleReference */;
13399
13399
  }
13400
+ function isFullSourceFile(sourceFile) {
13401
+ return (sourceFile == null ? void 0 : sourceFile.kind) === 307 /* SourceFile */;
13402
+ }
13400
13403
  function isSourceFileJS(file) {
13401
13404
  return isInJSFile(file);
13402
13405
  }
@@ -17038,12 +17041,12 @@ function getModuleSpecifierEndingPreference(preference, resolutionMode, compiler
17038
17041
  return 1 /* Index */;
17039
17042
  }
17040
17043
  if (!shouldAllowImportingTsExtension(compilerOptions)) {
17041
- return usesExtensionsOnImports(sourceFile) ? 2 /* JsExtension */ : 0 /* Minimal */;
17044
+ return sourceFile && usesExtensionsOnImports(sourceFile) ? 2 /* JsExtension */ : 0 /* Minimal */;
17042
17045
  }
17043
17046
  return inferPreference();
17044
17047
  function inferPreference() {
17045
17048
  let usesJsExtensions = false;
17046
- const specifiers = sourceFile.imports.length ? sourceFile.imports : isSourceFileJS(sourceFile) ? getRequiresAtTopOfFile(sourceFile).map((r) => r.arguments[0]) : emptyArray;
17049
+ const specifiers = (sourceFile == null ? void 0 : sourceFile.imports.length) ? sourceFile.imports : sourceFile && isSourceFileJS(sourceFile) ? getRequiresAtTopOfFile(sourceFile).map((r) => r.arguments[0]) : emptyArray;
17047
17050
  for (const specifier of specifiers) {
17048
17051
  if (pathIsRelative(specifier.text)) {
17049
17052
  if (moduleResolutionIsNodeNext && resolutionMode === 1 /* CommonJS */ && getModeForUsageLocation(sourceFile, specifier, compilerOptions) === 99 /* ESNext */) {
@@ -38853,7 +38856,7 @@ function loadModuleFromImportsOrExports(extensions, state, cache, redirectedRefe
38853
38856
  moduleName
38854
38857
  );
38855
38858
  }
38856
- const expandingKeys = sort(filter(getOwnKeys(lookupTable), (k) => k.includes("*") || endsWith(k, "/")), comparePatternKeys);
38859
+ const expandingKeys = sort(filter(getOwnKeys(lookupTable), (k) => hasOneAsterisk(k) || endsWith(k, "/")), comparePatternKeys);
38857
38860
  for (const potentialTarget of expandingKeys) {
38858
38861
  if (state.features & 16 /* ExportsPatternTrailers */ && matchesPatternWithTrailer(potentialTarget, moduleName)) {
38859
38862
  const target = lookupTable[potentialTarget];
@@ -38897,6 +38900,10 @@ function loadModuleFromImportsOrExports(extensions, state, cache, redirectedRefe
38897
38900
  return startsWith(name, target.substring(0, starPos)) && endsWith(name, target.substring(starPos + 1));
38898
38901
  }
38899
38902
  }
38903
+ function hasOneAsterisk(patternKey) {
38904
+ const firstStar = patternKey.indexOf("*");
38905
+ return firstStar !== -1 && firstStar === patternKey.lastIndexOf("*");
38906
+ }
38900
38907
  function getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, moduleName, scope, isImports) {
38901
38908
  return loadModuleFromTargetImportOrExport;
38902
38909
  function loadModuleFromTargetImportOrExport(target, subpath, pattern, key) {
@@ -42665,7 +42672,7 @@ function getModuleSpecifierPreferences({ importModuleSpecifierPreference, import
42665
42672
  importModuleSpecifierEnding,
42666
42673
  resolutionMode ?? importingSourceFile.impliedNodeFormat,
42667
42674
  compilerOptions,
42668
- importingSourceFile
42675
+ isFullSourceFile(importingSourceFile) ? importingSourceFile : void 0
42669
42676
  );
42670
42677
  }
42671
42678
  }
@@ -42725,7 +42732,7 @@ function getModuleSpecifiersWithCacheInfo(moduleSymbol, checker, compilerOptions
42725
42732
  function computeModuleSpecifiers(modulePaths, compilerOptions, importingSourceFile, host, userPreferences, options = {}, forAutoImport) {
42726
42733
  const info = getInfo(importingSourceFile.fileName, host);
42727
42734
  const preferences = getModuleSpecifierPreferences(userPreferences, compilerOptions, importingSourceFile);
42728
- const existingSpecifier = forEach(modulePaths, (modulePath) => forEach(
42735
+ const existingSpecifier = isFullSourceFile(importingSourceFile) && forEach(modulePaths, (modulePath) => forEach(
42729
42736
  host.getFileIncludeReasons().get(toPath(modulePath.path, host.getCurrentDirectory(), info.getCanonicalFileName)),
42730
42737
  (reason) => {
42731
42738
  if (reason.kind !== 3 /* Import */ || reason.file !== importingSourceFile.path)
@@ -55717,13 +55724,13 @@ function createTypeChecker(host) {
55717
55724
  }
55718
55725
  function getUnionOrIntersectionProperty(type, name, skipObjectFunctionPropertyAugment) {
55719
55726
  var _a, _b, _c;
55720
- let property = ((_a = type.propertyCacheWithoutObjectFunctionPropertyAugment) == null ? void 0 : _a.get(name)) || !skipObjectFunctionPropertyAugment ? (_b = type.propertyCache) == null ? void 0 : _b.get(name) : void 0;
55727
+ let property = skipObjectFunctionPropertyAugment ? (_a = type.propertyCacheWithoutObjectFunctionPropertyAugment) == null ? void 0 : _a.get(name) : (_b = type.propertyCache) == null ? void 0 : _b.get(name);
55721
55728
  if (!property) {
55722
55729
  property = createUnionOrIntersectionProperty(type, name, skipObjectFunctionPropertyAugment);
55723
55730
  if (property) {
55724
55731
  const properties = skipObjectFunctionPropertyAugment ? type.propertyCacheWithoutObjectFunctionPropertyAugment || (type.propertyCacheWithoutObjectFunctionPropertyAugment = createSymbolTable()) : type.propertyCache || (type.propertyCache = createSymbolTable());
55725
55732
  properties.set(name, property);
55726
- if (skipObjectFunctionPropertyAugment && !((_c = type.propertyCache) == null ? void 0 : _c.get(name))) {
55733
+ if (skipObjectFunctionPropertyAugment && !(getCheckFlags(property) & 48 /* Partial */) && !((_c = type.propertyCache) == null ? void 0 : _c.get(name))) {
55727
55734
  const properties2 = type.propertyCache || (type.propertyCache = createSymbolTable());
55728
55735
  properties2.set(name, property);
55729
55736
  }
@@ -66706,7 +66713,7 @@ function createTypeChecker(host) {
66706
66713
  case 80 /* Identifier */:
66707
66714
  if (!isThisInTypeQuery(node)) {
66708
66715
  const symbol = getResolvedSymbol(node);
66709
- return isConstantVariable(symbol) || isParameterOrMutableLocalVariable(symbol) && !isSymbolAssigned(symbol);
66716
+ return isConstantVariable(symbol) || isParameterOrMutableLocalVariable(symbol) && !isSymbolAssigned(symbol) || !!symbol.valueDeclaration && isFunctionExpression(symbol.valueDeclaration);
66710
66717
  }
66711
66718
  break;
66712
66719
  case 211 /* PropertyAccessExpression */:
@@ -74718,7 +74725,7 @@ function createTypeChecker(host) {
74718
74725
  true
74719
74726
  );
74720
74727
  }
74721
- if (expr.kind === 213 /* CallExpression */ && expr.expression.kind === 80 /* Identifier */ && checkExpressionCached(expr.expression).symbol === func.symbol) {
74728
+ if (expr.kind === 213 /* CallExpression */ && expr.expression.kind === 80 /* Identifier */ && checkExpressionCached(expr.expression).symbol === getMergedSymbol(func.symbol) && (!isFunctionExpressionOrArrowFunction(func.symbol.valueDeclaration) || isConstantReference(expr.expression))) {
74722
74729
  hasReturnOfTypeNever = true;
74723
74730
  return;
74724
74731
  }
package/lib/typescript.js CHANGED
@@ -414,6 +414,7 @@ __export(typescript_exports, {
414
414
  createFileDiagnosticFromMessageChain: () => createFileDiagnosticFromMessageChain,
415
415
  createFlowNode: () => createFlowNode,
416
416
  createForOfBindingStatement: () => createForOfBindingStatement,
417
+ createFutureSourceFile: () => createFutureSourceFile,
417
418
  createGetCanonicalFileName: () => createGetCanonicalFileName,
418
419
  createGetSourceFile: () => createGetSourceFile,
419
420
  createGetSymbolAccessibilityDiagnosticForNode: () => createGetSymbolAccessibilityDiagnosticForNode,
@@ -1185,6 +1186,7 @@ __export(typescript_exports, {
1185
1186
  isAnyDirectorySeparator: () => isAnyDirectorySeparator,
1186
1187
  isAnyImportOrBareOrAccessedRequire: () => isAnyImportOrBareOrAccessedRequire,
1187
1188
  isAnyImportOrReExport: () => isAnyImportOrReExport,
1189
+ isAnyImportOrRequireStatement: () => isAnyImportOrRequireStatement,
1188
1190
  isAnyImportSyntax: () => isAnyImportSyntax,
1189
1191
  isAnySupportedFileExtension: () => isAnySupportedFileExtension,
1190
1192
  isApplicableVersionedTypesKey: () => isApplicableVersionedTypesKey,
@@ -1375,6 +1377,7 @@ __export(typescript_exports, {
1375
1377
  isForInitializer: () => isForInitializer,
1376
1378
  isForOfStatement: () => isForOfStatement,
1377
1379
  isForStatement: () => isForStatement,
1380
+ isFullSourceFile: () => isFullSourceFile,
1378
1381
  isFunctionBlock: () => isFunctionBlock,
1379
1382
  isFunctionBody: () => isFunctionBody,
1380
1383
  isFunctionDeclaration: () => isFunctionDeclaration,
@@ -2335,7 +2338,7 @@ module.exports = __toCommonJS(typescript_exports);
2335
2338
 
2336
2339
  // src/compiler/corePublic.ts
2337
2340
  var versionMajorMinor = "5.5";
2338
- var version = `${versionMajorMinor}.0-dev.20240409`;
2341
+ var version = `${versionMajorMinor}.0-dev.20240411`;
2339
2342
  var Comparison = /* @__PURE__ */ ((Comparison3) => {
2340
2343
  Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
2341
2344
  Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
@@ -16246,6 +16249,9 @@ function isAnyImportSyntax(node) {
16246
16249
  function isAnyImportOrBareOrAccessedRequire(node) {
16247
16250
  return isAnyImportSyntax(node) || isVariableDeclarationInitializedToBareOrAccessedRequire(node);
16248
16251
  }
16252
+ function isAnyImportOrRequireStatement(node) {
16253
+ return isAnyImportSyntax(node) || isRequireVariableStatement(node);
16254
+ }
16249
16255
  function isLateVisibilityPaintedStatement(node) {
16250
16256
  switch (node.kind) {
16251
16257
  case 272 /* ImportDeclaration */:
@@ -17282,6 +17288,9 @@ function getExternalModuleRequireArgument(node) {
17282
17288
  function isInternalModuleImportEqualsDeclaration(node) {
17283
17289
  return node.kind === 271 /* ImportEqualsDeclaration */ && node.moduleReference.kind !== 283 /* ExternalModuleReference */;
17284
17290
  }
17291
+ function isFullSourceFile(sourceFile) {
17292
+ return (sourceFile == null ? void 0 : sourceFile.kind) === 307 /* SourceFile */;
17293
+ }
17285
17294
  function isSourceFileJS(file) {
17286
17295
  return isInJSFile(file);
17287
17296
  }
@@ -21249,12 +21258,12 @@ function getModuleSpecifierEndingPreference(preference, resolutionMode, compiler
21249
21258
  return 1 /* Index */;
21250
21259
  }
21251
21260
  if (!shouldAllowImportingTsExtension(compilerOptions)) {
21252
- return usesExtensionsOnImports(sourceFile) ? 2 /* JsExtension */ : 0 /* Minimal */;
21261
+ return sourceFile && usesExtensionsOnImports(sourceFile) ? 2 /* JsExtension */ : 0 /* Minimal */;
21253
21262
  }
21254
21263
  return inferPreference();
21255
21264
  function inferPreference() {
21256
21265
  let usesJsExtensions = false;
21257
- const specifiers = sourceFile.imports.length ? sourceFile.imports : isSourceFileJS(sourceFile) ? getRequiresAtTopOfFile(sourceFile).map((r) => r.arguments[0]) : emptyArray;
21266
+ const specifiers = (sourceFile == null ? void 0 : sourceFile.imports.length) ? sourceFile.imports : sourceFile && isSourceFileJS(sourceFile) ? getRequiresAtTopOfFile(sourceFile).map((r) => r.arguments[0]) : emptyArray;
21258
21267
  for (const specifier of specifiers) {
21259
21268
  if (pathIsRelative(specifier.text)) {
21260
21269
  if (moduleResolutionIsNodeNext && resolutionMode === 1 /* CommonJS */ && getModeForUsageLocation(sourceFile, specifier, compilerOptions) === 99 /* ESNext */) {
@@ -43516,7 +43525,7 @@ function loadModuleFromImportsOrExports(extensions, state, cache, redirectedRefe
43516
43525
  moduleName
43517
43526
  );
43518
43527
  }
43519
- const expandingKeys = sort(filter(getOwnKeys(lookupTable), (k) => k.includes("*") || endsWith(k, "/")), comparePatternKeys);
43528
+ const expandingKeys = sort(filter(getOwnKeys(lookupTable), (k) => hasOneAsterisk(k) || endsWith(k, "/")), comparePatternKeys);
43520
43529
  for (const potentialTarget of expandingKeys) {
43521
43530
  if (state.features & 16 /* ExportsPatternTrailers */ && matchesPatternWithTrailer(potentialTarget, moduleName)) {
43522
43531
  const target = lookupTable[potentialTarget];
@@ -43560,6 +43569,10 @@ function loadModuleFromImportsOrExports(extensions, state, cache, redirectedRefe
43560
43569
  return startsWith(name, target.substring(0, starPos)) && endsWith(name, target.substring(starPos + 1));
43561
43570
  }
43562
43571
  }
43572
+ function hasOneAsterisk(patternKey) {
43573
+ const firstStar = patternKey.indexOf("*");
43574
+ return firstStar !== -1 && firstStar === patternKey.lastIndexOf("*");
43575
+ }
43563
43576
  function getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, moduleName, scope, isImports) {
43564
43577
  return loadModuleFromTargetImportOrExport;
43565
43578
  function loadModuleFromTargetImportOrExport(target, subpath, pattern, key) {
@@ -47310,6 +47323,7 @@ __export(ts_moduleSpecifiers_exports, {
47310
47323
  RelativePreference: () => RelativePreference,
47311
47324
  countPathComponents: () => countPathComponents,
47312
47325
  forEachFileNameOfModule: () => forEachFileNameOfModule,
47326
+ getLocalModuleSpecifierBetweenFileNames: () => getLocalModuleSpecifierBetweenFileNames,
47313
47327
  getModuleSpecifier: () => getModuleSpecifier,
47314
47328
  getModuleSpecifierPreferences: () => getModuleSpecifierPreferences,
47315
47329
  getModuleSpecifiers: () => getModuleSpecifiers,
@@ -47370,7 +47384,7 @@ function getModuleSpecifierPreferences({ importModuleSpecifierPreference, import
47370
47384
  importModuleSpecifierEnding,
47371
47385
  resolutionMode ?? importingSourceFile.impliedNodeFormat,
47372
47386
  compilerOptions,
47373
- importingSourceFile
47387
+ isFullSourceFile(importingSourceFile) ? importingSourceFile : void 0
47374
47388
  );
47375
47389
  }
47376
47390
  }
@@ -47475,10 +47489,22 @@ function getModuleSpecifiersWithCacheInfo(moduleSymbol, checker, compilerOptions
47475
47489
  cache == null ? void 0 : cache.set(importingSourceFile.path, moduleSourceFile.path, userPreferences, options, modulePaths, result);
47476
47490
  return { moduleSpecifiers: result, computedWithoutCache };
47477
47491
  }
47492
+ function getLocalModuleSpecifierBetweenFileNames(importingFile, targetFileName, compilerOptions, host, options = {}) {
47493
+ const info = getInfo(importingFile.fileName, host);
47494
+ const importMode = options.overrideImportMode ?? importingFile.impliedNodeFormat;
47495
+ return getLocalModuleSpecifier(
47496
+ targetFileName,
47497
+ info,
47498
+ compilerOptions,
47499
+ host,
47500
+ importMode,
47501
+ getModuleSpecifierPreferences({}, compilerOptions, importingFile)
47502
+ );
47503
+ }
47478
47504
  function computeModuleSpecifiers(modulePaths, compilerOptions, importingSourceFile, host, userPreferences, options = {}, forAutoImport) {
47479
47505
  const info = getInfo(importingSourceFile.fileName, host);
47480
47506
  const preferences = getModuleSpecifierPreferences(userPreferences, compilerOptions, importingSourceFile);
47481
- const existingSpecifier = forEach(modulePaths, (modulePath) => forEach(
47507
+ const existingSpecifier = isFullSourceFile(importingSourceFile) && forEach(modulePaths, (modulePath) => forEach(
47482
47508
  host.getFileIncludeReasons().get(toPath(modulePath.path, host.getCurrentDirectory(), info.getCanonicalFileName)),
47483
47509
  (reason) => {
47484
47510
  if (reason.kind !== 3 /* Import */ || reason.file !== importingSourceFile.path)
@@ -60486,13 +60512,13 @@ function createTypeChecker(host) {
60486
60512
  }
60487
60513
  function getUnionOrIntersectionProperty(type, name, skipObjectFunctionPropertyAugment) {
60488
60514
  var _a, _b, _c;
60489
- let property = ((_a = type.propertyCacheWithoutObjectFunctionPropertyAugment) == null ? void 0 : _a.get(name)) || !skipObjectFunctionPropertyAugment ? (_b = type.propertyCache) == null ? void 0 : _b.get(name) : void 0;
60515
+ let property = skipObjectFunctionPropertyAugment ? (_a = type.propertyCacheWithoutObjectFunctionPropertyAugment) == null ? void 0 : _a.get(name) : (_b = type.propertyCache) == null ? void 0 : _b.get(name);
60490
60516
  if (!property) {
60491
60517
  property = createUnionOrIntersectionProperty(type, name, skipObjectFunctionPropertyAugment);
60492
60518
  if (property) {
60493
60519
  const properties = skipObjectFunctionPropertyAugment ? type.propertyCacheWithoutObjectFunctionPropertyAugment || (type.propertyCacheWithoutObjectFunctionPropertyAugment = createSymbolTable()) : type.propertyCache || (type.propertyCache = createSymbolTable());
60494
60520
  properties.set(name, property);
60495
- if (skipObjectFunctionPropertyAugment && !((_c = type.propertyCache) == null ? void 0 : _c.get(name))) {
60521
+ if (skipObjectFunctionPropertyAugment && !(getCheckFlags(property) & 48 /* Partial */) && !((_c = type.propertyCache) == null ? void 0 : _c.get(name))) {
60496
60522
  const properties2 = type.propertyCache || (type.propertyCache = createSymbolTable());
60497
60523
  properties2.set(name, property);
60498
60524
  }
@@ -71475,7 +71501,7 @@ function createTypeChecker(host) {
71475
71501
  case 80 /* Identifier */:
71476
71502
  if (!isThisInTypeQuery(node)) {
71477
71503
  const symbol = getResolvedSymbol(node);
71478
- return isConstantVariable(symbol) || isParameterOrMutableLocalVariable(symbol) && !isSymbolAssigned(symbol);
71504
+ return isConstantVariable(symbol) || isParameterOrMutableLocalVariable(symbol) && !isSymbolAssigned(symbol) || !!symbol.valueDeclaration && isFunctionExpression(symbol.valueDeclaration);
71479
71505
  }
71480
71506
  break;
71481
71507
  case 211 /* PropertyAccessExpression */:
@@ -79487,7 +79513,7 @@ function createTypeChecker(host) {
79487
79513
  true
79488
79514
  );
79489
79515
  }
79490
- if (expr.kind === 213 /* CallExpression */ && expr.expression.kind === 80 /* Identifier */ && checkExpressionCached(expr.expression).symbol === func.symbol) {
79516
+ if (expr.kind === 213 /* CallExpression */ && expr.expression.kind === 80 /* Identifier */ && checkExpressionCached(expr.expression).symbol === getMergedSymbol(func.symbol) && (!isFunctionExpressionOrArrowFunction(func.symbol.valueDeclaration) || isConstantReference(expr.expression))) {
79491
79517
  hasReturnOfTypeNever = true;
79492
79518
  return;
79493
79519
  }
@@ -134688,7 +134714,7 @@ function getQuotePreference(sourceFile, preferences) {
134688
134714
  if (preferences.quotePreference && preferences.quotePreference !== "auto") {
134689
134715
  return preferences.quotePreference === "single" ? 0 /* Single */ : 1 /* Double */;
134690
134716
  } else {
134691
- const firstModuleSpecifier = sourceFile.imports && find(sourceFile.imports, (n) => isStringLiteral(n) && !nodeIsSynthesized(n.parent));
134717
+ const firstModuleSpecifier = isFullSourceFile(sourceFile) && sourceFile.imports && find(sourceFile.imports, (n) => isStringLiteral(n) && !nodeIsSynthesized(n.parent));
134692
134718
  return firstModuleSpecifier ? quotePreferenceFromString(firstModuleSpecifier, sourceFile) : 1 /* Double */;
134693
134719
  }
134694
134720
  }
@@ -134746,14 +134772,24 @@ function findModifier(node, kind) {
134746
134772
  return canHaveModifiers(node) ? find(node.modifiers, (m) => m.kind === kind) : void 0;
134747
134773
  }
134748
134774
  function insertImports(changes, sourceFile, imports, blankLineBetween, preferences) {
134775
+ var _a;
134749
134776
  const decl = isArray(imports) ? imports[0] : imports;
134750
134777
  const importKindPredicate = decl.kind === 243 /* VariableStatement */ ? isRequireVariableStatement : isAnyImportSyntax;
134751
134778
  const existingImportStatements = filter(sourceFile.statements, importKindPredicate);
134752
134779
  const { comparer, isSorted } = ts_OrganizeImports_exports.getOrganizeImportsStringComparerWithDetection(existingImportStatements, preferences);
134753
134780
  const sortedNewImports = isArray(imports) ? stableSort(imports, (a, b) => ts_OrganizeImports_exports.compareImportsOrRequireStatements(a, b, comparer)) : [imports];
134754
- if (!existingImportStatements.length) {
134755
- changes.insertNodesAtTopOfFile(sourceFile, sortedNewImports, blankLineBetween);
134756
- } else if (existingImportStatements && isSorted) {
134781
+ if (!(existingImportStatements == null ? void 0 : existingImportStatements.length)) {
134782
+ if (isFullSourceFile(sourceFile)) {
134783
+ changes.insertNodesAtTopOfFile(sourceFile, sortedNewImports, blankLineBetween);
134784
+ } else {
134785
+ for (const newImport of sortedNewImports) {
134786
+ changes.insertStatementsInNewFile(sourceFile.fileName, [newImport], (_a = getOriginalNode(newImport)) == null ? void 0 : _a.getSourceFile());
134787
+ }
134788
+ }
134789
+ return;
134790
+ }
134791
+ Debug.assert(isFullSourceFile(sourceFile));
134792
+ if (existingImportStatements && isSorted) {
134757
134793
  for (const newImport of sortedNewImports) {
134758
134794
  const insertionIndex = ts_OrganizeImports_exports.getImportDeclarationInsertionIndex(existingImportStatements, newImport, comparer);
134759
134795
  if (insertionIndex === 0) {
@@ -135679,7 +135715,7 @@ function createPackageJsonImportFilter(fromFile, preferences, host) {
135679
135715
  return moduleSpecifierIsCoveredByPackageJson(moduleSpecifier);
135680
135716
  }
135681
135717
  function isAllowedCoreNodeModulesImport(moduleSpecifier) {
135682
- if (isSourceFileJS(fromFile) && ts_JsTyping_exports.nodeCoreModules.has(moduleSpecifier)) {
135718
+ if (isFullSourceFile(fromFile) && isSourceFileJS(fromFile) && ts_JsTyping_exports.nodeCoreModules.has(moduleSpecifier)) {
135683
135719
  if (usesNodeCoreModules === void 0) {
135684
135720
  usesNodeCoreModules = consumesNodeCoreModules(fromFile);
135685
135721
  }
@@ -135986,6 +136022,25 @@ function isBlockLike(node) {
135986
136022
  return false;
135987
136023
  }
135988
136024
  }
136025
+ function createFutureSourceFile(fileName, syntaxModuleIndicator, program, moduleResolutionHost) {
136026
+ var _a;
136027
+ const result = getImpliedNodeFormatForFileWorker(fileName, (_a = program.getPackageJsonInfoCache) == null ? void 0 : _a.call(program), moduleResolutionHost, program.getCompilerOptions());
136028
+ let impliedNodeFormat, packageJsonScope;
136029
+ if (typeof result === "object") {
136030
+ impliedNodeFormat = result.impliedNodeFormat;
136031
+ packageJsonScope = result.packageJsonScope;
136032
+ }
136033
+ return {
136034
+ path: toPath(fileName, program.getCurrentDirectory(), program.getCanonicalFileName),
136035
+ fileName,
136036
+ externalModuleIndicator: syntaxModuleIndicator === 99 /* ESNext */ ? true : void 0,
136037
+ commonJsModuleIndicator: syntaxModuleIndicator === 1 /* CommonJS */ ? true : void 0,
136038
+ impliedNodeFormat,
136039
+ packageJsonScope,
136040
+ statements: emptyArray,
136041
+ imports: emptyArray
136042
+ };
136043
+ }
135989
136044
 
135990
136045
  // src/services/exportInfoMap.ts
135991
136046
  var ImportKind = /* @__PURE__ */ ((ImportKind2) => {
@@ -152163,15 +152218,27 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre
152163
152218
  const addToNamespace = [];
152164
152219
  const importType = [];
152165
152220
  const addToExisting = /* @__PURE__ */ new Map();
152221
+ const removeExisting = /* @__PURE__ */ new Set();
152222
+ const verbatimImports = /* @__PURE__ */ new Set();
152166
152223
  const newImports = /* @__PURE__ */ new Map();
152167
- return { addImportFromDiagnostic, addImportFromExportedSymbol, writeFixes, hasFixes };
152224
+ return { addImportFromDiagnostic, addImportFromExportedSymbol, writeFixes, hasFixes, addImportForUnresolvedIdentifier, addImportForNonExistentExport, removeExistingImport, addVerbatimImport };
152225
+ function addVerbatimImport(declaration) {
152226
+ verbatimImports.add(declaration);
152227
+ }
152228
+ function addImportForUnresolvedIdentifier(context, symbolToken, useAutoImportProvider2) {
152229
+ const info = getFixInfosWithoutDiagnostic(context, symbolToken, useAutoImportProvider2);
152230
+ if (!info || !info.length)
152231
+ return;
152232
+ addImport(first(info));
152233
+ }
152168
152234
  function addImportFromDiagnostic(diagnostic, context) {
152169
152235
  const info = getFixInfos(context, diagnostic.code, diagnostic.start, useAutoImportProvider);
152170
152236
  if (!info || !info.length)
152171
152237
  return;
152172
152238
  addImport(first(info));
152173
152239
  }
152174
- function addImportFromExportedSymbol(exportedSymbol, isValidTypeOnlyUseSite) {
152240
+ function addImportFromExportedSymbol(exportedSymbol, isValidTypeOnlyUseSite, referenceImport) {
152241
+ var _a;
152175
152242
  const moduleSymbol = Debug.checkDefined(exportedSymbol.parent);
152176
152243
  const symbolName2 = getNameForExportedSymbol(exportedSymbol, getEmitScriptTarget(compilerOptions));
152177
152244
  const checker = program.getTypeChecker();
@@ -152189,7 +152256,7 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre
152189
152256
  cancellationToken
152190
152257
  );
152191
152258
  const useRequire = shouldUseRequire(sourceFile, program);
152192
- const fix = getImportFixForSymbol(
152259
+ let fix = getImportFixForSymbol(
152193
152260
  sourceFile,
152194
152261
  Debug.checkDefined(exportInfo),
152195
152262
  program,
@@ -152201,9 +152268,72 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre
152201
152268
  preferences
152202
152269
  );
152203
152270
  if (fix) {
152204
- addImport({ fix, symbolName: symbolName2, errorIdentifierText: void 0 });
152271
+ const localName = ((_a = tryCast(referenceImport == null ? void 0 : referenceImport.name, isIdentifier)) == null ? void 0 : _a.text) ?? symbolName2;
152272
+ if (referenceImport && isTypeOnlyImportDeclaration(referenceImport) && (fix.kind === 3 /* AddNew */ || fix.kind === 2 /* AddToExisting */) && fix.addAsTypeOnly === 1 /* Allowed */) {
152273
+ fix = { ...fix, addAsTypeOnly: 2 /* Required */ };
152274
+ }
152275
+ addImport({ fix, symbolName: localName ?? symbolName2, errorIdentifierText: void 0 });
152205
152276
  }
152206
152277
  }
152278
+ function addImportForNonExistentExport(exportName, exportingFileName, exportKind, exportedMeanings, isImportUsageValidAsTypeOnly) {
152279
+ const exportingSourceFile = program.getSourceFile(exportingFileName);
152280
+ const useRequire = shouldUseRequire(sourceFile, program);
152281
+ if (exportingSourceFile && exportingSourceFile.symbol) {
152282
+ const { fixes } = getImportFixes(
152283
+ [{
152284
+ exportKind,
152285
+ isFromPackageJson: false,
152286
+ moduleFileName: exportingFileName,
152287
+ moduleSymbol: exportingSourceFile.symbol,
152288
+ targetFlags: exportedMeanings
152289
+ }],
152290
+ /*usagePosition*/
152291
+ void 0,
152292
+ isImportUsageValidAsTypeOnly,
152293
+ useRequire,
152294
+ program,
152295
+ sourceFile,
152296
+ host,
152297
+ preferences
152298
+ );
152299
+ if (fixes.length) {
152300
+ addImport({ fix: fixes[0], symbolName: exportName, errorIdentifierText: exportName });
152301
+ }
152302
+ } else {
152303
+ const futureExportingSourceFile = createFutureSourceFile(exportingFileName, 99 /* ESNext */, program, host);
152304
+ const moduleSpecifier = ts_moduleSpecifiers_exports.getLocalModuleSpecifierBetweenFileNames(
152305
+ sourceFile,
152306
+ exportingFileName,
152307
+ compilerOptions,
152308
+ createModuleSpecifierResolutionHost(program, host)
152309
+ );
152310
+ const importKind = getImportKind(futureExportingSourceFile, exportKind, compilerOptions);
152311
+ const addAsTypeOnly = getAddAsTypeOnly(
152312
+ isImportUsageValidAsTypeOnly,
152313
+ /*isForNewImportDeclaration*/
152314
+ true,
152315
+ /*symbol*/
152316
+ void 0,
152317
+ exportedMeanings,
152318
+ program.getTypeChecker(),
152319
+ compilerOptions
152320
+ );
152321
+ const fix = {
152322
+ kind: 3 /* AddNew */,
152323
+ moduleSpecifier,
152324
+ importKind,
152325
+ addAsTypeOnly,
152326
+ useRequire
152327
+ };
152328
+ addImport({ fix, symbolName: exportName, errorIdentifierText: exportName });
152329
+ }
152330
+ }
152331
+ function removeExistingImport(declaration) {
152332
+ if (declaration.kind === 273 /* ImportClause */) {
152333
+ Debug.assertIsDefined(declaration.name, "ImportClause should have a name if it's being removed");
152334
+ }
152335
+ removeExisting.add(declaration);
152336
+ }
152207
152337
  function addImport(info) {
152208
152338
  var _a, _b;
152209
152339
  const { fix, symbolName: symbolName2 } = info;
@@ -152216,10 +152346,9 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre
152216
152346
  break;
152217
152347
  case 2 /* AddToExisting */: {
152218
152348
  const { importClauseOrBindingPattern, importKind, addAsTypeOnly } = fix;
152219
- const key = String(getNodeId(importClauseOrBindingPattern));
152220
- let entry = addToExisting.get(key);
152349
+ let entry = addToExisting.get(importClauseOrBindingPattern);
152221
152350
  if (!entry) {
152222
- addToExisting.set(key, entry = { importClauseOrBindingPattern, defaultImport: void 0, namedImports: /* @__PURE__ */ new Map() });
152351
+ addToExisting.set(importClauseOrBindingPattern, entry = { importClauseOrBindingPattern, defaultImport: void 0, namedImports: /* @__PURE__ */ new Map() });
152223
152352
  }
152224
152353
  if (importKind === 0 /* Named */) {
152225
152354
  const prevValue = entry == null ? void 0 : entry.namedImports.get(symbolName2);
@@ -152301,8 +152430,9 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre
152301
152430
  }
152302
152431
  }
152303
152432
  function writeFixes(changeTracker, oldFileQuotePreference) {
152433
+ var _a, _b;
152304
152434
  let quotePreference;
152305
- if (sourceFile.imports.length === 0 && oldFileQuotePreference !== void 0) {
152435
+ if (isFullSourceFile(sourceFile) && sourceFile.imports.length === 0 && oldFileQuotePreference !== void 0) {
152306
152436
  quotePreference = oldFileQuotePreference;
152307
152437
  } else {
152308
152438
  quotePreference = getQuotePreference(sourceFile, preferences);
@@ -152313,6 +152443,82 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre
152313
152443
  for (const fix of importType) {
152314
152444
  addImportType(changeTracker, sourceFile, fix, quotePreference);
152315
152445
  }
152446
+ let importSpecifiersToRemoveWhileAdding;
152447
+ if (removeExisting.size) {
152448
+ Debug.assert(isFullSourceFile(sourceFile), "Cannot remove imports from a future source file");
152449
+ const importDeclarationsWithRemovals = new Set(mapDefined([...removeExisting], (d) => findAncestor(d, isImportDeclaration)));
152450
+ const variableDeclarationsWithRemovals = new Set(mapDefined([...removeExisting], (d) => findAncestor(d, isVariableDeclarationInitializedToRequire)));
152451
+ const emptyImportDeclarations = [...importDeclarationsWithRemovals].filter(
152452
+ (d) => {
152453
+ var _a2, _b2, _c;
152454
+ return (
152455
+ // nothing added to the import declaration
152456
+ !addToExisting.has(d.importClause) && // no default, or default is being removed
152457
+ (!((_a2 = d.importClause) == null ? void 0 : _a2.name) || removeExisting.has(d.importClause)) && // no namespace import, or namespace import is being removed
152458
+ (!tryCast((_b2 = d.importClause) == null ? void 0 : _b2.namedBindings, isNamespaceImport) || removeExisting.has(d.importClause.namedBindings)) && // no named imports, or all named imports are being removed
152459
+ (!tryCast((_c = d.importClause) == null ? void 0 : _c.namedBindings, isNamedImports) || every(d.importClause.namedBindings.elements, (e) => removeExisting.has(e)))
152460
+ );
152461
+ }
152462
+ );
152463
+ const emptyVariableDeclarations = [...variableDeclarationsWithRemovals].filter(
152464
+ (d) => (
152465
+ // no binding elements being added to the variable declaration
152466
+ (d.name.kind !== 206 /* ObjectBindingPattern */ || !addToExisting.has(d.name)) && // no binding elements, or all binding elements are being removed
152467
+ (d.name.kind !== 206 /* ObjectBindingPattern */ || every(d.name.elements, (e) => removeExisting.has(e)))
152468
+ )
152469
+ );
152470
+ const namedBindingsToDelete = [...importDeclarationsWithRemovals].filter(
152471
+ (d) => {
152472
+ var _a2, _b2;
152473
+ return (
152474
+ // has named bindings
152475
+ ((_a2 = d.importClause) == null ? void 0 : _a2.namedBindings) && // is not being fully removed
152476
+ emptyImportDeclarations.indexOf(d) === -1 && // is not gaining named imports
152477
+ !((_b2 = addToExisting.get(d.importClause)) == null ? void 0 : _b2.namedImports) && // all named imports are being removed
152478
+ (d.importClause.namedBindings.kind === 274 /* NamespaceImport */ || every(d.importClause.namedBindings.elements, (e) => removeExisting.has(e)))
152479
+ );
152480
+ }
152481
+ );
152482
+ for (const declaration of [...emptyImportDeclarations, ...emptyVariableDeclarations]) {
152483
+ changeTracker.delete(sourceFile, declaration);
152484
+ }
152485
+ for (const declaration of namedBindingsToDelete) {
152486
+ changeTracker.replaceNode(
152487
+ sourceFile,
152488
+ declaration.importClause,
152489
+ factory.updateImportClause(
152490
+ declaration.importClause,
152491
+ declaration.importClause.isTypeOnly,
152492
+ declaration.importClause.name,
152493
+ /*namedBindings*/
152494
+ void 0
152495
+ )
152496
+ );
152497
+ }
152498
+ for (const declaration of removeExisting) {
152499
+ const importDeclaration = findAncestor(declaration, isImportDeclaration);
152500
+ if (importDeclaration && emptyImportDeclarations.indexOf(importDeclaration) === -1 && namedBindingsToDelete.indexOf(importDeclaration) === -1) {
152501
+ if (declaration.kind === 273 /* ImportClause */) {
152502
+ changeTracker.delete(sourceFile, declaration.name);
152503
+ } else {
152504
+ Debug.assert(declaration.kind === 276 /* ImportSpecifier */, "NamespaceImport should have been handled earlier");
152505
+ if ((_a = addToExisting.get(importDeclaration.importClause)) == null ? void 0 : _a.namedImports) {
152506
+ (importSpecifiersToRemoveWhileAdding ?? (importSpecifiersToRemoveWhileAdding = /* @__PURE__ */ new Set())).add(declaration);
152507
+ } else {
152508
+ changeTracker.delete(sourceFile, declaration);
152509
+ }
152510
+ }
152511
+ } else if (declaration.kind === 208 /* BindingElement */) {
152512
+ if ((_b = addToExisting.get(declaration.parent)) == null ? void 0 : _b.namedImports) {
152513
+ (importSpecifiersToRemoveWhileAdding ?? (importSpecifiersToRemoveWhileAdding = /* @__PURE__ */ new Set())).add(declaration);
152514
+ } else {
152515
+ changeTracker.delete(sourceFile, declaration);
152516
+ }
152517
+ } else if (declaration.kind === 271 /* ImportEqualsDeclaration */) {
152518
+ changeTracker.delete(sourceFile, declaration);
152519
+ }
152520
+ }
152521
+ }
152316
152522
  addToExisting.forEach(({ importClauseOrBindingPattern, defaultImport, namedImports }) => {
152317
152523
  doAddExistingFix(
152318
152524
  changeTracker,
@@ -152320,6 +152526,7 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre
152320
152526
  importClauseOrBindingPattern,
152321
152527
  defaultImport,
152322
152528
  arrayFrom(namedImports.entries(), ([name, addAsTypeOnly]) => ({ addAsTypeOnly, name })),
152529
+ importSpecifiersToRemoveWhileAdding,
152323
152530
  preferences
152324
152531
  );
152325
152532
  });
@@ -152338,6 +152545,7 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre
152338
152545
  );
152339
152546
  newDeclarations = combine(newDeclarations, declarations);
152340
152547
  });
152548
+ newDeclarations = combine(newDeclarations, getCombinedVerbatimImports());
152341
152549
  if (newDeclarations) {
152342
152550
  insertImports(
152343
152551
  changeTracker,
@@ -152349,8 +152557,85 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre
152349
152557
  );
152350
152558
  }
152351
152559
  }
152560
+ function getCombinedVerbatimImports() {
152561
+ if (!verbatimImports.size)
152562
+ return void 0;
152563
+ const importDeclarations = new Set(mapDefined([...verbatimImports], (d) => findAncestor(d, isImportDeclaration)));
152564
+ const requireStatements = new Set(mapDefined([...verbatimImports], (d) => findAncestor(d, isRequireVariableStatement)));
152565
+ return [
152566
+ ...mapDefined([...verbatimImports], (d) => d.kind === 271 /* ImportEqualsDeclaration */ ? getSynthesizedDeepClone(
152567
+ d,
152568
+ /*includeTrivia*/
152569
+ true
152570
+ ) : void 0),
152571
+ ...[...importDeclarations].map((d) => {
152572
+ var _a;
152573
+ if (verbatimImports.has(d)) {
152574
+ return getSynthesizedDeepClone(
152575
+ d,
152576
+ /*includeTrivia*/
152577
+ true
152578
+ );
152579
+ }
152580
+ return getSynthesizedDeepClone(
152581
+ factory.updateImportDeclaration(
152582
+ d,
152583
+ d.modifiers,
152584
+ d.importClause && factory.updateImportClause(
152585
+ d.importClause,
152586
+ d.importClause.isTypeOnly,
152587
+ verbatimImports.has(d.importClause) ? d.importClause.name : void 0,
152588
+ verbatimImports.has(d.importClause.namedBindings) ? d.importClause.namedBindings : ((_a = tryCast(d.importClause.namedBindings, isNamedImports)) == null ? void 0 : _a.elements.some((e) => verbatimImports.has(e))) ? factory.updateNamedImports(
152589
+ d.importClause.namedBindings,
152590
+ d.importClause.namedBindings.elements.filter((e) => verbatimImports.has(e))
152591
+ ) : void 0
152592
+ ),
152593
+ d.moduleSpecifier,
152594
+ d.attributes
152595
+ ),
152596
+ /*includeTrivia*/
152597
+ true
152598
+ );
152599
+ }),
152600
+ ...[...requireStatements].map((s) => {
152601
+ if (verbatimImports.has(s)) {
152602
+ return getSynthesizedDeepClone(
152603
+ s,
152604
+ /*includeTrivia*/
152605
+ true
152606
+ );
152607
+ }
152608
+ return getSynthesizedDeepClone(
152609
+ factory.updateVariableStatement(
152610
+ s,
152611
+ s.modifiers,
152612
+ factory.updateVariableDeclarationList(
152613
+ s.declarationList,
152614
+ mapDefined(s.declarationList.declarations, (d) => {
152615
+ if (verbatimImports.has(d)) {
152616
+ return d;
152617
+ }
152618
+ return factory.updateVariableDeclaration(
152619
+ d,
152620
+ d.name.kind === 206 /* ObjectBindingPattern */ ? factory.updateObjectBindingPattern(
152621
+ d.name,
152622
+ d.name.elements.filter((e) => verbatimImports.has(e))
152623
+ ) : d.name,
152624
+ d.exclamationToken,
152625
+ d.type,
152626
+ d.initializer
152627
+ );
152628
+ })
152629
+ )
152630
+ ),
152631
+ /*includeTrivia*/
152632
+ true
152633
+ );
152634
+ })
152635
+ ];
152636
+ }
152352
152637
  function hasFixes() {
152353
- return addToNamespace.length > 0 || importType.length > 0 || addToExisting.size > 0 || newImports.size > 0;
152638
+ return addToNamespace.length > 0 || importType.length > 0 || addToExisting.size > 0 || newImports.size > 0 || verbatimImports.size > 0 || removeExisting.size > 0;
152354
152639
  }
152355
152640
  }
152356
152641
  function createImportSpecifierResolver(importingFile, program, host, preferences) {
@@ -152459,9 +152744,12 @@ function getSingleExportInfoForSymbol(symbol, symbolName2, moduleSymbol, program
152459
152744
  }
152460
152745
  }
152461
152746
  }
152462
- function getImportFixes(exportInfos, usagePosition, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences, importMap = createExistingImportMap(program.getTypeChecker(), sourceFile, program.getCompilerOptions()), fromCacheOnly) {
152747
+ function isFutureSymbolExportInfoArray(info) {
152748
+ return info[0].symbol === void 0;
152749
+ }
152750
+ function getImportFixes(exportInfos, usagePosition, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences, importMap = isFullSourceFile(sourceFile) ? createExistingImportMap(program.getTypeChecker(), sourceFile, program.getCompilerOptions()) : void 0, fromCacheOnly) {
152463
152751
  const checker = program.getTypeChecker();
152464
- const existingImports = flatMap(exportInfos, importMap.getImportsForExportInfo);
152752
+ const existingImports = importMap && !isFutureSymbolExportInfoArray(exportInfos) ? flatMap(exportInfos, importMap.getImportsForExportInfo) : emptyArray;
152465
152753
  const useNamespace = usagePosition !== void 0 && tryUseExistingNamespaceImport(existingImports, usagePosition);
152466
152754
  const addToExisting = tryAddToExistingImport(existingImports, isValidTypeOnlyUseSite, checker, program.getCompilerOptions());
152467
152755
  if (addToExisting) {
@@ -152517,7 +152805,7 @@ function getAddAsTypeOnly(isValidTypeOnlyUseSite, isForNewImportDeclaration, sym
152517
152805
  if (!isValidTypeOnlyUseSite) {
152518
152806
  return 4 /* NotAllowed */;
152519
152807
  }
152520
- if (compilerOptions.verbatimModuleSyntax && (!(targetFlags & 111551 /* Value */) || !!checker.getTypeOnlyAliasDeclaration(symbol))) {
152808
+ if (symbol && compilerOptions.verbatimModuleSyntax && (!(targetFlags & 111551 /* Value */) || !!checker.getTypeOnlyAliasDeclaration(symbol))) {
152521
152809
  return 2 /* Required */;
152522
152810
  }
152523
152811
  return 1 /* Allowed */;
@@ -152604,7 +152892,7 @@ function createExistingImportMap(checker, importingFile, compilerOptions) {
152604
152892
  };
152605
152893
  }
152606
152894
  function shouldUseRequire(sourceFile, program) {
152607
- if (!isSourceFileJS(sourceFile)) {
152895
+ if (!hasJSFileExtension(sourceFile.fileName)) {
152608
152896
  return false;
152609
152897
  }
152610
152898
  if (sourceFile.commonJsModuleIndicator && !sourceFile.externalModuleIndicator)
@@ -152633,14 +152921,14 @@ function createGetChecker(program, host) {
152633
152921
  return memoizeOne((isFromPackageJson) => isFromPackageJson ? host.getPackageJsonAutoImportProvider().getTypeChecker() : program.getTypeChecker());
152634
152922
  }
152635
152923
  function getNewImportFixes(program, sourceFile, usagePosition, isValidTypeOnlyUseSite, useRequire, exportInfo, host, preferences, fromCacheOnly) {
152636
- const isJs = isSourceFileJS(sourceFile);
152924
+ const isJs = hasJSFileExtension(sourceFile.fileName);
152637
152925
  const compilerOptions = program.getCompilerOptions();
152638
152926
  const moduleSpecifierResolutionHost = createModuleSpecifierResolutionHost(program, host);
152639
152927
  const getChecker = createGetChecker(program, host);
152640
152928
  const moduleResolution = getEmitModuleResolutionKind(compilerOptions);
152641
152929
  const rejectNodeModulesRelativePaths = moduleResolutionUsesNodeModules(moduleResolution);
152642
- const getModuleSpecifiers2 = fromCacheOnly ? (moduleSymbol) => ({ moduleSpecifiers: ts_moduleSpecifiers_exports.tryGetModuleSpecifiersFromCache(moduleSymbol, sourceFile, moduleSpecifierResolutionHost, preferences), computedWithoutCache: false }) : (moduleSymbol, checker) => ts_moduleSpecifiers_exports.getModuleSpecifiersWithCacheInfo(
152643
- moduleSymbol,
152930
+ const getModuleSpecifiers2 = fromCacheOnly ? (exportInfo2) => ({ moduleSpecifiers: ts_moduleSpecifiers_exports.tryGetModuleSpecifiersFromCache(exportInfo2.moduleSymbol, sourceFile, moduleSpecifierResolutionHost, preferences), computedWithoutCache: false }) : (exportInfo2, checker) => ts_moduleSpecifiers_exports.getModuleSpecifiersWithCacheInfo(
152931
+ exportInfo2.moduleSymbol,
152644
152932
  checker,
152645
152933
  compilerOptions,
152646
152934
  sourceFile,
@@ -152654,7 +152942,7 @@ function getNewImportFixes(program, sourceFile, usagePosition, isValidTypeOnlyUs
152654
152942
  let computedWithoutCacheCount = 0;
152655
152943
  const fixes = flatMap(exportInfo, (exportInfo2, i) => {
152656
152944
  const checker = getChecker(exportInfo2.isFromPackageJson);
152657
- const { computedWithoutCache, moduleSpecifiers } = getModuleSpecifiers2(exportInfo2.moduleSymbol, checker);
152945
+ const { computedWithoutCache, moduleSpecifiers } = getModuleSpecifiers2(exportInfo2, checker);
152658
152946
  const importedSymbolHasValueMeaning = !!(exportInfo2.targetFlags & 111551 /* Value */);
152659
152947
  const addAsTypeOnly = getAddAsTypeOnly(
152660
152948
  isValidTypeOnlyUseSite,
@@ -152745,6 +153033,11 @@ function sortFixInfo(fixes, sourceFile, program, packageJsonImportFilter, host)
152745
153033
  const _toPath = (fileName) => toPath(fileName, host.getCurrentDirectory(), hostGetCanonicalFileName(host));
152746
153034
  return sort(fixes, (a, b) => compareBooleans(!!a.isJsxNamespaceFix, !!b.isJsxNamespaceFix) || compareValues(a.fix.kind, b.fix.kind) || compareModuleSpecifiers(a.fix, b.fix, sourceFile, program, packageJsonImportFilter.allowsImportingSpecifier, _toPath));
152747
153035
  }
153036
+ function getFixInfosWithoutDiagnostic(context, symbolToken, useAutoImportProvider) {
153037
+ const info = getFixesInfoForNonUMDImport(context, symbolToken, useAutoImportProvider);
153038
+ const packageJsonImportFilter = createPackageJsonImportFilter(context.sourceFile, context.preferences, context.host);
153039
+ return info && sortFixInfo(info, context.sourceFile, context.program, packageJsonImportFilter, context.host);
153040
+ }
152748
153041
  function getBestFix(fixes, sourceFile, program, packageJsonImportFilter, host) {
152749
153042
  if (!some(fixes))
152750
153043
  return;
@@ -152768,17 +153061,17 @@ function getBestFix(fixes, sourceFile, program, packageJsonImportFilter, host) {
152768
153061
  function compareModuleSpecifiers(a, b, importingFile, program, allowsImportingSpecifier, toPath3) {
152769
153062
  if (a.kind !== 0 /* UseNamespace */ && b.kind !== 0 /* UseNamespace */) {
152770
153063
  return compareBooleans(allowsImportingSpecifier(b.moduleSpecifier), allowsImportingSpecifier(a.moduleSpecifier)) || compareNodeCoreModuleSpecifiers(a.moduleSpecifier, b.moduleSpecifier, importingFile, program) || compareBooleans(
152771
- isFixPossiblyReExportingImportingFile(a, importingFile, program.getCompilerOptions(), toPath3),
152772
- isFixPossiblyReExportingImportingFile(b, importingFile, program.getCompilerOptions(), toPath3)
153064
+ isFixPossiblyReExportingImportingFile(a, importingFile.path, toPath3),
153065
+ isFixPossiblyReExportingImportingFile(b, importingFile.path, toPath3)
152773
153066
  ) || compareNumberOfDirectorySeparators(a.moduleSpecifier, b.moduleSpecifier);
152774
153067
  }
152775
153068
  return 0 /* EqualTo */;
152776
153069
  }
152777
- function isFixPossiblyReExportingImportingFile(fix, importingFile, compilerOptions, toPath3) {
153070
+ function isFixPossiblyReExportingImportingFile(fix, importingFilePath, toPath3) {
152778
153071
  var _a;
152779
153072
  if (fix.isReExport && ((_a = fix.exportInfo) == null ? void 0 : _a.moduleFileName) && isIndexFileName(fix.exportInfo.moduleFileName)) {
152780
153073
  const reExportDir = toPath3(getDirectoryPath(fix.exportInfo.moduleFileName));
152781
- return startsWith(importingFile.path, reExportDir);
153074
+ return startsWith(importingFilePath, reExportDir);
152782
153075
  }
152783
153076
  return false;
152784
153077
  }
@@ -152868,8 +153161,8 @@ function getUmdImportKind(importingFile, compilerOptions, forceImportKeyword) {
152868
153161
  case 2 /* AMD */:
152869
153162
  case 1 /* CommonJS */:
152870
153163
  case 3 /* UMD */:
152871
- if (isInJSFile(importingFile)) {
152872
- return isExternalModule(importingFile) || forceImportKeyword ? 2 /* Namespace */ : 3 /* CommonJS */;
153164
+ if (hasJSFileExtension(importingFile.fileName)) {
153165
+ return importingFile.externalModuleIndicator || forceImportKeyword ? 2 /* Namespace */ : 3 /* CommonJS */;
152873
153166
  }
152874
153167
  return 3 /* CommonJS */;
152875
153168
  case 4 /* System */:
@@ -152980,14 +153273,14 @@ function getExportInfos(symbolName2, isJsxTagName, currentTokenMeaning, cancella
152980
153273
  }
152981
153274
  function getExportEqualsImportKind(importingFile, compilerOptions, forceImportKeyword) {
152982
153275
  const allowSyntheticDefaults = getAllowSyntheticDefaultImports(compilerOptions);
152983
- const isJS = isInJSFile(importingFile);
153276
+ const isJS = hasJSFileExtension(importingFile.fileName);
152984
153277
  if (!isJS && getEmitModuleKind(compilerOptions) >= 5 /* ES2015 */) {
152985
153278
  return allowSyntheticDefaults ? 1 /* Default */ : 2 /* Namespace */;
152986
153279
  }
152987
153280
  if (isJS) {
152988
- return isExternalModule(importingFile) || forceImportKeyword ? allowSyntheticDefaults ? 1 /* Default */ : 2 /* Namespace */ : 3 /* CommonJS */;
153281
+ return importingFile.externalModuleIndicator || forceImportKeyword ? allowSyntheticDefaults ? 1 /* Default */ : 2 /* Namespace */ : 3 /* CommonJS */;
152989
153282
  }
152990
- for (const statement of importingFile.statements) {
153283
+ for (const statement of importingFile.statements ?? emptyArray) {
152991
153284
  if (isImportEqualsDeclaration(statement) && !nodeIsMissing(statement.moduleReference)) {
152992
153285
  return 3 /* CommonJS */;
152993
153286
  }
@@ -153018,6 +153311,8 @@ function codeActionForFixWorker(changes, sourceFile, symbolName2, fix, includeSy
153018
153311
  importClauseOrBindingPattern,
153019
153312
  importKind === 1 /* Default */ ? { name: symbolName2, addAsTypeOnly } : void 0,
153020
153313
  importKind === 0 /* Named */ ? [{ name: symbolName2, addAsTypeOnly }] : emptyArray,
153314
+ /*removeExistingImportSpecifiers*/
153315
+ void 0,
153021
153316
  preferences
153022
153317
  );
153023
153318
  const moduleSpecifierWithoutQuotes = stripQuotes(moduleSpecifier);
@@ -153132,9 +153427,33 @@ function promoteFromTypeOnly(changes, aliasDeclaration, program, sourceFile, pre
153132
153427
  }
153133
153428
  }
153134
153429
  }
153135
- function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImports, preferences) {
153430
+ function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImports, removeExistingImportSpecifiers, preferences) {
153136
153431
  var _a;
153137
153432
  if (clause.kind === 206 /* ObjectBindingPattern */) {
153433
+ if (removeExistingImportSpecifiers && clause.elements.some((e) => removeExistingImportSpecifiers.has(e))) {
153434
+ changes.replaceNode(
153435
+ sourceFile,
153436
+ clause,
153437
+ factory.createObjectBindingPattern([
153438
+ ...clause.elements.filter((e) => !removeExistingImportSpecifiers.has(e)),
153439
+ ...defaultImport ? [factory.createBindingElement(
153440
+ /*dotDotDotToken*/
153441
+ void 0,
153442
+ /*propertyName*/
153443
+ "default",
153444
+ defaultImport.name
153445
+ )] : emptyArray,
153446
+ ...namedImports.map((i) => factory.createBindingElement(
153447
+ /*dotDotDotToken*/
153448
+ void 0,
153449
+ /*propertyName*/
153450
+ void 0,
153451
+ i.name
153452
+ ))
153453
+ ])
153454
+ );
153455
+ return;
153456
+ }
153138
153457
  if (defaultImport) {
153139
153458
  addElementToBindingPattern(clause, defaultImport.name, "default");
153140
153459
  }
@@ -153167,7 +153486,16 @@ function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImpor
153167
153486
  ),
153168
153487
  specifierComparer
153169
153488
  );
153170
- if ((existingSpecifiers == null ? void 0 : existingSpecifiers.length) && isSorted !== false) {
153489
+ if (removeExistingImportSpecifiers) {
153490
+ changes.replaceNode(
153491
+ sourceFile,
153492
+ clause.namedBindings,
153493
+ factory.updateNamedImports(
153494
+ clause.namedBindings,
153495
+ stableSort([...existingSpecifiers.filter((s) => !removeExistingImportSpecifiers.has(s)), ...newSpecifiers], specifierComparer)
153496
+ )
153497
+ );
153498
+ } else if ((existingSpecifiers == null ? void 0 : existingSpecifiers.length) && isSorted !== false) {
153171
153499
  const transformedExistingSpecifiers = promoteFromTypeOnly2 && existingSpecifiers ? factory.updateNamedImports(
153172
153500
  clause.namedBindings,
153173
153501
  sameMap(existingSpecifiers, (e) => factory.updateImportSpecifier(
@@ -162003,13 +162331,13 @@ function getCompletionData(program, log, sourceFile, compilerOptions, position,
162003
162331
  ({ exportInfo: exportInfo2 = info[0], moduleSpecifier } = result);
162004
162332
  }
162005
162333
  const isDefaultExport = exportInfo2.exportKind === 1 /* Default */;
162006
- const symbol = isDefaultExport && getLocalSymbolForExportDefault(exportInfo2.symbol) || exportInfo2.symbol;
162334
+ const symbol = isDefaultExport && getLocalSymbolForExportDefault(Debug.checkDefined(exportInfo2.symbol)) || Debug.checkDefined(exportInfo2.symbol);
162007
162335
  pushAutoImportSymbol(symbol, {
162008
162336
  kind: moduleSpecifier ? 32 /* ResolvedExport */ : 4 /* Export */,
162009
162337
  moduleSpecifier,
162010
162338
  symbolName: symbolName2,
162011
162339
  exportMapKey,
162012
- exportName: exportInfo2.exportKind === 2 /* ExportEquals */ ? "export=" /* ExportEquals */ : exportInfo2.symbol.name,
162340
+ exportName: exportInfo2.exportKind === 2 /* ExportEquals */ ? "export=" /* ExportEquals */ : Debug.checkDefined(exportInfo2.symbol).name,
162013
162341
  fileName: exportInfo2.moduleFileName,
162014
162342
  isDefaultExport,
162015
162343
  moduleSymbol: exportInfo2.moduleSymbol,
@@ -175463,6 +175791,7 @@ __export(ts_exports2, {
175463
175791
  createFileDiagnosticFromMessageChain: () => createFileDiagnosticFromMessageChain,
175464
175792
  createFlowNode: () => createFlowNode,
175465
175793
  createForOfBindingStatement: () => createForOfBindingStatement,
175794
+ createFutureSourceFile: () => createFutureSourceFile,
175466
175795
  createGetCanonicalFileName: () => createGetCanonicalFileName,
175467
175796
  createGetSourceFile: () => createGetSourceFile,
175468
175797
  createGetSymbolAccessibilityDiagnosticForNode: () => createGetSymbolAccessibilityDiagnosticForNode,
@@ -176234,6 +176563,7 @@ __export(ts_exports2, {
176234
176563
  isAnyDirectorySeparator: () => isAnyDirectorySeparator,
176235
176564
  isAnyImportOrBareOrAccessedRequire: () => isAnyImportOrBareOrAccessedRequire,
176236
176565
  isAnyImportOrReExport: () => isAnyImportOrReExport,
176566
+ isAnyImportOrRequireStatement: () => isAnyImportOrRequireStatement,
176237
176567
  isAnyImportSyntax: () => isAnyImportSyntax,
176238
176568
  isAnySupportedFileExtension: () => isAnySupportedFileExtension,
176239
176569
  isApplicableVersionedTypesKey: () => isApplicableVersionedTypesKey,
@@ -176424,6 +176754,7 @@ __export(ts_exports2, {
176424
176754
  isForInitializer: () => isForInitializer,
176425
176755
  isForOfStatement: () => isForOfStatement,
176426
176756
  isForStatement: () => isForStatement,
176757
+ isFullSourceFile: () => isFullSourceFile,
176427
176758
  isFunctionBlock: () => isFunctionBlock,
176428
176759
  isFunctionBody: () => isFunctionBody,
176429
176760
  isFunctionDeclaration: () => isFunctionDeclaration,
@@ -189704,6 +190035,7 @@ if (typeof console !== "undefined") {
189704
190035
  createFileDiagnosticFromMessageChain,
189705
190036
  createFlowNode,
189706
190037
  createForOfBindingStatement,
190038
+ createFutureSourceFile,
189707
190039
  createGetCanonicalFileName,
189708
190040
  createGetSourceFile,
189709
190041
  createGetSymbolAccessibilityDiagnosticForNode,
@@ -190475,6 +190807,7 @@ if (typeof console !== "undefined") {
190475
190807
  isAnyDirectorySeparator,
190476
190808
  isAnyImportOrBareOrAccessedRequire,
190477
190809
  isAnyImportOrReExport,
190810
+ isAnyImportOrRequireStatement,
190478
190811
  isAnyImportSyntax,
190479
190812
  isAnySupportedFileExtension,
190480
190813
  isApplicableVersionedTypesKey,
@@ -190665,6 +190998,7 @@ if (typeof console !== "undefined") {
190665
190998
  isForInitializer,
190666
190999
  isForOfStatement,
190667
191000
  isForStatement,
191001
+ isFullSourceFile,
190668
191002
  isFunctionBlock,
190669
191003
  isFunctionBody,
190670
191004
  isFunctionDeclaration,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "typescript",
3
3
  "author": "Microsoft Corp.",
4
4
  "homepage": "https://www.typescriptlang.org/",
5
- "version": "5.5.0-dev.20240409",
5
+ "version": "5.5.0-dev.20240411",
6
6
  "license": "Apache-2.0",
7
7
  "description": "TypeScript is a language for application scale JavaScript development",
8
8
  "keywords": [
@@ -111,5 +111,5 @@
111
111
  "node": "20.1.0",
112
112
  "npm": "8.19.4"
113
113
  },
114
- "gitHead": "7a4cbfa7ea8c6b7a09a84d04bd7e45c815e8e0d1"
114
+ "gitHead": "806d7340472082e5ff6d844ecdb70a4b5165e8c5"
115
115
  }