Skip to content

Conversation

@arendjr
Copy link
Contributor

@arendjr arendjr commented Jun 13, 2025

Summary

This addresses a major omission we had so far when it came to supporting import syntax: We didn't support resolving symbols from import * as namespace syntax yet. Now we do :)

The approach works as follows:

  • We added a new special type: TypeData::ImportNamespace(ModuleId). An instance of this type gets registered for every module that is imported in the module resolver, so that we have something to point to in case we discover ImportSymbol::All (the variant used to represent import * as namespace syntax) cases down the line.
  • Whenever we run into an import qualifier of type that resolves to ImportSymbol::All, we resolve it to ResolvedTypeId::new(TypeResolverLevel::Import, module_id). TypeResolverLevel::Import was still unused inside the module resolver, so we could repurpose it for this.
  • Whenever a resolved type ID of level TypeResolverLevel::Import needs to be retrieved, we can return the preregistered TypeData::ImportNamespace(ModuleId).
  • During flattening, we can flatten static member expressions on objects of kind TypeData::ImportNamespace(module_id) into a lookup for the member in the right module. This is what makes it so that namespace.foo gets resolved to the correct symbol foo in the module aliased as namespace.

Test Plan

Test added. Snapshots updated.

@arendjr arendjr requested review from a team June 13, 2025 11:55
@github-actions github-actions bot added A-Project Area: project L-JavaScript Language: JavaScript and super languages labels Jun 13, 2025
@arendjr arendjr moved this to In review in Type Inference Jun 13, 2025
@arendjr arendjr merged commit ff0de8e into biomejs:next Jun 13, 2025
10 checks passed
@github-project-automation github-project-automation bot moved this from In review to Done in Type Inference Jun 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Project Area: project L-JavaScript Language: JavaScript and super languages

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants