/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
/**
* @module
* @description
* Entry point for all APIs of the compiler package.
*
*
*
*
* All compiler apis are currently considered experimental and private!
*
*
* We expect the APIs in this package to keep on changing. Do not rely on them.
*
*
*/
export * from './schema_registry_mock';
export * from './directive_resolver_mock';
export * from './ng_module_resolver_mock';
export * from './pipe_resolver_mock';
import {createPlatformFactory, ModuleWithComponentFactories, Injectable, CompilerOptions, COMPILER_OPTIONS, CompilerFactory, NgModuleFactory, Injector, NgModule, Component, Directive, Pipe, Type, PlatformRef} from '@angular/core';
import {MetadataOverride} from '@angular/core/testing';
import {TestingCompilerFactory, TestingCompiler} from './private_import_core';
import {platformCoreDynamic, JitCompiler, DirectiveResolver, NgModuleResolver, PipeResolver} from '@angular/compiler';
import {MockDirectiveResolver} from './directive_resolver_mock';
import {MockNgModuleResolver} from './ng_module_resolver_mock';
import {MockPipeResolver} from './pipe_resolver_mock';
import {MetadataOverrider} from './metadata_overrider';
@Injectable()
export class TestingCompilerFactoryImpl implements TestingCompilerFactory {
constructor(private _compilerFactory: CompilerFactory) {}
createTestingCompiler(options: CompilerOptions[]): TestingCompiler {
const compiler = this._compilerFactory.createCompiler(options);
return new TestingCompilerImpl(
compiler, compiler.injector.get(MockDirectiveResolver),
compiler.injector.get(MockPipeResolver), compiler.injector.get(MockNgModuleResolver));
}
}
export class TestingCompilerImpl implements TestingCompiler {
private _overrider = new MetadataOverrider();
constructor(
private _compiler: JitCompiler, private _directiveResolver: MockDirectiveResolver,
private _pipeResolver: MockPipeResolver, private _moduleResolver: MockNgModuleResolver) {}
get injector(): Injector { return this._compiler.injector; }
compileModuleSync(moduleType: Type): NgModuleFactory {
return this._compiler.compileModuleSync(moduleType);
}
compileModuleAsync(moduleType: Type): Promise> {
return this._compiler.compileModuleAsync(moduleType);
}
compileModuleAndAllComponentsSync(moduleType: Type): ModuleWithComponentFactories {
return this._compiler.compileModuleAndAllComponentsSync(moduleType);
}
compileModuleAndAllComponentsAsync(moduleType: Type):
Promise> {
return this._compiler.compileModuleAndAllComponentsAsync(moduleType);
}
getNgContentSelectors(component: Type): string[] {
return this._compiler.getNgContentSelectors(component);
}
overrideModule(ngModule: Type, override: MetadataOverride): void {
const oldMetadata = this._moduleResolver.resolve(ngModule, false);
this._moduleResolver.setNgModule(
ngModule, this._overrider.overrideMetadata(NgModule, oldMetadata, override));
}
overrideDirective(directive: Type, override: MetadataOverride): void {
const oldMetadata = this._directiveResolver.resolve(directive, false);
this._directiveResolver.setDirective(
directive, this._overrider.overrideMetadata(Directive, oldMetadata, override));
}
overrideComponent(component: Type, override: MetadataOverride): void {
const oldMetadata = this._directiveResolver.resolve(component, false);
this._directiveResolver.setDirective(
component, this._overrider.overrideMetadata(Component, oldMetadata, override));
}
overridePipe(pipe: Type, override: MetadataOverride): void {
const oldMetadata = this._pipeResolver.resolve(pipe, false);
this._pipeResolver.setPipe(pipe, this._overrider.overrideMetadata(Pipe, oldMetadata, override));
}
clearCache(): void { this._compiler.clearCache(); }
clearCacheFor(type: Type) { this._compiler.clearCacheFor(type); }
}
/**
* Platform for dynamic tests
*
* @experimental
*/
export const platformCoreDynamicTesting: (extraProviders?: any[]) => PlatformRef =
createPlatformFactory(platformCoreDynamic, 'coreDynamicTesting', [
{
provide: COMPILER_OPTIONS,
useValue: {
providers: [
MockPipeResolver, {provide: PipeResolver, useExisting: MockPipeResolver},
MockDirectiveResolver, {provide: DirectiveResolver, useExisting: MockDirectiveResolver},
MockNgModuleResolver, {provide: NgModuleResolver, useExisting: MockNgModuleResolver}
]
},
multi: true
},
{provide: TestingCompilerFactory, useClass: TestingCompilerFactoryImpl}
]);