16 lines
465 B
JavaScript
16 lines
465 B
JavaScript
var b = require("ast-types").builders;
|
|
|
|
module.exports = function (ast, file) {
|
|
var body = ast.program.body;
|
|
var first = body[0];
|
|
|
|
var noStrict = !first || first.type !== "ExpressionStatement" || first.expression.type !== "Literal" || first.expression.value !== "use strict";
|
|
|
|
if (noStrict) {
|
|
if (file.opts._noStrict) return;
|
|
body.unshift(b.expressionStatement(b.literal("use strict")));
|
|
} else {
|
|
if (file.opts._noStrict) body.shift();
|
|
}
|
|
};
|