refactor(core): add a deprecation message for using PLATFORM_DIRECTIVES
/ PLATFORM_PIPES
/ CompilerConfig
/ XHR
as regular providers in bootstrap
.
We still support this via a hack, but should remove this soon. This also fixes tests for module directives / pipes as they used directives / pipes that were already present in the underlying platform.
This commit is contained in:
@ -11,7 +11,7 @@ import {COMPILER_PROVIDERS, CompilerConfig, XHR} from '@angular/compiler';
|
||||
import {AppModule, AppModuleRef, ApplicationRef, Compiler, ComponentRef, ComponentResolver, ExceptionHandler, PLATFORM_DIRECTIVES, PLATFORM_PIPES, ReflectiveInjector, Type, coreLoadAndBootstrap, isDevMode, lockRunMode} from '@angular/core';
|
||||
import {BROWSER_APP_PROVIDERS, BrowserModule, WORKER_APP_APPLICATION_PROVIDERS, WORKER_SCRIPT, WORKER_UI_APPLICATION_PROVIDERS, bootstrapModuleFactory, browserPlatform, workerAppPlatform, workerUiPlatform} from '@angular/platform-browser';
|
||||
|
||||
import {ReflectionCapabilities, reflector} from './core_private';
|
||||
import {Console, ReflectionCapabilities, reflector} from './core_private';
|
||||
import {getDOM, initDomAdapter} from './platform_browser_private';
|
||||
import {PromiseWrapper} from './src/facade/async';
|
||||
import {ConcreteType, isPresent, stringify} from './src/facade/lang';
|
||||
@ -212,6 +212,7 @@ export function bootstrap<C>(
|
||||
precompile = normalizeArray(customProvidersOrDynamicModule.precompile);
|
||||
compiler = customProvidersOrDynamicModule.compiler;
|
||||
}
|
||||
let deprecationMessages: string[] = [];
|
||||
if (providers && providers.length > 0) {
|
||||
// Note: This is a hack to still support the old way
|
||||
// of configuring platform directives / pipes and the compiler xhr.
|
||||
@ -223,20 +224,44 @@ export function bootstrap<C>(
|
||||
// and provide a CompilerConfig out of it
|
||||
directives = directives.concat(compilerConfig.platformDirectives);
|
||||
pipes = pipes.concat(compilerConfig.platformPipes);
|
||||
deprecationMessages.push(
|
||||
`Passing a CompilerConfig to "bootstrap()" as provider is deprecated. Pass the provider to "createCompiler()" and call "bootstrap()" with the created compiler instead.`);
|
||||
} else {
|
||||
// If nobody provided a CompilerConfig, use the
|
||||
// PLATFORM_DIRECTIVES / PLATFORM_PIPES values directly.
|
||||
directives = directives.concat(inj.get(PLATFORM_DIRECTIVES, []));
|
||||
pipes = pipes.concat(inj.get(PLATFORM_PIPES, []));
|
||||
let platformDirectives = inj.get(PLATFORM_DIRECTIVES, []);
|
||||
if (platformDirectives.length > 0) {
|
||||
deprecationMessages.push(
|
||||
`Passing PLATFORM_DIRECTIVES to "bootstrap()" as provider is deprecated. Use the new parameter "directives" of "bootstrap()" instead.`);
|
||||
}
|
||||
directives = directives.concat(platformDirectives);
|
||||
let platformPipes = inj.get(PLATFORM_PIPES, []);
|
||||
if (platformPipes.length > 0) {
|
||||
deprecationMessages.push(
|
||||
`Passing PLATFORM_PIPES to "bootstrap()" as provider is deprecated. Use the new parameter "pipes" of "bootstrap()" instead.`);
|
||||
}
|
||||
pipes = pipes.concat(platformPipes);
|
||||
}
|
||||
let xhr = inj.get(XHR, null);
|
||||
if (xhr) {
|
||||
compilerProviders.push([{provide: XHR, useValue: xhr}]);
|
||||
deprecationMessages.push(
|
||||
`Passing an instance of XHR to "bootstrap()" as provider is deprecated. Pass the provider to "createCompiler()" and call "bootstrap()" with the created compiler instead.`);
|
||||
}
|
||||
// Need to copy console from providers to compiler
|
||||
// as well so that we can test the above deprecation messages!
|
||||
let console = inj.get(Console, null);
|
||||
if (console) {
|
||||
compilerProviders.push([{provide: Console, useValue: console}]);
|
||||
}
|
||||
}
|
||||
if (!compiler) {
|
||||
compiler = browserCompiler({providers: compilerProviders});
|
||||
}
|
||||
deprecationMessages.forEach((msg) => {
|
||||
let console: Console = compiler.injector.get(Console);
|
||||
console.warn(msg);
|
||||
});
|
||||
|
||||
@AppModule({
|
||||
providers: providers,
|
||||
|
Reference in New Issue
Block a user