Created
August 1, 2018 04:50
-
-
Save deecewan/60d579309171a536cf2e19159997115a to your computer and use it in GitHub Desktop.
A jscodeshift codemod designed to split combined var declarations into multiple declarations
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
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