Skip to content
Closed
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 @@ -576,8 +576,9 @@ export function getDownlevelDecoratorsTransform(
modifiers = [...decoratorsToKeep, ...(classModifiers || [])];
}

return ts.factory.createClassDeclaration(
modifiers, classDecl.name, classDecl.typeParameters, classDecl.heritageClauses, members);
return ts.factory.updateClassDeclaration(
classDecl, modifiers, classDecl.name, classDecl.typeParameters, classDecl.heritageClauses,
members);
}

/**
Expand Down
27 changes: 27 additions & 0 deletions packages/compiler-cli/test/downlevel_decorators_transform_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,33 @@ describe('downlevel decorator transform', () => {
expect(output).not.toContain('tslib');
});

it('should allow for type-only references to be removed with `emitDecoratorMetadata` from custom decorators',
() => {
context.writeFile('/external-interface.ts', `
export interface ExternalInterface {
id?: string;
}
`);

const {output} = transform(
`
import { ExternalInterface } from './external-interface';

export function CustomDecorator() {
return <T>(target, propertyKey, descriptor: TypedPropertyDescriptor<T>) => {}
}

export class Foo {
@CustomDecorator() static test(): ExternalInterface { return {}; }
}
`,
{emitDecoratorMetadata: true});

expect(diagnostics.length).toBe(0);
expect(output).not.toContain('ExternalInterface');
expect(output).toContain('metadata("design:returntype", Object)');
});

describe('class decorators skipped', () => {
beforeEach(() => skipClassDecorators = true);

Expand Down