Skip to content

Comments

feat: show import declaration span in CannotCallNamespace error#8223

Merged
graphite-app[bot] merged 1 commit intomainfrom
copilot/show-import-namespace-declaration
Feb 7, 2026
Merged

feat: show import declaration span in CannotCallNamespace error#8223
graphite-app[bot] merged 1 commit intomainfrom
copilot/show-import-namespace-declaration

Conversation

Copy link
Contributor

Copilot AI commented Feb 6, 2026

✅ Completed: Show import namespace declaration span for CannotCallNamespace error

Summary

Successfully implemented the feature to show the import namespace declaration span in the CannotCallNamespace error message. The error now displays both:

  1. The location where the namespace is incorrectly called
  2. The location where it was imported/declared

Changes Made

  • Modified CannotCallNamespace struct to include declaration_span field
  • Updated the constructor in constructors.rs to accept the import declaration span parameter
  • Modified import_analyzer.rs to retrieve the import declaration span from NamedImport and pass it to the error constructor
  • Updated the on_diagnostic method to display both spans with appropriate labels
  • Fixed the declaration span to point only to the identifier (e.g., ns) instead of the entire specifier (e.g., * as ns)
  • Verified the fix works with existing tests (2 test snapshots automatically updated)
  • Format Rust code and pass all linting checks
  • All Rust tests passing (729/729 rolldown tests, 47/47 rollup tests)

Example Output

Before: Only showed where the error occurred

After: Shows both locations with precise span:

[CANNOT_CALL_NAMESPACE] Warning: Cannot call a namespace ("ns").
   ╭─[ test-namespace-error.js:4:1 ]
   │
 1 │ import * as ns from './module.js'
   │             ─┬  
   │              ╰── "ns" is imported as a namespace here
   │ 
 4 │ ns()
   │ ──┬─  
   │   ╰─── This will cause an error at runtime because "ns" is a module namespace object and not a function. Consider changing "ns" to a default import instead.
───╯

Files Changed

  • crates/rolldown/src/ast_scanner/mod.rs - Use spec.local.span() instead of spec.span to point to just the identifier
  • crates/rolldown_error/src/build_diagnostic/events/cannot_call_namespace.rs - Added declaration_span field and second label
  • crates/rolldown_error/src/build_diagnostic/constructors.rs - Updated constructor signature
  • crates/rolldown/src/ast_scanner/import_analyzer.rs - Extract and pass declaration span
  • crates/rolldown/tests/rolldown/warnings/cannot_call_namespace/artifacts.snap - Updated snapshot
  • crates/rolldown/tests/esbuild/default/call_import_namespace_warning/artifacts.snap - Updated snapshot
Original prompt

Show the import namespace declaration span for CannotCallNamespace error message


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@netlify
Copy link

netlify bot commented Feb 6, 2026

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit a3f2b53
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/69870e4649dbe10008aefed6

Copilot AI changed the title [WIP] Show import namespace declaration span for CannotCallNamespace error Show import declaration span in CannotCallNamespace error Feb 6, 2026
Copilot AI requested a review from sapphi-red February 6, 2026 13:21
@sapphi-red sapphi-red changed the title Show import declaration span in CannotCallNamespace error feat: show import declaration span in CannotCallNamespace error Feb 7, 2026
@sapphi-red sapphi-red marked this pull request as ready for review February 7, 2026 09:47
Copilot AI review requested due to automatic review settings February 7, 2026 09:47
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

Adds richer diagnostics for CannotCallNamespace warnings by showing both the call-site span and the original namespace import declaration span, improving debuggability when users accidentally call a namespace import.

Changes:

  • Extend CannotCallNamespace to carry an additional declaration_span and render it as a second diagnostic label.
  • Plumb the namespace import identifier span from AST scanning (spec.local.span()) through import analysis into the diagnostic constructor.
  • Update warning snapshots to reflect the new two-location output.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/rolldown_error/src/build_diagnostic/events/cannot_call_namespace.rs Adds declaration_span and emits a second label pointing at the namespace import declaration.
crates/rolldown_error/src/build_diagnostic/constructors.rs Updates cannot_call_namespace constructor signature to accept declaration_span.
crates/rolldown/src/ast_scanner/mod.rs Ensures namespace import span points to the local identifier (ns) instead of the whole * as ns specifier.
crates/rolldown/src/ast_scanner/import_analyzer.rs Extracts the stored import span for namespace imports and passes it into the diagnostic.
crates/rolldown/tests/rolldown/warnings/cannot_call_namespace/artifacts.snap Updates snapshots to include the new import-declaration label.
crates/rolldown/tests/esbuild/default/call_import_namespace_warning/artifacts.snap Updates snapshots to include the new import-declaration label.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2026

