termi / es6-transpiler

Tomorrow's JavaScript syntax today
Other
216 stars 18 forks source link

Spread and destructor adds erroneous parenthesis. #52

Open Naddiseo opened 10 years ago

Naddiseo commented 10 years ago

Test case:

var p = [];
var [a,b] = Object(...p);

Partial output:

// .... Snip....
var p = [];
var a = (b = Object.apply(null, ITER$0(p))[0], b = b[1]);

As you can see from the output, the initializer for a is wrapped in parenthesis, which causes b = b[1] to not be part of the var declaration, thus, b is never defined.

Side question: what is the reasoning behind doing the destructoring this way instead of similar to how traceur does it with a temporary?

 var p = [];
  var $__27 = Object.apply(null, $traceurRuntime.spread(p)),
      a = $__27[0],
      b = $__27[1];