Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature:
importOrderMergeDuplicateImports
(#19)
This PR implements import declaration merging for duplicate imports. I had to adjust getCodeFromAST so that we could still provide the original nodes, even if some of the nodes were being deleted. It leverages the existing chunking logic, so if there's a side-effect import, or a prettier-ignore import, it won't merge across that boundary. I did not implement conversion of import type { stuff } into import { type stuff } as it was not obvious when this would be wise. If we want to control that with an additional config option, something like importOrderMergeTypeStyle: "none" | "to-normal-import" | "unmerge" I could be convinced. I forsee people wanting opposite sides of the coin for that one. * Add TypeScript enforcement to not-forgetting our Options schema! * Change syntax of getCodeFromAst to allow for node deletion * Github-linguist doesn't understand `ecmascript 6` Just use javascript or js * Feature: `importOrderMergeDuplicateImports` - Fixes #4 * switch from toMatchInlineSnapshot to toEqual * PR Feedback: rename `regular` imports to `value` imports * PR Feedback: Readme wording * PR Feedback: rename getCodeFromAst parameters Try to improve the naming and docs for the parameters, particularly the nodes vs importNodes distinciton * PR Feedback: import-flavor @returns documentation * PR Feedback: hoist hasIgnoreNextNode for reuse * PR Feedback: Add strong types for ChunkType/FlavorType * PR Feedback: deleteContext -> nodesToDelete * PR Feedback: comment-update: once you mutate nodes, lines/locations are stale! * Add a few tests and comments
- Loading branch information
Showing
19 changed files
with
682 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { getImportFlavorOfNode } from '../get-import-flavor-of-node'; | ||
import { getImportNodes } from '../get-import-nodes'; | ||
|
||
it('should correctly classify a bunch of import expressions', () => { | ||
expect( | ||
getImportNodes( | ||
` | ||
import "./side-effects"; | ||
import { a } from "a"; | ||
import type { b } from "b"; | ||
import { type C } from "c"; | ||
import D from "d"; | ||
import e = require("e"); // Doesn't count as import | ||
const f = require("f"); // Doesn't count as import | ||
// prettier-ignore | ||
import { g } from "g"; | ||
`, | ||
{ plugins: ['typescript'] }, | ||
).map((node) => getImportFlavorOfNode(node)), | ||
).toMatchInlineSnapshot(` | ||
Array [ | ||
"side-effect", | ||
"value", | ||
"type", | ||
"value", | ||
"value", | ||
"prettier-ignore", | ||
] | ||
`); | ||
}); |
Oops, something went wrong.