diff --git a/packages/core/src/linker/system_js_ng_module_factory_loader.ts b/packages/core/src/linker/system_js_ng_module_factory_loader.ts index 5168a8ce67..db9d2455c5 100644 --- a/packages/core/src/linker/system_js_ng_module_factory_loader.ts +++ b/packages/core/src/linker/system_js_ng_module_factory_loader.ts @@ -8,6 +8,7 @@ import {Injectable, Optional} from '../di'; +import {ivyEnabled} from '../ivy_switch'; import {Compiler} from './compiler'; import {NgModuleFactory} from './ng_module_factory'; @@ -56,8 +57,8 @@ export class SystemJsNgModuleLoader implements NgModuleFactoryLoader { } load(path: string): Promise> { - const offlineMode = this._compiler instanceof Compiler; - return offlineMode ? this.loadFactory(path) : this.loadAndCompile(path); + const legacyOfflineMode = !ivyEnabled && this._compiler instanceof Compiler; + return legacyOfflineMode ? this.loadFactory(path) : this.loadAndCompile(path); } private loadAndCompile(path: string): Promise> { diff --git a/packages/core/test/linker/system_ng_module_factory_loader_spec.ts b/packages/core/test/linker/system_ng_module_factory_loader_spec.ts index ceb031c251..b4baf714f9 100644 --- a/packages/core/test/linker/system_ng_module_factory_loader_spec.ts +++ b/packages/core/test/linker/system_ng_module_factory_loader_spec.ts @@ -10,6 +10,7 @@ import {Compiler, SystemJsNgModuleLoader} from '@angular/core'; import {global} from '@angular/core/src/util/global'; import {async} from '@angular/core/testing'; import {afterEach, beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal'; +import {modifiedInIvy, onlyInIvy} from '@angular/private/testing'; function mockSystem(modules: {[module: string]: any}) { return { @@ -20,9 +21,9 @@ function mockSystem(modules: {[module: string]: any}) { }; } -{ - describe('SystemJsNgModuleLoader', () => { - let oldSystem: any = null; +describe('SystemJsNgModuleLoader', () => { + let oldSystem: any = null; + modifiedInIvy('only loads ngfactory shims in View Engine').describe('(View Engine)', () => { beforeEach(() => { oldSystem = global['System']; global['System'] = mockSystem({ @@ -54,4 +55,26 @@ function mockSystem(modules: {[module: string]: any}) { }); })); }); -} + + onlyInIvy('loads modules directly in Ivy').describe('(Ivy)', () => { + beforeEach(() => { + oldSystem = global['System']; + global['System'] = mockSystem({ + 'test': {'default': 'test module', 'NamedModule': 'test NamedModule'}, + }); + }); + afterEach(() => { global['System'] = oldSystem; }); + + it('loads a default module', async(() => { + const loader = new SystemJsNgModuleLoader(new Compiler()); + loader.load('test').then( + contents => { expect(contents.moduleType).toBe('test module' as any); }); + })); + it('loads a named module', async(() => { + const loader = new SystemJsNgModuleLoader(new Compiler()); + loader.load('test#NamedModule').then(contents => { + expect(contents.moduleType).toBe('test NamedModule' as any); + }); + })); + }); +});