Update with.js

This commit is contained in:
Rohit Paul 2023-08-30 03:36:15 +05:30 committed by GitHub
parent f0ca9cfbe6
commit 5325d5df69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,20 +1,20 @@
var assert = require("assert"); let assert = require("assert");
var UglifyJS = require("../node"); let UglifyJS = require("../node");
describe("With", function() { describe("With", function() {
it("Should throw syntaxError when using with statement in strict mode", function() { it("Should throw syntaxError when using with statement in strict mode", function() {
var code = '"use strict";\nthrow NotEarlyError;\nwith ({}) { }'; let code = '"use strict";\nthrow NotEarlyError;\nwith ({}) { }';
var test = function() { let test = function() {
UglifyJS.parse(code); UglifyJS.parse(code);
} }
var error = function(e) { let error = function(e) {
return e instanceof UglifyJS.JS_Parse_Error return e instanceof UglifyJS.JS_Parse_Error
&& e.message === "Strict mode may not include a with statement"; && e.message === "Strict mode may not include a with statement";
} }
assert.throws(test, error); assert.throws(test, error);
}); });
it("Should set uses_with for scopes involving With statements", function() { it("Should set uses_with for scopes involving With statements", function() {
var ast = UglifyJS.parse("with(e) {f(1, 2)}"); let ast = UglifyJS.parse("with(e) {f(1, 2)}");
ast.figure_out_scope(); ast.figure_out_scope();
assert.equal(ast.uses_with, true); assert.equal(ast.uses_with, true);
assert.equal(ast.body[0].expression.scope.resolve().uses_with, true); assert.equal(ast.body[0].expression.scope.resolve().uses_with, true);