Benchmarks Rust

  • target: main(37b648d)
  • pr: copilot/show-import-namespace-declaration(8770001)
group                                                        pr                                     target
-----                                                        --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol              1.02     60.6±1.68ms        ? ?/sec    1.00     59.3±0.98ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap    1.01     65.8±1.25ms        ? ?/sec    1.00     64.9±1.04ms        ? ?/sec
bundle/bundle@rome_ts                                        1.00     91.1±1.72ms        ? ?/sec    1.00     90.7±1.27ms        ? ?/sec
bundle/bundle@rome_ts-sourcemap                              1.00    103.2±1.12ms        ? ?/sec    1.00    103.4±1.61ms        ? ?/sec
bundle/bundle@threejs                                        1.00     33.1±2.06ms        ? ?/sec    1.00     33.1±2.15ms        ? ?/sec
bundle/bundle@threejs-sourcemap                              1.00     37.5±0.55ms        ? ?/sec    1.00     37.5±0.52ms        ? ?/sec
bundle/bundle@threejs10x                                     1.00    336.5±2.66ms        ? ?/sec    1.00    335.0±2.41ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                           1.00    397.0±2.04ms        ? ?/sec    1.00    397.2±2.86ms        ? ?/sec
scan/scan@rome_ts                                            1.00     71.8±1.21ms        ? ?/sec    1.00     71.9±1.01ms        ? ?/sec
scan/scan@threejs                                            1.02     25.7±1.73ms        ? ?/sec    1.00     25.1±0.31ms        ? ?/sec
scan/scan@threejs10x                                         1.00    260.8±2.85ms        ? ?/sec    1.00    259.9±2.56ms        ? ?/sec

Copy link
Member

sapphi-red commented Feb 7, 2026

Merge activity

  • Feb 7, 10:04 AM UTC: The merge label 'graphite: merge-when-ready' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Feb 7, 10:04 AM UTC: sapphi-red added this pull request to the Graphite merge queue.
  • Feb 7, 10:13 AM UTC: Merged by the Graphite merge queue.

## ✅ Completed: Show import namespace declaration span for CannotCallNamespace error

### Summary
Successfully implemented the feature to show the import namespace declaration span in the CannotCallNamespace error message. The error now displays both:
1. The location where the namespace is incorrectly called
2. The location where it was imported/declared

### Changes Made
- [x] Modified `CannotCallNamespace` struct to include `declaration_span` field
- [x] Updated the constructor in `constructors.rs` to accept the import declaration span parameter
- [x] Modified `import_analyzer.rs` to retrieve the import declaration span from `NamedImport` and pass it to the error constructor
- [x] Updated the `on_diagnostic` method to display both spans with appropriate labels
- [x] Fixed the declaration span to point only to the identifier (e.g., `ns`) instead of the entire specifier (e.g., `* as ns`)
- [x] Verified the fix works with existing tests (2 test snapshots automatically updated)
- [x] Format Rust code and pass all linting checks
- [x] All Rust tests passing (729/729 rolldown tests, 47/47 rollup tests)

### Example Output
**Before:** Only showed where the error occurred

**After:** Shows both locations with precise span:
```
[CANNOT_CALL_NAMESPACE] Warning: Cannot call a namespace ("ns").
   ╭─[ test-namespace-error.js:4:1 ]
   │
 1 │ import * as ns from './module.js'
   │             ─┬
   │              ╰── "ns" is imported as a namespace here
   │
 4 │ ns()
   │ ──┬─
   │   ╰─── This will cause an error at runtime because "ns" is a module namespace object and not a function. Consider changing "ns" to a default import instead.
───╯
```

### Files Changed
- `crates/rolldown/src/ast_scanner/mod.rs` - Use `spec.local.span()` instead of `spec.span` to point to just the identifier
- `crates/rolldown_error/src/build_diagnostic/events/cannot_call_namespace.rs` - Added declaration_span field and second label
- `crates/rolldown_error/src/build_diagnostic/constructors.rs` - Updated constructor signature
- `crates/rolldown/src/ast_scanner/import_analyzer.rs` - Extract and pass declaration span
- `crates/rolldown/tests/rolldown/warnings/cannot_call_namespace/artifacts.snap` - Updated snapshot
- `crates/rolldown/tests/esbuild/default/call_import_namespace_warning/artifacts.snap` - Updated snapshot

<!-- START COPILOT CODING AGENT SUFFIX -->

<!-- START COPILOT ORIGINAL PROMPT -->

<details>

<summary>Original prompt</summary>

> Show the import namespace declaration span for CannotCallNamespace error message

