/** * @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 */ import {OpaqueToken} from '../di'; import {BaseError} from '../facade/errors'; import {stringify} from '../facade/lang'; import {ViewEncapsulation} from '../metadata'; import {Type} from '../type'; import {ComponentFactory} from './component_factory'; import {NgModuleFactory} from './ng_module_factory'; /** * Indicates that a component is still being loaded in a synchronous compile. * * @stable */ export class ComponentStillLoadingError extends BaseError { constructor(public compType: Type) { super(`Can't compile synchronously as ${stringify(compType)} is still being loaded!`); } } /** * Combination of NgModuleFactory and ComponentFactorys. * * @experimental */ export class ModuleWithComponentFactories { constructor( public ngModuleFactory: NgModuleFactory, public componentFactories: ComponentFactory[]) {} } function _throwError() { throw new Error(`Runtime compiler is not loaded`); } /** * Low-level service for running the angular compiler during runtime * to create {@link ComponentFactory}s, which * can later be used to create and render a Component instance. * * Each `@NgModule` provides an own `Compiler` to its injector, * that will use the directives/pipes of the ng module for compilation * of components. * @stable */ export class Compiler { /** * Compiles the given NgModule and all of its components. All templates of the components listed * in `entryComponents` * have to be inlined. Otherwise throws a {@link ComponentStillLoadingError}. */ compileModuleSync(moduleType: Type): NgModuleFactory { throw _throwError(); } /** * Compiles the given NgModule and all of its components */ compileModuleAsync(moduleType: Type): Promise> { throw _throwError(); } /** * Same as {@link compileModuleSync} put also creates ComponentFactories for all components. */ compileModuleAndAllComponentsSync(moduleType: Type): ModuleWithComponentFactories { throw _throwError(); } /** * Same as {@link compileModuleAsync} put also creates ComponentFactories for all components. */ compileModuleAndAllComponentsAsync(moduleType: Type): Promise> { throw _throwError(); } /** * Clears all caches */ clearCache(): void {} /** * Clears the cache for the given component/ngModule. */ clearCacheFor(type: Type) {} } /** * Options for creating a compiler * * @experimental */ export type CompilerOptions = { useDebug?: boolean, useJit?: boolean, defaultEncapsulation?: ViewEncapsulation, providers?: any[], }; /** * Token to provide CompilerOptions in the platform injector. * * @experimental */ export const COMPILER_OPTIONS = new OpaqueToken('compilerOptions'); /** * A factory for creating a Compiler * * @experimental */ export abstract class CompilerFactory { abstract createCompiler(options?: CompilerOptions[]): Compiler; }