New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

babel-plugin-transform-async-to-module-method async class method affects the scope so super cannot be called (T7346) #4284

Closed
babel-bot opened this Issue May 8, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@babel-bot
Copy link
Collaborator

babel-bot commented May 8, 2016

Issue originally made by @madole

Bug information

  • Babel version: 6
  • Node version: 5
  • npm version: 3

Input code

class Animal {
    constructor(name) {
        this.name = name;
    }

    async getAge() {
        const age = await getAgeFromAPI();
        return age;
    }
}

class Dog extends Animal {
    async getAge() {
        const age = await super.getAge();
        return age * 7;
    }
}

Description

I should be able to call getAge on the Dog instance and it should call the parent's prototype method of the same name.

It actually compiles to

class Dog extends Animal {
    getAge() {
        return (0, _bluebird.coroutine)(function* () {
            const age = yield super.getAge();
            return age * 7;
        })();
    }
}

Which means super is in the wrong scope... it could detect this scenario and compile to something like this..

class Dog extends Animal {
    getAge() {
        var _this = this;

        return (0, _bluebird.coroutine)(function* () {
            const age = yield Animal.prototype.getAge.call(_this);
            return age * 5;
        })();
    }
@loganfsmyth

This comment has been minimized.

Copy link
Member

loganfsmyth commented Sep 24, 2016

Duplicate of #3930

@lock lock bot added the outdated label May 6, 2018

@lock lock bot locked as resolved and limited conversation to collaborators May 6, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.