feat(core): support import namespaces #6303
Merged
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
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:
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 discoverImportSymbol::All
(the variant used to representimport * as namespace
syntax) cases down the line.ImportSymbol::All
, we resolve it toResolvedTypeId::new(TypeResolverLevel::Import, module_id)
.TypeResolverLevel::Import
was still unused inside the module resolver, so we could repurpose it for this.TypeResolverLevel::Import
needs to be retrieved, we can return the preregisteredTypeData::ImportNamespace(ModuleId)
.TypeData::ImportNamespace(module_id)
into a lookup for the member in the right module. This is what makes it so thatnamespace.foo
gets resolved to the correct symbolfoo
in the module aliased asnamespace
.Test Plan
Test added. Snapshots updated.