@typescript-deploys/pr-build 5.5.0-pr-57267-12 → 5.5.0-pr-57717-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/tsserver.js CHANGED
@@ -161,6 +161,7 @@ __export(server_exports, {
161
161
  SignatureKind: () => SignatureKind,
162
162
  SmartSelectionRange: () => ts_SmartSelectionRange_exports,
163
163
  SnippetKind: () => SnippetKind,
164
+ SortKind: () => SortKind,
164
165
  StructureIsReused: () => StructureIsReused,
165
166
  SymbolAccessibility: () => SymbolAccessibility,
166
167
  SymbolDisplay: () => ts_SymbolDisplay_exports,
@@ -495,6 +496,7 @@ __export(server_exports, {
495
496
  defaultIncludeSpec: () => defaultIncludeSpec,
496
497
  defaultInitCompilerOptions: () => defaultInitCompilerOptions,
497
498
  defaultMaximumTruncationLength: () => defaultMaximumTruncationLength,
499
+ detectSortCaseSensitivity: () => detectSortCaseSensitivity,
498
500
  diagnosticCategoryName: () => diagnosticCategoryName,
499
501
  diagnosticToString: () => diagnosticToString,
500
502
  directoryProbablyExists: () => directoryProbablyExists,
@@ -2323,7 +2325,7 @@ module.exports = __toCommonJS(server_exports);
2323
2325
 
2324
2326
  // src/compiler/corePublic.ts
2325
2327
  var versionMajorMinor = "5.5";
2326
- var version = `${versionMajorMinor}.0-insiders.20240309`;
2328
+ var version = `${versionMajorMinor}.0-insiders.20240311`;
2327
2329
  var Comparison = /* @__PURE__ */ ((Comparison3) => {
2328
2330
  Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
2329
2331
  Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
@@ -2872,6 +2874,30 @@ function arrayIsSorted(array, comparer) {
2872
2874
  }
2873
2875
  return true;
2874
2876
  }
2877
+ var SortKind = /* @__PURE__ */ ((SortKind2) => {
2878
+ SortKind2[SortKind2["None"] = 0] = "None";
2879
+ SortKind2[SortKind2["CaseSensitive"] = 1] = "CaseSensitive";
2880
+ SortKind2[SortKind2["CaseInsensitive"] = 2] = "CaseInsensitive";
2881
+ SortKind2[SortKind2["Both"] = 3] = "Both";
2882
+ return SortKind2;
2883
+ })(SortKind || {});
2884
+ function detectSortCaseSensitivity(array, getString, compareStringsCaseSensitive2, compareStringsCaseInsensitive2) {
2885
+ let kind = 3 /* Both */;
2886
+ if (array.length < 2)
2887
+ return kind;
2888
+ let prevElement = getString(array[0]);
2889
+ for (let i = 1, len = array.length; i < len && kind !== 0 /* None */; i++) {
2890
+ const element = getString(array[i]);
2891
+ if (kind & 1 /* CaseSensitive */ && compareStringsCaseSensitive2(prevElement, element) > 0) {
2892
+ kind &= ~1 /* CaseSensitive */;
2893
+ }
2894
+ if (kind & 2 /* CaseInsensitive */ && compareStringsCaseInsensitive2(prevElement, element) > 0) {
2895
+ kind &= ~2 /* CaseInsensitive */;
2896
+ }
2897
+ prevElement = element;
2898
+ }
2899
+ return kind;
2900
+ }
2875
2901
  function arrayIsEqualTo(array1, array2, equalityComparer = equateValues) {
2876
2902
  if (!array1 || !array2) {
2877
2903
  return array1 === array2;
@@ -58256,7 +58282,7 @@ function createTypeChecker(host) {
58256
58282
  if (!lateSymbol)
58257
58283
  lateSymbols.set(memberName, lateSymbol = createSymbol(0 /* None */, memberName, 4096 /* Late */));
58258
58284
  const earlySymbol = earlySymbols && earlySymbols.get(memberName);
58259
- if (!(parent2.flags & 32 /* Class */) && (lateSymbol.flags & getExcludedSymbolFlags(symbolFlags) || earlySymbol)) {
58285
+ if (!(parent2.flags & 32 /* Class */) && lateSymbol.flags & getExcludedSymbolFlags(symbolFlags)) {
58260
58286
  const declarations = earlySymbol ? concatenate(earlySymbol.declarations, lateSymbol.declarations) : lateSymbol.declarations;
58261
58287
  const name = !(type.flags & 8192 /* UniqueESSymbol */) && unescapeLeadingUnderscores(memberName) || declarationNameToString(declName);
58262
58288
  forEach(declarations, (declaration) => error2(getNameOfDeclaration(declaration) || declaration, Diagnostics.Property_0_was_also_declared_here, name));
@@ -132952,13 +132978,15 @@ function insertImports(changes, sourceFile, imports, blankLineBetween, preferenc
132952
132978
  const decl = isArray(imports) ? imports[0] : imports;
132953
132979
  const importKindPredicate = decl.kind === 243 /* VariableStatement */ ? isRequireVariableStatement : isAnyImportSyntax;
132954
132980
  const existingImportStatements = filter(sourceFile.statements, importKindPredicate);
132955
- const { comparer, isSorted } = ts_OrganizeImports_exports.getOrganizeImportsStringComparerWithDetection(existingImportStatements, preferences);
132981
+ let sortKind = isArray(imports) ? ts_OrganizeImports_exports.detectImportDeclarationSorting(imports, preferences) : 3 /* Both */;
132982
+ const comparer = ts_OrganizeImports_exports.getOrganizeImportsComparer(preferences, sortKind === 2 /* CaseInsensitive */);
132956
132983
  const sortedNewImports = isArray(imports) ? stableSort(imports, (a, b) => ts_OrganizeImports_exports.compareImportsOrRequireStatements(a, b, comparer)) : [imports];
132957
132984
  if (!existingImportStatements.length) {
132958
132985
  changes.insertNodesAtTopOfFile(sourceFile, sortedNewImports, blankLineBetween);
132959
- } else if (existingImportStatements && isSorted) {
132986
+ } else if (existingImportStatements && (sortKind = ts_OrganizeImports_exports.detectImportDeclarationSorting(existingImportStatements, preferences))) {
132987
+ const comparer2 = ts_OrganizeImports_exports.getOrganizeImportsComparer(preferences, sortKind === 2 /* CaseInsensitive */);
132960
132988
  for (const newImport of sortedNewImports) {
132961
- const insertionIndex = ts_OrganizeImports_exports.getImportDeclarationInsertionIndex(existingImportStatements, newImport, comparer);
132989
+ const insertionIndex = ts_OrganizeImports_exports.getImportDeclarationInsertionIndex(existingImportStatements, newImport, comparer2);
132962
132990
  if (insertionIndex === 0) {
132963
132991
  const options = existingImportStatements[0] === sourceFile.statements[0] ? { leadingTriviaOption: ts_textChanges_exports.LeadingTriviaOption.Exclude } : {};
132964
132992
  changes.insertNodeBefore(
@@ -151224,7 +151252,8 @@ function promoteFromTypeOnly(changes, aliasDeclaration, program, sourceFile, pre
151224
151252
  switch (aliasDeclaration.kind) {
151225
151253
  case 276 /* ImportSpecifier */:
151226
151254
  if (aliasDeclaration.isTypeOnly) {
151227
- if (aliasDeclaration.parent.elements.length > 1) {
151255
+ const sortKind = ts_OrganizeImports_exports.detectImportSpecifierSorting(aliasDeclaration.parent.elements, preferences);
151256
+ if (aliasDeclaration.parent.elements.length > 1 && sortKind) {
151228
151257
  const newSpecifier = factory.updateImportSpecifier(
151229
151258
  aliasDeclaration,
151230
151259
  /*isTypeOnly*/
@@ -151232,8 +151261,8 @@ function promoteFromTypeOnly(changes, aliasDeclaration, program, sourceFile, pre
151232
151261
  aliasDeclaration.propertyName,
151233
151262
  aliasDeclaration.name
151234
151263
  );
151235
- const { specifierComparer } = ts_OrganizeImports_exports.getNamedImportSpecifierComparerWithDetection(aliasDeclaration.parent.parent.parent, preferences, sourceFile);
151236
- const insertionIndex = ts_OrganizeImports_exports.getImportSpecifierInsertionIndex(aliasDeclaration.parent.elements, newSpecifier, specifierComparer);
151264
+ const comparer = ts_OrganizeImports_exports.getOrganizeImportsComparer(preferences, sortKind === 2 /* CaseInsensitive */);
151265
+ const insertionIndex = ts_OrganizeImports_exports.getImportSpecifierInsertionIndex(aliasDeclaration.parent.elements, newSpecifier, comparer, preferences);
151237
151266
  if (insertionIndex !== aliasDeclaration.parent.elements.indexOf(aliasDeclaration)) {
151238
151267
  changes.delete(sourceFile, aliasDeclaration);
151239
151268
  changes.insertImportSpecifierAtIndex(sourceFile, newSpecifier, aliasDeclaration.parent, insertionIndex);
@@ -151273,8 +151302,7 @@ function promoteFromTypeOnly(changes, aliasDeclaration, program, sourceFile, pre
151273
151302
  if (convertExistingToTypeOnly) {
151274
151303
  const namedImports = tryCast(importClause.namedBindings, isNamedImports);
151275
151304
  if (namedImports && namedImports.elements.length > 1) {
151276
- const sortState = ts_OrganizeImports_exports.getNamedImportSpecifierComparerWithDetection(importClause.parent, preferences, sourceFile);
151277
- if (sortState.isSorted !== false && aliasDeclaration.kind === 276 /* ImportSpecifier */ && namedImports.elements.indexOf(aliasDeclaration) !== 0) {
151305
+ if (ts_OrganizeImports_exports.detectImportSpecifierSorting(namedImports.elements, preferences) && aliasDeclaration.kind === 276 /* ImportSpecifier */ && namedImports.elements.indexOf(aliasDeclaration) !== 0) {
151278
151306
  changes.delete(sourceFile, aliasDeclaration);
151279
151307
  changes.insertImportSpecifierAtIndex(sourceFile, aliasDeclaration, namedImports, 0);
151280
151308
  }
@@ -151310,7 +151338,19 @@ function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImpor
151310
151338
  changes.insertNodeAt(sourceFile, clause.getStart(sourceFile), factory.createIdentifier(defaultImport.name), { suffix: ", " });
151311
151339
  }
151312
151340
  if (namedImports.length) {
151313
- const { specifierComparer, isSorted } = ts_OrganizeImports_exports.getNamedImportSpecifierComparerWithDetection(clause.parent, preferences, sourceFile);
151341
+ let ignoreCaseForSorting;
151342
+ if (typeof preferences.organizeImportsIgnoreCase === "boolean") {
151343
+ ignoreCaseForSorting = preferences.organizeImportsIgnoreCase;
151344
+ } else if (existingSpecifiers) {
151345
+ const targetImportSorting = ts_OrganizeImports_exports.detectImportSpecifierSorting(existingSpecifiers, preferences);
151346
+ if (targetImportSorting !== 3 /* Both */) {
151347
+ ignoreCaseForSorting = targetImportSorting === 2 /* CaseInsensitive */;
151348
+ }
151349
+ }
151350
+ if (ignoreCaseForSorting === void 0) {
151351
+ ignoreCaseForSorting = ts_OrganizeImports_exports.detectSorting(sourceFile, preferences) === 2 /* CaseInsensitive */;
151352
+ }
151353
+ const comparer = ts_OrganizeImports_exports.getOrganizeImportsComparer(preferences, ignoreCaseForSorting);
151314
151354
  const newSpecifiers = stableSort(
151315
151355
  namedImports.map(
151316
151356
  (namedImport) => factory.createImportSpecifier(
@@ -151320,11 +151360,12 @@ function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImpor
151320
151360
  factory.createIdentifier(namedImport.name)
151321
151361
  )
151322
151362
  ),
151323
- specifierComparer
151363
+ (s1, s2) => ts_OrganizeImports_exports.compareImportOrExportSpecifiers(s1, s2, comparer)
151324
151364
  );
151325
- if ((existingSpecifiers == null ? void 0 : existingSpecifiers.length) && isSorted !== false) {
151365
+ const specifierSort = (existingSpecifiers == null ? void 0 : existingSpecifiers.length) && ts_OrganizeImports_exports.detectImportSpecifierSorting(existingSpecifiers, preferences);
151366
+ if (specifierSort && !(ignoreCaseForSorting && specifierSort === 1 /* CaseSensitive */)) {
151326
151367
  for (const spec of newSpecifiers) {
151327
- const insertionIndex = ts_OrganizeImports_exports.getImportSpecifierInsertionIndex(existingSpecifiers, spec, specifierComparer);
151368
+ const insertionIndex = promoteFromTypeOnly2 && !spec.isTypeOnly ? 0 : ts_OrganizeImports_exports.getImportSpecifierInsertionIndex(existingSpecifiers, spec, comparer, preferences);
151328
151369
  changes.insertImportSpecifierAtIndex(sourceFile, spec, clause.namedBindings, insertionIndex);
151329
151370
  }
151330
151371
  } else if (existingSpecifiers == null ? void 0 : existingSpecifiers.length) {
@@ -166498,16 +166539,18 @@ function getRightHandSideOfAssignment(rightHandSide) {
166498
166539
  // src/services/_namespaces/ts.OrganizeImports.ts
166499
166540
  var ts_OrganizeImports_exports = {};
166500
166541
  __export(ts_OrganizeImports_exports, {
166542
+ coalesceExports: () => coalesceExports,
166543
+ coalesceImports: () => coalesceImports,
166544
+ compareImportOrExportSpecifiers: () => compareImportOrExportSpecifiers,
166501
166545
  compareImportsOrRequireStatements: () => compareImportsOrRequireStatements,
166502
166546
  compareModuleSpecifiers: () => compareModuleSpecifiers2,
166503
- getDetectionLists: () => getDetectionLists,
166547
+ detectImportDeclarationSorting: () => detectImportDeclarationSorting,
166548
+ detectImportSpecifierSorting: () => detectImportSpecifierSorting,
166549
+ detectSorting: () => detectSorting,
166504
166550
  getImportDeclarationInsertionIndex: () => getImportDeclarationInsertionIndex,
166505
166551
  getImportSpecifierInsertionIndex: () => getImportSpecifierInsertionIndex,
166506
- getNamedImportSpecifierComparerWithDetection: () => getNamedImportSpecifierComparerWithDetection,
166507
- getOrganizeImportsStringComparerWithDetection: () => getOrganizeImportsStringComparerWithDetection,
166508
- organizeImports: () => organizeImports,
166509
- testCoalesceExports: () => testCoalesceExports,
166510
- testCoalesceImports: () => testCoalesceImports
166552
+ getOrganizeImportsComparer: () => getOrganizeImportsComparer,
166553
+ organizeImports: () => organizeImports
166511
166554
  });
166512
166555
 
166513
166556
  // src/services/organizeImports.ts
@@ -166516,48 +166559,39 @@ function organizeImports(sourceFile, formatContext, host, program, preferences,
166516
166559
  const shouldSort = mode === "SortAndCombine" /* SortAndCombine */ || mode === "All" /* All */;
166517
166560
  const shouldCombine = shouldSort;
166518
166561
  const shouldRemove = mode === "RemoveUnused" /* RemoveUnused */ || mode === "All" /* All */;
166519
- const topLevelImportDecls = sourceFile.statements.filter(isImportDeclaration);
166520
- const topLevelImportGroupDecls = groupByNewlineContiguous(sourceFile, topLevelImportDecls);
166521
- const { comparersToTest, typeOrdersToTest } = getDetectionLists(preferences);
166522
- const defaultComparer = comparersToTest[0];
166523
- const comparer = {
166524
- moduleSpecifierComparer: typeof preferences.organizeImportsIgnoreCase === "boolean" ? defaultComparer : void 0,
166525
- namedImportComparer: typeof preferences.organizeImportsIgnoreCase === "boolean" ? defaultComparer : void 0,
166526
- typeOrder: preferences.organizeImportsTypeOrder
166562
+ const topLevelImportGroupDecls = groupByNewlineContiguous(sourceFile, sourceFile.statements.filter(isImportDeclaration));
166563
+ const comparer = getOrganizeImportsComparerWithDetection(preferences, shouldSort ? () => detectSortingWorker(topLevelImportGroupDecls, preferences) === 2 /* CaseInsensitive */ : void 0);
166564
+ const processImportsOfSameModuleSpecifier = (importGroup) => {
166565
+ if (shouldRemove)
166566
+ importGroup = removeUnusedImports(importGroup, sourceFile, program);
166567
+ if (shouldCombine)
166568
+ importGroup = coalesceImportsWorker(importGroup, comparer, sourceFile, preferences);
166569
+ if (shouldSort)
166570
+ importGroup = stableSort(importGroup, (s1, s2) => compareImportsOrRequireStatements(s1, s2, comparer));
166571
+ return importGroup;
166527
166572
  };
166528
- if (typeof preferences.organizeImportsIgnoreCase !== "boolean") {
166529
- ({ comparer: comparer.moduleSpecifierComparer } = detectModuleSpecifierCaseBySort(topLevelImportGroupDecls, comparersToTest));
166530
- }
166531
- if (!comparer.typeOrder || typeof preferences.organizeImportsIgnoreCase !== "boolean") {
166532
- const namedImportSort = detectNamedImportOrganizationBySort(topLevelImportDecls, comparersToTest, typeOrdersToTest);
166533
- if (namedImportSort) {
166534
- const { namedImportComparer, typeOrder } = namedImportSort;
166535
- comparer.namedImportComparer = comparer.namedImportComparer ?? namedImportComparer;
166536
- comparer.typeOrder = comparer.typeOrder ?? typeOrder;
166537
- }
166538
- }
166539
- topLevelImportGroupDecls.forEach((importGroupDecl) => organizeImportsWorker(importGroupDecl, comparer));
166573
+ topLevelImportGroupDecls.forEach((importGroupDecl) => organizeImportsWorker(importGroupDecl, processImportsOfSameModuleSpecifier));
166540
166574
  if (mode !== "RemoveUnused" /* RemoveUnused */) {
166541
- getTopLevelExportGroups(sourceFile).forEach((exportGroupDecl) => organizeExportsWorker(exportGroupDecl, comparer.namedImportComparer));
166575
+ getTopLevelExportGroups(sourceFile).forEach((exportGroupDecl) => organizeImportsWorker(exportGroupDecl, (group2) => coalesceExportsWorker(group2, comparer, preferences)));
166542
166576
  }
166543
166577
  for (const ambientModule of sourceFile.statements.filter(isAmbientModule)) {
166544
166578
  if (!ambientModule.body)
166545
166579
  continue;
166546
166580
  const ambientModuleImportGroupDecls = groupByNewlineContiguous(sourceFile, ambientModule.body.statements.filter(isImportDeclaration));
166547
- ambientModuleImportGroupDecls.forEach((importGroupDecl) => organizeImportsWorker(importGroupDecl, comparer));
166581
+ ambientModuleImportGroupDecls.forEach((importGroupDecl) => organizeImportsWorker(importGroupDecl, processImportsOfSameModuleSpecifier));
166548
166582
  if (mode !== "RemoveUnused" /* RemoveUnused */) {
166549
166583
  const ambientModuleExportDecls = ambientModule.body.statements.filter(isExportDeclaration);
166550
- organizeExportsWorker(ambientModuleExportDecls, comparer.namedImportComparer);
166584
+ organizeImportsWorker(ambientModuleExportDecls, (group2) => coalesceExportsWorker(group2, comparer, preferences));
166551
166585
  }
166552
166586
  }
166553
166587
  return changeTracker.getChanges();
166554
- function organizeDeclsWorker(oldImportDecls, coalesce) {
166588
+ function organizeImportsWorker(oldImportDecls, coalesce) {
166555
166589
  if (length(oldImportDecls) === 0) {
166556
166590
  return;
166557
166591
  }
166558
166592
  setEmitFlags(oldImportDecls[0], 1024 /* NoLeadingComments */);
166559
166593
  const oldImportGroups = shouldCombine ? group(oldImportDecls, (importDecl) => getExternalModuleName2(importDecl.moduleSpecifier)) : [oldImportDecls];
166560
- const sortedImportGroups = shouldSort ? stableSort(oldImportGroups, (group1, group2) => compareModuleSpecifiersWorker(group1[0].moduleSpecifier, group2[0].moduleSpecifier, comparer.moduleSpecifierComparer ?? defaultComparer)) : oldImportGroups;
166594
+ const sortedImportGroups = shouldSort ? stableSort(oldImportGroups, (group1, group2) => compareModuleSpecifiersWorker(group1[0].moduleSpecifier, group2[0].moduleSpecifier, comparer)) : oldImportGroups;
166561
166595
  const newImportDecls = flatMap(sortedImportGroups, (importGroup) => getExternalModuleName2(importGroup[0].moduleSpecifier) || importGroup[0].moduleSpecifier === void 0 ? coalesce(importGroup) : importGroup);
166562
166596
  if (newImportDecls.length === 0) {
166563
166597
  changeTracker.deleteNodes(
@@ -166584,40 +166618,6 @@ function organizeImports(sourceFile, formatContext, host, program, preferences,
166584
166618
  }, hasTrailingComment);
166585
166619
  }
166586
166620
  }
166587
- function organizeImportsWorker(oldImportDecls, comparer2) {
166588
- const detectedModuleCaseComparer = comparer2.moduleSpecifierComparer ?? defaultComparer;
166589
- const detectedNamedImportCaseComparer = comparer2.namedImportComparer ?? defaultComparer;
166590
- const detectedTypeOrder = comparer2.typeOrder ?? "last";
166591
- const specifierComparer = getNamedImportSpecifierComparer({ organizeImportsTypeOrder: detectedTypeOrder }, detectedNamedImportCaseComparer);
166592
- const processImportsOfSameModuleSpecifier = (importGroup) => {
166593
- if (shouldRemove)
166594
- importGroup = removeUnusedImports(importGroup, sourceFile, program);
166595
- if (shouldCombine)
166596
- importGroup = coalesceImportsWorker(importGroup, detectedModuleCaseComparer, specifierComparer, sourceFile);
166597
- if (shouldSort)
166598
- importGroup = stableSort(importGroup, (s1, s2) => compareImportsOrRequireStatements(s1, s2, detectedModuleCaseComparer));
166599
- return importGroup;
166600
- };
166601
- organizeDeclsWorker(oldImportDecls, processImportsOfSameModuleSpecifier);
166602
- }
166603
- function organizeExportsWorker(oldExportDecls, specifierCaseComparer) {
166604
- const useComparer = getNamedImportSpecifierComparer(preferences, specifierCaseComparer);
166605
- organizeDeclsWorker(oldExportDecls, (group2) => coalesceExportsWorker(group2, useComparer));
166606
- }
166607
- }
166608
- function getDetectionLists(preferences) {
166609
- return {
166610
- comparersToTest: typeof preferences.organizeImportsIgnoreCase === "boolean" ? [getOrganizeImportsStringComparer(preferences, preferences.organizeImportsIgnoreCase)] : [getOrganizeImportsStringComparer(
166611
- preferences,
166612
- /*ignoreCase*/
166613
- true
166614
- ), getOrganizeImportsStringComparer(
166615
- preferences,
166616
- /*ignoreCase*/
166617
- false
166618
- )],
166619
- typeOrdersToTest: preferences.organizeImportsTypeOrder ? [preferences.organizeImportsTypeOrder] : ["last", "inline", "first"]
166620
- };
166621
166621
  }
166622
166622
  function groupByNewlineContiguous(sourceFile, decls) {
166623
166623
  const scanner2 = createScanner(
@@ -166655,33 +166655,6 @@ function isNewGroup(sourceFile, decl, scanner2) {
166655
166655
  }
166656
166656
  return false;
166657
166657
  }
166658
- function getTopLevelExportGroups(sourceFile) {
166659
- const topLevelExportGroups = [];
166660
- const statements = sourceFile.statements;
166661
- const len = length(statements);
166662
- let i = 0;
166663
- let groupIndex = 0;
166664
- while (i < len) {
166665
- if (isExportDeclaration(statements[i])) {
166666
- if (topLevelExportGroups[groupIndex] === void 0) {
166667
- topLevelExportGroups[groupIndex] = [];
166668
- }
166669
- const exportDecl = statements[i];
166670
- if (exportDecl.moduleSpecifier) {
166671
- topLevelExportGroups[groupIndex].push(exportDecl);
166672
- i++;
166673
- } else {
166674
- while (i < len && isExportDeclaration(statements[i])) {
166675
- topLevelExportGroups[groupIndex].push(statements[i++]);
166676
- }
166677
- groupIndex++;
166678
- }
166679
- } else {
166680
- i++;
166681
- }
166682
- }
166683
- return flatMap(topLevelExportGroups, (exportGroupDecls) => groupByNewlineContiguous(sourceFile, exportGroupDecls));
166684
- }
166685
166658
  function removeUnusedImports(oldImports, sourceFile, program) {
166686
166659
  const typeChecker = program.getTypeChecker();
166687
166660
  const compilerOptions = program.getCompilerOptions();
@@ -166733,38 +166706,18 @@ function removeUnusedImports(oldImports, sourceFile, program) {
166733
166706
  return jsxElementsPresent && (identifier.text === jsxNamespace || jsxFragmentFactory && identifier.text === jsxFragmentFactory) && jsxModeNeedsExplicitImport(compilerOptions.jsx) || ts_FindAllReferences_exports.Core.isSymbolReferencedInFile(identifier, typeChecker, sourceFile);
166734
166707
  }
166735
166708
  }
166709
+ function hasModuleDeclarationMatchingSpecifier(sourceFile, moduleSpecifier) {
166710
+ const moduleSpecifierText = isStringLiteral(moduleSpecifier) && moduleSpecifier.text;
166711
+ return isString(moduleSpecifierText) && some(sourceFile.moduleAugmentations, (moduleName) => isStringLiteral(moduleName) && moduleName.text === moduleSpecifierText);
166712
+ }
166736
166713
  function getExternalModuleName2(specifier) {
166737
166714
  return specifier !== void 0 && isStringLiteralLike(specifier) ? specifier.text : void 0;
166738
166715
  }
166739
- function getCategorizedImports(importGroup) {
166740
- let importWithoutClause;
166741
- const typeOnlyImports = { defaultImports: [], namespaceImports: [], namedImports: [] };
166742
- const regularImports = { defaultImports: [], namespaceImports: [], namedImports: [] };
166743
- for (const importDeclaration of importGroup) {
166744
- if (importDeclaration.importClause === void 0) {
166745
- importWithoutClause = importWithoutClause || importDeclaration;
166746
- continue;
166747
- }
166748
- const group2 = importDeclaration.importClause.isTypeOnly ? typeOnlyImports : regularImports;
166749
- const { name, namedBindings } = importDeclaration.importClause;
166750
- if (name) {
166751
- group2.defaultImports.push(importDeclaration);
166752
- }
166753
- if (namedBindings) {
166754
- if (isNamespaceImport(namedBindings)) {
166755
- group2.namespaceImports.push(importDeclaration);
166756
- } else {
166757
- group2.namedImports.push(importDeclaration);
166758
- }
166759
- }
166760
- }
166761
- return {
166762
- importWithoutClause,
166763
- typeOnlyImports,
166764
- regularImports
166765
- };
166716
+ function coalesceImports(importGroup, ignoreCase, sourceFile, preferences) {
166717
+ const comparer = getOrganizeImportsOrdinalStringComparer(ignoreCase);
166718
+ return coalesceImportsWorker(importGroup, comparer, sourceFile, preferences);
166766
166719
  }
166767
- function coalesceImportsWorker(importGroup, comparer, specifierComparer, sourceFile) {
166720
+ function coalesceImportsWorker(importGroup, comparer, sourceFile, preferences) {
166768
166721
  if (importGroup.length === 0) {
166769
166722
  return importGroup;
166770
166723
  }
@@ -166831,7 +166784,7 @@ function coalesceImportsWorker(importGroup, comparer, specifierComparer, sourceF
166831
166784
  }
166832
166785
  newImportSpecifiers.push(...getNewImportSpecifiers(namedImports));
166833
166786
  const sortedImportSpecifiers = factory.createNodeArray(
166834
- stableSort(newImportSpecifiers, specifierComparer),
166787
+ sortSpecifiers(newImportSpecifiers, comparer, preferences),
166835
166788
  firstNamedImport == null ? void 0 : firstNamedImport.importClause.namedBindings.elements.hasTrailingComma
166836
166789
  );
166837
166790
  const newNamedImports = sortedImportSpecifiers.length === 0 ? newDefaultImport ? void 0 : factory.createNamedImports(emptyArray) : firstNamedImport ? factory.updateNamedImports(firstNamedImport.importClause.namedBindings, sortedImportSpecifiers) : factory.createNamedImports(sortedImportSpecifiers);
@@ -166864,7 +166817,39 @@ function coalesceImportsWorker(importGroup, comparer, specifierComparer, sourceF
166864
166817
  }
166865
166818
  return coalescedImports;
166866
166819
  }
166867
- function coalesceExportsWorker(exportGroup, specifierComparer) {
166820
+ function getCategorizedImports(importGroup) {
166821
+ let importWithoutClause;
166822
+ const typeOnlyImports = { defaultImports: [], namespaceImports: [], namedImports: [] };
166823
+ const regularImports = { defaultImports: [], namespaceImports: [], namedImports: [] };
166824
+ for (const importDeclaration of importGroup) {
166825
+ if (importDeclaration.importClause === void 0) {
166826
+ importWithoutClause = importWithoutClause || importDeclaration;
166827
+ continue;
166828
+ }
166829
+ const group2 = importDeclaration.importClause.isTypeOnly ? typeOnlyImports : regularImports;
166830
+ const { name, namedBindings } = importDeclaration.importClause;
166831
+ if (name) {
166832
+ group2.defaultImports.push(importDeclaration);
166833
+ }
166834
+ if (namedBindings) {
166835
+ if (isNamespaceImport(namedBindings)) {
166836
+ group2.namespaceImports.push(importDeclaration);
166837
+ } else {
166838
+ group2.namedImports.push(importDeclaration);
166839
+ }
166840
+ }
166841
+ }
166842
+ return {
166843
+ importWithoutClause,
166844
+ typeOnlyImports,
166845
+ regularImports
166846
+ };
166847
+ }
166848
+ function coalesceExports(exportGroup, ignoreCase, preferences) {
166849
+ const comparer = getOrganizeImportsOrdinalStringComparer(ignoreCase);
166850
+ return coalesceExportsWorker(exportGroup, comparer, preferences);
166851
+ }
166852
+ function coalesceExportsWorker(exportGroup, comparer, preferences) {
166868
166853
  if (exportGroup.length === 0) {
166869
166854
  return exportGroup;
166870
166855
  }
@@ -166879,7 +166864,7 @@ function coalesceExportsWorker(exportGroup, specifierComparer) {
166879
166864
  }
166880
166865
  const newExportSpecifiers = [];
166881
166866
  newExportSpecifiers.push(...flatMap(exportGroup2, (i) => i.exportClause && isNamedExports(i.exportClause) ? i.exportClause.elements : emptyArray));
166882
- const sortedExportSpecifiers = stableSort(newExportSpecifiers, specifierComparer);
166867
+ const sortedExportSpecifiers = sortSpecifiers(newExportSpecifiers, comparer, preferences);
166883
166868
  const exportDecl = exportGroup2[0];
166884
166869
  coalescedExports.push(
166885
166870
  factory.updateExportDeclaration(
@@ -166923,6 +166908,9 @@ function updateImportDeclarationAndClause(importDeclaration, name, namedBindings
166923
166908
  importDeclaration.attributes
166924
166909
  );
166925
166910
  }
166911
+ function sortSpecifiers(specifiers, comparer, preferences) {
166912
+ return stableSort(specifiers, (s1, s2) => compareImportOrExportSpecifiers(s1, s2, comparer, preferences));
166913
+ }
166926
166914
  function compareImportOrExportSpecifiers(s1, s2, comparer, preferences) {
166927
166915
  switch (preferences == null ? void 0 : preferences.organizeImportsTypeOrder) {
166928
166916
  case "first":
@@ -166933,14 +166921,15 @@ function compareImportOrExportSpecifiers(s1, s2, comparer, preferences) {
166933
166921
  return compareBooleans(s1.isTypeOnly, s2.isTypeOnly) || comparer(s1.name.text, s2.name.text);
166934
166922
  }
166935
166923
  }
166924
+ function compareModuleSpecifiers2(m1, m2, ignoreCase) {
166925
+ const comparer = getOrganizeImportsOrdinalStringComparer(!!ignoreCase);
166926
+ return compareModuleSpecifiersWorker(m1, m2, comparer);
166927
+ }
166936
166928
  function compareModuleSpecifiersWorker(m1, m2, comparer) {
166937
166929
  const name1 = m1 === void 0 ? void 0 : getExternalModuleName2(m1);
166938
166930
  const name2 = m2 === void 0 ? void 0 : getExternalModuleName2(m2);
166939
166931
  return compareBooleans(name1 === void 0, name2 === void 0) || compareBooleans(isExternalModuleNameRelative(name1), isExternalModuleNameRelative(name2)) || comparer(name1, name2);
166940
166932
  }
166941
- function getModuleNamesFromDecls(decls) {
166942
- return decls.map((s) => getExternalModuleName2(getModuleSpecifierExpression(s)) || "");
166943
- }
166944
166933
  function getModuleSpecifierExpression(declaration) {
166945
166934
  var _a;
166946
166935
  switch (declaration.kind) {
@@ -166952,114 +166941,164 @@ function getModuleSpecifierExpression(declaration) {
166952
166941
  return declaration.declarationList.declarations[0].initializer.arguments[0];
166953
166942
  }
166954
166943
  }
166955
- function hasModuleDeclarationMatchingSpecifier(sourceFile, moduleSpecifier) {
166956
- const moduleSpecifierText = isStringLiteral(moduleSpecifier) && moduleSpecifier.text;
166957
- return isString(moduleSpecifierText) && some(sourceFile.moduleAugmentations, (moduleName) => isStringLiteral(moduleName) && moduleName.text === moduleSpecifierText);
166958
- }
166959
- function getNewImportSpecifiers(namedImports) {
166960
- return flatMap(namedImports, (namedImport) => map(tryGetNamedBindingElements(namedImport), (importSpecifier) => importSpecifier.name && importSpecifier.propertyName && importSpecifier.name.escapedText === importSpecifier.propertyName.escapedText ? factory.updateImportSpecifier(
166961
- importSpecifier,
166962
- importSpecifier.isTypeOnly,
166963
- /*propertyName*/
166964
- void 0,
166965
- importSpecifier.name
166966
- ) : importSpecifier));
166967
- }
166968
- function tryGetNamedBindingElements(namedImport) {
166969
- var _a;
166970
- return ((_a = namedImport.importClause) == null ? void 0 : _a.namedBindings) && isNamedImports(namedImport.importClause.namedBindings) ? namedImport.importClause.namedBindings.elements : void 0;
166971
- }
166972
- function detectModuleSpecifierCaseBySort(importDeclsByGroup, comparersToTest) {
166973
- const moduleSpecifiersByGroup = [];
166974
- importDeclsByGroup.forEach((importGroup) => {
166975
- moduleSpecifiersByGroup.push(getModuleNamesFromDecls(importGroup));
166976
- });
166977
- return detectCaseSensitivityBySort(moduleSpecifiersByGroup, comparersToTest);
166944
+ function detectSorting(sourceFile, preferences) {
166945
+ return detectSortingWorker(
166946
+ groupByNewlineContiguous(sourceFile, sourceFile.statements.filter(isImportDeclaration)),
166947
+ preferences
166948
+ );
166978
166949
  }
166979
- function detectNamedImportOrganizationBySort(originalGroups, comparersToTest, typesToTest) {
166980
- let bothNamedImports = false;
166981
- const importDeclsWithNamed = originalGroups.filter((i) => {
166982
- var _a, _b;
166983
- const namedImports = (_b = tryCast((_a = i.importClause) == null ? void 0 : _a.namedBindings, isNamedImports)) == null ? void 0 : _b.elements;
166984
- if (!(namedImports == null ? void 0 : namedImports.length))
166985
- return false;
166986
- if (!bothNamedImports && namedImports.some((n) => n.isTypeOnly) && namedImports.some((n) => !n.isTypeOnly)) {
166987
- bothNamedImports = true;
166988
- }
166989
- return true;
166990
- });
166991
- if (importDeclsWithNamed.length === 0)
166992
- return;
166993
- const namedImportsByDecl = importDeclsWithNamed.map((importDecl) => {
166994
- var _a, _b;
166995
- return (_b = tryCast((_a = importDecl.importClause) == null ? void 0 : _a.namedBindings, isNamedImports)) == null ? void 0 : _b.elements;
166996
- }).filter((elements) => elements !== void 0);
166997
- if (!bothNamedImports || typesToTest.length === 0) {
166998
- const sortState = detectCaseSensitivityBySort(namedImportsByDecl.map((i) => i.map((n) => n.name.text)), comparersToTest);
166999
- return {
167000
- namedImportComparer: sortState.comparer,
167001
- typeOrder: typesToTest.length === 1 ? typesToTest[0] : void 0,
167002
- isSorted: sortState.isSorted
167003
- };
167004
- }
167005
- const bestDiff = { first: Infinity, last: Infinity, inline: Infinity };
167006
- const bestComparer = { first: comparersToTest[0], last: comparersToTest[0], inline: comparersToTest[0] };
167007
- for (const curComparer of comparersToTest) {
167008
- const currDiff = { first: 0, last: 0, inline: 0 };
167009
- for (const importDecl of namedImportsByDecl) {
167010
- for (const typeOrder of typesToTest) {
167011
- currDiff[typeOrder] = (currDiff[typeOrder] ?? 0) + measureSortedness(importDecl, (n1, n2) => compareImportOrExportSpecifiers(n1, n2, curComparer, { organizeImportsTypeOrder: typeOrder }));
166950
+ function detectSortingWorker(importGroups, preferences) {
166951
+ const collateCaseSensitive = getOrganizeImportsComparer(
166952
+ preferences,
166953
+ /*ignoreCase*/
166954
+ false
166955
+ );
166956
+ const collateCaseInsensitive = getOrganizeImportsComparer(
166957
+ preferences,
166958
+ /*ignoreCase*/
166959
+ true
166960
+ );
166961
+ let sortState = 3 /* Both */;
166962
+ let seenUnsortedGroup = false;
166963
+ for (const importGroup of importGroups) {
166964
+ if (importGroup.length > 1) {
166965
+ const moduleSpecifierSort = detectSortCaseSensitivity(
166966
+ importGroup,
166967
+ (i) => {
166968
+ var _a;
166969
+ return ((_a = tryCast(i.moduleSpecifier, isStringLiteral)) == null ? void 0 : _a.text) ?? "";
166970
+ },
166971
+ collateCaseSensitive,
166972
+ collateCaseInsensitive
166973
+ );
166974
+ if (moduleSpecifierSort) {
166975
+ sortState &= moduleSpecifierSort;
166976
+ seenUnsortedGroup = true;
167012
166977
  }
167013
- }
167014
- for (const key of typesToTest) {
167015
- const typeOrder = key;
167016
- if (currDiff[typeOrder] < bestDiff[typeOrder]) {
167017
- bestDiff[typeOrder] = currDiff[typeOrder];
167018
- bestComparer[typeOrder] = curComparer;
166978
+ if (!sortState) {
166979
+ return sortState;
167019
166980
  }
167020
166981
  }
167021
- }
167022
- outer:
167023
- for (const bestKey of typesToTest) {
167024
- const bestTypeOrder = bestKey;
167025
- for (const testKey of typesToTest) {
167026
- const testTypeOrder = testKey;
167027
- if (bestDiff[testTypeOrder] < bestDiff[bestTypeOrder])
167028
- continue outer;
166982
+ const declarationWithNamedImports = find(
166983
+ importGroup,
166984
+ (i) => {
166985
+ var _a, _b;
166986
+ return ((_b = tryCast((_a = i.importClause) == null ? void 0 : _a.namedBindings, isNamedImports)) == null ? void 0 : _b.elements.length) > 1;
166987
+ }
166988
+ );
166989
+ if (declarationWithNamedImports) {
166990
+ const namedImportSort = detectImportSpecifierSorting(declarationWithNamedImports.importClause.namedBindings.elements, preferences);
166991
+ if (namedImportSort) {
166992
+ sortState &= namedImportSort;
166993
+ seenUnsortedGroup = true;
166994
+ }
166995
+ if (!sortState) {
166996
+ return sortState;
167029
166997
  }
167030
- return { namedImportComparer: bestComparer[bestTypeOrder], typeOrder: bestTypeOrder, isSorted: bestDiff[bestTypeOrder] === 0 };
167031
166998
  }
167032
- return { namedImportComparer: bestComparer.last, typeOrder: "last", isSorted: bestDiff.last === 0 };
167033
- }
167034
- function measureSortedness(arr, comparer) {
167035
- let i = 0;
167036
- for (let j = 0; j < arr.length - 1; j++) {
167037
- if (comparer(arr[j], arr[j + 1]) > 0) {
167038
- i++;
166999
+ if (sortState !== 3 /* Both */) {
167000
+ return sortState;
167039
167001
  }
167040
167002
  }
167041
- return i;
167003
+ return seenUnsortedGroup ? 0 /* None */ : sortState;
167042
167004
  }
167043
- function detectCaseSensitivityBySort(originalGroups, comparersToTest) {
167044
- let bestComparer;
167045
- let bestDiff = Infinity;
167046
- for (const curComparer of comparersToTest) {
167047
- let diffOfCurrentComparer = 0;
167048
- for (const listToSort of originalGroups) {
167049
- if (listToSort.length <= 1)
167050
- continue;
167051
- const diff = measureSortedness(listToSort, curComparer);
167052
- diffOfCurrentComparer += diff;
167005
+ function detectImportDeclarationSorting(imports, preferences) {
167006
+ const collateCaseSensitive = getOrganizeImportsComparer(
167007
+ preferences,
167008
+ /*ignoreCase*/
167009
+ false
167010
+ );
167011
+ const collateCaseInsensitive = getOrganizeImportsComparer(
167012
+ preferences,
167013
+ /*ignoreCase*/
167014
+ true
167015
+ );
167016
+ return detectSortCaseSensitivity(
167017
+ imports,
167018
+ (s) => getExternalModuleName2(getModuleSpecifierExpression(s)) || "",
167019
+ collateCaseSensitive,
167020
+ collateCaseInsensitive
167021
+ );
167022
+ }
167023
+ var ImportSpecifierSortingCache = class {
167024
+ has([specifiers, preferences]) {
167025
+ if (this._lastPreferences !== preferences || !this._cache)
167026
+ return false;
167027
+ return this._cache.has(specifiers);
167028
+ }
167029
+ get([specifiers, preferences]) {
167030
+ if (this._lastPreferences !== preferences || !this._cache)
167031
+ return void 0;
167032
+ return this._cache.get(specifiers);
167033
+ }
167034
+ set([specifiers, preferences], value) {
167035
+ if (this._lastPreferences !== preferences) {
167036
+ this._lastPreferences = preferences;
167037
+ this._cache = void 0;
167038
+ }
167039
+ this._cache ?? (this._cache = /* @__PURE__ */ new WeakMap());
167040
+ this._cache.set(specifiers, value);
167041
+ }
167042
+ };
167043
+ var detectImportSpecifierSorting = memoizeCached((specifiers, preferences) => {
167044
+ switch (preferences.organizeImportsTypeOrder) {
167045
+ case "first":
167046
+ if (!arrayIsSorted(specifiers, (s1, s2) => compareBooleans(s2.isTypeOnly, s1.isTypeOnly)))
167047
+ return 0 /* None */;
167048
+ break;
167049
+ case "inline":
167050
+ if (!arrayIsSorted(specifiers, (s1, s2) => {
167051
+ const comparer = getStringComparer(
167052
+ /*ignoreCase*/
167053
+ true
167054
+ );
167055
+ return comparer(s1.name.text, s2.name.text);
167056
+ })) {
167057
+ return 0 /* None */;
167058
+ }
167059
+ break;
167060
+ default:
167061
+ if (!arrayIsSorted(specifiers, (s1, s2) => compareBooleans(s1.isTypeOnly, s2.isTypeOnly)))
167062
+ return 0 /* None */;
167063
+ break;
167064
+ }
167065
+ const collateCaseSensitive = getOrganizeImportsComparer(
167066
+ preferences,
167067
+ /*ignoreCase*/
167068
+ false
167069
+ );
167070
+ const collateCaseInsensitive = getOrganizeImportsComparer(
167071
+ preferences,
167072
+ /*ignoreCase*/
167073
+ true
167074
+ );
167075
+ if (preferences.organizeImportsTypeOrder !== "inline") {
167076
+ const { type: regularImports, regular: typeImports } = groupBy(specifiers, (s) => s.isTypeOnly ? "type" : "regular");
167077
+ const regularCaseSensitivity = (regularImports == null ? void 0 : regularImports.length) ? detectSortCaseSensitivity(regularImports, (specifier) => specifier.name.text, collateCaseSensitive, collateCaseInsensitive) : void 0;
167078
+ const typeCaseSensitivity = (typeImports == null ? void 0 : typeImports.length) ? detectSortCaseSensitivity(typeImports, (specifier) => specifier.name.text ?? "", collateCaseSensitive, collateCaseInsensitive) : void 0;
167079
+ if (regularCaseSensitivity === void 0) {
167080
+ return typeCaseSensitivity ?? 0 /* None */;
167053
167081
  }
167054
- if (diffOfCurrentComparer < bestDiff) {
167055
- bestDiff = diffOfCurrentComparer;
167056
- bestComparer = curComparer;
167082
+ if (typeCaseSensitivity === void 0) {
167083
+ return regularCaseSensitivity;
167057
167084
  }
167085
+ if (regularCaseSensitivity === 0 /* None */ || typeCaseSensitivity === 0 /* None */) {
167086
+ return 0 /* None */;
167087
+ }
167088
+ return typeCaseSensitivity & regularCaseSensitivity;
167058
167089
  }
167059
- return {
167060
- comparer: bestComparer ?? comparersToTest[0],
167061
- isSorted: bestDiff === 0
167062
- };
167090
+ return detectSortCaseSensitivity(specifiers, (specifier) => specifier.name.text, collateCaseSensitive, collateCaseInsensitive);
167091
+ }, new ImportSpecifierSortingCache());
167092
+ function getImportDeclarationInsertionIndex(sortedImports, newImport, comparer) {
167093
+ const index = binarySearch(sortedImports, newImport, identity, (a, b) => compareImportsOrRequireStatements(a, b, comparer));
167094
+ return index < 0 ? ~index : index;
167095
+ }
167096
+ function getImportSpecifierInsertionIndex(sortedImports, newImport, comparer, preferences) {
167097
+ const index = binarySearch(sortedImports, newImport, identity, (s1, s2) => compareImportOrExportSpecifiers(s1, s2, comparer, preferences));
167098
+ return index < 0 ? ~index : index;
167099
+ }
167100
+ function compareImportsOrRequireStatements(s1, s2, comparer) {
167101
+ return compareModuleSpecifiersWorker(getModuleSpecifierExpression(s1), getModuleSpecifierExpression(s2), comparer) || compareImportKind(s1, s2);
167063
167102
  }
167064
167103
  function compareImportKind(s1, s2) {
167065
167104
  return compareValues(getImportKindOrder(s1), getImportKindOrder(s2));
@@ -167083,6 +167122,19 @@ function getImportKindOrder(s1) {
167083
167122
  return 6;
167084
167123
  }
167085
167124
  }
167125
+ function getNewImportSpecifiers(namedImports) {
167126
+ return flatMap(namedImports, (namedImport) => map(tryGetNamedBindingElements(namedImport), (importSpecifier) => importSpecifier.name && importSpecifier.propertyName && importSpecifier.name.escapedText === importSpecifier.propertyName.escapedText ? factory.updateImportSpecifier(
167127
+ importSpecifier,
167128
+ importSpecifier.isTypeOnly,
167129
+ /*propertyName*/
167130
+ void 0,
167131
+ importSpecifier.name
167132
+ ) : importSpecifier));
167133
+ }
167134
+ function tryGetNamedBindingElements(namedImport) {
167135
+ var _a;
167136
+ return ((_a = namedImport.importClause) == null ? void 0 : _a.namedBindings) && isNamedImports(namedImport.importClause.namedBindings) ? namedImport.importClause.namedBindings.elements : void 0;
167137
+ }
167086
167138
  function getOrganizeImportsOrdinalStringComparer(ignoreCase) {
167087
167139
  return ignoreCase ? compareStringsCaseInsensitiveEslintCompatible : compareStringsCaseSensitive;
167088
167140
  }
@@ -167110,61 +167162,40 @@ function getOrganizeImportsLocale(preferences) {
167110
167162
  const resolvedLocale = supportedLocales.length ? supportedLocales[0] : "en";
167111
167163
  return resolvedLocale;
167112
167164
  }
167113
- function getOrganizeImportsStringComparer(preferences, ignoreCase) {
167165
+ function getOrganizeImportsComparer(preferences, ignoreCase) {
167114
167166
  const collation = preferences.organizeImportsCollation ?? "ordinal";
167115
167167
  return collation === "unicode" ? getOrganizeImportsUnicodeStringComparer(ignoreCase, preferences) : getOrganizeImportsOrdinalStringComparer(ignoreCase);
167116
167168
  }
167117
- function getOrganizeImportsStringComparerWithDetection(originalImportDecls, preferences) {
167118
- return detectModuleSpecifierCaseBySort([originalImportDecls], getDetectionLists(preferences).comparersToTest);
167169
+ function getOrganizeImportsComparerWithDetection(preferences, detectIgnoreCase) {
167170
+ const ignoreCase = typeof preferences.organizeImportsIgnoreCase === "boolean" ? preferences.organizeImportsIgnoreCase : (detectIgnoreCase == null ? void 0 : detectIgnoreCase()) ?? false;
167171
+ return getOrganizeImportsComparer(preferences, ignoreCase);
167119
167172
  }
167120
- function getNamedImportSpecifierComparer(preferences, comparer) {
167121
- const stringComparer = comparer ?? getOrganizeImportsOrdinalStringComparer(!!preferences.organizeImportsIgnoreCase);
167122
- return (s1, s2) => compareImportOrExportSpecifiers(s1, s2, stringComparer, preferences);
167123
- }
167124
- function getNamedImportSpecifierComparerWithDetection(importDecl, preferences, sourceFile) {
167125
- const { comparersToTest, typeOrdersToTest } = getDetectionLists(preferences);
167126
- const detectFromDecl = detectNamedImportOrganizationBySort([importDecl], comparersToTest, typeOrdersToTest);
167127
- let specifierComparer = getNamedImportSpecifierComparer(preferences, comparersToTest[0]);
167128
- let isSorted;
167129
- if (typeof preferences.organizeImportsIgnoreCase !== "boolean" || !preferences.organizeImportsTypeOrder) {
167130
- if (detectFromDecl) {
167131
- const { namedImportComparer, typeOrder, isSorted: isDetectedSorted } = detectFromDecl;
167132
- isSorted = isDetectedSorted;
167133
- specifierComparer = getNamedImportSpecifierComparer({ organizeImportsTypeOrder: typeOrder }, namedImportComparer);
167134
- } else if (sourceFile) {
167135
- const detectFromFile = detectNamedImportOrganizationBySort(sourceFile.statements.filter(isImportDeclaration), comparersToTest, typeOrdersToTest);
167136
- if (detectFromFile) {
167137
- const { namedImportComparer, typeOrder, isSorted: isDetectedSorted } = detectFromFile;
167138
- isSorted = isDetectedSorted;
167139
- specifierComparer = getNamedImportSpecifierComparer({ organizeImportsTypeOrder: typeOrder }, namedImportComparer);
167173
+ function getTopLevelExportGroups(sourceFile) {
167174
+ const topLevelExportGroups = [];
167175
+ const statements = sourceFile.statements;
167176
+ const len = length(statements);
167177
+ let i = 0;
167178
+ let groupIndex = 0;
167179
+ while (i < len) {
167180
+ if (isExportDeclaration(statements[i])) {
167181
+ if (topLevelExportGroups[groupIndex] === void 0) {
167182
+ topLevelExportGroups[groupIndex] = [];
167140
167183
  }
167184
+ const exportDecl = statements[i];
167185
+ if (exportDecl.moduleSpecifier) {
167186
+ topLevelExportGroups[groupIndex].push(exportDecl);
167187
+ i++;
167188
+ } else {
167189
+ while (i < len && isExportDeclaration(statements[i])) {
167190
+ topLevelExportGroups[groupIndex].push(statements[i++]);
167191
+ }
167192
+ groupIndex++;
167193
+ }
167194
+ } else {
167195
+ i++;
167141
167196
  }
167142
167197
  }
167143
- return { specifierComparer, isSorted };
167144
- }
167145
- function getImportDeclarationInsertionIndex(sortedImports, newImport, comparer) {
167146
- const index = binarySearch(sortedImports, newImport, identity, (a, b) => compareImportsOrRequireStatements(a, b, comparer));
167147
- return index < 0 ? ~index : index;
167148
- }
167149
- function getImportSpecifierInsertionIndex(sortedImports, newImport, comparer) {
167150
- const index = binarySearch(sortedImports, newImport, identity, comparer);
167151
- return index < 0 ? ~index : index;
167152
- }
167153
- function compareImportsOrRequireStatements(s1, s2, comparer) {
167154
- return compareModuleSpecifiersWorker(getModuleSpecifierExpression(s1), getModuleSpecifierExpression(s2), comparer) || compareImportKind(s1, s2);
167155
- }
167156
- function testCoalesceImports(importGroup, ignoreCase, sourceFile, preferences) {
167157
- const comparer = getOrganizeImportsOrdinalStringComparer(ignoreCase);
167158
- const specifierComparer = getNamedImportSpecifierComparer({ organizeImportsTypeOrder: preferences == null ? void 0 : preferences.organizeImportsTypeOrder }, comparer);
167159
- return coalesceImportsWorker(importGroup, comparer, specifierComparer, sourceFile);
167160
- }
167161
- function testCoalesceExports(exportGroup, ignoreCase, preferences) {
167162
- const comparer = (s1, s2) => compareImportOrExportSpecifiers(s1, s2, getOrganizeImportsOrdinalStringComparer(ignoreCase), { organizeImportsTypeOrder: (preferences == null ? void 0 : preferences.organizeImportsTypeOrder) ?? "last" });
167163
- return coalesceExportsWorker(exportGroup, comparer);
167164
- }
167165
- function compareModuleSpecifiers2(m1, m2, ignoreCase) {
167166
- const comparer = getOrganizeImportsOrdinalStringComparer(!!ignoreCase);
167167
- return compareModuleSpecifiersWorker(m1, m2, comparer);
167198
+ return flatMap(topLevelExportGroups, (exportGroupDecls) => groupByNewlineContiguous(sourceFile, exportGroupDecls));
167168
167199
  }
167169
167200
 
167170
167201
  // src/services/_namespaces/ts.OutliningElementsCollector.ts
@@ -173317,6 +173348,7 @@ __export(ts_exports2, {
173317
173348
  SignatureKind: () => SignatureKind,
173318
173349
  SmartSelectionRange: () => ts_SmartSelectionRange_exports,
173319
173350
  SnippetKind: () => SnippetKind,
173351
+ SortKind: () => SortKind,
173320
173352
  StructureIsReused: () => StructureIsReused,
173321
173353
  SymbolAccessibility: () => SymbolAccessibility,
173322
173354
  SymbolDisplay: () => ts_SymbolDisplay_exports,
@@ -173651,6 +173683,7 @@ __export(ts_exports2, {
173651
173683
  defaultIncludeSpec: () => defaultIncludeSpec,
173652
173684
  defaultInitCompilerOptions: () => defaultInitCompilerOptions,
173653
173685
  defaultMaximumTruncationLength: () => defaultMaximumTruncationLength,
173686
+ detectSortCaseSensitivity: () => detectSortCaseSensitivity,
173654
173687
  diagnosticCategoryName: () => diagnosticCategoryName,
173655
173688
  diagnosticToString: () => diagnosticToString,
173656
173689
  directoryProbablyExists: () => directoryProbablyExists,
@@ -188090,6 +188123,7 @@ start(initializeNodeSystem(), require("os").platform());
188090
188123
  SignatureKind,
188091
188124
  SmartSelectionRange,
188092
188125
  SnippetKind,
188126
+ SortKind,
188093
188127
  StructureIsReused,
188094
188128
  SymbolAccessibility,
188095
188129
  SymbolDisplay,
@@ -188424,6 +188458,7 @@ start(initializeNodeSystem(), require("os").platform());
188424
188458
  defaultIncludeSpec,
188425
188459
  defaultInitCompilerOptions,
188426
188460
  defaultMaximumTruncationLength,
188461
+ detectSortCaseSensitivity,
188427
188462
  diagnosticCategoryName,
188428
188463
  diagnosticToString,
188429
188464
  directoryProbablyExists,