From bb9c9707aa6b4c625ad985798aea879080411ce1 Mon Sep 17 00:00:00 2001 From: Anthony Van de Gejuchte Date: Sun, 12 Jun 2016 18:58:20 +0200 Subject: [PATCH] Don't allow with statements in strict mode --- lib/parse.js | 3 +++ test/mocha/with.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 test/mocha/with.js diff --git a/lib/parse.js b/lib/parse.js index 4530c2d9..2c007965 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -928,6 +928,9 @@ function parse($TEXT, options) { return tmp = const_(), semicolon(), tmp; case "with": + if (S.input.has_directive("use strict")) { + croak("Strict mode may not include a with statement"); + } return new AST_With({ expression : parenthesised(), body : statement() diff --git a/test/mocha/with.js b/test/mocha/with.js new file mode 100644 index 00000000..d284f1c2 --- /dev/null +++ b/test/mocha/with.js @@ -0,0 +1,16 @@ +var assert = require("assert"); +var uglify = require("../../"); + +describe("With", function() { + it ("Should throw syntaxError when using with statement in strict mode", function() { + var code = '"use strict";\nthrow NotEarlyError;\nwith ({}) { }'; + var test = function() { + uglify.parse(code); + } + var error = function(e) { + return e instanceof uglify.JS_Parse_Error && + e.message === "Strict mode may not include a with statement"; + } + assert.throws(test, error); + }); +}); \ No newline at end of file -- 2.34.1