fix(compiler): also create .ngfactory.js
files in non obvious cases (#19301)
E.g. when an exported class contains a ctor argument which is from another compilation unit. PR Close #19301
This commit is contained in:
@ -840,6 +840,7 @@ describe('ngc transformer command-line', () => {
|
|||||||
})
|
})
|
||||||
export class Module {}
|
export class Module {}
|
||||||
`);
|
`);
|
||||||
|
write('lib1/class1.ts', `export class Class1 {}`);
|
||||||
|
|
||||||
// Lib 2
|
// Lib 2
|
||||||
write('lib2/tsconfig-lib2.json', `{
|
write('lib2/tsconfig-lib2.json', `{
|
||||||
@ -855,6 +856,13 @@ describe('ngc transformer command-line', () => {
|
|||||||
write('lib2/module.ts', `
|
write('lib2/module.ts', `
|
||||||
export {Module} from 'lib1_built/module';
|
export {Module} from 'lib1_built/module';
|
||||||
`);
|
`);
|
||||||
|
write('lib2/class2.ts', `
|
||||||
|
import {Class1} from 'lib1_built/class1';
|
||||||
|
|
||||||
|
export class Class2 {
|
||||||
|
constructor(class1: Class1) {}
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
|
||||||
// Application
|
// Application
|
||||||
write('app/tsconfig-app.json', `{
|
write('app/tsconfig-app.json', `{
|
||||||
@ -904,6 +912,12 @@ describe('ngc transformer command-line', () => {
|
|||||||
shouldExist('lib2_built/module.ngfactory.js');
|
shouldExist('lib2_built/module.ngfactory.js');
|
||||||
shouldExist('lib2_built/module.ngfactory.d.ts');
|
shouldExist('lib2_built/module.ngfactory.d.ts');
|
||||||
|
|
||||||
|
shouldExist('lib2_built/class2.ngsummary.json');
|
||||||
|
shouldNotExist('lib2_built/class2.ngsummary.js');
|
||||||
|
shouldNotExist('lib2_built/class2.ngsummary.d.ts');
|
||||||
|
shouldExist('lib2_built/class2.ngfactory.js');
|
||||||
|
shouldExist('lib2_built/class2.ngfactory.d.ts');
|
||||||
|
|
||||||
// app
|
// app
|
||||||
// make `shouldExist` / `shouldNotExist` relative to `built`
|
// make `shouldExist` / `shouldNotExist` relative to `built`
|
||||||
outDir = path.resolve(basePath, 'built');
|
outDir = path.resolve(basePath, 'built');
|
||||||
|
@ -34,7 +34,7 @@ import {ResolvedStaticSymbol, StaticSymbolResolver} from './static_symbol_resolv
|
|||||||
import {createForJitStub, serializeSummaries} from './summary_serializer';
|
import {createForJitStub, serializeSummaries} from './summary_serializer';
|
||||||
import {ngfactoryFilePath, splitTypescriptSuffix, summaryFileName, summaryForJitFileName, summaryForJitName} from './util';
|
import {ngfactoryFilePath, splitTypescriptSuffix, summaryFileName, summaryForJitFileName, summaryForJitName} from './util';
|
||||||
|
|
||||||
export enum StubEmitFlags {
|
enum StubEmitFlags {
|
||||||
Basic = 1 << 0,
|
Basic = 1 << 0,
|
||||||
TypeCheck = 1 << 1,
|
TypeCheck = 1 << 1,
|
||||||
All = TypeCheck | Basic
|
All = TypeCheck | Basic
|
||||||
@ -170,22 +170,14 @@ export class AotCompiler {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// make sure we create a .ngfactory if we have a least one component
|
// Make sure we create a .ngfactory if we have a injectable/directive/pipe/NgModule
|
||||||
// in the file.
|
// or a reference to a non source file.
|
||||||
|
// Note: This is overestimating the required .ngfactory files as the real calculation is harder.
|
||||||
// Only do this for StubEmitFlags.Basic, as adding a type check block
|
// Only do this for StubEmitFlags.Basic, as adding a type check block
|
||||||
// does not change this file (as we generate type check blocks based on NgModules).
|
// does not change this file (as we generate type check blocks based on NgModules).
|
||||||
if (outputCtx.statements.length === 0 && (emitFlags & StubEmitFlags.Basic) &&
|
if (outputCtx.statements.length === 0 && (emitFlags & StubEmitFlags.Basic) &&
|
||||||
file.directives.some(
|
(file.directives.length || file.pipes.length || file.injectables.length ||
|
||||||
dir => this._metadataResolver.getNonNormalizedDirectiveMetadata(
|
file.ngModules.length || file.exportsNonSourceFiles)) {
|
||||||
dir) !.metadata.isComponent)) {
|
|
||||||
_createEmptyStub(outputCtx);
|
|
||||||
}
|
|
||||||
|
|
||||||
// make sure we create a .ngfactory if we reexport a non source file.
|
|
||||||
// Only do this for StubEmitFlags.Basic, as adding a type check block
|
|
||||||
// does not change this file (as we generate type check blocks based on NgModules).
|
|
||||||
if (outputCtx.statements.length === 0 && (emitFlags & StubEmitFlags.Basic) &&
|
|
||||||
file.exportsNonSourceFiles) {
|
|
||||||
_createEmptyStub(outputCtx);
|
_createEmptyStub(outputCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -648,22 +640,29 @@ export function analyzeFile(
|
|||||||
if (!symbolMeta || symbolMeta.__symbolic === 'error') {
|
if (!symbolMeta || symbolMeta.__symbolic === 'error') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
exportsNonSourceFiles =
|
let isNgSymbol = false;
|
||||||
exportsNonSourceFiles || isValueExportingNonSourceFile(host, symbolMeta);
|
|
||||||
if (symbolMeta.__symbolic === 'class') {
|
if (symbolMeta.__symbolic === 'class') {
|
||||||
if (metadataResolver.isDirective(symbol)) {
|
if (metadataResolver.isDirective(symbol)) {
|
||||||
|
isNgSymbol = true;
|
||||||
directives.push(symbol);
|
directives.push(symbol);
|
||||||
} else if (metadataResolver.isPipe(symbol)) {
|
} else if (metadataResolver.isPipe(symbol)) {
|
||||||
|
isNgSymbol = true;
|
||||||
pipes.push(symbol);
|
pipes.push(symbol);
|
||||||
} else if (metadataResolver.isInjectable(symbol)) {
|
} else if (metadataResolver.isInjectable(symbol)) {
|
||||||
|
isNgSymbol = true;
|
||||||
injectables.push(symbol);
|
injectables.push(symbol);
|
||||||
} else {
|
} else {
|
||||||
const ngModule = metadataResolver.getNgModuleMetadata(symbol, false);
|
const ngModule = metadataResolver.getNgModuleMetadata(symbol, false);
|
||||||
if (ngModule) {
|
if (ngModule) {
|
||||||
|
isNgSymbol = true;
|
||||||
ngModules.push(ngModule);
|
ngModules.push(ngModule);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!isNgSymbol) {
|
||||||
|
exportsNonSourceFiles =
|
||||||
|
exportsNonSourceFiles || isValueExportingNonSourceFile(host, symbolMeta);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
Reference in New Issue
Block a user