Repository navigation
Conversation
The fix turned `ns.default`, `ns.enum` and `ns['my-key']` into
`{ default }`, `{ enum }` and `{ my-key }`, which do not parse.
Reserved words and restricted names now get a local alias
(`{ default as ns_default }`), and a key that is not an identifier
leaves the import without a fix.
Fixes import-js#3315
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hq1ACTsK85bRrY28fUQ7b3
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3317 +/- ##
=======================================
Coverage 79.59% 79.60%
=======================================
Files 98 98
Lines 4549 4556 +7
Branches 1543 1578 +35
=======================================
+ Hits 3621 3627 +6
- Misses 928 929 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Fixes #3315.
The autofix turned every
ns.propandns['prop']into a named import with the same name, sons.default,ns.enum(as inz.enumfrom zod) andns['my-key']became{ default },{ enum }and{ my-key }, which fail to parse.What changes:
default, reserved words and strict-mode restricted names (eval,arguments) can be imported but not bound, so they now always get a local alias with the existing naming scheme:import { default as ns_default, enum as ns_enum } from './foo'. The usual conflict handling still applies (ns_default_1ifns_defaultis taken).ns['my-key']) has no named import equivalent without arbitrary module namespace names, so the rule still reports the namespace import but offers no fix, the same as when the namespace is used as an object.Tests: three new cases in
tests/src/rules/no-namespace.js(reserved names with aliases, a conflict on the alias, a non-identifier key with no fix). They fail without the change; the fixed output for the reserved-name case parses with espree atecmaVersion: 2015. I also added the CHANGELOG entry.I used Claude to help write and test this change.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Hq1ACTsK85bRrY28fUQ7b3