Skip to content

Commit 6ad0f2d

Browse files
filipesilvawKoza
authored andcommitted
1 parent 71c4afa commit 6ad0f2d

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

packages/core/src/linker/system_js_ng_module_factory_loader.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99

1010
import {Injectable, Optional} from '../di';
11+
import {ivyEnabled} from '../ivy_switch';
1112

1213
import {Compiler} from './compiler';
1314
import {NgModuleFactory} from './ng_module_factory';
@@ -56,8 +57,8 @@ export class SystemJsNgModuleLoader implements NgModuleFactoryLoader {
5657
}
5758

5859
load(path: string): Promise<NgModuleFactory<any>> {
59-
const offlineMode = this._compiler instanceof Compiler;
60-
return offlineMode ? this.loadFactory(path) : this.loadAndCompile(path);
60+
const legacyOfflineMode = !ivyEnabled && this._compiler instanceof Compiler;
61+
return legacyOfflineMode ? this.loadFactory(path) : this.loadAndCompile(path);
6162
}
6263

6364
private loadAndCompile(path: string): Promise<NgModuleFactory<any>> {

packages/core/test/linker/system_ng_module_factory_loader_spec.ts

+27-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {Compiler, SystemJsNgModuleLoader} from '@angular/core';
1010
import {global} from '@angular/core/src/util/global';
1111
import {async} from '@angular/core/testing';
1212
import {afterEach, beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
13+
import {modifiedInIvy, onlyInIvy} from '@angular/private/testing';
1314

1415
function mockSystem(modules: {[module: string]: any}) {
1516
return {
@@ -20,9 +21,9 @@ function mockSystem(modules: {[module: string]: any}) {
2021
};
2122
}
2223

23-
{
24-
describe('SystemJsNgModuleLoader', () => {
25-
let oldSystem: any = null;
24+
describe('SystemJsNgModuleLoader', () => {
25+
let oldSystem: any = null;
26+
modifiedInIvy('only loads ngfactory shims in View Engine').describe('(View Engine)', () => {
2627
beforeEach(() => {
2728
oldSystem = global['System'];
2829
global['System'] = mockSystem({
@@ -54,4 +55,26 @@ function mockSystem(modules: {[module: string]: any}) {
5455
});
5556
}));
5657
});
57-
}
58+
59+
onlyInIvy('loads modules directly in Ivy').describe('(Ivy)', () => {
60+
beforeEach(() => {
61+
oldSystem = global['System'];
62+
global['System'] = mockSystem({
63+
'test': {'default': 'test module', 'NamedModule': 'test NamedModule'},
64+
});
65+
});
66+
afterEach(() => { global['System'] = oldSystem; });
67+
68+
it('loads a default module', async(() => {
69+
const loader = new SystemJsNgModuleLoader(new Compiler());
70+
loader.load('test').then(
71+
contents => { expect(contents.moduleType).toBe('test module' as any); });
72+
}));
73+
it('loads a named module', async(() => {
74+
const loader = new SystemJsNgModuleLoader(new Compiler());
75+
loader.load('test#NamedModule').then(contents => {
76+
expect(contents.moduleType).toBe('test NamedModule' as any);
77+
});
78+
}));
79+
});
80+
});

0 commit comments

Comments
 (0)