Skip to content

Conversation

@andrewbranch
Copy link
Member

Fixes #33839

When import declarations/specifiers are already sorted, we insert new declarations/specifiers in the appropriate location. The sort order of import specifiers is alphabetical (reusing the existing logic from organize imports). The sort order for import declarations is alphabetical by module specifier, with module specifier ties being broken by the secondary sort order:

  1. Side-effect imports
  2. Type-only imports
  3. Namespace imports
  4. Default imports
  5. Named imports
  6. ImportEqualsDeclarations
  7. Require variable statements

The organize imports logic has been updated to use that tiebreaker as well.

Copy link
Member

@amcasey amcasey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the new order, but I'm concerned about the number of baseline changes. It seems like anyone who upgrades is going to have a lot of diffs.

Also, can we include that nice summary of the sort order in the code somewhere?

@andrewbranch andrewbranch merged commit 03c79d7 into microsoft:master Jul 8, 2020
@andrewbranch andrewbranch deleted the feature/33839 branch July 8, 2020 22:25
cangSDARM added a commit to cangSDARM/TypeScript that referenced this pull request Jul 9, 2020
* upstream/master: (75 commits)
  Insert auto-imports in sorted order (microsoft#39394)
  LEGO: check in for master to temporary branch.
  Better checking of @param/@Property tags (microsoft#39487)
  fix(25155): add space before optional parameters/properties (microsoft#38798)
  Add regression test for microsoft#38834 (microsoft#39479)
  Fixes searches for symbols exported using export * as (microsoft#39507)
  fix(39421): omit prefix text for rest binding element (microsoft#39433)
  fix(39440): show QF for abstract classes with methods which include 'this' parameter (microsoft#39465)
  Remove unnecessary assert (microsoft#39483)
  LEGO: check in for master to temporary branch.
  Update user baselines (microsoft#39220)
  Type `this` in more constructor functions (microsoft#39447)
  LEGO: check in for master to temporary branch.
  LEGO: check in for master to temporary branch.
  Properly handle rest parameters in function declarations with @type annotations (microsoft#39473)
  Ensure type/namespaceish statics are included in the list of namespace merge members (microsoft#38920)
  Fix getTypeAtLocation for dotted implements clauses (microsoft#39363)
  Add workflow_dispatch to our nightly publish script. (microsoft#39485)
  Fix crash in decorator metadata calculation when serializing template literal type nodes (microsoft#39481)
  Fix test semantic merge conflict between microsoft#39348 and microsoft#39130 (microsoft#39478)
  ...

# Conflicts:
#	src/compiler/scanner.ts
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

auto-import with alphabetized order by default

3 participants