Skip to content
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

Constructor return type annotations produce invalid JS syntax #795

Closed
rtsao opened this issue May 2, 2023 · 1 comment · Fixed by #800
Closed

Constructor return type annotations produce invalid JS syntax #795

rtsao opened this issue May 2, 2023 · 1 comment · Fixed by #800

Comments

@rtsao
Copy link

rtsao commented May 2, 2023

Source:

class Foo {
  constructor(): Foo {
    return this;
  }
}

Transformed (actual):

class Foo {
  constructor():  {
    return this;
  }
}

Transformed (expected):

class Foo {
  constructor()  {
    return this;
  }
}

Reproductions:

@alangpierce
Copy link
Owner

Hi @rtsao , sorry for the delay, and thanks for reporting! That syntax is actually invalid in both TypeScript and Flow, so I'd normally call it out of scope for Sucrase, but I understand the error is pretty confusing, and it's easy to fix in Sucrase, so I'll put up a PR to fix.

alangpierce added a commit that referenced this issue Jun 29, 2023
Fixes #795

This syntax isn't actually valid, but it's easy enough to product working JS to
avoid blocking the developer, so this implements that.
alangpierce added a commit that referenced this issue Jun 29, 2023
Fixes #795

This syntax isn't actually valid, but it's easy enough to product working JS to
avoid blocking the developer, so this implements that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants