Skip to content

Commit bd4078d

Browse files
alan-agius4dgp1130
authored andcommitted
fix(@ngtools/webpack): don't elide decorated method parameter type reference
Fixes #17080 (cherry picked from commit 678180e)
1 parent e6a9f78 commit bd4078d

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

packages/ngtools/webpack/src/transformers/elide_imports.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,9 @@ export function elideImports(
7878
(ts.isConstructorDeclaration(parent.parent) && !!parent.parent.parent.decorators?.length));
7979
break;
8080
}
81+
8182
if (isTypeReferenceForDecoratoredNode) {
82-
symbol = typeChecker.getSymbolAtLocation(node);
83-
} else {
84-
// If type reference is not for Decorator skip and marked as unused.
85-
return;
83+
symbol = typeChecker.getSymbolAtLocation(node.typeName);
8684
}
8785
} else {
8886
switch (node.kind) {

packages/ngtools/webpack/src/transformers/elide_imports_spec.ts

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,27 @@ describe('@ngtools/webpack transformers', () => {
281281
expect(tags.oneLine`${result}`).toEqual(tags.oneLine`${output}`);
282282
});
283283

284+
it(`should remove import for 'ExpressionWithTypeArguments' implements token`, () => {
285+
const input = tags.stripIndent`
286+
import { Bar, Buz, Unused } from './bar';
287+
288+
export class Foo extends Bar implements Buz { }
289+
290+
${dummyNode}
291+
`;
292+
293+
const output = tags.stripIndent`
294+
import { Bar } from './bar';
295+
296+
export class Foo extends Bar { }
297+
`;
298+
299+
const { program, compilerHost } = createTypescriptContext(input);
300+
const result = transformTypescript(undefined, [transformer(program)], program, compilerHost);
301+
302+
expect(tags.oneLine`${result}`).toEqual(tags.oneLine`${output}`);
303+
});
304+
284305
describe('should elide imports decorator type references when emitDecoratorMetadata is false', () => {
285306
const extraCompilerOptions: ts.CompilerOptions = {
286307
emitDecoratorMetadata: false,
@@ -317,27 +338,6 @@ describe('@ngtools/webpack transformers', () => {
317338
});
318339
});
319340

320-
it(`should remove import for 'ExpressionWithTypeArguments' implements token`, () => {
321-
const input = tags.stripIndent`
322-
import { Bar, Buz, Unused } from './bar';
323-
324-
export class Foo extends Bar implements Buz { }
325-
326-
${dummyNode}
327-
`;
328-
329-
const output = tags.stripIndent`
330-
import { Bar } from './bar';
331-
332-
export class Foo extends Bar { }
333-
`;
334-
335-
const { program, compilerHost } = createTypescriptContext(input);
336-
const result = transformTypescript(undefined, [transformer(program)], program, compilerHost);
337-
338-
expect(tags.oneLine`${result}`).toEqual(tags.oneLine`${output}`);
339-
});
340-
341341
describe('should not elide imports decorator type references when emitDecoratorMetadata is true', () => {
342342
const extraCompilerOptions: ts.CompilerOptions = {
343343
emitDecoratorMetadata: true,
@@ -515,6 +515,8 @@ describe('@ngtools/webpack transformers', () => {
515515
import { __decorate, __metadata } from "tslib";
516516
517517
import { Decorator } from './decorator';
518+
import { Service } from './service';
519+
518520
export class Foo { name(f) { } }
519521
520522
__decorate([ Decorator(), __metadata("design:type", Function), __metadata("design:paramtypes", [Service]),

0 commit comments

Comments
 (0)