refactor(ivy): misc minor fixes in the JIT compiler ()

PR Close 
This commit is contained in:
Victor Berchet 2018-06-05 10:11:43 -07:00
parent 83a06863f9
commit 9c403753e2

@ -29,34 +29,47 @@ export function compileNgModule(type: Type<any>, ngModule: NgModule): void {
// Compute transitiveCompileScope // Compute transitiveCompileScope
const transitiveCompileScope = { const transitiveCompileScope = {
directives: [] as any[], directives: new Set<any>(),
pipes: [] as any[], pipes: new Set<any>(),
modules: new Set<any>(),
}; };
function addExportsFrom(module: Type<any>& {ngModuleDef: NgModuleDef<any>}): void { function addExportsFrom(module: Type<any>& {ngModuleDef: NgModuleDef<any>}): void {
module.ngModuleDef.exports.forEach((exp: any) => { if (!transitiveCompileScope.modules.has(module)) {
if (isNgModule(exp)) { module.ngModuleDef.exports.forEach((exp: any) => {
addExportsFrom(exp); if (isNgModule(exp)) {
} else if (exp.ngPipeDef) { addExportsFrom(exp);
transitiveCompileScope.pipes.push(exp); } else if (exp.ngPipeDef) {
} else { transitiveCompileScope.pipes.add(exp);
transitiveCompileScope.directives.push(exp); } else {
} transitiveCompileScope.directives.add(exp);
}); }
});
}
} }
flatten([(ngModule.imports || EMPTY_ARRAY), (ngModule.exports || EMPTY_ARRAY)]) flatten([
.filter(importExport => isNgModule(importExport)) (ngModule.imports || EMPTY_ARRAY), (ngModule.exports || EMPTY_ARRAY)
.forEach(mod => addExportsFrom(mod)); ]).forEach(importExport => {
const maybeModule = expandModuleWithProviders(importExport);
if (isNgModule(maybeModule)) {
addExportsFrom(maybeModule);
}
});
flatten(ngModule.declarations || EMPTY_ARRAY).forEach(decl => { flatten(ngModule.declarations || EMPTY_ARRAY).forEach(decl => {
if (decl.ngPipeDef) { if (decl.ngPipeDef) {
transitiveCompileScope.pipes.push(decl); transitiveCompileScope.pipes.add(decl);
} else if (decl.ngDirectiveDef) {
transitiveCompileScope.directives.add(decl);
} else if (decl.ngComponentDef) { } else if (decl.ngComponentDef) {
transitiveCompileScope.directives.push(decl); transitiveCompileScope.directives.add(decl);
patchComponentWithScope(decl, type as any); patchComponentWithScope(decl, type as any);
} else { } else {
transitiveCompileScope.directives.push(decl); // A component that has not been compiled yet because the template is being fetched
// we need to store a reference to the module to update the selector scope after
// the component gets compiled
transitiveCompileScope.directives.add(decl);
decl.ngSelectorScope = type; decl.ngSelectorScope = type;
} }
}); });
@ -77,7 +90,10 @@ export function compileNgModule(type: Type<any>, ngModule: NgModule): void {
}; };
const res = compileR3NgModule(meta); const res = compileR3NgModule(meta);
def = jitExpression(res.expression, angularCoreEnv, `ng://${type.name}/ngModuleDef.js`); def = jitExpression(res.expression, angularCoreEnv, `ng://${type.name}/ngModuleDef.js`);
def.transitiveCompileScope = transitiveCompileScope; def.transitiveCompileScope = {
directives: Array.from(transitiveCompileScope.directives),
pipes: Array.from(transitiveCompileScope.pipes),
};
} }
return def; return def;
}, },