Skip to content

Instantly share code, notes, and snippets.

@cletusw
Last active August 16, 2017 21:39
Show Gist options
  • Save cletusw/8a37bc41ee321a316bbd00300e35649a to your computer and use it in GitHub Desktop.
Save cletusw/8a37bc41ee321a316bbd00300e35649a to your computer and use it in GitHub Desktop.
Remove top-level `"use strict";`. It can cause problems with bundlers that concatenate scripts, and so is not a recommended practice.
module.exports = function transformer(file, api) {
const j = api.jscodeshift;
return j(file.source)
.find(j.ExpressionStatement).filter(path => (
path.parentPath.node.type === "Program" &&
path.value.expression.type === 'Literal' &&
path.value.expression.value === 'use strict'
))
.forEach(path => j(path).remove())
.toSource();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment