satyr / coco

Unfancy CoffeeScript
http://satyr.github.com/coco/
MIT License
498 stars 48 forks source link

spread call miscompilation #222

Closed edef1c closed 6 years ago

edef1c commented 11 years ago

coco: f ...[x for x of [1, 2, 3]] expected compilation:

var x;
f.apply(null, [(function(){
  var i$, ref$, len$, results$ = [];
  for (i$ = 0, len$ = (ref$ = [1, 2, 3]).length; i$ < len$; ++i$) {
    x = ref$[i$];
    results$.push(x);
  }
  return results$;
}())]);

actual compilation:

var x;
f((function(){
  var i$, ref$, len$, results$ = [];
  for (i$ = 0, len$ = (ref$ = [1, 2, 3]).length; i$ < len$; ++i$) {
    x = ref$[i$];
    results$.push(x);
  }
  return results$;
}()));

f ...([x for x of [1, 2, 3]]) compiles to the correct JS.

satyr commented 11 years ago

It's an optimization. f ...[a, b] is unrolled to f a, b pre-compile.

edef1c commented 11 years ago

A mis-optimisation, though? One of them calls a function with a single array argument, the other calls a function with multiple arguments.

vendethiel commented 11 years ago

.apply takes an array of arguments.