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

Improve parse error location? #16205

Open
1 task
fisker opened this issue Jan 6, 2024 · 4 comments
Open
1 task

Improve parse error location? #16205

fisker opened this issue Jan 6, 2024 · 4 comments

Comments

@fisker
Copy link
Contributor

fisker commented Jan 6, 2024

💻

  • Would you like to work on this feature?

What problem are you trying to solve?

For some parse errors, it's fine to point the error to a single character. But some other errors, it will be nicer to have a start/end range.

Describe the solution you'd like

Add end location to error.

Describe alternatives you've considered

N/A

Documentation, Adoption, Migration Strategy

// Code
a = await

// Current
Unexpected token (1:9)

> 1 | a = await
    |          ^

// Expected
Unexpected token (1:9)

> 1 | a = await
    |     ^^^^^
Code

(
  a
  + a
  // ... really long
  + a
  + a
  + a
  + a
) ++

// Current
Invalid left-hand side in postfix operation. (2:1)

  1 | (
> 2 | 	a
    | 	^
  3 |   + a
  4 |   // ... really long
  5 |   + a

// Expected
Invalid left-hand side in postfix operation. (2:1)

  1 | (
>   | ^
  2 | 	a
    | 	^ 
  3 |   + a
    |   ^^^
  4 |   // ... really long
    |   ^^^^^^^^^^^^^^^^^^
  5 |    + a
    |   ^^^
  6 |    + a
    |   ^^^
  7 |    + a
    |   ^^^
  8 |    + a
    |   ^^^
  9 |  ) ++
    |  ^
@babel-bot
Copy link
Collaborator

Hey @fisker! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

@liuxingbaoyu liuxingbaoyu closed this as not planned Won't fix, can't repro, duplicate, stale Jan 7, 2024
@liuxingbaoyu liuxingbaoyu reopened this Jan 7, 2024
@liuxingbaoyu
Copy link
Member

Sorry, I accidentally closed it.🤦‍♂️

@liuxingbaoyu
Copy link
Member

The first example may not be possible because the unexpected token actually refers to EOF.

@nicolo-ribaudo
Copy link
Member

In many places we already pass the AST node to our internal utilities that generate errors, so with some minimal changes we could experiment reading both its start and end locations and see how good it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants