Last active
June 26, 2018 22:50
-
-
Save Aosanders/245a21b2685ea9e063090206d59386eb to your computer and use it in GitHub Desktop.
Code mod for adding use strict to file
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); | |
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