handle star imports for alias#5743
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR fixes how the ImportVar class handles star imports with aliases (e.g., import * as React from "react"). The core issue was in the ImportVar.name property where star imports with aliases were being incorrectly rendered.
The problem occurred because star imports are treated as "default" imports (is_default=True) in the codebase, but the existing logic would return only the alias name when is_default=True, generating invalid JavaScript like import React from "react" instead of the correct import * as React from "react".
The fix adds a special condition in the name property to check if self.tag != "*" before applying the default import logic. This ensures that star imports always fall through to the full tag as alias formatting, even when marked as default imports. This change maintains the semantic meaning of importing all exports under an alias namespace.
The PR also includes a comprehensive test case that verifies the fix works correctly, ensuring that ImportVar(tag="*", alias="AliasTag") properly returns "* as AliasTag" as expected. Type annotations were also added to the test function for better code quality.
Confidence score: 5/5
- This PR is safe to merge with minimal risk as it addresses a specific bug with a targeted fix
- Score reflects a well-tested, minimal change that fixes incorrect import generation without affecting other functionality
- No files require special attention as the change is straightforward and well-covered by tests
2 files reviewed, no comments
CodSpeed Performance ReportMerging #5743 will not alter performanceComparing Summary
|
fixes #5740