fix(js_semantic): import namespace handling #2812
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
Fix #2796
This PR improves the handling of import namespace in the JavaScript/TypeScript semantic model.
We now handle import namespace as TypeScript namespace: we consider them as values (variables) and allow their reference in an ambient context only inside a qualified name.
Some examples:
Unfortunately it is not enough because import namespace can be imported as a
type
.In this specific case, we consider them as types.
However, it is always invalid of referencing a namespace in an unqualified name.
I added an exception in the name resolution where we report the reference as unresolved if it is not a qualified name and if it is referencing an import namespace.
This allows handling this case:
I also fixed an issue where exporting as a type a TypeScript namespace was not correctly resolved.
Test Plan
I added non-regression tests.
Mote: the new tests for
useImportType
anduseExportType
are not non-regression tests. More tests is always good no :)