8000 Improve @babel/parser error types by liuxingbaoyu · Pull Request #17531 · babel/babel · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@liuxingbaoyu
Copy link
Member
Q                       A
Fixed Issues? Fixes #1, Fixes #2
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This PR is based on #17521, only the last commit is new.

@babel-bot
Copy link
Collaborator
babel-bot commented Sep 29, 2025

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/60629

@pkg-pr-new
Copy link
pkg-pr-new bot commented Sep 29, 2025

Open in StackBlitz

commit: bab537c

@nicolo-ribaudo
Copy link
Member

Rebase? :)

@liuxingbaoyu liuxingbaoyu added the PR: Polish 💅 A type of pull request used for our changelog categories label Oct 3, 2025
@liuxingbaoyu
Copy link
Member Author
liuxingbaoyu commented Oct 3, 2025

I realized an issue, errors that were misnamed in Babel 7 are now correctly named in types.
However, this is somewhat difficult to fix.
Fixed.

Gulpfile.mjs Outdated
SetAccessorCannotHaveRestParameter: "SetAccesorCannotHaveRestParameter",
SetAccessorCannotHaveReturnType: "SetAccesorCannotHaveReturnType",
};
for (const k of Object.keys(oldReasonCodes)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object.entries()?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately Node.js 6 does not support Object.entries.

Gulpfile.mjs Outdated

if (output.includes("babel-parser.d.ts")) {
let code = fs.readFileSync(output, "utf-8");
const oldReasonCodes = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these only being included for Babel 7?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it should be!

Gulpfile.mjs Outdated
});

if (
!bool(process.env.BABEL_8_BREAKING) &&
Copy link
Member
@nicolo-ribaudo nicolo-ribaudo Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to ask again, but could you rebase so that we can remove these checks?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course!

@liuxingbaoyu
Copy link
Member Author

What do you think about manually maintaining error messages instead of using a TypeScript type system?

For example, type ErrorTypes = [["AccessorIsGenerator",{{ kind: "get" | "set"; }}], "ArgumentsInClass", "AsyncFunctionInSingleStatementContext", ...].

This could significantly reduce the size of the .dts file, but it requires us to manually synchronize type changes.

@nicolo-ribaudo
Copy link
Member

It seems like it would save us about 2kB (the space taken by all the string annotations), but I'm worried that it would get out of sync.

Maybe we can explore generating it at build time.

@liuxingbaoyu
Copy link
Member Author

I tried compressing it into an array, but TypeScript complained that the type was too complex, so I had to compress it into an object.

@liuxingbaoyu liuxingbaoyu requested a review from JLHwung January 27, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: parser PR: Polish 💅 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

0