From 5b75b116287787eaa40c78abce280b6a62d50deb Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Wed, 18 Feb 2015 10:21:57 +1100 Subject: [PATCH] add error message to use of `eval();` and enable strict mode on the parser --- lib/babel/messages.js | 3 ++- lib/babel/transformation/file.js | 2 +- lib/babel/transformation/transformers/other/use-strict.js | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/babel/messages.js b/lib/babel/messages.js index 475e667136..8a6b6fec0c 100644 --- a/lib/babel/messages.js +++ b/lib/babel/messages.js @@ -16,7 +16,8 @@ exports.messages = { readOnly: "$1 is read-only", modulesIllegalExportName: "Illegal export $1", unknownForHead: "Unknown node type $1 in ForStatement", - didYouMean: "Did you mean $1?" + didYouMean: "Did you mean $1?", + evalInStrictMode: "eval is not allowed in strict mode" }; exports.get = function (key) { diff --git a/lib/babel/transformation/file.js b/lib/babel/transformation/file.js index e74beccab5..74eb9e5916 100644 --- a/lib/babel/transformation/file.js +++ b/lib/babel/transformation/file.js @@ -368,7 +368,7 @@ File.prototype.parse = function (code) { var opts = this.opts; opts.allowImportExportEverywhere = this.isLoose("es6.modules"); - //opts.strictMode = this.transformers.useStrict.canRun(); + opts.strictMode = this.transformers.useStrict.canRun(); return parse(opts, code, function (tree) { self.transform(tree); diff --git a/lib/babel/transformation/transformers/other/use-strict.js b/lib/babel/transformation/transformers/other/use-strict.js index 92be48e0f1..947bcca27e 100644 --- a/lib/babel/transformation/transformers/other/use-strict.js +++ b/lib/babel/transformation/transformers/other/use-strict.js @@ -1,6 +1,7 @@ "use strict"; var useStrict = require("../../helpers/use-strict"); +var messages = require("../../../messages"); var t = require("../../../types"); exports.Program = function (program) { @@ -17,3 +18,9 @@ exports.FunctionExpression = function () { exports.ThisExpression = function () { return t.identifier("undefined"); }; + +exports.CallExpression = function (node, parent, scope, file) { + if (t.isIdentifier(node.callee, { name: "eval" })) { + throw file.errorWithNode(node, messages.get("evalInStrictMode")); + } +};