Last active
April 14, 2018 16:48
-
-
Save johnnyji/72d10b10b4a4fab10f3f to your computer and use it in GitHub Desktop.
Codemod for Babel 6 Semicolon Requirement
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
module.exports = function (file, api) { | |
var j = api.jscodeshift; | |
var root = j(file.source); | |
// Finds the all classes that have properties | |
root | |
.find(j.ClassDeclaration, { | |
body: { | |
type: 'ClassBody', | |
body: [{ | |
type: 'ClassProperty' | |
}] | |
} | |
}) | |
.forEach((path) => { | |
// Finds the properties themselves on the class | |
j(path) | |
.find(j.ClassProperty) | |
.replaceWith(function (path) { | |
// Adds a semicolon if necessary | |
var source = j(path).toSource(); | |
if (source[source.length - 1] === ';') return source; | |
return source.concat(';'); | |
}); | |
}); | |
return root.toSource(sourceOptions); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem running this script :
ReferenceError: sourceOptions is not defined