Skip to content

Instantly share code, notes, and snippets.

@Aosanders
Last active June 26, 2018 22: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 Aosanders/245a21b2685ea9e063090206d59386eb to your computer and use it in GitHub Desktop.
Save Aosanders/245a21b2685ea9e063090206d59386eb to your computer and use it in GitHub Desktop.
Code mod for adding use strict to file
module.exports = function(file, api){
var j = api.jscodeshift;
var root = j(file.source);
var useStrict = '"use strict";';
var hasUseStrict = root.find(j.ExpressionStatement,{
expression: {
type: 'Literal',
value: 'use strict',
},
});
if(hasUseStrict.length === 0){
root.get().node.program.body.unshift(useStrict);
}
return root.toSource();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment