overlookmotel / livepack

Serialize live running code to Javascript
MIT License
30 stars 0 forks source link

Var called `arguments` internal to serialized function should not be renamed #547

Closed overlookmotel closed 7 months ago

overlookmotel commented 7 months ago

Input:

// Sloppy mode
module.exports = function() {
  var arguments;
  return arguments;
};

Current output:

// `mangle: false`
module.exports = function() { var arguments$0; return arguments$0; };
// `mangle: true`
module.exports = function() { var a; return a; };

A var binding in a function with a parameter of same name creates a new binding, but that binding inherits the initial value of the param. e.g. (x => { var x; return x; })(123) evaluates to 123.

Livepack handles this case correctly - if the var names are mangled, they'll both be renamed the same so the inheritance between the param x and var x is maintained.

However, it does not do the same for arguments, as the implicit arguments created by the function is not renamed, and the var binding is.