Skip to content

Commit b6f1be7

Browse files
filipesilvaBrocco
authored andcommitted
fix(@ngtools/webpack): don't elide identifiers that are still exported
Fix #9180
1 parent 7352bcb commit b6f1be7

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Diff for: packages/@ngtools/webpack/src/transformers/elide_imports.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ export function elideImports(
9999
.forEach((id) => {
100100
if (removedSymbolMap.has(id.text)) {
101101
const symbol = removedSymbolMap.get(id.text);
102-
if (typeChecker.getSymbolAtLocation(id) === symbol.symbol) {
102+
103+
// Check if the symbol is the same or if it is a named export.
104+
// Named exports don't have the same symbol but will have the same name.
105+
if ((id.parent && id.parent.kind === ts.SyntaxKind.ExportSpecifier)
106+
|| typeChecker.getSymbolAtLocation(id) === symbol.symbol) {
103107
symbol.all.push(id);
104108
}
105109
}

Diff for: packages/@ngtools/webpack/src/transformers/remove_decorators.spec.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe('@ngtools/webpack transformers', () => {
111111

112112
it('should not remove imports from types that are still used', () => {
113113
const input = stripIndent`
114-
import { Component, EventEmitter } from '@angular/core';
114+
import { Component, ChangeDetectionStrategy, EventEmitter } from '@angular/core';
115115
116116
@Component({
117117
selector: 'app-root',
@@ -123,16 +123,20 @@ describe('@ngtools/webpack transformers', () => {
123123
notify: EventEmitter<string> = new EventEmitter<string>();
124124
title = 'app';
125125
}
126+
127+
export { ChangeDetectionStrategy };
126128
`;
127129
const output = stripIndent`
128-
import { EventEmitter } from '@angular/core';
130+
import { ChangeDetectionStrategy, EventEmitter } from '@angular/core';
129131
130132
export class AppComponent {
131133
constructor() {
132134
this.notify = new EventEmitter();
133135
this.title = 'app';
134136
}
135137
}
138+
139+
export { ChangeDetectionStrategy };
136140
`;
137141

138142
const { program, compilerHost } = createTypescriptContext(input);

0 commit comments

Comments
 (0)