2016-06-24 08:46:43 -07:00
|
|
|
/**
|
|
|
|
|
* @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
|
|
|
|
|
*/
|
|
|
|
|
|
2017-01-03 16:54:46 -08:00
|
|
|
import {Injectable, InjectionToken} from '../di';
|
2017-01-25 23:26:49 -08:00
|
|
|
import {MissingTranslationStrategy} from '../i18n/tokens';
|
2016-08-10 18:21:28 -07:00
|
|
|
import {ViewEncapsulation} from '../metadata';
|
|
|
|
|
import {Type} from '../type';
|
2016-06-24 08:46:43 -07:00
|
|
|
|
|
|
|
|
import {ComponentFactory} from './component_factory';
|
2016-07-18 03:50:31 -07:00
|
|
|
import {NgModuleFactory} from './ng_module_factory';
|
2016-06-24 08:46:43 -07:00
|
|
|
|
2016-07-28 04:54:49 -07:00
|
|
|
/**
|
|
|
|
|
* Combination of NgModuleFactory and ComponentFactorys.
|
|
|
|
|
*
|
|
|
|
|
* @experimental
|
|
|
|
|
*/
|
|
|
|
|
export class ModuleWithComponentFactories<T> {
|
|
|
|
|
constructor(
|
|
|
|
|
public ngModuleFactory: NgModuleFactory<T>,
|
|
|
|
|
public componentFactories: ComponentFactory<any>[]) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _throwError() {
|
2016-08-25 00:50:16 -07:00
|
|
|
throw new Error(`Runtime compiler is not loaded`);
|
2016-07-28 04:54:49 -07:00
|
|
|
}
|
|
|
|
|
|
2016-06-24 08:46:43 -07:00
|
|
|
/**
|
2016-08-19 13:51:45 -07:00
|
|
|
* Low-level service for running the angular compiler during runtime
|
2016-06-24 08:46:43 -07:00
|
|
|
* to create {@link ComponentFactory}s, which
|
|
|
|
|
* can later be used to create and render a Component instance.
|
2016-06-30 13:07:17 -07:00
|
|
|
*
|
2016-07-18 03:50:31 -07:00
|
|
|
* Each `@NgModule` provides an own `Compiler` to its injector,
|
|
|
|
|
* that will use the directives/pipes of the ng module for compilation
|
2016-06-30 13:07:17 -07:00
|
|
|
* of components.
|
2016-06-24 08:46:43 -07:00
|
|
|
* @stable
|
|
|
|
|
*/
|
2016-12-15 09:12:40 -08:00
|
|
|
@Injectable()
|
2016-06-24 08:46:43 -07:00
|
|
|
export class Compiler {
|
2016-06-28 09:54:42 -07:00
|
|
|
/**
|
2016-07-28 04:54:49 -07:00
|
|
|
* Compiles the given NgModule and all of its components. All templates of the components listed
|
2017-01-27 13:19:00 -08:00
|
|
|
* in `entryComponents` have to be inlined.
|
2016-06-28 09:54:42 -07:00
|
|
|
*/
|
2016-08-10 18:21:28 -07:00
|
|
|
compileModuleSync<T>(moduleType: Type<T>): NgModuleFactory<T> { throw _throwError(); }
|
2016-07-28 04:54:49 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Compiles the given NgModule and all of its components
|
|
|
|
|
*/
|
2016-08-10 18:21:28 -07:00
|
|
|
compileModuleAsync<T>(moduleType: Type<T>): Promise<NgModuleFactory<T>> { throw _throwError(); }
|
2016-06-28 09:54:42 -07:00
|
|
|
|
2016-07-28 04:54:49 -07:00
|
|
|
/**
|
2016-09-05 21:37:21 +08:00
|
|
|
* Same as {@link compileModuleSync} but also creates ComponentFactories for all components.
|
2016-07-28 04:54:49 -07:00
|
|
|
*/
|
2016-08-10 18:21:28 -07:00
|
|
|
compileModuleAndAllComponentsSync<T>(moduleType: Type<T>): ModuleWithComponentFactories<T> {
|
2016-07-28 04:54:49 -07:00
|
|
|
throw _throwError();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-09-05 21:37:21 +08:00
|
|
|
* Same as {@link compileModuleAsync} but also creates ComponentFactories for all components.
|
2016-07-28 04:54:49 -07:00
|
|
|
*/
|
2016-08-10 18:21:28 -07:00
|
|
|
compileModuleAndAllComponentsAsync<T>(moduleType: Type<T>):
|
2016-07-28 04:54:49 -07:00
|
|
|
Promise<ModuleWithComponentFactories<T>> {
|
|
|
|
|
throw _throwError();
|
2016-06-28 09:54:42 -07:00
|
|
|
}
|
|
|
|
|
|
2016-11-02 22:38:00 +00:00
|
|
|
/**
|
|
|
|
|
* Exposes the CSS-style selectors that have been used in `ngContent` directives within
|
|
|
|
|
* the template of the given component.
|
|
|
|
|
* This is used by the `upgrade` library to compile the appropriate transclude content
|
2017-01-26 22:30:42 -08:00
|
|
|
* in the AngularJS wrapper component.
|
2016-11-02 22:38:00 +00:00
|
|
|
*/
|
|
|
|
|
getNgContentSelectors(component: Type<any>): string[] { throw _throwError(); }
|
|
|
|
|
|
2016-06-24 08:46:43 -07:00
|
|
|
/**
|
2016-09-05 21:37:21 +08:00
|
|
|
* Clears all caches.
|
2016-06-24 08:46:43 -07:00
|
|
|
*/
|
|
|
|
|
clearCache(): void {}
|
2016-06-28 09:54:42 -07:00
|
|
|
|
2016-06-24 08:46:43 -07:00
|
|
|
/**
|
2016-07-18 03:50:31 -07:00
|
|
|
* Clears the cache for the given component/ngModule.
|
2016-06-24 08:46:43 -07:00
|
|
|
*/
|
2016-08-10 18:21:28 -07:00
|
|
|
clearCacheFor(type: Type<any>) {}
|
2016-06-24 08:46:43 -07:00
|
|
|
}
|
2016-07-08 10:47:17 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Options for creating a compiler
|
|
|
|
|
*
|
|
|
|
|
* @experimental
|
|
|
|
|
*/
|
|
|
|
|
export type CompilerOptions = {
|
|
|
|
|
useDebug?: boolean,
|
|
|
|
|
useJit?: boolean,
|
|
|
|
|
defaultEncapsulation?: ViewEncapsulation,
|
|
|
|
|
providers?: any[],
|
2017-01-25 23:26:49 -08:00
|
|
|
missingTranslation?: MissingTranslationStrategy,
|
2017-01-10 19:07:03 -08:00
|
|
|
// Whether to support the `<template>` tag and the `template` attribute to define angular
|
|
|
|
|
// templates. They have been deprecated in 4.x, `<ng-template>` should be used instead.
|
|
|
|
|
enableLegacyTemplate?: boolean,
|
2016-07-18 03:50:31 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Token to provide CompilerOptions in the platform injector.
|
|
|
|
|
*
|
|
|
|
|
* @experimental
|
|
|
|
|
*/
|
2017-01-03 16:54:46 -08:00
|
|
|
export const COMPILER_OPTIONS = new InjectionToken<CompilerOptions[]>('compilerOptions');
|
2016-07-08 10:47:17 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A factory for creating a Compiler
|
|
|
|
|
*
|
|
|
|
|
* @experimental
|
|
|
|
|
*/
|
|
|
|
|
export abstract class CompilerFactory {
|
2016-07-18 03:50:31 -07:00
|
|
|
abstract createCompiler(options?: CompilerOptions[]): Compiler;
|
2016-07-08 10:47:17 -07:00
|
|
|
}
|