
BREAKING CHANGE: Exceptions are no longer part of the public API. We don't expect that anyone should be referring to the Exception types. ExceptionHandler.call(exception: any, stackTrace?: any, reason?: string): void; change to: ErrorHandler.handleError(error: any): void;
123 lines
3.1 KiB
TypeScript
123 lines
3.1 KiB
TypeScript
/**
|
|
* @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<any>) {
|
|
super(`Can't compile synchronously as ${stringify(compType)} is still being loaded!`);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Combination of NgModuleFactory and ComponentFactorys.
|
|
*
|
|
* @experimental
|
|
*/
|
|
export class ModuleWithComponentFactories<T> {
|
|
constructor(
|
|
public ngModuleFactory: NgModuleFactory<T>,
|
|
public componentFactories: ComponentFactory<any>[]) {}
|
|
}
|
|
|
|
|
|
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<T>(moduleType: Type<T>): NgModuleFactory<T> { throw _throwError(); }
|
|
|
|
/**
|
|
* Compiles the given NgModule and all of its components
|
|
*/
|
|
compileModuleAsync<T>(moduleType: Type<T>): Promise<NgModuleFactory<T>> { throw _throwError(); }
|
|
|
|
/**
|
|
* Same as {@link compileModuleSync} put also creates ComponentFactories for all components.
|
|
*/
|
|
compileModuleAndAllComponentsSync<T>(moduleType: Type<T>): ModuleWithComponentFactories<T> {
|
|
throw _throwError();
|
|
}
|
|
|
|
/**
|
|
* Same as {@link compileModuleAsync} put also creates ComponentFactories for all components.
|
|
*/
|
|
compileModuleAndAllComponentsAsync<T>(moduleType: Type<T>):
|
|
Promise<ModuleWithComponentFactories<T>> {
|
|
throw _throwError();
|
|
}
|
|
|
|
/**
|
|
* Clears all caches
|
|
*/
|
|
clearCache(): void {}
|
|
|
|
/**
|
|
* Clears the cache for the given component/ngModule.
|
|
*/
|
|
clearCacheFor(type: Type<any>) {}
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|