BREAKING CHANGE: previously deprecated @Component.directives and @Component.pipes support was removed. All the components and pipes now must be declarated via an NgModule. NgModule is the basic compilation block passed into the Angular compiler via Compiler#compileModuleSync or #compileModuleAsync. Because of this change, the Compiler#compileComponentAsync and #compileComponentSync were removed as well - any code doing compilation should compile module instead using the apis mentioned above. Lastly, since modules are the basic compilation unit, the ngUpgrade module was modified to always require an NgModule to be passed into the UpgradeAdapter's constructor - previously this was optional.
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 {BaseException} from '../facade/exceptions';
|
|
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 BaseException {
|
|
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 BaseException(`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;
|
|
}
|