fix(isolated-declarations): incorrect nested namespace output in isolated declarations#15800
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
CodSpeed Performance ReportMerging #15800 will not alter performanceComparing Summary
Footnotes
|
68e00dd to
5cf7227
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a variable shadowing bug in the isolated declarations transformer that caused dotted namespace syntax (export namespace X.Y.Z {}) to be incorrectly transformed. The namespace name was corrupted from the first identifier to the last identifier (e.g., X.Y.Z became Y.Z.Z).
Key changes:
- Renamed pattern match variable from
decltoinner_declintransform_ts_module_declarationto prevent shadowing the function parameter - Added comprehensive test coverage for dotted namespace syntax with varying nesting depths (2, 3, and 4 levels)
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
crates/oxc_isolated_declarations/src/declaration.rs |
Fixed variable shadowing by renaming pattern match variable to inner_decl, preserving access to outer declaration's identifier |
crates/oxc_isolated_declarations/tests/fixtures/nested-namespace-dotted.ts |
Added test fixtures for dotted namespace syntax covering empty namespaces, namespaces with exports, and deeply nested structures |
crates/oxc_isolated_declarations/tests/snapshots/nested-namespace-dotted.snap |
Added snapshot expectations showing correct namespace name preservation in isolated declaration output |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merge activity
|
…ated declarations (#15800) Dotted namespace syntax `export namespace X.Y.Z {}` was incorrectly transformed to `export declare namespace Y.Z.Z {}` instead of `export declare namespace X.Y.Z {}`. **Root cause:** Variable shadowing in `transform_ts_module_declaration`. When processing nested `TSModuleDeclaration` bodies, the pattern match variable `decl` shadowed the function parameter, causing the inner namespace name to be used instead of the outer one. **Changes:** - Renamed pattern match variable from `decl` to `inner_decl` to preserve access to outer declaration's identifier - Added test coverage for dotted namespace syntax with varying nesting depths **Example:** ```ts // Input export namespace X.Y.Z {} // Before: Y.Z.Z (incorrect) // After: X.Y.Z (correct) export declare namespace X.Y.Z { export {}; } ``` <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Isolated declarations: Incorrect output for nested `namespace`</issue_title> > <issue_description>Input: > > ```ts > // _____ > export namespace X.Y.Z {} > ``` > > Isolated declarations output: > > ```ts > // _____ > export declare namespace Y.Z.Z { > export {}; > } > ``` > > [Playground](https://playground.oxc.rs/#eNptU01v2zAM/SuBzlnRFRhQ5Da0CzCgW7J1WLdhF1pmXKWy6FF00sLIfx/lWEoK9GT5Ufx4j0+DsWZh8LkjllmAFmMHFme/Ln5f/JkNh7/BzA2ZxWC4D+njXRCz2ICPODcb4hZEkAsiDCEmuCAukgfB+hatBwZxFKJZCPca2z86OTYs11sIjT/9Wmo7xqgZExAtdRo+5seXtiKf/+ymma4d5qYDjmmuQbkJhqhtladEpQPe0/47Ss9h1Ut0NS77YNNguVJqibzDNbCmZnTM+3n9OQg7LWhLIKJOLc5+YiaeUB0hSTWOoOczpQbTR/wB1YmTQPXgank0i6u5wVCvNncuKEnjNzpup91kil9fajeXFPrWk5xk2sbn+zfgf+lvzdRpLwPxXUCssdaauian4zU31LaQYt4rqjxcIatc9pm/xvfwkrSrGOwTyr3uTNPz5YyqfY6TT/2p2qKVB4ZOa2RRU6Nx1o+iQla9Toj8Kk3diOxaDAJ+pUcQ4jVFd1xRUsiopMVqR1EFuEG1psF4dfn+g3ZRmW9xo4WXxDceYlw69HXZ2nkXNSeNbU7R1klBv6BADaJKTat929SDicqoU4MgB1BfZjNaqrHB8f2EZIRi2W2sSd/fJHkIJGOtjHhs8t2xSn4LyVH5oShz6u5wh6XoE2L3Nb3k8wHUtOSXauCUsUOuKGbBE5+QFpVC5XRQuB7lS3A5HRKeZM6cDv8BbLGFnw==) > > Maybe this code is the cause? > > https://github.com/oxc-project/oxc/blob/4608549fc7715ee76c4a6d7a78069ff339f52267/crates/oxc_isolated_declarations/src/lib.rs#L521-L523 > > Looks fishy! Shouldn't it walk down to find the nested `TSModuleBlock` when `decl.body` is a `TSModuleDeclarationBody::TSModuleDeclaration`?</issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> - Fixes #15729 <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.
51bc6c3 to
7d1ebad
Compare
### 💥 BREAKING CHANGES - cbb27fd ast: [**BREAKING**] Add `TSGlobalDeclaration` type (#15712) (overlookmotel) ### 🚀 Features - 0c1f82b linter/plugins: Add `tokens` property to `Program` (#16020) (overlookmotel) - 6cff132 span: Add `Span::merge_within` method (#15869) (sapphi-red) - 102365d allocator/vec: Add `Vec::into_bump_slice` method (#15770) (Dunqing) ### 🐛 Bug Fixes - e2ca770 codegen: Add support for printing type arguments in new expressions (#15963) (Ives van Hoorne) - 2bd3cb6 apps, editors, napi: Fix `oxlint-disable` comments (#16014) (overlookmotel) - 622cb5e parser: Preserve legal comments with @preserve/@license when preceded by other annotations (#15929) (copilot-swe-agent) - 7c46a9e transformer/tagged-template-transform: Handle `\n` escape sequences (#15830) (Dunqing) - f386efc minifier: Avoid generating invalid spans (#15778) (sapphi-red) - d4ff004 parser: Forbid invalid modifiers on `module` and `global` (#15723) (overlookmotel) - 2191ae9 semantic: Allow reserved keywords in typescript ambient contexts (#15495) (sapphi-red) - 7d1ebad isolated-declarations: Incorrect nested namespace output in isolated declarations (#15800) (copilot-swe-agent) ### ⚡ Performance - b4b0ed8 transformer/typescript: Reverse order of checks (#15722) (overlookmotel) ### 📚 Documentation - c81a331 data_structures: Doc comments on fields of `Stack` (#15793) (overlookmotel) - cfae31d allocator: Use `allocator` as var name in examples (#15781) (overlookmotel) Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
…ated declarations (oxc-project#15800) Dotted namespace syntax `export namespace X.Y.Z {}` was incorrectly transformed to `export declare namespace Y.Z.Z {}` instead of `export declare namespace X.Y.Z {}`. **Root cause:** Variable shadowing in `transform_ts_module_declaration`. When processing nested `TSModuleDeclaration` bodies, the pattern match variable `decl` shadowed the function parameter, causing the inner namespace name to be used instead of the outer one. **Changes:** - Renamed pattern match variable from `decl` to `inner_decl` to preserve access to outer declaration's identifier - Added test coverage for dotted namespace syntax with varying nesting depths **Example:** ```ts // Input export namespace X.Y.Z {} // Before: Y.Z.Z (incorrect) // After: X.Y.Z (correct) export declare namespace X.Y.Z { export {}; } ``` <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Isolated declarations: Incorrect output for nested `namespace`</issue_title> > <issue_description>Input: > > ```ts > // _____ > export namespace X.Y.Z {} > ``` > > Isolated declarations output: > > ```ts > // _____ > export declare namespace Y.Z.Z { > export {}; > } > ``` > > [Playground](https://playground.oxc.rs/#eNptU01v2zAM/SuBzlnRFRhQ5Da0CzCgW7J1WLdhF1pmXKWy6FF00sLIfx/lWEoK9GT5Ufx4j0+DsWZh8LkjllmAFmMHFme/Ln5f/JkNh7/BzA2ZxWC4D+njXRCz2ICPODcb4hZEkAsiDCEmuCAukgfB+hatBwZxFKJZCPca2z86OTYs11sIjT/9Wmo7xqgZExAtdRo+5seXtiKf/+ymma4d5qYDjmmuQbkJhqhtladEpQPe0/47Ss9h1Ut0NS77YNNguVJqibzDNbCmZnTM+3n9OQg7LWhLIKJOLc5+YiaeUB0hSTWOoOczpQbTR/wB1YmTQPXgank0i6u5wVCvNncuKEnjNzpup91kil9fajeXFPrWk5xk2sbn+zfgf+lvzdRpLwPxXUCssdaauian4zU31LaQYt4rqjxcIatc9pm/xvfwkrSrGOwTyr3uTNPz5YyqfY6TT/2p2qKVB4ZOa2RRU6Nx1o+iQla9Toj8Kk3diOxaDAJ+pUcQ4jVFd1xRUsiopMVqR1EFuEG1psF4dfn+g3ZRmW9xo4WXxDceYlw69HXZ2nkXNSeNbU7R1klBv6BADaJKTat929SDicqoU4MgB1BfZjNaqrHB8f2EZIRi2W2sSd/fJHkIJGOtjHhs8t2xSn4LyVH5oShz6u5wh6XoE2L3Nb3k8wHUtOSXauCUsUOuKGbBE5+QFpVC5XRQuB7lS3A5HRKeZM6cDv8BbLGFnw==) > > Maybe this code is the cause? > > https://github.com/oxc-project/oxc/blob/4608549fc7715ee76c4a6d7a78069ff339f52267/crates/oxc_isolated_declarations/src/lib.rs#L521-L523 > > Looks fishy! Shouldn't it walk down to find the nested `TSModuleBlock` when `decl.body` is a `TSModuleDeclarationBody::TSModuleDeclaration`?</issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> - Fixes oxc-project#15729 <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.
### 💥 BREAKING CHANGES - cbb27fd ast: [**BREAKING**] Add `TSGlobalDeclaration` type (oxc-project#15712) (overlookmotel) ### 🚀 Features - 0c1f82b linter/plugins: Add `tokens` property to `Program` (oxc-project#16020) (overlookmotel) - 6cff132 span: Add `Span::merge_within` method (oxc-project#15869) (sapphi-red) - 102365d allocator/vec: Add `Vec::into_bump_slice` method (oxc-project#15770) (Dunqing) ### 🐛 Bug Fixes - e2ca770 codegen: Add support for printing type arguments in new expressions (oxc-project#15963) (Ives van Hoorne) - 2bd3cb6 apps, editors, napi: Fix `oxlint-disable` comments (oxc-project#16014) (overlookmotel) - 622cb5e parser: Preserve legal comments with @preserve/@license when preceded by other annotations (oxc-project#15929) (copilot-swe-agent) - 7c46a9e transformer/tagged-template-transform: Handle `\n` escape sequences (oxc-project#15830) (Dunqing) - f386efc minifier: Avoid generating invalid spans (oxc-project#15778) (sapphi-red) - d4ff004 parser: Forbid invalid modifiers on `module` and `global` (oxc-project#15723) (overlookmotel) - 2191ae9 semantic: Allow reserved keywords in typescript ambient contexts (oxc-project#15495) (sapphi-red) - 7d1ebad isolated-declarations: Incorrect nested namespace output in isolated declarations (oxc-project#15800) (copilot-swe-agent) ### ⚡ Performance - b4b0ed8 transformer/typescript: Reverse order of checks (oxc-project#15722) (overlookmotel) ### 📚 Documentation - c81a331 data_structures: Doc comments on fields of `Stack` (oxc-project#15793) (overlookmotel) - cfae31d allocator: Use `allocator` as var name in examples (oxc-project#15781) (overlookmotel) Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Dotted namespace syntax
export namespace X.Y.Z {}was incorrectly transformed toexport declare namespace Y.Z.Z {}instead ofexport declare namespace X.Y.Z {}.Root cause: Variable shadowing in
transform_ts_module_declaration. When processing nestedTSModuleDeclarationbodies, the pattern match variabledeclshadowed the function parameter, causing the inner namespace name to be used instead of the outer one.Changes:
decltoinner_declto preserve access to outer declaration's identifierExample:
Original prompt
namespace#15729💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.