Visitar URL original
fix: clarify numeric escape errors by oovz · Pull Request #18421 · babel/babel · GitHub
Skip to content

fix: clarify numeric escape errors - #18421

Open
oovz wants to merge 1 commit into
babel:mainfrom
oovz:fix/numeric-escape-diagnostic-13791
Open

oovz wants to merge 1 commit into
babel:mainfrom
oovz:fix/numeric-escape-diagnostic-13791

Conversation

@oovz

@oovz oovz commented Oct 26, 2026 •

Copy link
Copy Markdown
Q A
Fixed Issues? Fixes #13791
Patch: Bug Fix? No
Major: Breaking Change? No
Minor: New Feature? No
Tests Added + Pass? Yes
Documentation PR Link N/A
Any Dependency Changes? No
Need backport? No
License MIT

Replace previous The only valid numeric escape in strict mode is '\\0'. message with the new Invalid numeric escape '${escape}' in strict mode. that shows the offending escape, such as \8 in original issue, as well as its position, making it easier to find in long strings.

Fixtures are updated. Added a test.

Edit: code and tests are assisted by AI.

Use an `Invalid numeric escape` message that shows the offending escape.

Fixes babel#13791.

Assisted-by: GPT-6 (Codex)
@babel-bot

Copy link
Copy Markdown
Collaborator

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

@pkg-pr-new

pkg-pr-new Bot commented Oct 26, 2026

Copy link
Copy Markdown

Open in StackBlitz

commit: 26d0fef

@nicolo-ribaudo nicolo-ribaudo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't understand the code changes. The only thing that changed in the tests are error messages and nothing else, it shouldn't require changes to the error reporting logic.

@nicolo-ribaudo nicolo-ribaudo added the PR: Polish 💅 A type of pull request used for our changelog categories label Oct 26, 2026
@oovz

oovz commented Oct 26, 2026

Copy link
Copy Markdown
Author

the issue wants this error message to include failing escape character. the code change adds that, as well as the position of the failing character ("detail").
existing implementation does not report the actual failing character.

@JLHwung

JLHwung commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

I don't think this PR really fixes #13791. The culprit of #13791 is that the error is thrown in a position with large column such that the code frame does not easily fit in a small screen. This is common when passing minified source or source with large string to Babel.

To properly fix this issue, I suggest we introduce a maxWidth: number option to @babel/code-frame. maxWidth should be a positive integer, when maxWidth is set, @babel/code-frame will print a window-wrapped code frame, e.g.

/repl.js: The only valid numeric escape in strict mode is '\0'. (1:244)

> 1 | [...]\'ajS>\0~y\8PZ*|-BRY&m%U[...]
    |                 ^
  2 |

And now without the parser message change, it is very clear that \8 in the original source causes this error, such that we don't have to duplicate that information again in the parser error message. The code-frame is exactly for the purpose of locating the problematic input. With this option, we don't have to update other parser errors: since one could argument that another parser error does not contain the source and they can not view the error on their screens.

@oovz It will be a new feature for @babel/code-frame, do you want to open a PR?

@oovz

oovz commented Oct 29, 2026

Copy link
Copy Markdown
Author

@JLHwung thank you! I agree that instead of removing the position we should introduce a maxWidth (or wrapWidth) to keep the position output while fitting the terminal properly.
I'm wondering if the caller need to adjust as well to adapt with this new variable and do I need to make that change too?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Improve message for StrictNumericEscape

4 participants