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

[Bug]: Wrong ASI after get in class body #16713

Closed
1 task
nicolo-ribaudo opened this issue Aug 2, 2024 · 4 comments
Closed
1 task

[Bug]: Wrong ASI after get in class body #16713

nicolo-ribaudo opened this issue Aug 2, 2024 · 4 comments
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser

Comments

@nicolo-ribaudo
Copy link
Member

💻

  • Would you like to work on a fix?

How are you using Babel?

Other (Next.js, Gatsby, vue-cli, ...)

Input code

class A2 {
  get
  *a(){}
}

Configuration file name

No response

Configuration

n/a

Current and expected behavior

Babel inserts a semicolon after get, parsing that class as containing a field named get and a generator method.

This is wrong, and Babel should report an error for that code.

Environment

Babel 7.25.0

Possible solution

No response

Additional context

No response

@JLHwung
Copy link
Contributor

JLHwung commented Aug 5, 2024

I think the current behaviour is correct and the parser works as-is.

get *a(){} is never allowed in the MethodDefinition production, so the token * becomes the offending token per rules of ASI, since * is separated from the previous token by a line break, ASI is applied and therefore get becomes get; which is then parsed as a class property.

@liuxingbaoyu
Copy link
Member

class A2 {
  get
  *a(){}
}
const a2 = new A2();
console.log(a2.a);
console.log("get" in a2);

The browser seems to accept the form like this, whereas TypeScript complains about it.

@nicolo-ribaudo
Copy link
Member Author

Oh and Firefox rejects that code. I'll investigate a bit more and report the appropriate bugs.

@nicolo-ribaudo
Copy link
Member Author

I submitted a test262 test: tc39/test262#4189

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Nov 7, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser
Projects
None yet
Development

No branches or pull requests

3 participants