Skip to content

handle star imports for alias#5743

Merged
adhami3310 merged 1 commit into
mainfrom
handle-star-imports-for-alias
Aug 29, 2025
Merged

handle star imports for alias#5743
adhami3310 merged 1 commit into
mainfrom
handle-star-imports-for-alias

Conversation

@adhami3310

Copy link
Copy Markdown
Member

fixes #5740

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Edit Code Review Bot Settings | Greptile

@codspeed-hq

codspeed-hq Bot commented Aug 27, 2025

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #5743 will not alter performance

Comparing handle-star-imports-for-alias (d6a5189) with main (817b8b4)

Summary

✅ 8 untouched benchmarks

@masenf masenf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

cool feature

@adhami3310 adhami3310 merged commit 155dbeb into main Aug 29, 2025
40 of 41 checks passed
@adhami3310 adhami3310 deleted the handle-star-imports-for-alias branch August 29, 2025 00:12
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.

Allow for import '*' as ALIAS from DEP as a special case

2 participants