Skip to content

Instantly share code, notes, and snippets.

@johnnyji
Last active April 14, 2018 16:48
Show Gist options
  • Save johnnyji/72d10b10b4a4fab10f3f to your computer and use it in GitHub Desktop.
Save johnnyji/72d10b10b4a4fab10f3f to your computer and use it in GitHub Desktop.
Codemod for Babel 6 Semicolon Requirement
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);
};
@Aarbel
Copy link

Aarbel commented Apr 14, 2018

Problem running this script : ReferenceError: sourceOptions is not defined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment