add error message to use of eval(); and enable strict mode on the parser

This commit is contained in:
Sebastian McKenzie 2015-02-18 10:21:57 +11:00
parent 1890fb5bd3
commit 5b75b11628
3 changed files with 10 additions and 2 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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"));
}
};