jashkenas / coffeescript

Unfancy JavaScript
https://coffeescript.org/
MIT License
16.45k stars 1.98k forks source link

Bug: Excessive variable and shallow copy for leading or middle rest parameter #5444

Open 123-Notus opened 1 year ago

123-Notus commented 1 year ago

Input Code

f1 = (a..., b) ->

f2 = (c, d..., e) ->

Expected Behavior

var f1, f2,
  splice = [].splice;

f1 = function(...a) {
  var b;
  [b] = splice.call(a, -1);
};

f2 = function(c, ...d) {
  var e;
  [e] = splice.call(d, -1);
};

Current Behavior

var f1, f2,
  splice = [].splice;

f1 = function(...a) {
  var b, ref;
  ref = a, [...a] = ref, [b] = splice.call(a, -1);
};

f2 = function(c, ...d) {
  var e, ref;
  ref = d, [...d] = ref, [e] = splice.call(d, -1);
};

Environment