- Notifications
You must be signed in to change notification settings - Fork13.2k
Update type-only import semantics to allow type queries#36092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
Show all changes
27 commits Select commitHold shift + click to select a range
b40284c Change type-only semantics to allow type queries
andrewbranch2ae9edc Don’t error using type-only import in ambient context
andrewbranchdb93eb2 Fix default import
andrewbrancha2548c8 Fix namespace import
andrewbranch8d3f167 Update more baselines
andrewbranchb56ad7d Prevent circular resolution
andrewbranch0547a3d Track const enum expression usage
andrewbranch124dcd6 Update baselines
andrewbranch2dd3690 Perf tuning 1
andrewbrancheefa335 Test commit for perf impact
andrewbranch9a24cba Weave type-only alias declaration finding into alias resolution
andrewbranch875349d Fix namespace import of type-only exported symbols
andrewbranch171e314 type-only exports do not contribute to the module object type
andrewbranch910dd84 Update APIs
andrewbranch2a7c472 Fix enum casing, remove type-only conversion suggestion
andrewbranch11ba11a Short circuit type-only checks in resolveEntityName faster
andrewbranch0c28994 Fix casing in API
andrewbranch40a2c3c Remove unused parameter
andrewbranch1cbfb81 Merge branch 'master' into type-only-2
andrewbranch124d746 Fix error on qualified names in type queries
andrewbranchbbbcbd5 Merge branch 'master' into type-only-2
andrewbranch1044c5c Allow type-only imports in computed property names
andrewbrancha5ca492 Fix computed property names of types and abstract members
andrewbranch8571a8a Remove unused util
andrewbranch8b4c235 Commit missing baselines
andrewbranchbe5f50f Merge branch master into type-only-2
andrewbranch19b3206 Rename “check” functions so as not to overload the word “check”
andrewbranchFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Track const enum expression usage
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit0547a3dc2dfdcbd3d52ac37827d5e1a1f802bce2
There are no files selected for viewing
43 changes: 26 additions & 17 deletionssrc/compiler/checker.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2532,6 +2532,15 @@ namespace ts { | ||
| } | ||
| } | ||
| // Aliases that resolve to const enums are not marked as referenced because they are not emitted, | ||
| // but their usage in value positions must be tracked to determine if the import can be type-only. | ||
| function markConstEnumAliasAsReferenced(symbol: Symbol) { | ||
| const links = getSymbolLinks(symbol); | ||
| if (!links.constEnumReferenced) { | ||
| links.constEnumReferenced = true; | ||
| } | ||
| } | ||
andrewbranch marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| // This function is only for imports with entity names | ||
| function getSymbolOfPartOfRightHandSideOfImportEquals(entityName: EntityName, dontResolveAlias?: boolean): Symbol | undefined { | ||
| // There are three things we might try to look for. In the following examples, | ||
| @@ -20211,12 +20220,13 @@ namespace ts { | ||
| } | ||
| function markAliasReferenced(symbol: Symbol, location: Node) { | ||
| if (isNonLocalAlias(symbol, /*excludes*/ SymbolFlags.Value) && !isInTypeQuery(location) && !getTypeOnlyAliasDeclaration(symbol)) { | ||
| if (compilerOptions.preserveConstEnums && isExportOrExportExpression(location) || !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) { | ||
| markAliasSymbolAsReferenced(symbol); | ||
| } | ||
| else { | ||
| markConstEnumAliasAsReferenced(symbol); | ||
| } | ||
| } | ||
| } | ||
| @@ -33045,17 +33055,15 @@ namespace ts { | ||
| } | ||
| function importClauseContainsReferencedImport(importClause: ImportClause) { | ||
| return forEachImportClauseDeclaration(importClause, declaration => { | ||
| return !!getSymbolOfNode(declaration).isReferenced; | ||
| }); | ||
| } | ||
| function importClauseContainsConstEnumUsedAsValue(importClause: ImportClause) { | ||
| return forEachImportClauseDeclaration(importClause, declaration => { | ||
| return !!getSymbolLinks(getSymbolOfNode(declaration)).constEnumReferenced; | ||
| }); | ||
| } | ||
| function checkImportsForTypeOnlyConversion(sourceFile: SourceFile) { | ||
| @@ -33065,7 +33073,8 @@ namespace ts { | ||
| statement.importClause && | ||
| !statement.importClause.isTypeOnly && | ||
| importClauseContainsReferencedImport(statement.importClause) && | ||
| !isReferencedAliasDeclaration(statement.importClause, /*checkChildren*/ true) && | ||
| !importClauseContainsConstEnumUsedAsValue(statement.importClause) | ||
| ) { | ||
| const isError = compilerOptions.importsNotUsedAsValues === importsNotUsedAsValues.Error; | ||
| errorOrSuggestion( | ||
3 changes: 2 additions & 1 deletionsrc/compiler/types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletionssrc/compiler/utilities.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletionstests/cases/conformance/externalModules/typeOnly/importsNotUsedAsValues_error.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
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.