Repository navigation
fix(semantic): preserve catch and var binding identities - #28739
Conversation
f1bc845 to
f7ef6ae
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
915c2cb to
428c655
Compare
Monitor OxcCommit:
|
Minify Size
No size change across 109,516 files. Full report (Test Minify Size summary): top files and packages each way, and before/after diffs of the files that changed most. Output bytes of oxc's full minify pipeline (compress + mangle + whitespace) over monitor-oxc's |
da458ae to
59943c4
Compare
baltasarblanco
left a comment
There was a problem hiding this comment.
Two small things, then the numbers.
-
This also fixes #27864, which isn't in the Closes list. The snippet from that issue,
(function a() { try {} catch (a) { var a; } console.log(typeof a); })();, minifies to(function e(){console.log(typeof e)})();on the base (a2bd61d), which printsfunction. On this PR it minifies to(function(){try{}catch(e){var e}console.log(typeof e)})();, which printsundefined, the same as the original. If you want to close it here, no test covers that shape yet. This one fails on the base and passes on the head:#[test] fn catch_var_shadows_named_function_expression() { test_smallest( "(function a() { try {} catch (a) { var a } console.log(typeof a) })();", "(function() { try {} catch (a) { var a } console.log(typeof a) })();", ); }
-
The
keepNamespropagation inConstraints::new(crates/oxc_mangler/src/lib.rs:540-548) has no test. If I remove thekept.set_bit(outer.index())line, alloxc_manglerandoxc_minifiertests still pass. WithkeepNames,function _() { var foo; try {} catch (foo) { var foo = function() {} } }then mangles tocatch (e) { var e = function() {} }, so the function's.namebecomese. With the PR as is,foois kept. That line inkeep_name_casesoftests/mangler/mod.rswould catch it.
What I checked, on the head (7d8f809) against the base (a2bd61d):
cargo test -p oxc_semantic -p oxc_mangler -p oxc_minifier -p oxc_linter -p oxc_transformerpasses on the head, and on the head merged locally ontomainatccdc579(the lastmainit merges with cleanly).- With a differential fuzzer that minifies each program and runs the original and the output under Node 24: 1,080 generated programs around
catch (x) { var x }(outer parameter,varbefore or after, function declaration or no outer binding; thevarin a block,for-inor closure; nested catches; directeval; sloppy and strict), plus 11 hand-written ones. With default options and withkeepNames, 210 of the generated and 7 of the hand-written ones behave differently from the original on the base, and none on this PR (one hand-written case changes a function.namewithoutkeepNames, which is expected). - On 18,749 files from npm packages and 261 small test cases, the minified output is byte-identical between the base and this PR, except for two of my small cases that are the #27864 shape (now correct) and two npm files (CJS and ESM builds of the same library). There, with
keepNames, two locals that a latervar x = function () {}redeclares now keep their original names (i,u) instead of being mangled, which looks like the intended redeclaration inference inkeep_names.rs.
I used AI assistance (Claude Code) to set up and run these checks. I re-ran them and checked the outputs myself.
|
@baltasarblanco Thanks, both points confirmed.
Both are in 915c207. The commits after the one you reviewed (7d8f809) only simplify the mangler lookup and the minifier's handling of regenerated Generated by Claude Code |
When a binding in scope `S` gets a slot, slot liveness walks up from every scope the binding is used in (its references, redeclarations, and declaration), marking scopes until it reaches `S` or an ancestor of `S`. The list of start scopes also included `S` itself. `scope_ancestors(S)` yields `S` first, which hits the stop condition immediately, so that walk never marked anything. It still cost an iterator setup and a branch per binding in the mangler's hottest loop. Drop it. Slot assignment is unchanged, so mangled output is identical. Split out of #28739, where CodSpeed attributed its 3–7% mangler improvements to this line. --- _Generated by [Claude Code](https://claude.ai/code/session_01RRFyUsLZG6bkKvSHoFJuow)_
26db2fd to
062fb5d
Compare
a2ce35a to
e1e4ea3
Compare
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@Dunqing can you open an issue in the backlog for this.
|
|
Some executed evidence on the final head (
I used AI assistance (Claude Code) to set up and run these checks. I re-ran them and checked the outputs myself. |
Merge activity
|
## Problem [Annex B.3.4](https://tc39.es/ecma262/#sec-variablestatements-in-catch-blocks) lets a `var` reuse the name of a simple catch parameter, and that one identifier then refers to two different bindings: ```js function f() { try { throw 1 } catch (e) { var e = 2; // declares `e` in f's scope, but `= 2` assigns the catch parameter console.log(e); // 2: the catch parameter } return e; // undefined: f's own `e`, which was never assigned } ``` Semantic analysis merged the two into the catch parameter's symbol. When the enclosing var scope had no binding of that name yet, it moved the catch parameter's binding there. Otherwise it kept the catch parameter as the only symbol, and the `var` declared nothing of its own. Either way, oxc saw one binding where the program has two, and every consumer inherited the mistake: - The mangler could give the catch parameter a name that is used outside the catch, so the printed `var` declared that name in the function and shadowed an outer variable (#28520). - After the move, the inner catch scope of nested catches no longer bound the name, so its reads resolved to the outer catch parameter. Mangled output then read the wrong value, and `no-unused-vars` reported the wrong parameter (#29076). - The minifier could drop `catch (a) { var a }` as dead code, so `typeof a` in a named function expression `a` resolved to the function itself instead of the hoisted `var` (#27864). ## Fix Keep the two bindings as separate symbols. The `var` declares the binding in the enclosing var scope as usual. Its identifier carries the catch parameter, because the initializer writes there, and it is recorded as a redeclaration of the catch parameter. `Scoping::catch_var_binding` finds the link: a catch parameter with a `var` redeclaration, and the binding with the same name in the nearest var scope. With nested catches, the innermost catch parameter is the one assigned. Consumers that rename or rewrite declarations follow the link: - **Mangler**: the name of a linked catch parameter is reserved for the file, as with the `reserved` option. The catch parameter, the enclosing binding, and any Annex B block function of that name in the catch all keep it. Only files containing the pattern lose that name. Monitor Oxc found no size change across 109,516 `node_modules` files. - **Minifier**: a `var` regenerated from removed code gets the binding a fresh analysis would give it where it is placed, recording the link when it lands in a surviving catch. A catch-local `var` is kept while the enclosing binding is used. An assignment is kept when a direct `eval` in the binding's scope could read it. - **Linter**: `no-unused-vars`, `no-redeclare`, `no-useless-assignment`, `block-scoped-var`, and `prefer-optional-catch-binding` treat the catch parameter and the enclosing binding as the separate bindings they are. They do not suggest fixes that would retarget the initializer. For #29076, `no-unused-vars` now reports the same two bindings as ESLint. A follow-up should keep catch parameters in their own catch scope (`builder.rs` currently moves them into the catch body's block) rather than expanding this change. Tracked in oxc-project/backlog#249. Closes #28520 Closes #29076 Closes #27864 Supersedes these PRs, which address the same issues and need closing by hand after merge (closing keywords do not close PRs): - #28573: mangler-only fix for #28520 - #29084: nested-catch fix for #29076 - #27923: named function expression scope for #27864 - #27535: nested-catch resolution Related: #17307 (its regression tests now get smaller output), #21366 (its minifier workaround for that issue), #17528 (an earlier attempt at the same semantic change). AI assistance: Claude Code was used to investigate, implement, and test this change.
6c560d8 to
1dc0ee9
Compare
### 💥 BREAKING CHANGES - d742f8b ast: [**BREAKING**] Add `LabelId` to `LabelIdentifier` (#29611) (camc314) ### 🚀 Features - 63b8158 minifier: Inline single use function declaration to assignment (#28917) (Aadharsh Pannirselvam) - eb1833e mangler: Mangle labels (#29614) (camc314) - 702e734 codegen: Print label names from scoping (#29613) (camc314) - 750033a semantic: Resolve labels to label IDs (#29612) (camc314) - ccca379 minifier: Remove unused labels (#29607) (camc314) - e375dff lexer: Complete NEON support for aarch64 (#29390) (Shanon Jackson) - bfe9a81 data_structures: Add buffered vector batch reservations (#29365) (Boshen) - fa492d6 minifier: Merge adjacent switch cases with identical bodies (#29316) (camc314) - 8cc6101 minifier: Inline member reads into callees as indirect calls (#29305) (camc314) - e3d7d91 minifier: Inline member reads into `new` expressions (#29304) (camc314) - 57211d0 minifier: Inline member reads into call arguments (#29303) (camc314) - 523a063 lexer: Publish lexer and SIMD crates (#29264) (Boshen) - 2a5d710 data_structures: Add `unreachable_unchecked!` macro (#29131) (overlookmotel) - 061becc react-compiler: Support logical assignment operators (#29137) (Yagiz Nizipli) ### 🐛 Bug Fixes - d520358 transformer: Retain decorated fields with define semantics (#29444) (Dunqing) - 83fb644 lexer: Combine surrogate pairs written with any escape form (#29658) (Shanon Jackson) - f8e329c transformer: Preserve optional calls on private field chains (#29443) (Dunqing) - 4b86eba react-compiler: Do not report hoisted function declaration initializer as access before declaration (#29641) (Boshen) - 7e41638 parser: Keep whole parenthesized `TSInstantiationExpression` with `preserve_parens: false` (#29359) (leaysgur) - 5aa6c17 napi/parser: Release native parse result eagerly (#29569) (Boshen) - 1dc0ee9 semantic: Preserve catch and var binding identities (#28739) (Dunqing) - 11dbaf4 ecmascript: Prefer hex integers when lengths tie (#29436) (camc314) - e64155e transformer/react-refresh: Recognize TypeScript wrappers in HOC arguments (#29290) (camc314) - 9085be1 react-compiler: Only report zero-argument new Date in render body (#29419) (Boshen) - 9f465fd react-compiler: Preserve ref mutation hints (#28553) (Nash Aschenbath) - 075b74f lexer: Do not drop UTF-8 validation errors in TSX type arguments (#29409) (overlookmotel) - 59cbbbf lexer: Fix source length assertion (#29408) (overlookmotel) - f37f271 react-compiler: Resolve computed dependencies in merged memo scopes (#29376) (camc314) - ab73590 parser: Preserve re-exported default import names in raw transfer (#29234) (camc314) - 6e6bd61 react-compiler: Avoid invariants for catch phis and ref-free callbacks (#29018) (camc314) - 19b1691 isolated-declarations: Retain types used by exported ambient variables (#28996) (camc314) - b372b04 transformer/optional-chaining: Preserve parenthesized chain boundaries (#29218) (camc314) - efcdf06 transformer: Isolate logical assignment temporaries in parameters (#29182) (Dunqing) - 177fdd7 parser: Classify re-exported namespaces as indirect exports (#29196) (Boshen) - 053cc40 parser: Preserve type-only flags on re-exported imports (#29195) (Boshen) - 34172e0 data_structures: Fix `assert_unchecked!` macro (#29130) (overlookmotel) - b515929 transformer: Lower wrapped assignments and preserve computed receivers (#29113) (camc314) - 59aed23 parser: Highlight invalid numeric separators (#29117) (camc314) - 8f5e82c parser: Reject exponentiation operands hidden by assertions (#29115) (camc314) - 42e790c parser: Require `declare` before `abstract` modifiers (#29111) (camc314) ### ⚡ Performance - dd9af34 parser: Make parser and lexer checkpoints `Copy` (#29662) (Boshen) - 4ebe523 parser: Keep the tokens read while classifying `()` and `(x)` arrows (#29560) (Boshen) - 7a6b0a4 parser: Lex the token after `let` and `?.` once (#29559) (Boshen) - bd9fa9b parser: Lex the token after a modifier keyword once (#29558) (Boshen) - 2c6ee72 parser: Skip arrow speculation for array and object literals (#29557) (Boshen) - 85c0269 parser: Rule out type arguments from tokens before speculating (#29556) (Boshen) - b6edb78 parser: Avoid token loop restart after newlines (#29423) (Boshen) - 762bbcf lexer: Cut NEON lexing cost in carve, coalesce and compress (#29414) (Shanon Jackson) - f09af45 lexer: Keep source position in registers across byte handlers (#29401) (Boshen) - ae1a375 lexer: Complete single-byte tokens without a byte handler (#29400) (Boshen) - 11daf98 lexer: Build tokens once from pending state (#29399) (Boshen) - c49e1bd str: Hash identifiers without branching on length (#29397) (Boshen) - 8a6e0c1 lexer: Borrow contiguous escaped string values (#29372) (Boshen) - 27baf0c lexer: Buffer more comments before arena allocation (#29371) (Boshen) - baa84fc lexer: Size escaped strings before allocating (#29369) (Boshen) - 4313dee parser: Buffer module record entries (#29368) (Boshen) - 2df1f19 parser: Reduce regex, template, and comment allocations (#29361) (Boshen) - f26d9d9 parser: Reduce arena allocations and reallocations (#29358) (Boshen) - 846adbb mangler: Skip a liveness walk that never marks a scope (#29391) (Dunqing) - 0d2e41a parser: Reduce identifier dispatch overhead (#29347) (Boshen) - 1aaf3b0 parser: Reuse pure re-export storage (#29216) (Boshen) - 9add80d parser: Buffer decorator and heritage lists (#29215) (Boshen) - cb5cf55 parser: Collect prefixed import lists once (#29214) (Boshen) - ec6b166 parser: Omit discarded recovered parentheses (#29213) (Boshen) - 01e2b66 parser: Avoid discarded TypeScript instantiations (#29210) (Boshen) - 727610a parser: Collect short named import lists (#29209) (Boshen) - d1eaed0 parser: Collect short template literal lists (#29208) (Boshen) - 0301b92 parser: Reserve module record batches (#29207) (Boshen) - 9734804 parser: Collect short switch consequent lists (#29206) (Boshen) - 6674b7a parser: Collect short JSX child lists (#29205) (Boshen) - cc03246 parser: Collect short binding pattern lists (#29204) (Boshen) - e36dd2d parser: Avoid discarded cover parameter allocations (#29203) (Boshen) - 2d5864c parser: Collect short sequence expression lists (#29202) (Boshen) - 6495e66 parser: Avoid discarded block allocations (#29199) (Boshen) - 2601c45 parser: Collect short formal parameter lists (#29198) (Boshen) - 10fddc3 parser: Collect short TypeScript type lists (#29197) (Boshen) - 4140fb0 parser: Keep class heritage on the stack (#29190) (Boshen) - e028d74 parser: Collect short statement lists before allocating (#29189) (Boshen) - 69c7892 parser: Collect short declaration lists before allocating (#29188) (Boshen) - aed0190 parser: Skip unused identifier hashes (#29168) (Boshen) - 2c0a6c1 parser: Avoid allocating discarded directive statements (#29186) (Boshen) - 48532bb parser: Buffer remaining parser lists (#29185) (Boshen) - e59d413 parser: Reuse export entry storage (#29172) (Boshen) - f815f54 parser: Reduce arena list reallocations (#29169) (Boshen) ### 📚 Documentation - 9e5a2bb agents: Require runnable playground reproductions in PRs (#29450) (Dunqing) - c4d1024 minifier: Require examples in fix and optimization PRs (#29439) (Dunqing) - 43e0829 parser: Fix grammar context formatting (#29373) (camc314) - 3e947d7 napi/parser: Correct TS-ESTree differences (#29268) (fisker Cheung) - 521d194 transformer: Require reproductions in fix PR descriptions (#29224) (Dunqing) - 24c4b78 simd: Improve comment (#29244) (overlookmotel) - 306b96a lexer: Correct safety comment on `TokensView::new` (#29231) (overlookmotel) - 44c65f0 lexer: Add comments (#29226) (overlookmotel) - 796255d simd: Use consistent formatting for bullet points in doc comments (#29133) (overlookmotel) - 794cf47 isolated-declarations: Add agent guide (#29125) (camc314) - 768cc29 parser: Clarify syntax support and AST preservation (#29121) (camc314) - 67ecd8c estree: Correct serialization capabilities (#29120) (camc314)
# Oxlint ### 🚀 Features - db5bc6b linter: Output recommended flag in `--rules` JSON output (#29338) (Cam McHenry) - acd8814 linter/typescript/no-misused-promises: Add `flagUnions` option (#29380) (camc314) - fa492d6 minifier: Merge adjacent switch cases with identical bodies (#29316) (camc314) - ca3b2cb linter/vue/no-shared-component-data: Implement fixer (#29291) (Mikhail Baev) - bfe3498 linter: Mark oxc rules as recommended (#28091) (Cam McHenry) - 5da83ae linter/eslint/no-unused-vars: Suggest removing unused type parameters (#28762) (YanYunCY) - 6816662 linter/jsdoc/require-param-description: Implement suggestion (#29118) (Mikhail Baev) ### 🐛 Bug Fixes - 97ed4b7 linter: Mark undefined argument removal as dangerous (#29266) (周星星同学) - 58ef81d linter/typescript/prefer-function-type: Strip a trailing comma from the fixed signature (#28145) (NavpreetSSidhu) - dcb465f linter/jsx-a11y/prefer-tag-over-role: Allow role="img" on svg (#29440) (Nadir Ali) - 994ddc3 linter/eslint/no-div-regex: Offer regex rewrites as suggestions (#29493) (oxc-captain[bot]) - dc5add7 linter/jsx-a11y/lang: Don't report a missing lang attribute (#29441) (Nadir Ali) - f010115 linter/jest/prefer-to-be,linter/vitest/prefer-to-be: Emit rewrites as suggestions (#29503) (oxc-captain[bot]) - b31fb57 linter/eslint/no-new-wrappers: Offer wrapper rewrites as suggestions (#29494) (oxc-captain[bot]) - 9abb941 linter/jsx-a11y/scope: Preserve effectful attribute values in safe fixes (#29507) (oxc-captain[bot]) - a1664a9 linter/jsx-a11y/no-redundant-roles: Use the first valid ARIA role token (#29497) (oxc-captain[bot]) - 64df21d linter/eslint/yoda: Skip safe fixes for relational regex comparisons (#29495) (oxc-captain[bot]) - df8887a linter/typescript/no-import-type-side-effects: Make the import rewrite a suggestion (#29502) (oxc-captain[bot]) - 2ce7f06 linter/jest/no-unneeded-async-expect-function,linter/vitest/no-unneeded-async-expect-function: Suggest unwrapping async callbacks (#29501) (oxc-captain[bot]) - 45c2159 linter/eslint/no-regex-spaces: Offer regex rewrites as suggestions (#29499) (oxc-captain[bot]) - 5167945 linter/vitest/prefer-import-in-mock: Preserve quotes and escapes in fixes (#29509) (oxc-captain[bot]) - 7127aa6 linter/jest/prefer-called-with,linter/vitest/prefer-called-with: Offer matcher rewrites as suggestions (#29498) (oxc-captain[bot]) - 5472a21 linter/typescript: Offer @ts-ignore rewrites as suggestions (#29511) (oxc-captain[bot]) - 523d59b linter/eslint/no-useless-escape: Demote useless escape fixes to suggestions (#29508) (oxc-captain[bot]) - 7ce5692 linter/jest/prefer-todo,linter/vitest/prefer-todo: Restrict safe fixes (#29512) (oxc-captain[bot]) - 0d3f45a linter/vitest/prefer-importing-vitest-globals: Avoid duplicate imports for type-only bindings (#29564) (Ahmed Alhaidary) - d22f2c2 linter/vitest/prefer-strict-boolean-matchers: Offer rewrites as suggestions (#29500) (oxc-captain[bot]) - 2170319 linter/react/only-export-components: Classify export specifiers like declarations (#29520) (Rahul Kashyap) - 79c0b73 linter/eslint/prefer-object-spread: Skip __proto__ sources and suggest unsafe rewrites (#29510) (oxc-captain[bot]) - 69be73e linter/jsx-a11y: Match event handler props case-insensitively (#29570) (Nadir Ali) - 1ae09b9 linter/jsx-a11y/aria-unsupported-elements: Preserve effectful attribute values (#29506) (oxc-captain[bot]) - 4092e2f linter/jsx-a11y/no-aria-hidden-on-focusable: Suggest removing aria-hidden (#29505) (oxc-captain[bot]) - 4059ff7 linter/react/rules-of-hooks: Match namespaced additional effect hooks (#29517) (Boshen) - 65659e6 linter/react/no-unstable-nested-components: Ignore prop callbacks that return an object holding JSX (#29605) (Nadir Ali) - bff48d0 linter/unicorn/prefer-set-size: Keep a space after a keyword before `[` (#29597) (Jingbo Chai) - 2bb4c72 linter/vitest/prefer-importing-vitest-globals: Skip value imports from non-Vitest sources (#29563) (Abdul karim mia) - a087125 linter/oxc/no-accumulating-spread: Check reduce callbacks that take the index or array (#29573) (Nadir Ali) - 1a6fa05 linter/eslint/no-useless-rename: Don't fix a parenthesized target with a default (#29602) (Jingbo Chai) - 121b55c linter/typescript/prefer-function-type: Don't fix or double-report `export default interface` (#29593) (Jingbo Chai) - 9a3d7a1 linter/unicorn/prefer-export-from: Don't offer a fix that drops other names from the export list (#29574) (Nadir Ali) - b188db6 linter/unicorn/prefer-response-static-json: Fix the suggestion when a comment follows `new` (#29591) (Jingbo Chai) - 915a851 linter/eslint/no-var: Don't fix when `let` or `const` changes behavior (#29590) (Jingbo Chai) - 9674aec linter: Don't skip code between comments when checking for an ASI hazard (#29601) (Jingbo Chai) - 5e74d21 linter/unicorn/prefer-at: Preserve grouping in slice pop and shift fixes (#29598) (Jingbo Chai) - c39f4fc linter/oxc/only-used-in-recursion: Keep the line break after a line comment (#29606) (Jingbo Chai) - 66d30ee linter/jest/no-untyped-mock-factory: Copy the module name as written (#29604) (Jingbo Chai) - 1a0460a linter/unicorn/prefer-single-call: Skip comments when checking for a trailing comma (#29596) (Jingbo Chai) - 42395f2 linter/import/no-duplicates: Handle comments after a trailing comma when merging (#29595) (Jingbo Chai) - 22cfb3f linter/eslint/curly: Don't remove braces when the statement needs a semicolon (#29592) (Jingbo Chai) - 40b81d2 linter/unicorn/no-useless-spread: Replace holes with `undefined` in spread arguments (#29600) (Jingbo Chai) - 00704a6 linter: Print config: remove redundant extends in output (#29585) (Cam McHenry) - fe779e8 linter/vitest/require-awaited-expect-poll: Allow implicit arrow-function returns (#29576) (oxc-captain[bot]) - 6da36f8 linter: Print config: validate CLI options before printing config (#29538) (Cam McHenry) - dda4d11 linter: Print config: reflect CLI options like `--type-aware` in the printed config (#29537) (Cam McHenry) - dadb64f linter: Print config: include JS plugin settings in output JSON (#29534) (Cam McHenry) - 0b643b3 linter: Print config: use resolved config instead of config builder (#29533) (Cam McHenry) - 0a557ae linter: Print config: flatten single-element options arrays (#29531) (Cam McHenry) - 09ef22f linter: Print config: preserve original rule configuration when generating rule sets (#29530) (Cam McHenry) - 9314042 linter/react: Exhaustive-deps misses ref.current method calls on custom refs (#29571) (Boshen) - 1dc0ee9 semantic: Preserve catch and var binding identities (#28739) (Dunqing) - bebe76c linter/unicorn/prefer-spread: Avoid stack overflow on cyclic initializers (#29433) (camc314) - eefd253 linter/react/exhaustive-deps: Stop autofixing missing dependency arrays (#29430) (camc314) - 2b4f13e linter/unicorn/prefer-date-now: Preserve negation and comments (#29352) (Guru 🦄) - 2dc1839 linter/eslint/func-style: Report functions sharing type names (#29378) (Abdul karim mia) - db80510 linter/jsx-a11y/no-redundant-roles: Preserve link roles without href (#29384) (oxc-captain[bot]) - 9c20c2a linter: Infer omitted RegExp flags from known patterns (#29428) (oxc-captain[bot]) - 95f1081 linter/unicorn/no-accessor-recursion: Distinguish private and public keys (#29429) (oxc-captain[bot]) - 9f465fd react-compiler: Preserve ref mutation hints (#28553) (Nash Aschenbath) - e5fb59e linter/vitest/require-test-timeout: Avoid overflow when sorting configurations (#29299) (camc314) - 9f72ce2 linter/unicorn/consistent-template-literal-escape: Avoid panics after CRLF (#29298) (camc314) - a2bd61d linter/react/jsx-key: Only check direct JSX array elements (#29294) (camc314) - ed4fb73 linter/oxc/no-accumulating-spread: Avoid panic on parenthesized optional chains (#29293) (camc314) - 4a9d681 linter/jest/prefer-to-be,linter/vitest/prefer-to-be: Avoid Unicode whitespace panics (#29292) (camc314) - d8c1333 linter/vitest/prefer-called-once: Avoid panics on escaped matcher names (#29289) (camc314) - 4959267 linter/unicorn/prefer-includes: Avoid panic on parenthesized optional chains (#29286) (camc314) - a5f7617 linter/unicorn/prefer-object-from-entries: Avoid panic on wrapped callees (#29285) (camc314) - 925633b linter/unicorn/prefer-dom-node-remove: Avoid panic on parenthesized optional chains (#29279) (camc314) - f991b20 linter/unicorn/no-length-as-slice-end: Avoid panic on wrapped callees (#29277) (camc314) - d5385ca linter/unicorn/no-useless-spread: Avoid panics on Unicode whitespace (#29278) (camc314) - 06d5e6d linter/typescript/consistent-type-imports: Avoid panic on quoted import names (#29274) (camc314) - db58bd1 linter/unicorn/prefer-set-has: Avoid panics on Unicode whitespace (#29276) (camc314) - a87cecd linter/unicorn/no-document-cookie: Stop resolving cyclic aliases (#29275) (camc314) - 9c9ffb6 linter/unicorn/prefer-array-flat: Avoid panic on rest parameters (#29273) (camc314) - d068722 linter/no-large-snapshots: Avoid panics on Unicode whitespace (#29272) (camc314) - 411624a linter/eslint/no-empty: Use byte offsets for finally suggestions (#29271) (camc314) - 84fd230 linter/import/no-duplicates: Ignore braces in module strings (#29270) (camc314) - 5d669bb linter/vitest/no-standalone-expect: Support Vitest `.extend` test functions (#29243) (camchenry) - d1bd197 linter/vitest/prefer-snapshot-hint: Recognize conditional test scopes (#29221) (camc314) - 3b16ccf linter/vitest/require-awaited-expect-poll: Avoid duplicated reports (#29174) (sapphi-red) - f0e3270 linter/prefer-mock-return-shorthand: Avoid mock return shorthand for mutations (#29136) (camc314) - 8fe22b1 linter/eslint/no-useless-assignment: Handle instance field captures (#29135) (camc314) - 3e1303e linter/eslint/no-use-before-defne: Fix numerous failing cases (#28861) (Cam McHenry) - 50278cc linter/eslint/no-restricted-imports: Report invalid regex configuration (#29119) (camc314) - dde6024 linter/eslint/arrow-body-style: Converge fixes for wrapped object returns (#29101) (camc314) - 5a32ad0 linter/unicorn/prefer-negative-index: Avoid panic on non-ASCII whitespace (#28877) (YT) ### ⚡ Performance - aed0190 parser: Skip unused identifier hashes (#29168) (Boshen) - 0dfb188 oxlint: Build diagnostic output while linting runs (#28747) (YT) ### 📚 Documentation - cdb5ac4 oxlint: Remove experimental label from `typeCheck` (#29175) (Yuji Sugiura) - ae514b3 linter: Move rule creation guidance into crate AGENTS.md (#29122) (camc314) # Oxfmt ### 🚀 Features - 21e1fc1 formatter_graphql: Support empty selection sets and braced unicode escapes (#29345) (leaysgur) - 292f216 oxfmt: Bump prettier to 3.10.1 (#29333) (leaysgur) ### 🐛 Bug Fixes - 552732b formatter: Fix parenthesized `TSInstantiationExpression` issue (#29389) (leaysgur) - 7e41638 parser: Keep whole parenthesized `TSInstantiationExpression` with `preserve_parens: false` (#29359) (leaysgur) - d41ed14 formatter: Keep the `;` of a lone statement in a Vue event handler (#29354) (leaysgur) - 58d7356 formatter: Break a conditional type alias with a generic constructor type after `=` (#29411) (leaysgur) - 59b8eaa formatter: Print binaryish or `yield` args like `return` (#29407) (leaysgur) - d6632f3 formatter: Keep a comment after `TSPropertySignature`'s `:` (#29393) (leaysgur) - cf50f9b formatter: Keep a blank line between dangling comments (#29392) (leaysgur) - e648de6 formatter: Print sequence in `yield` and unary like in `return` (#29353) (leaysgur) - 547684d formatter: Keep parens around `<` on the left of `>` (#29351) (leaysgur) - 16b84d3 formatter/htmlish: Print CDATA sections as nodes of their own (#29348) (leaysgur) - f9f2385 formatter_css: Print `@supports selector()` like rule selector (#29343) (leaysgur) - f31a8d1 formatter: Align union hug and conditional branch (#29261) (leaysgur) - 79064df formatter_htmlish/angular: Keep block params, ignore whole block (#29258) (leaysgur) - 4d50307 formatter_htmlish: Keep attrs holding character reference (#29257) (leaysgur) - 3205e84 formatter: Break after `=` for hugged type alias (#29256) (leaysgur) - bed54ab formatter_htmlish: Keep whitespace as written only between two CJ characters (#29171) (leaysgur) - 1905d2b formatter_markdown: Keep whitespace as written only between two CJ characters (#29170) (leaysgur) - a3660bb formatter_htmlish: Keep empty comment only element as-is (#29159) (leaysgur) - 49b832a formatter_htmlish/vue: Preserve `v-for` alias holding `in|of` (#29156) (leaysgur) ### 📚 Documentation - 63b9b38 formatter: Re-check divergences whose pins changed in Prettier 3.10 (#29412) (leaysgur) - 0467739 formatter: Classify js/ts conformance failures for prettier 3.10 (#29336) (leaysgur) - 9660ce4 oxfmt: Update htmlish and oxfmt divergences (#29334) (leaysgur)
Oxc now represents a catch parameter and the enclosing var it redeclares as separate symbols. Scan the implicit module var and coordinate printed names without linking the symbols' values. Group same-named bindings in the affected var scope so Annex B block functions keep their implicit assignment target. The normal wrapped-ESM hoisting path can replace the old catch-name filter. The immediate parent passes wrapped_esm_catch_param_redeclared and Rollup's catch-block-scope fixture; the first-bad revision fails both because implicit root vars are absent from statement declarations. Preserve execution coverage for those cases and add conflicts with imported names, nested catches, destructuring, loop bindings, and sloppy CommonJS block functions. Regenerate the paired-name/hoisting snapshot and new execution-fixture snapshots. First-bad-Oxc-Commit: 1dc0ee95180ec421b5678bf51ae8f30974c2640f Oxc-Revision: 1dc0ee95180ec421b5678bf51ae8f30974c2640f
Oxc now represents a catch parameter and the enclosing var it redeclares as separate symbols. Scan the implicit module var and coordinate printed names without linking the symbols' values. Group same-named bindings in the affected var scope so Annex B block functions keep their implicit assignment target. The normal wrapped-ESM hoisting path can replace the old catch-name filter. The immediate parent passes wrapped_esm_catch_param_redeclared and Rollup's catch-block-scope fixture; the first-bad revision fails both because implicit root vars are absent from statement declarations. Preserve execution coverage for those cases and add conflicts with imported names, nested catches, destructuring, loop bindings, and sloppy CommonJS block functions. Regenerate the paired-name/hoisting snapshot and new execution-fixture snapshots. First-bad-Oxc-Commit: 1dc0ee95180ec421b5678bf51ae8f30974c2640f Oxc-Revision: 1dc0ee95180ec421b5678bf51ae8f30974c2640f
Oxc now represents a catch parameter and the enclosing var it redeclares as separate symbols. Scan the implicit module var and coordinate printed names without linking the symbols' values. Group same-named bindings in the affected var scope so Annex B block functions keep their implicit assignment target. The normal wrapped-ESM hoisting path can replace the old catch-name filter. The immediate parent passes wrapped_esm_catch_param_redeclared and Rollup's catch-block-scope fixture; the first-bad revision fails both because implicit root vars are absent from statement declarations. Preserve execution coverage for those cases and add conflicts with imported names, nested catches, destructuring, loop bindings, and sloppy CommonJS block functions. Regenerate the paired-name/hoisting snapshot and new execution-fixture snapshots. Keep catch groups independently renameable when an import resolves to their own enclosing module var. Preserve the outer declaration when splitting the printed names. Add direct self-import and re-export-cycle execution coverage, including a var declared only in a catch loop, across ESM, CommonJS, minified, and wrapped output. First-bad-Oxc-Commit: 1dc0ee95180ec421b5678bf51ae8f30974c2640f Oxc-Revision: 1dc0ee95180ec421b5678bf51ae8f30974c2640f
## Summary - Upgrade Oxc Rust dependencies to 0.159.0. - Upgrade @oxc-project/runtime, @oxc-project/types, oxc-parser, and oxc-transform to 0.159.0. ## Root causes ### oxc-project/oxc#29238 Oxc adopts sourcemap v10, whose source entries may be null. Preserve null slots through map composition, path resolution, placeholder replacement, and the Rust/TypeScript boundary. Skip callbacks for unnamed entries while retaining their original indices, and keep single-source transform inference. Regenerate binding types and add execution coverage for nullable sources. ### oxc-project/oxc#29305 Oxc inlines single-use member callees as indirect calls, preserving the unbound receiver. Regenerate both wrapping variants of namespace_pure_reexport_barrel; their execution assertions retain the same values. ### oxc-project/oxc#29436 Oxc prefers hexadecimal integers when their spelling ties decimal. Regenerate the enum, advanced-chunk module-size, keep-names, and JSON large-integer expectations. Values and byte lengths remain unchanged, including chunk-size boundaries and JSON.parse precision loss. ### oxc-project/oxc#28739 Oxc separates catch parameters from the enclosing var bindings they redeclare. Scan implicit module vars, coordinate printed names without merging their values, and use normal wrapped-ESM declaration hoisting. Include same-named Annex B block functions in each naming group. Update the wrapped-ESM snapshot and add execution fixtures for imported-name conflicts, nested catches, loop/destructuring declarations, and sloppy CommonJS block functions. ### oxc-project/oxc#29607 Oxc removes unused labels. Regenerate minify_nested_labels_no_bundle: nested labels and blocks disappear while all 21 newline calls execute in the same order. ### oxc-project/oxc#28917 Oxc inlines single-use function declarations into assignments. Regenerate the minified CommonJS mixed_reexport_dynamic_entry and mixed_reexport_records snapshots: exported readers become function expressions, preserving values and evaluation order.
When the minifier removed a declaration of a redeclared symbol, its entry in `Scoping::symbol_redeclarations` stayed. In `catch (a) { var a }` the stale entry kept the catch parameter looking redeclared (and, with #28739, linked to the enclosing var binding), so the catch binding was only removed when the output was minified a second time.
Closes #27548
### Example
Input ([playground for this example](`` https://playground.oxc.rs/?t=codegen&options=%7B%22run%22%3A%7B%22compress%22%3Atrue%2C%22whitespace%22%3Atrue%7D%7D&code=export+function+f%28%29%7Btry%7Bx%28%29%3B%7Dcatch%28a%29%7Bvar+a%3B%7D%7D); `` playground.oxc.rs runs the released Oxc version, so it shows the behavior before this PR):
```js
export function f(){try{x();}catch(a){var a;}}
```
`cargo run -p oxc_minifier --example minifier -- input.js --nospace --twice` prints the first run, then a second run on that output.
Before output (parent commit d4c3cbe):
```text
export function f(){try{x()}catch(a){}}
export function f(){try{x()}catch{}}
same = false
```
After output:
```text
export function f(){try{x()}catch{}}
export function f(){try{x()}catch{}}
same = true
```
Before, the first run keeps the unused catch binding `a` and only a second run removes it. After, it is removed on the first run and the output is stable.
### Fix
`symbol_redeclarations` is kept in sync by the existing drop bookkeeping:
- `DroppedSubtreeCollector` (used by every `drop_*` / `replace_*` helper) records `(symbol, binding span)` for declarations of redeclared symbols. A `var` redeclaring a catch parameter also declares the enclosing var binding, so both are recorded (`redeclared_symbols`).
- `KeepVar`, the only place that re-emits a dropped binding with its symbol and span, records what it re-emits, and retires the old declaration when it rebinds a re-emitted `var` to another symbol. `remove_unused_variable_declaration` records the `KeepVar` declarators it removes.
- At pass flush, removed declarations are dropped with `Scoping::remove_symbol_declaration`. The program is walked only when a removed declaration was also re-emitted, to keep those still present.
- A span shared by several declarations of the same symbol (e.g. synthesized `SPAN`s) cannot tell which one was dropped, so those declarations are never pruned (`has_unique_span`). Such input keeps the previous behavior: correct output, with the catch binding removed on a second run.
A stale entry also affects more than the catch binding. Several checks treat a non-empty `symbol_redeclarations` as a signal to stay conservative: parameter inlining (`inline.rs`), function-summary dead code removal (`remove_dead_code.rs`), single-use assignment folding (`minimize_statements.rs`) and declaration-derived value facts (`ecma_context.rs`). A stale entry only disables those checks, which is safe but leaves the table inexact. After this PR the table is exact again.
Debug builds check the walk gate, allocation-free, through the `RedeclaredBindings` visitor: at flush, no pruned declaration is still in the program unless `KeepVar` re-emitted it.
Compared with #27596: no walk over every redeclaration on every pass, and pruning is driven by the existing drop helpers.
### Performance
A version that walked the program on every pass dropping a redeclared declaration cost −3.98% on `minifier[kitchen-sink.tsx]` (CodSpeed); skipping the walk unless `KeepVar` re-emitted a removed declaration brought it to +0.20% instructions (Callgrind, kitchen-sink.tsx, before the shared-span handling was simplified, which only removed work). CodSpeed reports no performance change. Pass count and output on kitchen-sink.tsx are unchanged.
### Test plan
- `optional_catch_binding_after_removed_var` (fails before, passes after, with idempotency checks): the #27548 repro, repeated `var`, dead-code removal through `KeepVar`, nested catches, and cases where the catch must stay.
- `redeclarations_with_synthetic_spans`: every binding gets `SPAN`, so the debug check runs on shared-span declarations.
- `cargo test -p oxc_minifier`, `cargo clippy -p oxc_minifier --all-targets -- -D warnings`.
- Debug build over the minsize corpus with the debug check: no failures.
- `cargo minsize`: no size change. `cargo allocs`: kitchen-sink.tsx +1 sys alloc.
- Node runtime comparison of original vs minified (with and without `--mangle`) for 8 catch/`var` inputs, calling each export with `x()` throwing: identical results.
- Monitor Oxc: Test262 passes and Minify Size reports no change. The transformer, compressor, formatter and Runtime (svelte) suites also fail on other PRs' runs today; codegen, whitespace and mangler fail as in this PR's earlier runs.
AI assistance (OpenAI Codex; Claude Code with Claude Opus 5.5, reasoning effort high) was used to implement this change, write the tests and write this description. The Codex model and reasoning effort were not recorded.
Problem
Annex B.3.4 lets a
varreuse the name of a simple catch parameter, and that one identifier then refers to two different bindings:Semantic analysis merged the two into the catch parameter's symbol. When the enclosing var scope had no binding of that name yet, it moved the catch parameter's binding there. Otherwise it kept the catch parameter as the only symbol, and the
vardeclared nothing of its own. Either way, oxc saw one binding where the program has two, and every consumer inherited the mistake:vardeclared that name in the function and shadowed an outer variable (mangler:var yinsidecatch (y)gets a name that shadows an outer variable #28520).no-unused-varsreported the wrong parameter (mangler:varin a nestedcatchmoves the catch parameter binding out, so references resolve to the outer catch parameter #29076).catch (a) { var a }as dead code, sotypeof ain a named function expressionaresolved to the function itself instead of the hoistedvar(minifier: droppingcatch (a) { var a }rebinds the own name of a named function expression #27864).Fix
Keep the two bindings as separate symbols. The
vardeclares the binding in the enclosing var scope as usual. Its identifier carries the catch parameter, because the initializer writes there, and it is recorded as a redeclaration of the catch parameter.Scoping::catch_var_bindingfinds the link: a catch parameter with avarredeclaration, and the binding with the same name in the nearest var scope. With nested catches, the innermost catch parameter is the one assigned.Consumers that rename or rewrite declarations follow the link:
reservedoption. The catch parameter, the enclosing binding, and any Annex B block function of that name in the catch all keep it. Only files containing the pattern lose that name. Monitor Oxc found no size change across 109,516node_modulesfiles.varregenerated from removed code gets the binding a fresh analysis would give it where it is placed, recording the link when it lands in a surviving catch. A catch-localvaris kept while the enclosing binding is used. An assignment is kept when a directevalin the binding's scope could read it.no-unused-vars,no-redeclare,no-useless-assignment,block-scoped-var, andprefer-optional-catch-bindingtreat the catch parameter and the enclosing binding as the separate bindings they are. They do not suggest fixes that would retarget the initializer. For mangler:varin a nestedcatchmoves the catch parameter binding out, so references resolve to the outer catch parameter #29076,no-unused-varsnow reports the same two bindings as ESLint.A follow-up should keep catch parameters in their own catch scope (
builder.rscurrently moves them into the catch body's block) rather than expanding this change. Tracked in #29739.Closes #28520
Closes #29076
Closes #27864
Supersedes these PRs, which address the same issues and need closing by hand after merge (closing keywords do not close PRs):
varthe name of the outer binding #28573: mangler-only fix for mangler:var yinsidecatch (y)gets a name that shadows an outer variable #28520varin a nestedcatchmoves the catch parameter binding out, so references resolve to the outer catch parameter #29076catch (a) { var a }rebinds the own name of a named function expression #27864Related: #17307 (its regression tests now get smaller output), #21366 (its minifier workaround for that issue), #17528 (an earlier attempt at the same semantic change).
AI assistance: Claude Code was used to investigate, implement, and test this change.