Don't allow with statements in strict mode
This commit is contained in:
@@ -928,6 +928,9 @@ function parse($TEXT, options) {
|
|||||||
return tmp = const_(), semicolon(), tmp;
|
return tmp = const_(), semicolon(), tmp;
|
||||||
|
|
||||||
case "with":
|
case "with":
|
||||||
|
if (S.input.has_directive("use strict")) {
|
||||||
|
croak("Strict mode may not include a with statement");
|
||||||
|
}
|
||||||
return new AST_With({
|
return new AST_With({
|
||||||
expression : parenthesised(),
|
expression : parenthesised(),
|
||||||
body : statement()
|
body : statement()
|
||||||
|
|||||||
16
test/mocha/with.js
Normal file
16
test/mocha/with.js
Normal file
@@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user