Babel: object-rest-spread doesn't handle getters/setters and loses [[HomeObject]] for super

Created on 3 Oct 2016  路  2Comments  路  Source: babel/babel

Filing as one issue since we probably just want to fix both at once. These two examples:

var child = {
  ...{},
  get counter(){
    return counter++;
  },
}

console.log(child.counter);
console.log(child.counter);

The counter is printed as 0 twice because the getter is currently called at declaration time.

var parent = {
  method(){
    return 'parent';
  }
};

var child = {
  __proto__: parent,

  ...{},
  method(){
    return 'child' + super.method();
  }
}

console.log(child.method());

throws because super.method is undefined because it does not properly reference parent.

Here it is in the REPL:

https://babeljs.io/repl/#?babili=false&evaluate=true&lineWrap=false&presets=stage-2&experimental=false&loose=false&spec=false&playground=false&code=%0Avar%20counter%20%3D%200%3B%0A%0Avar%20parent%20%3D%20%7B%0A%20%20method()%7B%0A%20%20%20%20return%20'parent'%3B%0A%20%20%7D%0A%7D%3B%0A%0Avar%20child%20%3D%20%7B%0A%20%20__proto__%3A%20parent%2C%0A%20%20%0A%20%20...%7B%7D%2C%0A%20%20get%20counter()%7B%0A%20%20%20%20return%20counter%2B%2B%3B%0A%20%20%7D%2C%0A%20%20%0A%20%20method()%7B%0A%20%20%20%20return%20'child'%20%2B%20super.method()%3B%0A%20%20%7D%0A%7D%0A%0Aconsole.log(child.counter)%3B%0Aconsole.log(child.counter)%3B%0A%0Aconsole.log(child.method())%3B&stage=0

PR Object ResSpread bug

Most helpful comment

This is still an issue. It also disagrees with the native implementation (you can verify this in chrome console)

All 2 comments

I'm interested in this one, is it still an ongoing issue?

This is still an issue. It also disagrees with the native implementation (you can verify this in chrome console)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sorrycc picture sorrycc  路  3Comments

JonathanRys picture JonathanRys  路  3Comments

tracker1 picture tracker1  路  3Comments

hzoo picture hzoo  路  3Comments

nicolo-ribaudo picture nicolo-ribaudo  路  3Comments