1- import {
2- NgModuleFactory ,
3- NgModule
4- } from '@angular/core' ;
1+ import { NgModuleFactory } from '@angular/core' ;
52
63import {
74 CompilerHost ,
@@ -21,7 +18,6 @@ import {dirname} from 'path';
2118import { CompileOptions , loadProjectOptions } from './options' ;
2219import { CompilerException } from 'exception' ;
2320import { Project } from '../project' ;
24- import { Reflector } from 'platform' ;
2521import { VirtualMachine } from './vm' ;
2622import { diagnosticsToException } from './diagnostics' ;
2723import { templateCompiler } from './template' ;
@@ -33,8 +29,11 @@ export class Compiler {
3329 constructor ( private project : Project ) {
3430 this . options = loadProjectOptions ( project ) ;
3531
36- if ( project . ngModule == null ||
37- project . ngModule . length < 2 ) {
32+ const { rootModule} = project ;
33+
34+ const none = ( identifier : string ) => identifier == null || identifier . length === 0 ;
35+
36+ if ( rootModule == null || none ( rootModule . source ) || none ( rootModule . symbol ) ) {
3837 throw new CompilerException ( 'Compiler requires a module ID and an export name in ngModule' ) ;
3938 }
4039 }
@@ -44,23 +43,23 @@ export class Compiler {
4443 try {
4544 await this . compileToVm ( vm ) ;
4645
47- const [ moduleId , exported ] = this . project . ngModule ;
46+ const { source , symbol } = this . project . rootModule ;
4847
49- const requiredModule = vm . require ( `${ moduleId } .ngfactory` ) ; // use the compiled template, not the jit version
48+ const requiredModule = vm . require ( `${ source } .ngfactory` ) ; // use the compiled template, not the jit version
5049 if ( requiredModule == null ) {
51- throw new CompilerException ( `Attempted to require ${ moduleId } .ngfactory but received a null or undefined object` ) ;
50+ throw new CompilerException ( `Attempted to load ${ source } .ngfactory but received a null or undefined object` ) ;
5251 }
5352
54- const rootModule =
55- ! exported
56- ? requiredModule
57- : requiredModule [ exported ] ;
53+ const factorySymbol =
54+ / N g F a c t o r y $ / . test ( symbol ) === false
55+ ? ` ${ symbol } NgFactory`
56+ : ` ${ symbol } ` ;
5857
59- if ( Reflector . decorated ( rootModule , NgModule ) === false ) {
60- throw new CompilerException ( `Root module type ${ rootModule . name } is not decorated with @NgModule ` ) ;
58+ if ( requiredModule . hasOwnProperty ( factorySymbol ) === false ) {
59+ throw new CompilerException ( `Module ${ source } does not export a ${ factorySymbol } symbol ` ) ;
6160 }
6261
63- return rootModule ;
62+ return requiredModule [ factorySymbol ] ;
6463 }
6564 finally {
6665 vm . dispose ( ) ;
0 commit comments