Repository navigation
react-compiler: decide an eslint suppression by the place of the comment - #45943
Conversation
The lexer records how far the last react-hooks `eslint-disable-next-line` comment reaches: the end of the line that the comment is for. A function is marked when it starts at or ahead of that position, tested before the parser steps over the closing brace of its body. So a comment counts for each function it is inside, and for a function that starts on the line it is for. The JSX tag lexer passes its comments to the same scan. The parser no longer writes suppression state: no function consumes the suppression, and no parameter list gives it back. With cjs and iife output, the functions after a suppressed function are compiled again.
|
Updated 9:45 AM PT - Oct 21st, 2026
❌ @robobun, your commit a1d9f06 has 1 failures in
🧪 To try this PR locally: bunx bun-pr 45943That installs a local version of the PR into your bun-45943 --bun |
|
Status: ready for review. It depends on #45550, whose branch is the base of this PR. Reproduction on the base, with export function First({ label }) {
// eslint-disable-next-line react-hooks/rules-of-hooks
const style = { color: label };
return <button style={style}>{label}</button>;
}
export function Second({ label }) {
const style = { color: label };
return <button style={style}>{label}</button>;
}
With this PR, |
There was a problem hiding this comment.
Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.
Beyond the inline findings, I also checked the move of the closing-brace next() out of parse_fn_body — its only two callers (parse_fn, parse_arrow_body) now consume the } themselves — and the new react_hooks_suppressed_until field, which is carried through LexerSnapshot save/restore so TypeScript backtracking does not lose it.
Extended reasoning...
The change rewrites how the JS lexer and parser attribute eslint react-hooks suppression comments to functions for the React Compiler, threading a start Loc through every parse_fn/parse_arrow_body caller; it touches no security-sensitive surface. Four confirmed findings are posted inline, so a human look is already signalled; this note records only the two adjacent concerns examined and ruled out.
…nd lines as JavaScript does A bare `eslint-disable` for a react-hooks rule sets the module-scope opt-out, so it counts for each function of the file, as upstream does. The function right above such a comment is left as written again. The line that a next-line comment is for ends at a line break of JavaScript: \n, \r\n, \r, U+2028 or U+2029. Once a comment reaches the end of the file, no later comment searches for a line break.
|
Reply to the review, for ae354c6:
Each thread has the details. The PR body has the new tables. |
There was a problem hiding this comment.
Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.
Beyond the inline finding, I checked the follow-up commit against the two concerns from the previous round: the next-line end is now found with strings::find_js_line_break (CR and U+2028 covered, with a fixture for each), and a bare eslint-disable now opts the whole module out via parse_entry.rs, so a function closing before it is no longer compiled. I also traced the p.lexer.next() moved out of parse_fn_body: both callers (parse_fn and block-bodied parse_arrow_body, including the TypeScript backtrack path) call it after the decision, and LexerSnapshot saves and restores the new react_hooks_suppressed_until field so backtracking rescans correctly.
Extended reasoning...
The change replaces the lexer's two sticky suppression booleans with a single react_hooks_suppressed_until position and decides each function's React Compiler opt-out from its start location, removing the consume/give-back counter and is_top_level plumbing; it touches the JS parser and lexer only, with no security-sensitive surface. The one surviving finding is pre-existing (prose mentions of the directive match), and the new commit addressed both earlier inline concerns, but the parser hot path and the per-format behavior table warrant a human look.
|
An independent branch fixes the same bug: The diff in one line. The lexer records the next-line comments. The parser records where functions end, only in a file that has such a comment. The visit pass decides per candidate with the containment rule of It is choice 1 of "Two choices for a maintainer", taken the other way. It follows babel-plugin-react-compiler 1.0.0 in full, so it prints Two parts of it are of use here, whatever the decision is:
The 17 rows
In the first eight rows the comment is a The branch also takes the candidate before the parameters are visited, as #45550 does. That part is not needed here. |
…param-default-candidate' into robobun/0e4be85e/react-compiler-suppression-in-params
|
Reply to the second review:
678352d merges the new head of #45550 (626f0b7). Its |
There was a problem hiding this comment.
I reviewed the latest push (ae354c6 plus the merge) and found no new bugs; since it changes the parse_fn_body contract (callers now consume the closing }) on every function parse and adds a scan to the JSX-mode lexer, a human look at the parser side is still worthwhile.
What was reviewed:
- The two earlier inline points are addressed in code: a bare
eslint-disablenow feeds the module-scope opt-out inparse_entry.rswherever it sits in the file, and the next-line end comes fromstrings::find_js_line_break(CR, CRLF, U+2028/2029, EOF fallback), with tests for both. parse_fn_bodyhas exactly two callers (parse_fn,parse_arrow_body); both decide the flag and then calllexer.next(), and no removed lexer/parser field is still referenced anywhere insrc/.- Dropping the
is_top_levelpropagation in namespace/enum bodies is safe: the three remaining readers are all gated onallow_await == AllowExpr, which those bodies reset toAllowIdent. - JSX-mode comment slices:
self.endis on the line terminator after a//comment and just past*/after a block comment, so theend - 2strip and the next-line search origin are right;react_hooks_suppressed_untilis saved and restored inLexerSnapshotfor backtracking.
Extended reasoning...
The change touches the JS lexer and parser (src/js_parser/lexer.rs, parse_fn.rs, parse_entry.rs and the call sites of parse_fn/parse_arrow_body) to replace sticky react-hooks suppression booleans with a single react_hooks_suppressed_until position, plus a 470-line test covering esm/cjs/iife, CR and U+2028 line ends, JSX-tag comments and TypeScript arrow paths. It touches no security-sensitive surface. The prior inline findings from this bot were addressed by commit ae354c6 and the bug hunt ran dry this round. Deferral rather than approval because the parse_fn_body lexer-advance contract changed for every function parse and the new scan runs inside the JSX lexer loop, which merits a maintainer's eye; no CODEOWNER covers the changed paths and no third-party objection is outstanding.
|
A count of where these comments are in published code. It is for choice 1 of "Two choices for a maintainer" (the line) and for the second bullet of Downsides. Sample, taken on 2026-10-19.
Result. 3,399 next-line comments match, in 2,114 files of 349 packages. 3,388 of them also match the pattern of babel-plugin-react-compiler.
So in this sample choice 1 changes the output of no function, and the limit for an expression-bodied arrow changes none. Limit of the sample: these are npm packages, and application code can differ. This comes from a separate look at the fault that this PR fixes (a comment right below a function declaration marks that declaration). This PR covers it, so there is no second PR. |
…param-default-candidate' into robobun/0e4be85e/react-compiler-suppression-in-params
|
a1d9f06 merges the new head of #45550 (a363e4b). The files of this PR did not change: the merge has the same tree as 678352d. On the third review: no finding is open. The two failures of the last build are not from this diff: an artifact download timed out on the darwin aarch64 test lane, and |
Depends on #45550: its branch is the base of this PR. Related to #36190.
Problem
bun build --react-compiler, aneslint-disable-next-line react-hooks/...comment marks the wrong functions: all later ones with cjs or iife output, the one right above it, and none from inside a JSX tag.parse_fn.rs:421), and only an esm parse has top-level code.Fix
take_react_hooks_suppressionof react-compiler: do not let a function in a parameter list take the component's candidate name or suppression #45550 is removed. The JSX tag lexer runs the same scan.eslint-disableopts the file out, as upstream does.SuppressionFollowsThePlaceOfTheComment-{esm,cjs,iife}inreact-compiler.test.ts, and the two fixture suites. Self-reviewed: 9 concerns raised, 9 addressed.Background
useMemo(() => value, [])becomesvalue.Vecand the end of each function.Downsides
eslint-disable(main compiled it)..textofbun_js_parseris 157 bytes smaller than on main.Notes
The rule. A next-line comment for
react-hooks/rules-of-hooksorreact-hooks/exhaustive-depscounts for a function when:A bare
eslint-disablefor one of these rules counts for every function of the file.Two choices for a maintainer.
The line. Upstream (babel-plugin-react-compiler 1.0.0) and the lint rule
react-hooks/rule-suppressioncount a next-line comment only for a function it is inside. The second case above keeps what main does under esm for a comment above a function. Without it the build changes what this hook returns:Upstream prints
value => { return value; }. Main, react-compiler: do not let a function in a parameter list take the component's candidate name or suppression #45550 and this PR print the hook as written. The fourAboveforms of the test of react-compiler: do not let a function in a parameter list take the component's candidate name or suppression #45550 keep their value. To follow upstream in full, store the start of the comment inscan_react_hooks_suppression: one expression.The bare
eslint-disable. Upstream and the text of the lint rule count it for every function of the file. Main counts it for the functions after it, and for the one right above it when no token is between. This PR follows upstream: the comment sets the module-scope opt-out that"use no memo"sets, where the per-file state is made (parse_entry.rs:981). Nothing is added to the parse path.History. No issue reports this. The review of #45550 found two of the layouts (#45550 (comment)). #45550 keeps the consume, and a function that closes in a parameter list records where it closed (
react_hooks_suppression_taken_at), so that the owner of the list still gets the suppression. This PR has no consume, so that field andtake_react_hooks_suppressiongo away.What changes on the base.
Cis// eslint-disable-next-line react-hooks/rules-of-hooks.CinsideA(body, parameter list, default)Aas writtenAas writtenACbetween the JSX attributes ofAAcompiledAcompiledAas writtenfunction B() {},C,function A() {}Bas written,AcompiledBcompiled,Aas writtenfunction T() {} // C, thenNon the next lineTas written,NcompiledTcompiled,Nas written;,C,AAas writtenAas writtenC, a statement that is not a function,AAas writtenAas writtenAcompiledC, a doc comment,AAas writtenAas writtenAcompiledC,const A = memo(, the function on the next lineAas writtenAas writtenAcompiledCin a class static block, thenAAas writtenAas writtenAcompiledC, an empty line,AAas writtenAas writtenAcompiledeslint-disable, thenAAas writtenAas writtenA, then a bareeslint-disableright belowAas writtenAas writtenA, a statement, then a bareeslint-disableAcompiledAcompiledAas writtenA comment that is inside
T, on a line ofTthat is right aboveN, also counts forN: it is for the line thatNstarts on.Reference. 125 probe files. Each was built with its comments and with the comments made inert, by babel-plugin-react-compiler 1.0.0 and by a debug build of the base (f9b900b, the head of #45550 at that time) and of this branch (ae354c6). 215 functions show a decision in both tools.
The 30 of this PR are all left as written:
eslint-disable-next-line no-console, react-hooks/rules-of-hooks): bun and ESLint honour it.Under esm, 25 decisions move to the reference and 18 move away from it. Each of the 18 is a function that starts on the line that a comment is for. On the base another function took that comment first. Under cjs and iife, 121 move to the reference and none away.
Not changed. An arrow with an expression body closes at the token after the expression, and the lexer scans a comment on the way to that token. So a comment right below such an arrow, with no
;between, counts for the arrow. The test has this form with its value. An exact test needs the end of the previous token, which the lexer does not keep.react-hooks/exhaustive-deps. It stays in the matcher. With default options, babel-plugin-react-compiler 1.0.0 skips a component that has this comment inside (CompileError: Suppression). Upstream compiles the fixtureexhaustive-deps/compile-files-with-exhaustive-deps-violation-in-effects.jsbecause of its@validateExhaustiveMemoizationDependencies. bun has that validation off (src/react_compiler/hir/environment_config.rs:155).The text of the comment. The match is as before:
eslint-disableanywhere in the comment, then the name of the rule anywhere after it. So a comment that only mentions the directive counts. The pattern of babel-plugin-react-compiler 1.0.0 is not anchored either, and ESLint and the lint rule anchor theirs. To anchor it is a separate choice.Lines. The end of a line is a line break of JavaScript:
\n,\r\n,\r, U+2028 or U+2029 (strings::find_js_line_break). Each matching comment searches for two of them. Once a comment reaches the end of the file, no later comment searches.#36190. It also ends the cjs and iife leak, by another route: each bundler parse becomes a module parse, so the flag is cleared. With this PR the suppression does not read
is_top_level. The two change different source files. The react-compiler tests of the one that lands second pass before it.Cost with the compiler off. From
cargo build --release -p bun_js_parser, thenobjdump,nm -Sandsizeon the rlib member, andrustc -Zprint-type-sizes. The counts are the instructions that serve the suppression on the path with no comment.parse_fn, per functionparse_arrow_body, per arrow.textof the rlibparse_fn(JS / TS)parse_fn_bodyparse_arrow_bodytake_react_hooks_suppressionscan_comment_textnext_inside_jsx_elementLexer/LexerSnapshot/ParserSnapshotFor this PR, one of the 4 instructions of
parse_fnand one of the 5 ofparse_arrow_bodykeep thestartargument. A parse oftypescript.js(9.1 MB) callsparse_fn12,597 times,parse_arrow_body9,120 times andparse_paren_expr11,427 times (gdb breakpoint counts). No allocation on any path.The start of a function.
parse_fnandparse_arrow_bodyget it as an argument: thefunctionorasynctoken, the first token of an arrow, or the key of a method. Each caller had it already.TS namespace and enum bodies. #34250 gave them a fresh
FnOrArrowDataParse, as esbuild does, and keptis_top_levelonly for the consume. Each other reader ofis_top_levelis behindallow_await == AllowExpr, which these bodies do not have.Tests. On a debug build of the base (626f0b7),
SuppressionFollowsThePlaceOfTheComment-esmdiffers in 10 of 56 lines,-cjsin 29 and-iifein 29.SuppressionAheadOfAFunctionInAParameterListandSuppressionInsideTSNamespaceDoesNotLeakpass before and after.Suites run on a debug build of this branch.
react-compiler.test.ts(124 pass, 1 skip, 1 todo),react-compiler-fixtures.test.ts(3,293 pass, with a longer hook timeout),react-compiler-fixtures-run.test.ts(849 pass),transpiler.test.js,test/bundler/esbuild/ts.test.ts,test/bundler/bundler_jsx.test.ts. No failure. In my container the debug build is slow to start, and some runs hit time limits on the base build too: the 120 s hook ofreact-compiler-fixtures.test.ts, and the 5 s limit of tests intest/cli/lint/react-compiler.test.tsandjsx-production.test.ts.no test proof · iteration 0 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/bundler/transpiler/react-compiler.test.ts