fix(ivy): ngcc - render namespaced imported decorators correctly (#31426)
The support for decorators that were imported via a namespace, e.g. `import * as core from `@angular/core` was implemented piecemeal. This meant that it was easy to miss situations where a decorator identifier needed to be handled as a namepsaced import rather than a direct import. One such issue was that UMD processing of decorators was not correct: the namespace was being omitted from references to decorators. Now the types have been modified to make it clear that a `Decorator.identifier` could hold a namespaced identifier, and the corresponding code that uses these types has been fixed. Fixes #31394 PR Close #31426
This commit is contained in:

committed by
Miško Hevery

parent
b66d82e308
commit
dd664f694c
@ -124,7 +124,7 @@ function classMemberToMetadata(
|
||||
function decoratorToMetadata(decorator: Decorator): ts.ObjectLiteralExpression {
|
||||
// Decorators have a type.
|
||||
const properties: ts.ObjectLiteralElementLike[] = [
|
||||
ts.createPropertyAssignment('type', ts.updateIdentifier(decorator.identifier)),
|
||||
ts.createPropertyAssignment('type', ts.getMutableClone(decorator.identifier)),
|
||||
];
|
||||
// Sometimes they have arguments.
|
||||
if (decorator.args !== null && decorator.args.length > 0) {
|
||||
|
@ -26,6 +26,16 @@ runInEachFileSystem(() => {
|
||||
`/*@__PURE__*/ i0.ɵsetClassMetadata(Target, [{ type: Component, args: ['metadata'] }], null, null);`);
|
||||
});
|
||||
|
||||
it('should convert namespaced decorated class metadata', () => {
|
||||
const res = compileAndPrint(`
|
||||
import * as core from '@angular/core';
|
||||
|
||||
@core.Component('metadata') class Target {}
|
||||
`);
|
||||
expect(res).toEqual(
|
||||
`/*@__PURE__*/ i0.ɵsetClassMetadata(Target, [{ type: core.Component, args: ['metadata'] }], null, null);`);
|
||||
});
|
||||
|
||||
it('should convert decorated class constructor parameter metadata', () => {
|
||||
const res = compileAndPrint(`
|
||||
import {Component, Inject, Injector} from '@angular/core';
|
||||
|
Reference in New Issue
Block a user