Skip to content
New issue

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

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

Already on GitHub? # to your account

super does not work in constructor #323

Closed
arv opened this issue Oct 25, 2018 · 2 comments
Closed

super does not work in constructor #323

arv opened this issue Oct 25, 2018 · 2 comments

Comments

@arv
Copy link
Contributor

arv commented Oct 25, 2018

class Y extends X {
    constructor() {
        super();
        super.m();
    }
};

https://sucrase.io/#selectedTransforms=jsx&code=%0Aclass%20Y%20extends%20X%20%7B%0A%20%20%20%20constructor()%20%7B%0A%20%20%20%20%20%20%20%20super()%3B%0A%20%20%20%20%20%20%20%20super.m()%3B%0A%20%20%20%20%7D%0A%7D%3B%0A

Same error happens with super.x and super.x = 1

@alangpierce
Copy link
Owner

Thanks for reporting. I actually didn't realize that super.m() was allowed in constructors. Should be a pretty easy fix: only consider tokens matching SUPER LPAREN when detecting the super constructor call within a constructor.

@arv
Copy link
Contributor Author

arv commented Oct 26, 2018

I was planning on fixing it today. Feel free to assign to me

arv added a commit to arv/sucrase that referenced this issue Oct 26, 2018
The old code assumed that `super` always followed by a `(` which is not
the case.

Also adds tests for invalid (at runtime) code with multiple `super()`
and `super.m()` / `super.x` / `super.x = 1` before `super()`.

Fixes alangpierce#323
arv added a commit to arv/sucrase that referenced this issue Oct 26, 2018
The old code assumed that `super` always followed by a `(` which is not
the case.

Also adds tests for invalid (at runtime) code with multiple `super()`
and `super.m()` / `super.x` / `super.x = 1` before `super()`.

Fixes alangpierce#323
alangpierce pushed a commit that referenced this issue Oct 28, 2018
The old code assumed that `super` always followed by a `(` which is not
the case.

Also adds tests for invalid (at runtime) code with multiple `super()`
and `super.m()` / `super.x` / `super.x = 1` before `super()`.

Fixes #323
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants