add "use strict" declaration - closes #78
This commit is contained in:
15
lib/6to5/transformers/_use-strict.js
Normal file
15
lib/6to5/transformers/_use-strict.js
Normal file
@@ -0,0 +1,15 @@
|
||||
var b = require("recast").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();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user