fix(ivy): don't load factories when using Ivy (#28685)
Related to https://github.com/angular/angular/pull/26947/files#r251221208 Related to angular/angular-cli#13524 PR Close #28685
This commit is contained in:
parent
b0578061ce
commit
bc6c671e6b
|
@ -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<NgModuleFactory<any>> {
|
||||
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<NgModuleFactory<any>> {
|
||||
|
|
|
@ -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;
|
||||
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);
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue