1
Vote

Eval Treatment MakeImmediateSafe and MakeAllSafe should preserve function arguments

description

Assume the following code:
var minifier = new Minifier();
var codeSettings = new CodeSettings();
codeSettings.EvalTreatment = EvalTreatment.MakeImmediateSafe;
codeSettings.PreserveImportantComments = false;

const string js = @"
var foo = (function() {
    return {
        log: function(arg1, arg2) {
            console.log(arg1);
            eval('console.log(arg2)');
        }
    }
}());

foo.log('bar', 'baz');";

var @out = minifier.MinifyJavaScript( js, codeSettings );
The value of @out is
var foo=function(){return{log:function(arg1){console.log(arg1);eval("console.log(arg2)")}}}();foo.log("bar","baz")
The original JS prints "bar" and then "baz". The minified JS print bar and then fails in the eval because arg2 is not defined.

arg1 has not been renamed (as expected) but arg2 is gone which breaks the eval section. I feel like MakeImmediateSafe should preserve the current scope function's arguments and MakeAllSafe should keep all the arguments.

comments