Created
October 4, 2018 02:18
-
-
Save nickbrowne/1647dbb9943960bc1ca8ec7cf5e05788 to your computer and use it in GitHub Desktop.
Hoist es6 imports to top of file
This file contains hidden or 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
export default function transformer(file, api) { | |
const j = api.jscodeshift; | |
const root = j(file.source); | |
let imports = []; | |
let paths = root.find(j.ImportDeclaration, { | |
type: "ImportDeclaration" | |
}).forEach((x) => imports.push(x)); | |
imports.reverse().forEach(path => { | |
let thing = j(path); | |
root.get().node.program.body.unshift(thing.toSource()); | |
thing.remove(); | |
}); | |
return root.toSource(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment