satyr / coco

Unfancy CoffeeScript

Home Page:http://satyr.github.com/coco/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spread call miscompilation

edef1c opened this issue · comments

commented

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.

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

commented

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

commented

.apply takes an array of arguments.