Skip to content

Commit d26a827

Browse files
hanslmprobst
authored andcommitted
fix(lazy-loading): fix an issue with webpack and lazy loader. (#11387)
The issue was introduced in PR#11049.
1 parent ea95c39 commit d26a827

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

modules/@angular/core/src/linker/system_js_ng_module_factory_loader.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,7 @@ const DEFAULT_CONFIG: SystemJsNgModuleLoaderConfig = {
4848
export class SystemJsNgModuleLoader implements NgModuleFactoryLoader {
4949
private _config: SystemJsNgModuleLoaderConfig;
5050

51-
/**
52-
* @internal
53-
*/
54-
_system: any;
55-
5651
constructor(private _compiler: Compiler, @Optional() config?: SystemJsNgModuleLoaderConfig) {
57-
this._system = () => System;
5852
this._config = config || DEFAULT_CONFIG;
5953
}
6054

@@ -67,8 +61,7 @@ export class SystemJsNgModuleLoader implements NgModuleFactoryLoader {
6761
let [module, exportName] = path.split(_SEPARATOR);
6862
if (exportName === undefined) exportName = 'default';
6963

70-
return this._system()
71-
.import(module)
64+
return System.import(module)
7265
.then((module: any) => module[exportName])
7366
.then((type: any) => checkNotEmpty(type, module, exportName))
7467
.then((type: any) => this._compiler.compileModuleAsync(type));
@@ -82,8 +75,7 @@ export class SystemJsNgModuleLoader implements NgModuleFactoryLoader {
8275
factoryClassSuffix = '';
8376
}
8477

85-
return this._system()
86-
.import(this._config.factoryPathPrefix + module + this._config.factoryPathSuffix)
78+
return System.import(this._config.factoryPathPrefix + module + this._config.factoryPathSuffix)
8779
.then((module: any) => module[exportName + factoryClassSuffix])
8880
.then((factory: any) => checkNotEmpty(factory, module, exportName));
8981
}

modules/@angular/core/test/linker/system_ng_module_factory_loader_spec.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,48 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {global} from '@angular/common/src/facade/lang';
910
import {Compiler, SystemJsNgModuleLoader} from '@angular/core';
1011
import {async, tick} from '@angular/core/testing';
11-
import {beforeEach, ddescribe, describe, expect, iit, it, xit} from '@angular/core/testing/testing_internal';
12+
import {afterEach, beforeEach, describe, expect, it} from '@angular/core/testing/testing_internal';
1213

13-
function mockSystem(module: string, contents: any) {
14+
function mockSystem(modules: {[module: string]: any}) {
1415
return {
1516
'import': (target: string) => {
16-
expect(target).toBe(module);
17-
return Promise.resolve(contents);
17+
expect(modules[target]).not.toBe(undefined);
18+
return Promise.resolve(modules[target]);
1819
}
1920
};
2021
}
2122

2223
export function main() {
2324
describe('SystemJsNgModuleLoader', () => {
25+
let oldSystem: any = null;
26+
beforeEach(() => {
27+
oldSystem = (global as any).System;
28+
(global as any).System = mockSystem({
29+
'test.ngfactory':
30+
{'default': 'test module factory', 'NamedNgFactory': 'test NamedNgFactory'},
31+
'prefixed/test/suffixed': {'NamedNgFactory': 'test module factory'}
32+
});
33+
});
34+
afterEach(() => { (global as any).System = oldSystem; });
35+
2436
it('loads a default factory by appending the factory suffix', async(() => {
2537
let loader = new SystemJsNgModuleLoader(new Compiler());
26-
loader._system = () => mockSystem('test.ngfactory', {'default': 'test module factory'});
2738
loader.load('test').then(contents => { expect(contents).toBe('test module factory'); });
2839
}));
2940
it('loads a named factory by appending the factory suffix', async(() => {
3041
let loader = new SystemJsNgModuleLoader(new Compiler());
31-
loader._system = () =>
32-
mockSystem('test.ngfactory', {'NamedNgFactory': 'test module factory'});
3342
loader.load('test#Named').then(contents => {
34-
expect(contents).toBe('test module factory');
43+
expect(contents).toBe('test NamedNgFactory');
3544
});
3645
}));
3746
it('loads a named factory with a configured prefix and suffix', async(() => {
3847
let loader = new SystemJsNgModuleLoader(new Compiler(), {
3948
factoryPathPrefix: 'prefixed/',
4049
factoryPathSuffix: '/suffixed',
4150
});
42-
loader._system = () =>
43-
mockSystem('prefixed/test/suffixed', {'NamedNgFactory': 'test module factory'});
4451
loader.load('test#Named').then(contents => {
4552
expect(contents).toBe('test module factory');
4653
});

0 commit comments

Comments
 (0)