Skip to content

fix(@ngtools/webpack): elide inlined const enum imports from rewritten import declarations - #34786

Open
thekhegay wants to merge 1 commit into
angular:mainfrom
thekhegay:webpack-const-enum-elide
Open

thekhegay wants to merge 1 commit into
angular:mainfrom
thekhegay:webpack-const-enum-elide

Conversation

@thekhegay

Copy link
Copy Markdown
Contributor

PR Checklist

PR Type

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #34760

isValueAlias treats alias of const enum as runtime value. In import { Period, PeriodFormatter } from './period' PeriodFormatter is removed as unused value, so declaration is rewritten and TS skips its own elision for it. Period is kept as used, but TS inlined Period.Month and enum has no runtime export, so webpack fails with export 'Period' (imported as 'Period') was not found

What 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, preserveConstEnums or verbatimModuleSyntax enum exists at runtime and import is kept as before

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Added specs next to existing const enum ones in both decorator metadata blocks, plus isolatedModules and preserveConstEnums cases. Checked against shipped 22.2.7 with issues files: import stays there, gone with the fix

…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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant