From d8d4e71b9ee022aeadc56821e086c641702009ee Mon Sep 17 00:00:00 2001 From: Anthony Van de Gejuchte Date: Fri, 1 Jul 2016 15:36:38 +0200 Subject: [PATCH] Fix uses_with/uses_eval/directives state in block scope --- lib/scope.js | 5 +++++ test/mocha/with.js | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/scope.js b/lib/scope.js index 7b8d38a0..11adbbfd 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -119,6 +119,11 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){ scope.init_scope_vars(nesting); scope.parent_scope = save_scope; scope.is_block_scope = true; + if (!(node instanceof AST_Scope)) { + scope.uses_with = save_scope.uses_with; + scope.uses_eval = save_scope.uses_eval; + scope.directives = save_scope.directives; + } descend(); scope = save_scope; return true; diff --git a/test/mocha/with.js b/test/mocha/with.js index 2e758d1e..d1bfcc80 100644 --- a/test/mocha/with.js +++ b/test/mocha/with.js @@ -13,4 +13,11 @@ describe("With", function() { } assert.throws(test, error); }); -}); \ No newline at end of file + 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); + }); +});