Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Destructing function parameters with "set" property in it #112

Closed
danez opened this issue Sep 8, 2016 · 0 comments
Closed

Destructing function parameters with "set" property in it #112

danez opened this issue Sep 8, 2016 · 0 comments
Labels

Comments

@danez
Copy link
Member

danez commented Sep 8, 2016

Reported by @pavelkornev

Following snippet:

function A({set}) {
  set = "a"
}

compiles to:

"use strict";

function A(_ref) {
  var set = _ref.set;

  set = "foo";
}

https://babeljs.io/repl/#?experimental=false&evaluate=true&loose=false&spec=false&code=function%20A(%7Bset%7D)%20%7B%0A%20%20set%20%3D%20%22a%22%0A%7D

But when we try to assign default value to "set":

function A({set="bar"}) {
  set="foo"
}

it crashes with the following error:

repl: Unexpected token (1:15)
> 1 | function A({set="bar"}) {
    |                ^
  2 |   set="foo"
  3 | }

https://babeljs.io/repl/#?experimental=false&evaluate=true&loose=false&spec=false&code=function%20A(%7Bset%3D%22bar%22%7D)%20%7B%0A%20%20set%3D%22foo%22%0A%7D

On other hand if we assign alias to it:

function A({set:set_="bar"}) {
  set="foo"
}

It compiles just fine:

"use strict";

function A(_ref) {
  var _ref$set = _ref.set;
  var set_ = _ref$set === undefined ? "bar" : _ref$set;

  set = "foo";
}

https://babeljs.io/repl/#?experimental=false&evaluate=true&loose=false&spec=false&code=function%20A(%7Bset%7D)%20%7B%0A%20%20set%3D%22foo%22%0A%7D

If "set" reserved why does it work in first case? If it's not why second case doesn't work? I consider this as a bug of compiler, am i right?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants