Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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}`);
});
});
});