Skip to content

Simple Array Destructuring shouldn't require use of $jscomp #2014

@arciisine

Description

@arciisine

When using a very simple destructuring pattern, it should be possible to convert this to simple assignments. Reading the spec, http://www.ecma-international.org/ecma-262/6.0/#sec-destructuring-assignment, I can see why the definition of $jscomp is what it is, but it seems like overkill for simple assignments.

Given the input:

function add(a) {
  let [b,c] = a;
  return b+c;
}

add([1,2])

I would expect the output to be something along the lines of:

function test(a) {
  var b = a[0], c = a[1];
  return b+c;
}

test([1,2])

Instead, what I'm seeing is:

/* $jscomp definition */;
function add(a){
   var b=$jscomp.makeIterator(a);
   a=b.next().value;
   b=b.next().value;
   return a+b
}
add([1,2]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions