Skip to content

Instantly share code, notes, and snippets.

@deecewan
Created August 1, 2018 04:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deecewan/60d579309171a536cf2e19159997115a to your computer and use it in GitHub Desktop.
Save deecewan/60d579309171a536cf2e19159997115a to your computer and use it in GitHub Desktop.
A jscodeshift codemod designed to split combined var declarations into multiple declarations
module.exports = function transformer(file, api) {
const j = api.jscodeshift;
return j(file.source)
.find(j.VariableDeclaration)
.filter(d => d.value.declarations.length > 1)
.forEach(path => {
console.log(path)
const newDeclarations = path.value.declarations.map(dec =>
j.variableDeclaration(path.value.kind, [
dec
]))
console.log(newDeclarations)
j(path).replaceWith(newDeclarations)
})
.toSource()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment