Skip to content

fix(@ngtools/webpack): elide imports for implements keywords #16995

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

Merged
merged 1 commit into from
Feb 19, 2020
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
7 changes: 7 additions & 0 deletions packages/ngtools/webpack/src/transformers/elide_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ export function elideImports(
return;
}

// Consider types for 'implements' as unused.
// A HeritageClause token can also be an 'AbstractKeyword'
// which in that case we should not elide the import.
if (ts.isHeritageClause(node) && node.token === ts.SyntaxKind.ImplementsKeyword) {
return;
}

// Record import and skip
if (ts.isImportDeclaration(node)) {
imports.push(node);
Expand Down
21 changes: 21 additions & 0 deletions packages/ngtools/webpack/src/transformers/elide_imports_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,27 @@ describe('@ngtools/webpack transformers', () => {
});
});

it(`should remove import for 'ExpressionWithTypeArguments' implements token`, () => {
const input = tags.stripIndent`
import { Bar, Buz, Unused } from './bar';

export class Foo extends Bar implements Buz { }

${dummyNode}
`;

const output = tags.stripIndent`
import { Bar } from './bar';

export class Foo extends Bar { }
`;

const { program, compilerHost } = createTypescriptContext(input);
const result = transformTypescript(undefined, [transformer(program)], program, compilerHost);

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

describe('should not elide imports decorator type references when emitDecoratorMetadata is true', () => {
const extraCompilerOptions: ts.CompilerOptions = {
emitDecoratorMetadata: true,
Expand Down