Repository navigation
Conversation
…n import declarations TypeScript inlines const enum usages and elides their imports. When an unused runtime value specifier was removed from the same import declaration, the declaration was rewritten, TypeScript skipped its own elision, and the const enum import was kept even though the enum has no runtime export.
There was a problem hiding this comment.
Code Review
This pull request updates the import elision logic in @ngtools/webpack to correctly handle const enum imports. Specifically, it modifies the isValueAlias function to accept compiler options and check if preserveConstEnums, isolatedModules, or verbatimModuleSyntax is enabled before deciding to retain a const enum import. Comprehensive unit tests have been added to verify this behavior under different compiler configurations. I have no feedback to provide as the changes are correct and well-tested.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PR Checklist
PR Type
What is the current behavior?
Issue Number: #34760
isValueAliastreats alias of const enum as runtime value. Inimport { Period, PeriodFormatter } from './period'PeriodFormatteris removed as unused value, so declaration is rewritten and TS skips its own elision for it.Periodis kept as used, but TS inlinedPeriod.Monthand enum has no runtime export, so webpack fails withexport 'Period' (imported as 'Period') was not foundWhat is the new behavior?
Alias that resolves to const enum is treated as non-value, like TS does, so it goes away together with removed specifier. With
isolatedModules,preserveConstEnumsorverbatimModuleSyntaxenum exists at runtime and import is kept as beforeDoes this PR introduce a breaking change?
Other information
Added specs next to existing const enum ones in both decorator metadata blocks, plus
isolatedModulesandpreserveConstEnumscases. Checked against shipped 22.2.7 with issues files: import stays there, gone with the fix