Skip to content

Commit 33f35b0

Browse files
crisbetoalxhub
authored andcommitted
fix(compiler): type-only symbols incorrectly retained when downlevelling custom decorators (#48638)
In #47167 an `updateClassDeclaration` call was swapped out with a `createClassDeclaration` which caused a regression where interface references were being retained when using a custom decorator in a project that has `emitDecoratorMetadata` enabled. These changes switch back to use `updateClassDeclaration`. Fixes #48448. PR Close #48638
1 parent 2d3c98d commit 33f35b0

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

packages/compiler-cli/src/transformers/downlevel_decorators_transform/downlevel_decorators_transform.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,9 @@ export function getDownlevelDecoratorsTransform(
576576
modifiers = [...decoratorsToKeep, ...(classModifiers || [])];
577577
}
578578

579-
return ts.factory.createClassDeclaration(
580-
modifiers, classDecl.name, classDecl.typeParameters, classDecl.heritageClauses, members);
579+
return ts.factory.updateClassDeclaration(
580+
classDecl, modifiers, classDecl.name, classDecl.typeParameters, classDecl.heritageClauses,
581+
members);
581582
}
582583

583584
/**

packages/compiler-cli/test/downlevel_decorators_transform_spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,33 @@ describe('downlevel decorator transform', () => {
702702
expect(output).not.toContain('tslib');
703703
});
704704

705+
it('should allow for type-only references to be removed with `emitDecoratorMetadata` from custom decorators',
706+
() => {
707+
context.writeFile('/external-interface.ts', `
708+
export interface ExternalInterface {
709+
id?: string;
710+
}
711+
`);
712+
713+
const {output} = transform(
714+
`
715+
import { ExternalInterface } from './external-interface';
716+
717+
export function CustomDecorator() {
718+
return <T>(target, propertyKey, descriptor: TypedPropertyDescriptor<T>) => {}
719+
}
720+
721+
export class Foo {
722+
@CustomDecorator() static test(): ExternalInterface { return {}; }
723+
}
724+
`,
725+
{emitDecoratorMetadata: true});
726+
727+
expect(diagnostics.length).toBe(0);
728+
expect(output).not.toContain('ExternalInterface');
729+
expect(output).toContain('metadata("design:returntype", Object)');
730+
});
731+
705732
describe('class decorators skipped', () => {
706733
beforeEach(() => skipClassDecorators = true);
707734

0 commit comments

Comments
 (0)