</details>

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).
@graphite-app graphite-app bot force-pushed the copilot/show-import-namespace-declaration branch from 8770001 to a3f2b53 Compare February 7, 2026 10:04
@graphite-app graphite-app bot merged commit a3f2b53 into main Feb 7, 2026
34 checks passed
@graphite-app graphite-app bot deleted the copilot/show-import-namespace-declaration branch February 7, 2026 10:13
This was referenced Feb 11, 2026
shulaoda added a commit that referenced this pull request Feb 11, 2026
## [1.0.0-rc.4] - 2026-02-11

💡 Granular `comments` Option
- New `output.comments` option provides fine-grained control over comment preservation
- The `output.legalComments` option is now deprecated and use `comments.legal` instead

### 🚀 Features

- rename error name to `RolldownError` from `RollupError` (#8262) by @sapphi-red
- add hidden `resolve_tsconfig` function for Vite (#8257) by @sapphi-red
- rust: introduce `rolldown_watcher` (#8161) by @hyf0
- unify `comments` and `legalComments` into a single granular `comments` option (#8229) by @IWANABETHATGUY
- add builtin plugin for visualizing chunk graph (#8162) by @IWANABETHATGUY
- show import declaration location in AssignToImport errors (#8222) by @Copilot
- show import declaration span in CannotCallNamespace error (#8223) by @Copilot
- emit error when plugin accidentally removes runtime module symbols (#8203) by @IWANABETHATGUY
- support tsconfig loading & inputMap for `transform` (#8180) by @sapphi-red
- rolldown_plugin_vite_reporter: update warning message to link to Rolldown docs (#8205) by @sapphi-red

### 🐛 Bug Fixes

- avoid panic on untranspiled JSX syntax by reporting a diagnostic error (#8226) by @IWANABETHATGUY
- rolldown_plugin_vite_import_glob: relax absolute path check and improve invalid glob warning (#8219) by @shulaoda
- merge chunks after detect circular reference (#8154) by @IWANABETHATGUY
- rust: detect runtime module side effects based on its content (#8209) by @hyf0

### 🚜 Refactor

- rename `other` to `jsdoc` in comments options (#8256) by @IWANABETHATGUY
- rename chunk-visualize plugin with bundle-analyzer plugin (#8255) by @IWANABETHATGUY
- remove EXPORT_UNDEFINED_VARIABLE error (#8228) by @Copilot
- consolidate missing runtime symbol errors into a single diagnostic (#8220) by @IWANABETHATGUY
- stabilize `parse` and `parseSync` (#8215) by @sapphi-red
- return errors instead of panicking on builtin plugin conversion failure (#8217) by @shulaoda
- expose `parse` / `minify` / `transform` from `rolldown/utils` (#8214) by @sapphi-red
- prepare defer chunk merging (#8153) by @IWANABETHATGUY

### 📚 Documentation

- remove `<script>` escape behavior difference note from `platform` option (#8253) by @sapphi-red
- TypeScript & JSX support by plugins (#8183) by @sapphi-red

### 🧪 Testing

- ensure runtime module is preserved even if it's not used but has side effects (#8213) by @hyf0

### ⚙️ Miscellaneous Tasks

- deps: update oxc to v0.113.0 (#8267) by @renovate[bot]
- deps: update dependency oxlint-tsgolint to v0.12.0 (#8272) by @renovate[bot]
- deps: update oxc apps (#8269) by @renovate[bot]
- deps: update test262 submodule for tests (#8261) by @sapphi-red
- deps: update crate-ci/typos action to v1.43.4 (#8260) by @renovate[bot]
- deps: update dependency esbuild to v0.27.3 (#8250) by @renovate[bot]
- deps: update rust crates (#8244) by @renovate[bot]
- deps: update dependency semver to v7.7.4 (#8247) by @renovate[bot]
- deps: update github-actions (#8243) by @renovate[bot]
- deps: update npm packages (#8245) by @renovate[bot]
- deps: update oxc resolver to v11.17.1 (#8240) by @renovate[bot]
- deps: update rust crate oxc_sourcemap to v6.0.2 (#8241) by @renovate[bot]
- rust: handle ignored `RUSTSEC-2025-0141` cargo check error (#8235) by @hyf0
- deps: update dependency oxlint-tsgolint to v0.11.5 (#8233) by @renovate[bot]
- deps: update dependency rolldown-plugin-dts to ^0.22.0 (#8232) by @renovate[bot]
- deps: update crate-ci/typos action to v1.43.3 (#8225) by @renovate[bot]
- deps: update dependency rolldown-plugin-dts to v0.21.9 (#8224) by @renovate[bot]
- deps: update crate-ci/typos action to v1.43.2 (#8212) by @renovate[bot]
- remove rolldown_plugin_vite_wasm_helper (#8207) by @shulaoda
- build docs for production (#8206) by @sapphi-red

Co-authored-by: shulaoda <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants