2016-06-23 09:47:54 -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
* /
feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead. This reflects the
changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
`configureModule` and can no longer be provided via the
`PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and
now takes a `PlatformRef` and a factory for a
`Compiler`.
- E.g. for the browser platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
```
AFTER:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {browserTestCompiler, browserDynamicTestPlatform,
BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
browserTestCompiler,
browserDynamicTestPlatform(),
BrowserDynamicTestModule);
```
- E.g. for the server platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS);
```
AFTER:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {serverTestCompiler, serverTestPlatform,
ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
serverTestCompiler,
serverTestPlatform(),
ServerTestModule);
```
Related to #9726
Closes #9846
2016-07-04 09:37:30 -07:00
import { AppModuleFactory , AppModuleMetadata , Compiler , ComponentFactory , ComponentResolver , ComponentStillLoadingError , Injectable , Injector , OptionalMetadata , Provider , SkipSelfMetadata } from '@angular/core' ;
2016-07-08 13:40:54 -07:00
import { Console } from '../core_private' ;
2016-06-08 16:38:52 -07:00
2016-04-28 17:50:03 -07:00
import { BaseException } from '../src/facade/exceptions' ;
2016-06-24 08:46:43 -07:00
import { ConcreteType , IS_DART , Type , isBlank , isString , stringify } from '../src/facade/lang' ;
2016-06-08 16:38:52 -07:00
import { ListWrapper , } from '../src/facade/collection' ;
2016-04-28 17:50:03 -07:00
import { PromiseWrapper } from '../src/facade/async' ;
2016-06-08 16:38:52 -07:00
import { createHostComponentMeta , CompileDirectiveMetadata , CompilePipeMetadata , CompileIdentifierMetadata } from './compile_metadata' ;
import { TemplateAst , } from './template_ast' ;
2016-06-24 08:46:43 -07:00
import { StyleCompiler , StylesCompileDependency , CompiledStylesheet } from './style_compiler' ;
import { ViewCompiler , ViewCompileResult , ViewFactoryDependency , ComponentFactoryDependency } from './view_compiler/view_compiler' ;
2016-06-28 09:54:42 -07:00
import { AppModuleCompiler } from './app_module_compiler' ;
2016-01-06 14:13:44 -08:00
import { TemplateParser } from './template_parser' ;
2016-06-28 09:54:42 -07:00
import { DirectiveNormalizer } from './directive_normalizer' ;
2016-02-18 10:53:21 -08:00
import { CompileMetadataResolver } from './metadata_resolver' ;
2016-01-06 14:13:44 -08:00
import { CompilerConfig } from './config' ;
import * as ir from './output/output_ast' ;
import { jitStatements } from './output/output_jit' ;
import { interpretStatements } from './output/output_interpreter' ;
2016-06-28 09:54:42 -07:00
import { SyncAsyncResult } from './util' ;
2015-10-06 06:53:39 -07:00
2016-01-06 14:13:44 -08:00
/ * *
* An internal module of the Angular compiler that begins with component types ,
* extracts templates , and eventually produces a compiled version of the component
* ready for linking into an application .
2016-06-28 11:01:35 -07:00
*
* @security When compiling templates at runtime , you must ensure that the entire template comes
* from a trusted source . Attacker - controlled data introduced by a template could expose your
* application to XSS risks . For more detail , see the [ Security Guide ] ( http : //g.co/ng/security).
2016-01-06 14:13:44 -08:00
* /
2015-10-01 10:07:49 -07:00
@Injectable ( )
2016-06-24 08:46:43 -07:00
export class RuntimeCompiler implements ComponentResolver , Compiler {
2016-06-28 09:54:42 -07:00
private _compiledTemplateCache = new Map < Type , CompiledTemplate > ( ) ;
private _compiledHostTemplateCache = new Map < Type , CompiledTemplate > ( ) ;
private _compiledAppModuleCache = new Map < Type , AppModuleFactory < any > > ( ) ;
2016-01-06 14:13:44 -08:00
2016-07-08 13:40:54 -07:00
private _warnOnComponentResolver = true ;
2016-06-08 16:38:52 -07:00
constructor (
feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead. This reflects the
changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
`configureModule` and can no longer be provided via the
`PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and
now takes a `PlatformRef` and a factory for a
`Compiler`.
- E.g. for the browser platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
```
AFTER:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {browserTestCompiler, browserDynamicTestPlatform,
BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
browserTestCompiler,
browserDynamicTestPlatform(),
BrowserDynamicTestModule);
```
- E.g. for the server platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS);
```
AFTER:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {serverTestCompiler, serverTestPlatform,
ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
serverTestCompiler,
serverTestPlatform(),
ServerTestModule);
```
Related to #9726
Closes #9846
2016-07-04 09:37:30 -07:00
private _injector : Injector , private _metadataResolver : CompileMetadataResolver ,
2016-06-08 16:38:52 -07:00
private _templateNormalizer : DirectiveNormalizer , private _templateParser : TemplateParser ,
2016-06-24 08:46:43 -07:00
private _styleCompiler : StyleCompiler , private _viewCompiler : ViewCompiler ,
2016-07-08 13:40:54 -07:00
private _appModuleCompiler : AppModuleCompiler , private _genConfig : CompilerConfig ,
private _console : Console ) {
const flatDeprecatedPlatformDirectives =
ListWrapper . flatten ( _genConfig . deprecatedPlatformDirectives ) ;
if ( flatDeprecatedPlatformDirectives . length > 0 ) {
this . _console . warn (
` Providing platform directives via the PLATFORM_DIRECTIVES provider or the "CompilerConfig" is deprecated. Provide platform directives via an @AppModule instead. Directives: ` +
flatDeprecatedPlatformDirectives . map ( stringify ) ) ;
}
const flatDeprecatedPlatformPipes = ListWrapper . flatten ( _genConfig . deprecatedPlatformPipes ) ;
if ( flatDeprecatedPlatformPipes . length > 0 ) {
this . _console . warn (
` Providing platform pipes via the PLATFORM_PIPES provider or the "CompilerConfig" is deprecated. Provide platform pipes via an @AppModule instead. Pipes: ` +
flatDeprecatedPlatformPipes . map ( stringify ) ) ;
}
}
2015-10-01 10:07:49 -07:00
feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead. This reflects the
changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
`configureModule` and can no longer be provided via the
`PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and
now takes a `PlatformRef` and a factory for a
`Compiler`.
- E.g. for the browser platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
```
AFTER:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {browserTestCompiler, browserDynamicTestPlatform,
BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
browserTestCompiler,
browserDynamicTestPlatform(),
BrowserDynamicTestModule);
```
- E.g. for the server platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS);
```
AFTER:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {serverTestCompiler, serverTestPlatform,
ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
serverTestCompiler,
serverTestPlatform(),
ServerTestModule);
```
Related to #9726
Closes #9846
2016-07-04 09:37:30 -07:00
get injector ( ) : Injector { return this . _injector ; }
2016-05-03 16:45:30 -07:00
resolveComponent ( component : Type | string ) : Promise < ComponentFactory < any > > {
if ( isString ( component ) ) {
2016-06-08 16:38:52 -07:00
return PromiseWrapper . reject (
new BaseException ( ` Cannot resolve component using ' ${ component } '. ` ) , null ) ;
2016-05-03 16:45:30 -07:00
}
2016-07-08 13:40:54 -07:00
if ( this . _warnOnComponentResolver ) {
this . _console . warn ( ComponentResolver . DynamicCompilationDeprecationMsg ) ;
this . _warnOnComponentResolver = false ;
}
2016-06-24 08:46:43 -07:00
return this . compileComponentAsync ( < ConcreteType < any > > component ) ;
}
2016-06-28 09:54:42 -07:00
compileAppModuleSync < T > ( moduleType : ConcreteType < T > , metadata : AppModuleMetadata = null ) :
AppModuleFactory < T > {
return this . _compileAppModule ( moduleType , true , metadata ) . syncResult ;
}
compileAppModuleAsync < T > ( moduleType : ConcreteType < T > , metadata : AppModuleMetadata = null ) :
Promise < AppModuleFactory < T > > {
return this . _compileAppModule ( moduleType , false , metadata ) . asyncResult ;
}
private _compileAppModule < T > (
moduleType : ConcreteType < T > , isSync : boolean ,
metadata : AppModuleMetadata = null ) : SyncAsyncResult < AppModuleFactory < T > > {
// Only cache if we read the metadata via the reflector,
// as we use the moduleType as cache key.
let useCache = ! metadata ;
let appModuleFactory = this . _compiledAppModuleCache . get ( moduleType ) ;
let componentCompilePromises : Promise < any > [ ] = [ ] ;
if ( ! appModuleFactory || ! useCache ) {
var compileModuleMeta = this . _metadataResolver . getAppModuleMetadata ( moduleType , metadata ) ;
feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead. This reflects the
changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
`configureModule` and can no longer be provided via the
`PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and
now takes a `PlatformRef` and a factory for a
`Compiler`.
- E.g. for the browser platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
```
AFTER:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {browserTestCompiler, browserDynamicTestPlatform,
BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
browserTestCompiler,
browserDynamicTestPlatform(),
BrowserDynamicTestModule);
```
- E.g. for the server platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS);
```
AFTER:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {serverTestCompiler, serverTestPlatform,
ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
serverTestCompiler,
serverTestPlatform(),
ServerTestModule);
```
Related to #9726
Closes #9846
2016-07-04 09:37:30 -07:00
let boundCompilerFactory = ( parentResolver : ComponentResolver ) = > new BoundCompiler (
feat(browser): use AppModules for bootstrap in the browser
This introduces the `BrowserModule` to be used for long form
bootstrap and offline compile bootstrap:
```
@AppModule({
modules: [BrowserModule],
precompile: [MainComponent],
providers: […], // additional providers
directives: […], // additional platform directives
pipes: […] // additional platform pipes
})
class MyModule {
constructor(appRef: ApplicationRef) {
appRef.bootstrap(MainComponent);
}
}
// offline compile
import {bootstrapModuleFactory} from ‘@angular/platform-browser’;
bootstrapModuleFactory(MyModuleNgFactory);
// runtime compile long form
import {bootstrapModule} from ‘@angular/platform-browser-dynamic’;
bootstrapModule(MyModule);
```
The short form, `bootstrap(...)`, can now creates a module on the fly,
given `directives`, `pipes, `providers`, `precompile` and `modules`
properties.
Related changes:
- make `SanitizationService`, `SecurityContext` public in `@angular/core` so that the offline compiler can resolve the token
- move `AnimationDriver` to `platform-browser` and make it
public so that the offline compiler can resolve the token
BREAKING CHANGES:
- short form bootstrap does no longer allow
to inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead.
To provide custom providers for the compiler,
create a custom compiler via `browserCompiler({providers: [...]})`
and pass that into the `bootstrap` method.
2016-06-30 13:07:17 -07:00
this , compileModuleMeta . directives . map ( dir = > dir . type . runtime ) ,
feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead. This reflects the
changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
`configureModule` and can no longer be provided via the
`PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and
now takes a `PlatformRef` and a factory for a
`Compiler`.
- E.g. for the browser platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
```
AFTER:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {browserTestCompiler, browserDynamicTestPlatform,
BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
browserTestCompiler,
browserDynamicTestPlatform(),
BrowserDynamicTestModule);
```
- E.g. for the server platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS);
```
AFTER:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {serverTestCompiler, serverTestPlatform,
ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
serverTestCompiler,
serverTestPlatform(),
ServerTestModule);
```
Related to #9726
Closes #9846
2016-07-04 09:37:30 -07:00
compileModuleMeta . pipes . map ( ( pipe ) = > pipe . type . runtime ) , parentResolver ) ;
// Always provide a bound Compiler and ComponentResolver
compileModuleMeta . providers . push (
this . _metadataResolver . getProviderMetadata ( new Provider ( Compiler , {
useFactory : boundCompilerFactory ,
deps : [ [ new OptionalMetadata ( ) , new SkipSelfMetadata ( ) , ComponentResolver ] ]
} ) ) ) ;
feat(browser): use AppModules for bootstrap in the browser
This introduces the `BrowserModule` to be used for long form
bootstrap and offline compile bootstrap:
```
@AppModule({
modules: [BrowserModule],
precompile: [MainComponent],
providers: […], // additional providers
directives: […], // additional platform directives
pipes: […] // additional platform pipes
})
class MyModule {
constructor(appRef: ApplicationRef) {
appRef.bootstrap(MainComponent);
}
}
// offline compile
import {bootstrapModuleFactory} from ‘@angular/platform-browser’;
bootstrapModuleFactory(MyModuleNgFactory);
// runtime compile long form
import {bootstrapModule} from ‘@angular/platform-browser-dynamic’;
bootstrapModule(MyModule);
```
The short form, `bootstrap(...)`, can now creates a module on the fly,
given `directives`, `pipes, `providers`, `precompile` and `modules`
properties.
Related changes:
- make `SanitizationService`, `SecurityContext` public in `@angular/core` so that the offline compiler can resolve the token
- move `AnimationDriver` to `platform-browser` and make it
public so that the offline compiler can resolve the token
BREAKING CHANGES:
- short form bootstrap does no longer allow
to inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead.
To provide custom providers for the compiler,
create a custom compiler via `browserCompiler({providers: [...]})`
and pass that into the `bootstrap` method.
2016-06-30 13:07:17 -07:00
compileModuleMeta . providers . push ( this . _metadataResolver . getProviderMetadata (
new Provider ( ComponentResolver , { useExisting : Compiler } ) ) ) ;
2016-06-28 09:54:42 -07:00
var compileResult = this . _appModuleCompiler . compile ( compileModuleMeta ) ;
compileResult . dependencies . forEach ( ( dep ) = > {
let compileResult = this . _compileComponent (
dep . comp . runtime , isSync ,
compileModuleMeta . directives . map ( compileType = > < any > compileType . runtime ) ,
compileModuleMeta . pipes . map ( compileType = > < any > compileType . runtime ) ) ;
dep . placeholder . runtime = compileResult . syncResult ;
componentCompilePromises . push ( compileResult . asyncResult ) ;
dep . placeholder . name = ` compFactory_ ${ dep . comp . name } ` ;
} ) ;
if ( IS_DART || ! this . _genConfig . useJit ) {
appModuleFactory =
interpretStatements ( compileResult . statements , compileResult . appModuleFactoryVar ) ;
} else {
appModuleFactory = jitStatements (
` ${ compileModuleMeta . type . name } .ngfactory.js ` , compileResult . statements ,
compileResult . appModuleFactoryVar ) ;
2016-06-24 08:46:43 -07:00
}
2016-06-28 09:54:42 -07:00
if ( useCache ) {
this . _compiledAppModuleCache . set ( moduleType , appModuleFactory ) ;
}
}
return new SyncAsyncResult (
appModuleFactory , Promise . all ( componentCompilePromises ) . then ( ( ) = > appModuleFactory ) ) ;
2016-06-24 08:46:43 -07:00
}
feat(browser): use AppModules for bootstrap in the browser
This introduces the `BrowserModule` to be used for long form
bootstrap and offline compile bootstrap:
```
@AppModule({
modules: [BrowserModule],
precompile: [MainComponent],
providers: […], // additional providers
directives: […], // additional platform directives
pipes: […] // additional platform pipes
})
class MyModule {
constructor(appRef: ApplicationRef) {
appRef.bootstrap(MainComponent);
}
}
// offline compile
import {bootstrapModuleFactory} from ‘@angular/platform-browser’;
bootstrapModuleFactory(MyModuleNgFactory);
// runtime compile long form
import {bootstrapModule} from ‘@angular/platform-browser-dynamic’;
bootstrapModule(MyModule);
```
The short form, `bootstrap(...)`, can now creates a module on the fly,
given `directives`, `pipes, `providers`, `precompile` and `modules`
properties.
Related changes:
- make `SanitizationService`, `SecurityContext` public in `@angular/core` so that the offline compiler can resolve the token
- move `AnimationDriver` to `platform-browser` and make it
public so that the offline compiler can resolve the token
BREAKING CHANGES:
- short form bootstrap does no longer allow
to inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead.
To provide custom providers for the compiler,
create a custom compiler via `browserCompiler({providers: [...]})`
and pass that into the `bootstrap` method.
2016-06-30 13:07:17 -07:00
compileComponentAsync < T > ( compType : ConcreteType < T > ) : Promise < ComponentFactory < T > > {
return this . _compileComponent ( compType , false , [ ] , [ ] ) . asyncResult ;
2016-06-28 09:54:42 -07:00
}
feat(browser): use AppModules for bootstrap in the browser
This introduces the `BrowserModule` to be used for long form
bootstrap and offline compile bootstrap:
```
@AppModule({
modules: [BrowserModule],
precompile: [MainComponent],
providers: […], // additional providers
directives: […], // additional platform directives
pipes: […] // additional platform pipes
})
class MyModule {
constructor(appRef: ApplicationRef) {
appRef.bootstrap(MainComponent);
}
}
// offline compile
import {bootstrapModuleFactory} from ‘@angular/platform-browser’;
bootstrapModuleFactory(MyModuleNgFactory);
// runtime compile long form
import {bootstrapModule} from ‘@angular/platform-browser-dynamic’;
bootstrapModule(MyModule);
```
The short form, `bootstrap(...)`, can now creates a module on the fly,
given `directives`, `pipes, `providers`, `precompile` and `modules`
properties.
Related changes:
- make `SanitizationService`, `SecurityContext` public in `@angular/core` so that the offline compiler can resolve the token
- move `AnimationDriver` to `platform-browser` and make it
public so that the offline compiler can resolve the token
BREAKING CHANGES:
- short form bootstrap does no longer allow
to inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead.
To provide custom providers for the compiler,
create a custom compiler via `browserCompiler({providers: [...]})`
and pass that into the `bootstrap` method.
2016-06-30 13:07:17 -07:00
compileComponentSync < T > ( compType : ConcreteType < T > ) : ComponentFactory < T > {
return this . _compileComponent ( compType , true , [ ] , [ ] ) . syncResult ;
2016-06-28 09:54:42 -07:00
}
feat(browser): use AppModules for bootstrap in the browser
This introduces the `BrowserModule` to be used for long form
bootstrap and offline compile bootstrap:
```
@AppModule({
modules: [BrowserModule],
precompile: [MainComponent],
providers: […], // additional providers
directives: […], // additional platform directives
pipes: […] // additional platform pipes
})
class MyModule {
constructor(appRef: ApplicationRef) {
appRef.bootstrap(MainComponent);
}
}
// offline compile
import {bootstrapModuleFactory} from ‘@angular/platform-browser’;
bootstrapModuleFactory(MyModuleNgFactory);
// runtime compile long form
import {bootstrapModule} from ‘@angular/platform-browser-dynamic’;
bootstrapModule(MyModule);
```
The short form, `bootstrap(...)`, can now creates a module on the fly,
given `directives`, `pipes, `providers`, `precompile` and `modules`
properties.
Related changes:
- make `SanitizationService`, `SecurityContext` public in `@angular/core` so that the offline compiler can resolve the token
- move `AnimationDriver` to `platform-browser` and make it
public so that the offline compiler can resolve the token
BREAKING CHANGES:
- short form bootstrap does no longer allow
to inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead.
To provide custom providers for the compiler,
create a custom compiler via `browserCompiler({providers: [...]})`
and pass that into the `bootstrap` method.
2016-06-30 13:07:17 -07:00
/ * *
* @internal
* /
_compileComponent < T > (
2016-06-28 09:54:42 -07:00
compType : ConcreteType < T > , isSync : boolean , moduleDirectives : ConcreteType < any > [ ] ,
modulePipes : ConcreteType < any > [ ] ) : SyncAsyncResult < ComponentFactory < T > > {
var templates =
this . _getTransitiveCompiledTemplates ( compType , true , moduleDirectives , modulePipes ) ;
var loadingPromises : Promise < any > [ ] = [ ] ;
2016-06-24 08:46:43 -07:00
templates . forEach ( ( template ) = > {
if ( template . loading ) {
2016-06-28 09:54:42 -07:00
if ( isSync ) {
feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead. This reflects the
changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
`configureModule` and can no longer be provided via the
`PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and
now takes a `PlatformRef` and a factory for a
`Compiler`.
- E.g. for the browser platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
```
AFTER:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {browserTestCompiler, browserDynamicTestPlatform,
BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
browserTestCompiler,
browserDynamicTestPlatform(),
BrowserDynamicTestModule);
```
- E.g. for the server platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS);
```
AFTER:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {serverTestCompiler, serverTestPlatform,
ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
serverTestCompiler,
serverTestPlatform(),
ServerTestModule);
```
Related to #9726
Closes #9846
2016-07-04 09:37:30 -07:00
throw new ComponentStillLoadingError ( template . compType . runtime ) ;
2016-06-28 09:54:42 -07:00
} else {
loadingPromises . push ( template . loading ) ;
}
2016-06-24 08:46:43 -07:00
}
} ) ;
2016-07-13 11:01:32 -07:00
const compile =
( ) = > { templates . forEach ( ( template ) = > { this . _compileTemplate ( template ) ; } ) ; } ;
2016-06-28 09:54:42 -07:00
if ( isSync ) {
compile ( ) ;
}
let result = this . _compiledHostTemplateCache . get ( compType ) . proxyComponentFactory ;
return new SyncAsyncResult ( result , Promise . all ( loadingPromises ) . then ( ( ) = > {
compile ( ) ;
return result ;
} ) ) ;
2016-06-24 08:46:43 -07:00
}
2016-06-28 09:54:42 -07:00
clearCacheFor ( type : Type ) {
this . _compiledAppModuleCache . delete ( type ) ;
this . _metadataResolver . clearCacheFor ( type ) ;
this . _compiledHostTemplateCache . delete ( type ) ;
var compiledTemplate = this . _compiledTemplateCache . get ( type ) ;
2016-06-24 08:46:43 -07:00
if ( compiledTemplate ) {
this . _templateNormalizer . clearCacheFor ( compiledTemplate . normalizedCompMeta ) ;
2016-06-28 09:54:42 -07:00
this . _compiledTemplateCache . delete ( type ) ;
2016-06-24 08:46:43 -07:00
}
2016-06-22 14:06:23 -07:00
}
clearCache ( ) : void {
2016-06-24 08:46:43 -07:00
this . _metadataResolver . clearCache ( ) ;
2016-06-22 14:06:23 -07:00
this . _compiledTemplateCache . clear ( ) ;
2016-06-24 08:46:43 -07:00
this . _compiledHostTemplateCache . clear ( ) ;
this . _templateNormalizer . clearCache ( ) ;
2016-06-28 09:54:42 -07:00
this . _compiledAppModuleCache . clear ( ) ;
2016-06-22 14:06:23 -07:00
}
2016-05-03 16:45:30 -07:00
2016-06-28 09:54:42 -07:00
private _createCompiledHostTemplate ( type : Type ) : CompiledTemplate {
2016-06-24 08:46:43 -07:00
var compiledTemplate = this . _compiledHostTemplateCache . get ( type ) ;
if ( isBlank ( compiledTemplate ) ) {
var compMeta = this . _metadataResolver . getDirectiveMetadata ( type ) ;
2016-01-06 14:13:44 -08:00
assertComponent ( compMeta ) ;
2016-06-24 08:46:43 -07:00
var hostMeta = createHostComponentMeta ( compMeta . type , compMeta . selector ) ;
compiledTemplate = new CompiledTemplate (
true , compMeta . selector , compMeta . type , [ ] , [ type ] , [ ] , [ ] ,
this . _templateNormalizer . normalizeDirective ( hostMeta ) ) ;
this . _compiledHostTemplateCache . set ( type , compiledTemplate ) ;
2016-01-06 14:13:44 -08:00
}
2016-06-24 08:46:43 -07:00
return compiledTemplate ;
2015-10-01 10:07:49 -07:00
}
2016-06-28 09:54:42 -07:00
private _createCompiledTemplate (
type : Type , moduleDirectives : ConcreteType < any > [ ] ,
modulePipes : ConcreteType < any > [ ] ) : CompiledTemplate {
2016-06-24 08:46:43 -07:00
var compiledTemplate = this . _compiledTemplateCache . get ( type ) ;
2016-01-06 14:13:44 -08:00
if ( isBlank ( compiledTemplate ) ) {
2016-07-13 11:01:32 -07:00
const compMeta = this . _metadataResolver . getDirectiveMetadata ( type ) ;
2016-06-24 08:46:43 -07:00
assertComponent ( compMeta ) ;
2016-07-13 11:01:32 -07:00
const viewDirectives : CompileDirectiveMetadata [ ] = [ ] ;
2016-06-28 09:54:42 -07:00
moduleDirectives . forEach (
( type ) = > viewDirectives . push ( this . _metadataResolver . getDirectiveMetadata ( type ) ) ) ;
2016-07-13 11:01:32 -07:00
const viewComponentTypes : Type [ ] = [ ] ;
2016-06-24 08:46:43 -07:00
this . _metadataResolver . getViewDirectivesMetadata ( type ) . forEach ( dirOrComp = > {
if ( dirOrComp . isComponent ) {
viewComponentTypes . push ( dirOrComp . type . runtime ) ;
} else {
viewDirectives . push ( dirOrComp ) ;
}
} ) ;
2016-07-13 11:01:32 -07:00
const precompileComponentTypes = compMeta . precompile . map ( ( typeMeta ) = > typeMeta . runtime ) ;
const pipes = [
2016-06-28 09:54:42 -07:00
. . . modulePipes . map ( ( type ) = > this . _metadataResolver . getPipeMetadata ( type ) ) ,
. . . this . _metadataResolver . getViewPipesMetadata ( type )
] ;
2016-06-24 08:46:43 -07:00
compiledTemplate = new CompiledTemplate (
false , compMeta . selector , compMeta . type , viewDirectives , viewComponentTypes ,
precompileComponentTypes , pipes , this . _templateNormalizer . normalizeDirective ( compMeta ) ) ;
this . _compiledTemplateCache . set ( type , compiledTemplate ) ;
2016-01-06 14:13:44 -08:00
}
return compiledTemplate ;
}
2016-06-24 08:46:43 -07:00
private _getTransitiveCompiledTemplates (
2016-06-28 09:54:42 -07:00
compType : Type , isHost : boolean , moduleDirectives : ConcreteType < any > [ ] ,
modulePipes : ConcreteType < any > [ ] ,
2016-06-24 08:46:43 -07:00
target : Set < CompiledTemplate > = new Set < CompiledTemplate > ( ) ) : Set < CompiledTemplate > {
2016-07-13 11:01:32 -07:00
const template = isHost ? this . _createCompiledHostTemplate ( compType ) :
this . _createCompiledTemplate ( compType , moduleDirectives , modulePipes ) ;
2016-06-24 08:46:43 -07:00
if ( ! target . has ( template ) ) {
target . add ( template ) ;
2016-06-28 09:54:42 -07:00
template . viewComponentTypes . forEach ( ( compType ) = > {
this . _getTransitiveCompiledTemplates (
compType , false , moduleDirectives , modulePipes , target ) ;
} ) ;
template . precompileHostComponentTypes . forEach ( ( compType ) = > {
this . _getTransitiveCompiledTemplates ( compType , true , moduleDirectives , modulePipes , target ) ;
} ) ;
2016-06-24 08:46:43 -07:00
}
return target ;
}
private _compileTemplate ( template : CompiledTemplate ) {
if ( template . isCompiled ) {
return ;
}
2016-07-13 11:01:32 -07:00
const compMeta = template . normalizedCompMeta ;
const externalStylesheetsByModuleUrl = new Map < string , CompiledStylesheet > ( ) ;
const stylesCompileResult = this . _styleCompiler . compileComponent ( compMeta ) ;
2016-06-24 08:46:43 -07:00
stylesCompileResult . externalStylesheets . forEach (
( r ) = > { externalStylesheetsByModuleUrl . set ( r . meta . moduleUrl , r ) ; } ) ;
this . _resolveStylesCompileResult (
stylesCompileResult . componentStylesheet , externalStylesheetsByModuleUrl ) ;
2016-07-13 11:01:32 -07:00
const viewCompMetas = template . viewComponentTypes . map (
2016-06-28 09:54:42 -07:00
( compType ) = > this . _compiledTemplateCache . get ( compType ) . normalizedCompMeta ) ;
2016-07-13 11:01:32 -07:00
const parsedTemplate = this . _templateParser . parse (
2016-06-24 08:46:43 -07:00
compMeta , compMeta . template . template , template . viewDirectives . concat ( viewCompMetas ) ,
template . viewPipes , compMeta . type . name ) ;
2016-07-13 11:01:32 -07:00
const compileResult = this . _viewCompiler . compileComponent (
2016-06-24 08:46:43 -07:00
compMeta , parsedTemplate , ir . variable ( stylesCompileResult . componentStylesheet . stylesVar ) ,
template . viewPipes ) ;
2016-07-13 11:01:32 -07:00
compileResult . dependencies . forEach ( ( dep ) = > {
2016-06-24 08:46:43 -07:00
let depTemplate : CompiledTemplate ;
2016-06-22 14:06:23 -07:00
if ( dep instanceof ViewFactoryDependency ) {
2016-06-29 10:26:45 -07:00
let vfd = < ViewFactoryDependency > dep ;
2016-06-28 09:54:42 -07:00
depTemplate = this . _compiledTemplateCache . get ( vfd . comp . runtime ) ;
2016-06-29 10:26:45 -07:00
vfd . placeholder . runtime = depTemplate . proxyViewFactory ;
vfd . placeholder . name = ` viewFactory_ ${ vfd . comp . name } ` ;
2016-06-22 14:06:23 -07:00
} else if ( dep instanceof ComponentFactoryDependency ) {
2016-06-29 10:26:45 -07:00
let cfd = < ComponentFactoryDependency > dep ;
2016-06-28 09:54:42 -07:00
depTemplate = this . _compiledHostTemplateCache . get ( cfd . comp . runtime ) ;
2016-06-29 10:26:45 -07:00
cfd . placeholder . runtime = depTemplate . proxyComponentFactory ;
cfd . placeholder . name = ` compFactory_ ${ cfd . comp . name } ` ;
2016-01-06 14:13:44 -08:00
}
} ) ;
2016-07-13 11:01:32 -07:00
const statements =
2016-06-24 08:46:43 -07:00
stylesCompileResult . componentStylesheet . statements . concat ( compileResult . statements ) ;
2016-07-13 11:01:32 -07:00
let factory : any ;
2016-01-06 14:13:44 -08:00
if ( IS_DART || ! this . _genConfig . useJit ) {
2016-06-28 09:54:42 -07:00
factory = interpretStatements ( statements , compileResult . viewFactoryVar ) ;
2016-01-06 14:13:44 -08:00
} else {
2016-06-08 16:38:52 -07:00
factory = jitStatements (
2016-06-28 09:54:42 -07:00
` ${ template . compType . name } .ngfactory.js ` , statements , compileResult . viewFactoryVar ) ;
2016-01-06 14:13:44 -08:00
}
2016-06-24 08:46:43 -07:00
template . compiled ( factory ) ;
2016-01-06 14:13:44 -08:00
}
2016-06-24 08:46:43 -07:00
private _resolveStylesCompileResult (
result : CompiledStylesheet , externalStylesheetsByModuleUrl : Map < string , CompiledStylesheet > ) {
result . dependencies . forEach ( ( dep , i ) = > {
var nestedCompileResult = externalStylesheetsByModuleUrl . get ( dep . moduleUrl ) ;
var nestedStylesArr = this . _resolveAndEvalStylesCompileResult (
nestedCompileResult , externalStylesheetsByModuleUrl ) ;
dep . valuePlaceholder . runtime = nestedStylesArr ;
dep . valuePlaceholder . name = ` importedStyles ${ i } ` ;
} ) ;
2016-01-06 14:13:44 -08:00
}
2016-06-24 08:46:43 -07:00
private _resolveAndEvalStylesCompileResult (
result : CompiledStylesheet ,
externalStylesheetsByModuleUrl : Map < string , CompiledStylesheet > ) : string [ ] {
this . _resolveStylesCompileResult ( result , externalStylesheetsByModuleUrl ) ;
if ( IS_DART || ! this . _genConfig . useJit ) {
2016-06-28 09:54:42 -07:00
return interpretStatements ( result . statements , result . stylesVar ) ;
2016-06-24 08:46:43 -07:00
} else {
return jitStatements ( ` ${ result . meta . moduleUrl } .css.js ` , result . statements , result . stylesVar ) ;
2016-01-06 14:13:44 -08:00
}
2016-06-22 14:06:23 -07:00
}
}
2016-01-06 14:13:44 -08:00
class CompiledTemplate {
2016-06-22 14:06:23 -07:00
private _viewFactory : Function = null ;
2016-01-06 14:13:44 -08:00
proxyViewFactory : Function ;
2016-06-24 08:46:43 -07:00
proxyComponentFactory : ComponentFactory < any > ;
loading : Promise < any > = null ;
private _normalizedCompMeta : CompileDirectiveMetadata = null ;
isCompiled = false ;
isCompiledWithDeps = false ;
constructor (
public isHost : boolean , selector : string , public compType : CompileIdentifierMetadata ,
public viewDirectives : CompileDirectiveMetadata [ ] , public viewComponentTypes : Type [ ] ,
public precompileHostComponentTypes : Type [ ] , public viewPipes : CompilePipeMetadata [ ] ,
2016-06-28 09:54:42 -07:00
_normalizeResult : SyncAsyncResult < CompileDirectiveMetadata > ) {
2016-06-24 08:46:43 -07:00
this . proxyViewFactory = ( . . . args : any [ ] ) = > this . _viewFactory . apply ( null , args ) ;
this . proxyComponentFactory = isHost ?
new ComponentFactory < any > ( selector , this . proxyViewFactory , compType . runtime ) :
null ;
if ( _normalizeResult . syncResult ) {
this . _normalizedCompMeta = _normalizeResult . syncResult ;
} else {
this . loading = _normalizeResult . asyncResult . then ( ( normalizedCompMeta ) = > {
this . _normalizedCompMeta = normalizedCompMeta ;
this . loading = null ;
} ) ;
}
}
get normalizedCompMeta ( ) : CompileDirectiveMetadata {
if ( this . loading ) {
throw new BaseException ( ` Template is still loading for ${ this . compType . name } ! ` ) ;
}
return this . _normalizedCompMeta ;
}
compiled ( viewFactory : Function ) {
this . _viewFactory = viewFactory ;
this . isCompiled = true ;
2016-01-06 14:13:44 -08:00
}
2016-06-24 08:46:43 -07:00
depsCompiled() { this . isCompiledWithDeps = true ; }
2016-01-06 14:13:44 -08:00
}
function assertComponent ( meta : CompileDirectiveMetadata ) {
if ( ! meta . isComponent ) {
throw new BaseException ( ` Could not compile ' ${ meta . type . name } ' because it is not a component. ` ) ;
2015-10-01 10:07:49 -07:00
}
}
feat(browser): use AppModules for bootstrap in the browser
This introduces the `BrowserModule` to be used for long form
bootstrap and offline compile bootstrap:
```
@AppModule({
modules: [BrowserModule],
precompile: [MainComponent],
providers: […], // additional providers
directives: […], // additional platform directives
pipes: […] // additional platform pipes
})
class MyModule {
constructor(appRef: ApplicationRef) {
appRef.bootstrap(MainComponent);
}
}
// offline compile
import {bootstrapModuleFactory} from ‘@angular/platform-browser’;
bootstrapModuleFactory(MyModuleNgFactory);
// runtime compile long form
import {bootstrapModule} from ‘@angular/platform-browser-dynamic’;
bootstrapModule(MyModule);
```
The short form, `bootstrap(...)`, can now creates a module on the fly,
given `directives`, `pipes, `providers`, `precompile` and `modules`
properties.
Related changes:
- make `SanitizationService`, `SecurityContext` public in `@angular/core` so that the offline compiler can resolve the token
- move `AnimationDriver` to `platform-browser` and make it
public so that the offline compiler can resolve the token
BREAKING CHANGES:
- short form bootstrap does no longer allow
to inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead.
To provide custom providers for the compiler,
create a custom compiler via `browserCompiler({providers: [...]})`
and pass that into the `bootstrap` method.
2016-06-30 13:07:17 -07:00
/ * *
* A wrapper around ` Compiler ` and ` ComponentResolver ` that
* provides default patform directives / pipes .
* /
class BoundCompiler implements Compiler , ComponentResolver {
constructor (
feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead. This reflects the
changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
`configureModule` and can no longer be provided via the
`PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and
now takes a `PlatformRef` and a factory for a
`Compiler`.
- E.g. for the browser platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
```
AFTER:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {browserTestCompiler, browserDynamicTestPlatform,
BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
browserTestCompiler,
browserDynamicTestPlatform(),
BrowserDynamicTestModule);
```
- E.g. for the server platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS);
```
AFTER:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {serverTestCompiler, serverTestPlatform,
ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
serverTestCompiler,
serverTestPlatform(),
ServerTestModule);
```
Related to #9726
Closes #9846
2016-07-04 09:37:30 -07:00
private _delegate : RuntimeCompiler , private _directives : any [ ] , private _pipes : any [ ] ,
private _parentComponentResolver : ComponentResolver ) { }
get injector ( ) : Injector { return this . _delegate . injector ; }
feat(browser): use AppModules for bootstrap in the browser
This introduces the `BrowserModule` to be used for long form
bootstrap and offline compile bootstrap:
```
@AppModule({
modules: [BrowserModule],
precompile: [MainComponent],
providers: […], // additional providers
directives: […], // additional platform directives
pipes: […] // additional platform pipes
})
class MyModule {
constructor(appRef: ApplicationRef) {
appRef.bootstrap(MainComponent);
}
}
// offline compile
import {bootstrapModuleFactory} from ‘@angular/platform-browser’;
bootstrapModuleFactory(MyModuleNgFactory);
// runtime compile long form
import {bootstrapModule} from ‘@angular/platform-browser-dynamic’;
bootstrapModule(MyModule);
```
The short form, `bootstrap(...)`, can now creates a module on the fly,
given `directives`, `pipes, `providers`, `precompile` and `modules`
properties.
Related changes:
- make `SanitizationService`, `SecurityContext` public in `@angular/core` so that the offline compiler can resolve the token
- move `AnimationDriver` to `platform-browser` and make it
public so that the offline compiler can resolve the token
BREAKING CHANGES:
- short form bootstrap does no longer allow
to inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead.
To provide custom providers for the compiler,
create a custom compiler via `browserCompiler({providers: [...]})`
and pass that into the `bootstrap` method.
2016-06-30 13:07:17 -07:00
resolveComponent ( component : Type | string ) : Promise < ComponentFactory < any > > {
if ( isString ( component ) ) {
feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead. This reflects the
changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
`configureModule` and can no longer be provided via the
`PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and
now takes a `PlatformRef` and a factory for a
`Compiler`.
- E.g. for the browser platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
```
AFTER:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {browserTestCompiler, browserDynamicTestPlatform,
BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
browserTestCompiler,
browserDynamicTestPlatform(),
BrowserDynamicTestModule);
```
- E.g. for the server platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS);
```
AFTER:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {serverTestCompiler, serverTestPlatform,
ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
serverTestCompiler,
serverTestPlatform(),
ServerTestModule);
```
Related to #9726
Closes #9846
2016-07-04 09:37:30 -07:00
if ( this . _parentComponentResolver ) {
return this . _parentComponentResolver . resolveComponent ( component ) ;
} else {
return PromiseWrapper . reject (
new BaseException ( ` Cannot resolve component using ' ${ component } '. ` ) , null ) ;
}
feat(browser): use AppModules for bootstrap in the browser
This introduces the `BrowserModule` to be used for long form
bootstrap and offline compile bootstrap:
```
@AppModule({
modules: [BrowserModule],
precompile: [MainComponent],
providers: […], // additional providers
directives: […], // additional platform directives
pipes: […] // additional platform pipes
})
class MyModule {
constructor(appRef: ApplicationRef) {
appRef.bootstrap(MainComponent);
}
}
// offline compile
import {bootstrapModuleFactory} from ‘@angular/platform-browser’;
bootstrapModuleFactory(MyModuleNgFactory);
// runtime compile long form
import {bootstrapModule} from ‘@angular/platform-browser-dynamic’;
bootstrapModule(MyModule);
```
The short form, `bootstrap(...)`, can now creates a module on the fly,
given `directives`, `pipes, `providers`, `precompile` and `modules`
properties.
Related changes:
- make `SanitizationService`, `SecurityContext` public in `@angular/core` so that the offline compiler can resolve the token
- move `AnimationDriver` to `platform-browser` and make it
public so that the offline compiler can resolve the token
BREAKING CHANGES:
- short form bootstrap does no longer allow
to inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead.
To provide custom providers for the compiler,
create a custom compiler via `browserCompiler({providers: [...]})`
and pass that into the `bootstrap` method.
2016-06-30 13:07:17 -07:00
}
return this . compileComponentAsync ( < ConcreteType < any > > component ) ;
}
compileComponentAsync < T > ( compType : ConcreteType < T > ) : Promise < ComponentFactory < T > > {
return this . _delegate . _compileComponent ( compType , false , this . _directives , this . _pipes )
. asyncResult ;
}
compileComponentSync < T > ( compType : ConcreteType < T > ) : ComponentFactory < T > {
return this . _delegate . _compileComponent ( compType , true , this . _directives , this . _pipes )
. syncResult ;
}
compileAppModuleSync < T > ( moduleType : ConcreteType < T > , metadata : AppModuleMetadata = null ) :
AppModuleFactory < T > {
return this . _delegate . compileAppModuleSync ( moduleType , metadata ) ;
}
compileAppModuleAsync < T > ( moduleType : ConcreteType < T > , metadata : AppModuleMetadata = null ) :
Promise < AppModuleFactory < T > > {
return this . _delegate . compileAppModuleAsync ( moduleType , metadata ) ;
}
/ * *
* Clears all caches
* /
feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead. This reflects the
changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
`configureModule` and can no longer be provided via the
`PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and
now takes a `PlatformRef` and a factory for a
`Compiler`.
- E.g. for the browser platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
```
AFTER:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {browserTestCompiler, browserDynamicTestPlatform,
BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
browserTestCompiler,
browserDynamicTestPlatform(),
BrowserDynamicTestModule);
```
- E.g. for the server platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS);
```
AFTER:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {serverTestCompiler, serverTestPlatform,
ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
serverTestCompiler,
serverTestPlatform(),
ServerTestModule);
```
Related to #9726
Closes #9846
2016-07-04 09:37:30 -07:00
clearCache ( ) : void {
this . _delegate . clearCache ( ) ;
if ( this . _parentComponentResolver ) {
this . _parentComponentResolver . clearCache ( ) ;
}
}
feat(browser): use AppModules for bootstrap in the browser
This introduces the `BrowserModule` to be used for long form
bootstrap and offline compile bootstrap:
```
@AppModule({
modules: [BrowserModule],
precompile: [MainComponent],
providers: […], // additional providers
directives: […], // additional platform directives
pipes: […] // additional platform pipes
})
class MyModule {
constructor(appRef: ApplicationRef) {
appRef.bootstrap(MainComponent);
}
}
// offline compile
import {bootstrapModuleFactory} from ‘@angular/platform-browser’;
bootstrapModuleFactory(MyModuleNgFactory);
// runtime compile long form
import {bootstrapModule} from ‘@angular/platform-browser-dynamic’;
bootstrapModule(MyModule);
```
The short form, `bootstrap(...)`, can now creates a module on the fly,
given `directives`, `pipes, `providers`, `precompile` and `modules`
properties.
Related changes:
- make `SanitizationService`, `SecurityContext` public in `@angular/core` so that the offline compiler can resolve the token
- move `AnimationDriver` to `platform-browser` and make it
public so that the offline compiler can resolve the token
BREAKING CHANGES:
- short form bootstrap does no longer allow
to inject compiler internals (i.e. everything
from `@angular/compiler). Inject `Compiler` instead.
To provide custom providers for the compiler,
create a custom compiler via `browserCompiler({providers: [...]})`
and pass that into the `bootstrap` method.
2016-06-30 13:07:17 -07:00
/ * *
* Clears the cache for the given component / appModule .
* /
clearCacheFor ( type : Type ) { this . _delegate . clearCacheFor ( type ) ; }
}