UglifyJS/test/mocha/with.js

24 lines
958 B
JavaScript
Raw Normal View History

2023-08-29 22:06:15 +00:00
let assert = require("assert");
let UglifyJS = require("../node");
describe("With", function() {
2016-07-03 22:51:09 +00:00
it("Should throw syntaxError when using with statement in strict mode", function() {
2023-08-29 22:06:15 +00:00
let code = '"use strict";\nthrow NotEarlyError;\nwith ({}) { }';
let test = function() {
2018-06-21 17:04:15 +00:00
UglifyJS.parse(code);
}
2023-08-29 22:06:15 +00:00
let error = function(e) {
2018-06-21 17:04:15 +00:00
return e instanceof UglifyJS.JS_Parse_Error
&& e.message === "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() {
2023-08-29 22:06:15 +00:00
let ast = UglifyJS.parse("with(e) {f(1, 2)}");
2016-07-03 22:51:09 +00:00
ast.figure_out_scope();
assert.equal(ast.uses_with, true);
assert.equal(ast.body[0].expression.scope.resolve().uses_with, true);
assert.equal(ast.body[0].body.body[0].body.expression.scope.resolve().uses_with, true);
2016-07-03 22:51:09 +00:00
});
});