Skip to content

Commit

Permalink
fix(@ngtools/webpack): don't elide decorated method parameter type re…
Browse files Browse the repository at this point in the history
…ference

Fixes #17080

(cherry picked from commit 678180e)
  • Loading branch information
alan-agius4 authored and dgp1130 committed Feb 26, 2020
1 parent e6a9f78 commit bd4078d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
6 changes: 2 additions & 4 deletions packages/ngtools/webpack/src/transformers/elide_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,9 @@ export function elideImports(
(ts.isConstructorDeclaration(parent.parent) && !!parent.parent.parent.decorators?.length));
break;
}

if (isTypeReferenceForDecoratoredNode) {
symbol = typeChecker.getSymbolAtLocation(node);
} else {
// If type reference is not for Decorator skip and marked as unused.
return;
symbol = typeChecker.getSymbolAtLocation(node.typeName);
}
} else {
switch (node.kind) {
Expand Down
44 changes: 23 additions & 21 deletions packages/ngtools/webpack/src/transformers/elide_imports_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,27 @@ describe('@ngtools/webpack transformers', () => {
expect(tags.oneLine`${result}`).toEqual(tags.oneLine`${output}`);
});

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 elide imports decorator type references when emitDecoratorMetadata is false', () => {
const extraCompilerOptions: ts.CompilerOptions = {
emitDecoratorMetadata: false,
Expand Down Expand Up @@ -317,27 +338,6 @@ 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 Expand Up @@ -515,6 +515,8 @@ describe('@ngtools/webpack transformers', () => {
import { __decorate, __metadata } from "tslib";
import { Decorator } from './decorator';
import { Service } from './service';
export class Foo { name(f) { } }
__decorate([ Decorator(), __metadata("design:type", Function), __metadata("design:paramtypes", [Service]),
Expand Down

0 comments on commit bd4078d

Please sign in to comment.