Repository navigation
fix(parser): do not record strict mode errors during lookahead - #18410
Merged
JLHwung merged 2 commits intoOct 29, 2026
Merged
Conversation
`let x: -01;`, `x as -08`, `type T = -"\8"` with the typescript plugin and
`export type 010`, `type T = { get 01(): x }`, `interface B { foo([ 02 ]): void }`
with the flow plugin crashed with `TypeError: Cannot read properties of
undefined (reading 'set')` in `recordStrictModeErrors`. `lookahead()` swaps
in the reduced `LookaheadState`, which has no `strict`/`strictErrors`
fields, and tokenizing a legacy octal number or a `\8`/`\7` string escape
during that lookahead tried to `strictErrors.set(...)`. Return early when
`isLookahead` is set, mirroring `raise`: lookahead errors are discarded, and
the token is read again (and the error recorded) by the real tokenizer.
Assisted-by: Claude Fable 5.1 <[email protected]>
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/62549 |
|
commit: |
Add `strict` to the lookahead state as it is used by readNumber
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The localized fix preserves normal strict-mode validation and includes targeted regression fixtures, with no blocking issues identified in static review; tests were not executed.
No open issues 🎉
What changed in this PR
Fixes Babel parser crashes on certain invalid Flow and TypeScript inputs by preventing strict-mode error recording during lookahead while preserving normal parsing diagnostics.
Changes:
- Skips strict-mode error recording during lookahead.
- Carries the strict-mode flag into lookahead state.
- Adds regression fixtures for legacy octal literals, escapes, and numeric separators, including error-recovery behavior.
| File | Description |
|---|---|
packages/babel-parser/test/fixtures/typescript/types/literal-string-negative-legacy-octal-escape/options.json |
Expects a syntax error for a negative string type. |
packages/babel-parser/test/fixtures/typescript/types/literal-string-negative-legacy-octal-escape/input.ts |
Adds the negative string escape case. |
packages/babel-parser/test/fixtures/typescript/types/literal-number-negative-legacy-octal/output.json |
Records the recovered type and octal diagnostic. |
packages/babel-parser/test/fixtures/typescript/types/literal-number-negative-legacy-octal/input.ts |
Adds a negative octal literal type. |
packages/babel-parser/test/fixtures/typescript/types/literal-number-negative-legacy-octal-separator/options.json |
Expects an octal error without recovery. |
packages/babel-parser/test/fixtures/typescript/types/literal-number-negative-legacy-octal-separator/input.ts |
Adds an octal type with a separator. |
packages/babel-parser/test/fixtures/typescript/cast/as-negative-legacy-octal/output.json |
Records the recovered cast and diagnostic. |
packages/babel-parser/test/fixtures/typescript/cast/as-negative-legacy-octal/input.ts |
Adds a cast to a negative leading-zero type. |
packages/babel-parser/test/fixtures/flow/type-exports/invalid-legacy-octal-name/options.json |
Expects an invalid export-name error. |
packages/babel-parser/test/fixtures/flow/type-exports/invalid-legacy-octal-name/input.js |
Adds an octal export-name case. |
packages/babel-parser/test/fixtures/flow/type-exports/invalid-legacy-octal-name-no-error-recovery/options.json |
Expects an octal error without recovery. |
packages/babel-parser/test/fixtures/flow/type-exports/invalid-legacy-octal-name-no-error-recovery/input.js |
Exercises the export case without recovery. |
packages/babel-parser/test/fixtures/flow/object-types/invalid-getter-legacy-octal-separator-key/options.json |
Expects an octal getter-key error. |
packages/babel-parser/test/fixtures/flow/object-types/invalid-getter-legacy-octal-separator-key/input.js |
Adds an octal getter key with a separator. |
packages/babel-parser/test/fixtures/flow/object-types/invalid-getter-legacy-octal-key/output.json |
Records the recovered getter and diagnostic. |
packages/babel-parser/test/fixtures/flow/object-types/invalid-getter-legacy-octal-key/input.js |
Adds an octal getter-key case. |
packages/babel-parser/test/fixtures/flow/object-types/invalid-getter-legacy-octal-escape-key/output.json |
Records the recovered escaped key and diagnostic. |
packages/babel-parser/test/fixtures/flow/object-types/invalid-getter-legacy-octal-escape-key/input.js |
Adds an octal escape in a getter key. |
packages/babel-parser/test/fixtures/flow/interface-types/invalid-method-param-legacy-octal/output.json |
Records the recovered tuple type and diagnostic. |
packages/babel-parser/test/fixtures/flow/interface-types/invalid-method-param-legacy-octal/input.js |
Adds an octal tuple element in an interface method. |
packages/babel-parser/src/tokenizer/state.ts |
Adds strict to the lookahead state type. |
packages/babel-parser/src/tokenizer/index.ts |
Copies strict state and guards error recording during lookahead. |
Review effort: Balanced
nicolo-ribaudo
approved these changes
Oct 25, 2026
Collaborator
|
Backported to 7.x in #18440. |
JLHwung
added a commit
that referenced
this pull request
Oct 29, 2026
fix(parser): do not record strict mode errors during lookahead (#18410) backport of 2060a76 Co-authored-by: Huáng Jùnliàng <[email protected]>
brandhaug
added a commit
to brandhaug/b2b-saas-starter
that referenced
this pull request
Nov 2, 2026
## pnpm-workspace.yaml (default) ## Dependency Updates | Package | From | To | Type | | --- | --- | --- | --- | | `@babel/core` | 8.0.9 | 8.0.10 | patch | | `@inlang/plugin-message-format` | 4.5.5 | 4.5.6 | patch | | `@tanstack/devtools-vite` | 0.8.5 | 0.8.6 | patch | | `ai` | 7.0.156 | 7.0.157 | patch | | `cn` | 0.5.0 | 0.5.1 | patch | | `seroval` | 1.7.4 | 1.7.5 | patch | ## Release Notes <details> <summary><b>@<!---->babel/core</b> (8.0.9 → 8.0.10)</summary> ## v8.0.10 (2026-10-29) Thanks @<!---->dagemawinegash, @<!---->nyan-left, @<!---->saiyam-jain-dev, and @<!---->yulman2207 for your first PRs! #### 🐛 Bug Fix * `babel-parser` * [#18420](babel/babel#18420) fix(parser): improve radix literal rounding ([@<!---->JLHwung](https://github.com/JLHwung)) * [#18372](babel/babel#18372) fix(parser): allow parenthesized assignment target in arrow initializer ([@<!---->JLHwung](https://github.com/JLHwung)) * [#18410](babel/babel#18410) fix(parser): do not record strict mode errors during lookahead ([@<!---->JLHwung](https://github.com/JLHwung)) * [#18433](babel/babel#18433) fix(parser): invalid expectOnePlugin usage ([@<!---->JLHwung](https://github.com/JLHwung)) * [#18409](babel/babel#18409) fix(parser): handle ASI after let followed by a reserved word on the next line ([@<!---->JLHwung](https://github.com/JLHwung)) * [#18406](babel/babel#18406) fix(parser): parser should not crash for `import defer {}` ([@<!---->JLHwung](https://github.com/JLHwung)) * [#18407](babel/babel#18407) fix(parser): record start location in `startNodeAt` ([@<!---->JLHwung](https://github.com/JLHwung)) * `babel-plugin-transform-block-scoping` * [#18371](babel/babel#18371) fix: closures in for-loop test and update capture wrong binding ([@<!---->joellemd](https://github.com/joellemd)) * `babel-generator` * [#18418](babel/babel#18418) fix(generator): keep aliases of string-literal module specifiers ([@<!---->JLHwung](https://github.com/JLHwung)) * [#18427](babel/babel#18427) Fix missing parentheses around TypeScript assertion targets ([@<!---->dagemawinegash](https://github.com/dagemawinegash)) * [#18324](babel/babel#18324) fix: invalid `minified: true` output for new expression ([@<!---->JLHwung](https://github.com/JLHwung)) * [#18437](https://github. …[full notes](https://github.com/babel/babel/releases/tag/v8.0.10) </details> <details> <summary><b>@<!---->tanstack/devtools-vite</b> (0.8.5 → 0.8.6)</summary> ### Patch Changes - [#539](TanStack/devtools#539) [`ed8b314`](TanStack/devtools@ed8b314) - Source injection no longer stops after the dev server parses a regex literal. Before this fix, a regex literal cached `value` as a child key of `Literal` nodes. Every later file with a string literal then threw during the walk and got zero `data-tsd-source` attributes. - [#540](TanStack/devtools#540) [`012421f`](TanStack/devtools@012421f) - Stop the console pipe feedback loop with Vite 8 `server.forwardConsole`. The server side of the pipe no longer sends browser logs that Vite printed in the terminal back to the browser. - [#548](TanStack/devtools#548) [`40f32e4`](TanStack/devtools@40f32e4) - Run source injection before the transforms of other plugins (unless they also use `order: 'pre'`), also when `devtools()` is not first in the plugins array. Before this fix, a framework plugin that changed the code of only one environment shifted the line numbers, so `data-tsd-source` differed between SSR and client and caused hydration warnings. - [#541](TanStack/devtools#541) [`df1464c`](TanStack/devtools@df1464c) - Fix "Go to Source" for files outside the current working directory, for example a package in a monorepo or Vite run from another directory. The editor got a path with the working directory added twice. Also answer a missing or malformed `source` with `400` instead of leaving the request pending. - [#542](TanStack/devtools#542) [`9c58288`](TanStack/devtools@9c58288) - Remove the `intent` bin from the published packages. It took over `node_modules/.bin/i …[full notes](https://github.com/TanStack/devtools/releases/tag/%40tanstack/devtools-vite%400.8.6) </details> <details> <summary><b>cn</b> (0.5.0 → 0.5.1)</summary> ### Patch Changes - [#165](shadcn-ui/cn#165) [`5e65675`](shadcn-ui/cn@5e65675) Thanks [@<!---->shadcn](https://github.com/shadcn)! - Group the legacy `bg-gradient-to-*` utilities as `bg-color`, the same as tailwind-merge. `cn("bg-background", "bg-gradient-to-r")` now returns `bg-gradient-to-r`, and `bg-gradient-to-r` no longer replaces `bg-linear-to-r` or an arbitrary `bg-[...]` image. </details> <details> <summary><b>seroval</b> (1.7.4 → 1.7.5)</summary> ### Patch Changes - d85ec3f: Keep two round-trip cases intact. An object whose own `constructor` key holds a falsy value, such as `{ constructor: undefined }`, now keeps `Object.prototype` instead of coming back with a null prototype. A null-prototype object with an own `__proto__` key, or any object serialized with `Feature.ObjectAssign` disabled, no longer turns equal-looking values such as two `new Set()` into one shared object in `serialize`, `crossSerialize` and `compileJSON` output. </details> --- *This PR was auto-generated by [catalog-update-action](https://github.com/brandhaug/catalog-update-action).* Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In this PR we fix an issue reported by Claude Fable 5.1: When Babel parses
let x: -01;,x as -08,type T = -"\8"with the typescript plugin andexport type 010,type T = { get 01(): x },interface B { foo([ 02 ]): void }with the flow plugin, it crashed withTypeError: Cannot read properties of undefined (reading 'set')inrecordStrictModeErrors.The culprit here is that in the
LookaheadState,there is nostrict/strictErrorsfields, so any strict error recording fails. Since we don't care syntax errors on lookahead, as the parser will eventually handle them, we can safely skip recording during the lookahead.