UglifyJS/test/mocha/with.js

24 lines
942 B
JavaScript
Raw Normal View History

var assert = require("assert");
var uglify = require("../../");
describe("With", function() {
2016-07-03 22:51:09 +00:00
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 &&
2016-06-18 15:28:22 +00:00
e.message === "SyntaxError: Strict mode may not include a with statement";
}
assert.throws(test, error);
});
2016-07-03 22:51:09 +00:00
it("Should set uses_with for scopes involving With statements", function() {
var ast = uglify.parse("with(e) {f(1, 2)}");
ast.figure_out_scope();
assert.equal(ast.uses_with, true);
assert.equal(ast.body[0].expression.scope.uses_with, true);
assert.equal(ast.body[0].body.body[0].body.expression.scope.uses_with, true);
});
});