I had a function, which was being transpiled correctly, but now is not.
const deepAssign = (...args) => (args = [].concat(...args)).length === 0 ? undefined : Object.assign(...args);
Essentially, I am assigning to the args variable but because I'm not passing the args variable anywhere, all references to it are being optimised to reference arguments directly.
The transpiled code contains a variable declartion for _ref2 but not for args:
var deepAssign = function() {
var _ref2;
return (args = (_ref2 = []).concat.apply(_ref2, arguments)).length === 0 ? undefined : _Object$assign.apply(Object, arguments);
};
In fact, it's even using arguments in the last part of the ternary expression even though that's not referencing the flattened array as returned by concat.
Expected output would be something similar to:
var deepAssign = function() {
var args = arguments, _ref2;
return (args = (_ref2 = []).concat.apply(_ref2, args)).length === 0 ? undefined : _Object$assign.apply(Object, args);
Although I don't know the extent of the repercussions, re compiler optimizations, the assignment of arguments to args will have. Should I just accept I can't do this in a one-liner and declare a different variable?
I had a function, which was being transpiled correctly, but now is not.
Essentially, I am assigning to the
argsvariable but because I'm not passing theargsvariable anywhere, all references to it are being optimised to referenceargumentsdirectly.The transpiled code contains a variable declartion for
_ref2but not forargs:In fact, it's even using
argumentsin the last part of the ternary expression even though that's not referencing the flattened array as returned byconcat.Expected output would be something similar to:
Although I don't know the extent of the repercussions, re compiler optimizations, the assignment of
argumentstoargswill have. Should I just accept I can't do this in a one-liner and declare a different variable?