Which behavior is correct (so where should I fill bug report)?
Till Schneidereit
till at tillschneidereit.net
Mon Jul 20 09:37:32 UTC 2015
It looks like Babel is taking some invalid shortcuts here. The
DestructuringAssignmentEvaluation runtime semantics[1] require the same
source object (the parameter `value`) to be used throughout the
destructuring operation. Babel compiles the first destructuring into
var bar = foo.bar;
var qaz = foo.qaz;
So `foo` gets looked up twice, with the second lookup resulting in a
different value, the one that the `bar` getter assigned to `foo`. In
SpiderMonkey, both getters get called (you can check this with console.log
calls in the getters) because the destructuring operates on the same value
throughout.
Curiously, the inline destructuring in the console.log call at the end
fares better here: it assigns `foo` to a temporary variable `_foo`, so
changing the value of `foo` doesn't influence results. (I do wonder if that
causes `foo` to be leaked forever, though: `_foo` is a global variable
defined at the script's top.)
[1]
http://www.ecma-international.org/ecma-262/6.0/index.html#sec-runtime-semantics-destructuringassignmentevaluation
On Mon, Jul 20, 2015 at 10:58 AM, Michał Wadas <michalwadas at gmail.com>
wrote:
> Following code:
>
>
> var foo = {
> get bar() {
> foo = {
> qaz: 'bar-r'
> };
> return 'bar-c';
> },
> get qaz() {
> foo = {
> bar: 'qaz-r'
> }
> return 'qaz-c';
> }
> };
>
> let {bar, qaz} = foo;
> console.log(({bar, qaz} = foo));
>
> Firefox:
> Object { bar: "qaz-r" }
> Babel:
> Object { qaz: "bar-r" }
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150720/a53a33d1/attachment.html>
More information about the es-discuss
mailing list