Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@ngtools/webpack): fix elide removing whole imports on single match #8519

Merged
merged 1 commit into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function elideImports(
})
.forEach((symbol) => {
// Remove the whole declaration if it's a single import.
const nodeToRemove = symbol.singleImport ? symbol.importSpec : symbol.importDecl;
const nodeToRemove = symbol.singleImport ? symbol.importDecl : symbol.importSpec;
ops.push(new RemoveNodeOperation(sourceFile, nodeToRemove));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,41 @@ describe('@ngtools/webpack transformers', () => {

expect(oneLine`${result}`).toEqual(oneLine`${output}`);
});

it('should not remove imports from types that are still used', () => {
const input = stripIndent`
import { Component, EventEmitter } from '@angular/core';

@Component({
selector: 'app-root',
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
notify: EventEmitter<string> = new EventEmitter<string>();
title = 'app';
}
`;
const output = stripIndent`
import { EventEmitter } from '@angular/core';

export class AppComponent {
constructor() {
this.notify = new EventEmitter();
this.title = 'app';
}
}
`;

const { program, compilerHost } = createTypescriptContext(input);
const transformer = removeDecorators(
() => true,
() => program.getTypeChecker(),
);
const result = transformTypescript(undefined, [transformer], program, compilerHost);

expect(oneLine`${result}`).toEqual(oneLine`${output}`);
});
});
});