Repository navigation
Commit b6bfa2c
committed
fix(@ngtools/webpack): elide imports used only in type re-exports or 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 #345801 parent 5deaace commit b6bfa2c
3 files changed
Lines changed: 63 additions & 0 deletions
File tree
- packages
- angular/build/src/tools/angular/transformers
- ngtools/webpack/src/transformers
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
145 | 156 | | |
146 | 157 | | |
147 | 158 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
62 | 73 | | |
63 | 74 | | |
64 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
414 | 414 | | |
415 | 415 | | |
416 | 416 | | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
417 | 458 | | |
418 | 459 | | |
419 | 460 | | |
| |||
0 commit comments