fix(ngcc): use the correct identifiers when updating typings files (#34254)
Previously the identifiers used in the typings files were the same as those used in the source files. When the typings files and the source files do not match exactly, e.g. when one of them is flattened, while the other is a deep tree, it is possible for identifiers to be renamed. This commit ensures that the correct identifier is used in typings files when the typings file does not export the same name as the source file. Fixes https://github.com/angular/ngcc-validation/pull/608 PR Close #34254
This commit is contained in:

committed by
Kara Erickson

parent
f22a6eb00e
commit
31be29a9f3
@ -235,6 +235,34 @@ runInEachFileSystem(() => {
|
||||
`TestClass.ɵprov = ɵngcc0.ɵɵdefineInjectable({`);
|
||||
});
|
||||
|
||||
it('should use the correct type name in typings files when an export has a different name in source files',
|
||||
() => {
|
||||
// We need to make sure that changes to the typings files use the correct name
|
||||
// static ɵprov: ɵngcc0.ɵɵInjectableDef<ɵangular_packages_common_common_a>;
|
||||
mainNgcc({
|
||||
basePath: '/node_modules',
|
||||
targetEntryPointPath: '@angular/common',
|
||||
propertiesToConsider: ['esm2015']
|
||||
});
|
||||
|
||||
// In `@angular/common` the `NgClassR3Impl` class gets exported as something like
|
||||
// `ɵangular_packages_common_common_a`.
|
||||
const jsContents = fs.readFile(_(`/node_modules/@angular/common/fesm2015/common.js`));
|
||||
const exportedNameMatch = jsContents.match(/export.* NgClassR3Impl as ([^ ,}]+)/);
|
||||
if (exportedNameMatch === null) {
|
||||
return fail(
|
||||
'Expected `/node_modules/@angular/common/fesm2015/common.js` to export `NgClassR3Impl` via an alias');
|
||||
}
|
||||
const exportedName = exportedNameMatch[1];
|
||||
|
||||
// We need to make sure that the flat typings file exports this directly
|
||||
const dtsContents = fs.readFile(_('/node_modules/@angular/common/common.d.ts'));
|
||||
expect(dtsContents)
|
||||
.toContain(`export declare class ${exportedName} implements ɵNgClassImpl`);
|
||||
// And that ngcc's modifications to that class use the correct (exported) name
|
||||
expect(dtsContents).toContain(`static ɵprov: ɵngcc0.ɵɵInjectableDef<${exportedName}>`);
|
||||
});
|
||||
|
||||
it('should add generic type for ModuleWithProviders and generate exports for private modules',
|
||||
() => {
|
||||
compileIntoApf('test-package', {
|
||||
|
Reference in New Issue
Block a user