fix(ivy): ngcc - support bare array constructor param decorators (#30591)
Previously we expected the constructor parameter `decorators` property to be an array wrapped in a function. Now we also support an array not wrapped in a function. PR Close #30591
This commit is contained in:

committed by
Kara Erickson

parent
869e3e8edc
commit
2dfd97d8f0
@ -25,6 +25,7 @@ runInEachFileSystem(() => {
|
||||
let _: typeof absoluteFrom;
|
||||
|
||||
let SOME_DIRECTIVE_FILE: TestFile;
|
||||
let CTOR_DECORATORS_ARRAY_FILE: TestFile;
|
||||
let ACCESSORS_FILE: TestFile;
|
||||
let SIMPLE_CLASS_FILE: TestFile;
|
||||
let CLASS_EXPRESSION_FILE: TestFile;
|
||||
@ -89,6 +90,17 @@ runInEachFileSystem(() => {
|
||||
`,
|
||||
};
|
||||
|
||||
CTOR_DECORATORS_ARRAY_FILE = {
|
||||
name: _('/ctor_decorated_as_array.js'),
|
||||
contents: `
|
||||
class CtorDecoratedAsArray {
|
||||
constructor(arg1) {
|
||||
}
|
||||
}
|
||||
CtorDecoratedAsArray.ctorParameters = [{ type: ParamType, decorators: [{ type: Inject },] }];
|
||||
`,
|
||||
};
|
||||
|
||||
ACCESSORS_FILE = {
|
||||
name: _('/accessors.js'),
|
||||
contents: `
|
||||
@ -1078,6 +1090,20 @@ runInEachFileSystem(() => {
|
||||
parameters, ['ViewContainerRef', 'TemplateRef', null]);
|
||||
});
|
||||
|
||||
it('should accept `ctorParameters` as an array', () => {
|
||||
loadTestFiles([CTOR_DECORATORS_ARRAY_FILE]);
|
||||
const {program} = makeTestBundleProgram(CTOR_DECORATORS_ARRAY_FILE.name);
|
||||
const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker());
|
||||
const classNode = getDeclaration(
|
||||
program, CTOR_DECORATORS_ARRAY_FILE.name, 'CtorDecoratedAsArray',
|
||||
isNamedClassDeclaration);
|
||||
const parameters = host.getConstructorParameters(classNode) !;
|
||||
|
||||
expect(parameters).toBeDefined();
|
||||
expect(parameters.map(parameter => parameter.name)).toEqual(['arg1']);
|
||||
expectTypeValueReferencesForParameters(parameters, ['ParamType']);
|
||||
});
|
||||
|
||||
it('should throw if the symbol is not a class', () => {
|
||||
loadTestFiles([FOO_FUNCTION_FILE]);
|
||||
const {program} = makeTestBundleProgram(FOO_FUNCTION_FILE.name);
|
||||
|
Reference in New Issue
Block a user