Repository navigation
fix(@ngtools/webpack): elide non-value aliases and type-only AST constructs (21.2.x) - #34666
Merged
Merged
Conversation
…type declarations
When `elideImports` removes unused import specifiers (such as after
`removeIvyJitSupportCalls` removes `ɵsetClassMetadata`), it previously
walked into `interface` declarations, `type` alias declarations, and
type-only `export` declarations/specifiers (`export type { X }`,
`export { type X }`). This caused it to mark those type-only imported
symbols as used at runtime and rewrite the `ImportDeclaration` while
retaining those specifiers.
Because the `ImportDeclaration` AST node was replaced by a `before`
transformer, TypeScript skipped its own type-only import elision on the
cloned declaration, leaving the type-only specifier in the emitted JS
output. With webpack 5.112.0+, unused import specifiers are still
link-checked against the target module, causing builds with
`strictExportPresence: true` to fail.
Skip pure type declarations (`InterfaceDeclaration`,
`TypeAliasDeclaration`, `TypeParameterDeclaration`) and type-only
exports (`ExportDeclaration` and `ExportSpecifier` with `isTypeOnly`)
when collecting used identifiers in `elideImports`.
Closes angular#34580
…y AST constructs Follow up to angular#34582 to cover remaining pure-type import elision cases and partial specifier removal in `replaceBootstrap`: - Elide imported alias symbols that do not resolve to a runtime value (or traverse a type-only alias declaration), handling non-`type` interface re-exports (`export { Foo }`) and interface parameter types under `emitDecoratorMetadata`. - Only rewrite a partially elided import declaration when a runtime value import must be removed or when the declaration was already replaced by a previous transformer. TypeScript skips its own import elision for declarations replaced by a transformer, so leaving other declarations untouched avoids retaining specifiers that TypeScript would have otherwise elided (such as inlined `const enum` imports). - Skip all non-`ExpressionWithTypeArguments` `TypeNode`s when `emitDecoratorMetadata` is disabled, and unconditionally skip `TypeQueryNode` (`typeof X`), `ImportTypeNode`, `IndexSignatureDeclaration`, ambient `declare` statements, and external `export ... from '...'` declarations. - Recursively visit child AST nodes when applying `elideImports` removals in `replaceBootstrap` so individual `ImportSpecifier`s are removed when `platformBrowserDynamic` shares an import with other used runtime exports.
…AST constructs Follow up to angular#34582 to apply the same import elision fixes made to `@ngtools/webpack` to the `replaceBootstrap` transformer used by the application builder: - Elide imported alias symbols that do not resolve to a runtime value (or traverse a type-only alias declaration), handling non-`type` interface re-exports (`export { Foo }`) and interface parameter types under `emitDecoratorMetadata`. - Only rewrite a partially elided import declaration when a runtime value import must be removed or when the declaration was already replaced by a previous transformer, so TypeScript's own import elision continues to apply to all other declarations. - Skip all non-`ExpressionWithTypeArguments` `TypeNode`s when `emitDecoratorMetadata` is disabled, and unconditionally skip `TypeQueryNode` (`typeof X`), `ImportTypeNode`, `IndexSignatureDeclaration`, ambient `declare` statements, and external `export ... from '...'` declarations. - Recursively visit child AST nodes when applying import removals in `replaceBootstrap` so individual `ImportSpecifier`s are removed when `platformBrowserDynamic` shares an import with other used runtime exports.
There was a problem hiding this comment.
Code Review
This pull request enhances import elision within the Angular build tools and Webpack transformers. Specifically, it refines the identification of type-only imports, type queries, ambient declarations, and unresolved or circular aliases to prevent over-elision of runtime values while correctly stripping unused type-only specifiers. Comprehensive unit tests have been added to verify these behaviors. I have no additional feedback to provide as there are no review comments to address.
1 task done
clydin
approved these changes
Nov 6, 2026
clydin
approved these changes
Nov 6, 2026
Collaborator
|
This PR was merged into the repository. The changes were merged into the following branches:
|
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.
Backport of #34582 and #34594 to
21.2.x.Closes #34665