diff --git a/lib/serialize/blocks.js b/lib/serialize/blocks.js index d327a809..4dbbb6ba 100644 --- a/lib/serialize/blocks.js +++ b/lib/serialize/blocks.js @@ -679,7 +679,9 @@ module.exports = { // Otherwise, can just make `arguments` a normal param. // This can be the case if `arguments` is behind a `with (...)` block, // or `arguments` is a user-defined variable, not `arguments` created by a function. - newName = transformVarName(paramName, true); + // If block contains a function containing `eval()`, prepend name of temp var with '_' + // as it'll be accessible to `eval()`. If param is frozen by `with ()`, this isn't required. + newName = transformVarName(paramName, containsEval); if (paramName === 'this') { frozenThisVarName = newName; } else { diff --git a/test/with.test.js b/test/with.test.js index aba3a50c..b657de1f 100644 --- a/test/with.test.js +++ b/test/with.test.js @@ -81,7 +81,7 @@ describe('with statements', () => { } return outer.call({x: 1}); }, - out: '(_a=>function(){return()=>this}.call(_a))({x:1})', + out: '(a=>function(){return()=>this}.call(a))({x:1})', validate(fn) { expect(fn).toBeFunction(); expect(fn()).toEqual({x: 1}); @@ -99,11 +99,11 @@ describe('with statements', () => { return outer.call({x: 1}); }, out: ` - (y=>_a=>function(){ + (y=>b=>function(){ return a=>{ with(a)return()=>[this,y] } - }.call(_a))(2)({x:1})({this:3,a:4}) + }.call(b))(2)({x:1})({this:3,a:4}) `, validate(fn) { expect(fn).toBeFunction(); @@ -170,11 +170,11 @@ describe('with statements', () => { }, out: ` ( - (_a,_b)=>function(){ + (b,c)=>function(){ return a=>{ with(a)return()=>[this,arguments] } - }.apply(_a,_b) + }.apply(b,c) )({x:1},function(){return arguments}(2,3,4))({a:5}) `, validate(fn) { @@ -201,14 +201,14 @@ describe('with statements', () => { }, out: ` ( - (_a,_b)=>function(){ + (b,c)=>function(){ return a=>{ with(a)return()=>{ "use strict"; return[this,arguments] } } - }.apply(_a,_b) + }.apply(b,c) )({x:1},function(){return arguments}(2,3,4))({a:5}) `, validate(fn) { @@ -232,12 +232,12 @@ describe('with statements', () => { }, out: `(()=>{ const a=( - (_a,b)=>function(){ + (b,c)=>function(){ return[ - ()=>b, + ()=>c, a=>{with(a)return()=>[x,this]} ] - }.call(_a) + }.call(b) )({y:2},function(){return arguments}(3,4,5));return[a[1]({x:1}),a[0]] })()`, validate([fn1, fn2]) {