fix(ngcc): use aliased exported types correctly (#38666)
If a type has been renamed when it was exported, we need to reference the external public alias name rather than the internal original name for the type. Otherwise we will try to import the type by its internal name, which is not publicly accessible. Fixes #38238 PR Close #38666
This commit is contained in:

committed by
atscott

parent
2c4a98a285
commit
7869de6136
@ -1140,6 +1140,57 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
|
||||
describe('getConstructorParameters()', () => {
|
||||
it('should always specify LOCAL type value references for decorated constructor parameter types',
|
||||
() => {
|
||||
const files = [
|
||||
{
|
||||
name: _('/node_modules/shared-lib/foo.d.ts'),
|
||||
contents: `
|
||||
declare class Foo {}
|
||||
export {Foo as Bar};
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: _('/node_modules/shared-lib/index.d.ts'),
|
||||
contents: `
|
||||
export {Bar as Baz} from './foo';
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: _('/local.js'),
|
||||
contents: `
|
||||
class Internal {}
|
||||
export {Internal as External};
|
||||
`
|
||||
},
|
||||
{
|
||||
name: _('/main.js'),
|
||||
contents: `
|
||||
import {Baz} from 'shared-lib';
|
||||
import {External} from './local';
|
||||
export class SameFile {}
|
||||
|
||||
export class SomeClass {
|
||||
constructor(arg1, arg2, arg3) {}
|
||||
}
|
||||
SomeClass.ctorParameters = [{ type: Baz }, { type: External }, { type: SameFile }];
|
||||
`,
|
||||
},
|
||||
];
|
||||
|
||||
loadTestFiles(files);
|
||||
const bundle = makeTestBundleProgram(_('/main.js'));
|
||||
const host =
|
||||
createHost(bundle, new Esm2015ReflectionHost(new MockLogger(), false, bundle));
|
||||
const classNode =
|
||||
getDeclaration(bundle.program, _('/main.js'), 'SomeClass', isNamedClassDeclaration);
|
||||
|
||||
const parameters = host.getConstructorParameters(classNode)!;
|
||||
|
||||
expect(parameters.map(p => p.name)).toEqual(['arg1', 'arg2', 'arg3']);
|
||||
expectTypeValueReferencesForParameters(parameters, ['Baz', 'External', 'SameFile']);
|
||||
});
|
||||
|
||||
it('should find the decorated constructor parameters', () => {
|
||||
loadFakeCore(getFileSystem());
|
||||
loadTestFiles([SOME_DIRECTIVE_FILE]);
|
||||
@ -1154,7 +1205,7 @@ runInEachFileSystem(() => {
|
||||
'_viewContainer', '_template', 'injected'
|
||||
]);
|
||||
expectTypeValueReferencesForParameters(
|
||||
parameters, ['ViewContainerRef', 'TemplateRef', null], '@angular/core');
|
||||
parameters, ['ViewContainerRef', 'TemplateRef', null]);
|
||||
});
|
||||
|
||||
it('should accept `ctorParameters` as an array', () => {
|
||||
|
Reference in New Issue
Block a user