Skip to content

Comments

fix(isolated-declarations): incorrect nested namespace output in isolated declarations#15800

Merged
graphite-app[bot] merged 1 commit intomainfrom
copilot/fix-namespace-declaration-output
Nov 18, 2025
Merged

fix(isolated-declarations): incorrect nested namespace output in isolated declarations#15800
graphite-app[bot] merged 1 commit intomainfrom
copilot/fix-namespace-declaration-output

Conversation

Copy link
Contributor

Copilot AI commented Nov 17, 2025

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:

// Input
export namespace X.Y.Z {}

// Before: Y.Z.Z (incorrect)
// After: X.Y.Z (correct)
export declare namespace X.Y.Z {
  export {};
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Isolated declarations: Incorrect output for nested namespace</issue_title>
<issue_description>Input:

//               _____
export namespace X.Y.Z {}

Isolated declarations output:

//                       _____
export declare namespace Y.Z.Z {
  export {};
}

Playground

Maybe this code is the cause?

let Some(TSModuleDeclarationBody::TSModuleBlock(block)) = &decl.body else {
continue;
};

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)


💡 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.

@graphite-app
Copy link
Contributor

graphite-app bot commented Nov 17, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

Copilot AI changed the title [WIP] Fix incorrect output for nested namespace declarations Fix nested namespace output in isolated declarations Nov 17, 2025
Copilot AI requested a review from Dunqing November 17, 2025 17:16
@github-actions github-actions bot added the A-isolated-declarations Isolated Declarations label Nov 18, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 18, 2025

CodSpeed Performance Report

Merging #15800 will not alter performance

Comparing copilot/fix-namespace-declaration-output (51bc6c3) with main (e615162)1

Summary

✅ 38 untouched
⏩ 7 skipped2

Footnotes

  1. No successful run was found on main (7f74c8a) during the generation of this report, so e615162 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Dunqing Dunqing force-pushed the copilot/fix-namespace-declaration-output branch from 68e00dd to 5cf7227 Compare November 18, 2025 01:40
@Dunqing Dunqing changed the title Fix nested namespace output in isolated declarations fix(isolated-declaration): incorrect nested namespace output in isolated declarations Nov 18, 2025
@Dunqing Dunqing changed the title fix(isolated-declaration): incorrect nested namespace output in isolated declarations fix(isolated-declarations): incorrect nested namespace output in isolated declarations Nov 18, 2025
@Dunqing Dunqing marked this pull request as ready for review November 18, 2025 03:31
Copilot AI review requested due to automatic review settings November 18, 2025 03:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 decl to inner_decl in transform_ts_module_declaration to 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.

@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Nov 18, 2025
Copy link
Member

Dunqing commented Nov 18, 2025

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.
@graphite-app graphite-app bot force-pushed the copilot/fix-namespace-declaration-output branch from 51bc6c3 to 7d1ebad Compare November 18, 2025 03:39
@graphite-app graphite-app bot merged commit 7d1ebad into main Nov 18, 2025
20 checks passed
@graphite-app graphite-app bot deleted the copilot/fix-namespace-declaration-output branch November 18, 2025 03:44
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Nov 18, 2025
overlookmotel pushed a commit that referenced this pull request Nov 24, 2025
### 💥 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>
taearls pushed a commit to taearls/oxc that referenced this pull request Dec 11, 2025
…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.
taearls pushed a commit to taearls/oxc that referenced this pull request Dec 11, 2025
### 💥 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-isolated-declarations Isolated Declarations C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Isolated declarations: Incorrect output for nested namespace

2 participants