fix: namespaced wildcard exports should not be flagged as duplicate identifiers#3243
Draft
whatfontisthis wants to merge 1 commit intoimport-js:mainfrom
Draft
Conversation
…espace When a module uses `export * as NS from '...'`, the re-exported module's internal names are namespaced under NS (e.g. NS.A), NOT re-exported into the flat namespace. Previously, `captureDependency` was adding such modules to `exportMap.dependencies`, which are iterated as flat star-exports. This caused the `export` rule to incorrectly report duplicate identifiers when a parent module did `export * from` a file containing `export * as NS`. Fix: in `ExportAllDeclaration` visitor, only add the getter to `dependencies` when there is no `exported` alias. When `astNode.exported` is present, the binding is a namespace alias handled by `processSpecifier`, not a flat re-export. Fixes import-js#3220 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3220.
When a module uses
export * as NS from '...', its internal names are bound under theNSnamespace (i.e.NS.A,NS.B), not re-exported into the flat namespace of the current module. However, theExportMapbuilder was unconditionally adding the dependency toexportMap.dependencieseven for namespaced wildcard re-exports. Sincedependenciesis iterated as flat star-exports inExportMap.forEach, this caused theexportrule to see the internal names (e.g.A,B) as if they were directly re-exported — leading to false-positive "duplicate identifier" errors.Example that was incorrectly reported as an error:
Root Cause
In
/src/exportMap/visitor.js,ExportAllDeclarationalways added the getter tothis.exportMap.dependencies. Forexport * as NS from '...', this is wrong — the module is aliased as a namespace, not star-re-exported. The namespace binding is correctly handled separately byprocessSpecifier.Fix
Only add to
dependencieswhen there is noexportedalias on theExportAllDeclarationnode. WhenastNode.exportedis set, it's a namespace re-export handled byprocessSpecifierand should not be added to flat star-export dependencies.Test Plan
tests/files/issue-3220-namespace-re-export/{AB.ts,ABFeature.ts,foo.ts}tests/src/rules/export.jsthat re-exports a file containingexport type * as AB from "./AB"alongside another file exportingtype A— previously this triggered a false positive, now it passes cleanly🤖 Generated with Claude Code