Commit 7d1ebad
committed
fix(isolated-declarations): incorrect nested namespace output in isolated 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.1 parent 82471c8 commit 7d1ebad
File tree
3 files changed
+39
-2
lines changed- crates/oxc_isolated_declarations
- src
- tests
- fixtures
- snapshots
3 files changed
+39
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
133 | | - | |
| 132 | + | |
| 133 | + | |
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| |||
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
0 commit comments