Skip to content

Commit

Permalink
fix(@ngtools/webpack): don't elide identifiers that are still exported
Browse files Browse the repository at this point in the history
Fix #9180
  • Loading branch information
filipesilva authored and Brocco committed Jan 19, 2018
1 parent d35aca5 commit f98bdaa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/@ngtools/webpack/src/transformers/elide_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ export function elideImports(
.forEach((id) => {
if (removedSymbolMap.has(id.text)) {
const symbol = removedSymbolMap.get(id.text);
if (typeChecker.getSymbolAtLocation(id) === symbol.symbol) {

// Check if the symbol is the same or if it is a named export.
// Named exports don't have the same symbol but will have the same name.
if ((id.parent && id.parent.kind === ts.SyntaxKind.ExportSpecifier)
|| typeChecker.getSymbolAtLocation(id) === symbol.symbol) {
symbol.all.push(id);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe('@ngtools/webpack transformers', () => {

it('should not remove imports from types that are still used', () => {
const input = stripIndent`
import { Component, EventEmitter } from '@angular/core';
import { Component, ChangeDetectionStrategy, EventEmitter } from '@angular/core';
@Component({
selector: 'app-root',
Expand All @@ -123,16 +123,20 @@ describe('@ngtools/webpack transformers', () => {
notify: EventEmitter<string> = new EventEmitter<string>();
title = 'app';
}
export { ChangeDetectionStrategy };
`;
const output = stripIndent`
import { EventEmitter } from '@angular/core';
import { ChangeDetectionStrategy, EventEmitter } from '@angular/core';
export class AppComponent {
constructor() {
this.notify = new EventEmitter();
this.title = 'app';
}
}
export { ChangeDetectionStrategy };
`;

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

0 comments on commit f98bdaa

Please sign in to comment.