diff --git a/modules/@angular/compiler-cli/src/codegen.ts b/modules/@angular/compiler-cli/src/codegen.ts index 4ea60f9dc2..64d79805aa 100644 --- a/modules/@angular/compiler-cli/src/codegen.ts +++ b/modules/@angular/compiler-cli/src/codegen.ts @@ -132,9 +132,7 @@ export class CodeGenerator { genDebugInfo: options.debug === true, defaultEncapsulation: ViewEncapsulation.Emulated, logBindingUpdate: false, - useJit: false, - platformDirectives: [], - platformPipes: [] + useJit: false }); const normalizer = new DirectiveNormalizer(xhr, urlResolver, htmlParser, config); const parser = new Parser(new Lexer()); diff --git a/modules/@angular/compiler-cli/src/extract_i18n.ts b/modules/@angular/compiler-cli/src/extract_i18n.ts index f69c616443..c9ae4f86c2 100644 --- a/modules/@angular/compiler-cli/src/extract_i18n.ts +++ b/modules/@angular/compiler-cli/src/extract_i18n.ts @@ -142,9 +142,7 @@ class Extractor { genDebugInfo: true, defaultEncapsulation: ViewEncapsulation.Emulated, logBindingUpdate: false, - useJit: false, - platformDirectives: [], - platformPipes: [] + useJit: false }); const normalizer = new DirectiveNormalizer(xhr, urlResolver, htmlParser, config); const parser = new Parser(new Lexer()); diff --git a/modules/@angular/compiler/src/compiler.ts b/modules/@angular/compiler/src/compiler.ts index bc1dd7b59f..0c3bb2fd30 100644 --- a/modules/@angular/compiler/src/compiler.ts +++ b/modules/@angular/compiler/src/compiler.ts @@ -92,8 +92,8 @@ export class _RuntimeCompilerFactory extends CompilerFactory { const inj = ReflectiveInjector.resolveAndCreate(options.deprecatedAppProviders); const compilerConfig: CompilerConfig = inj.get(CompilerConfig, null); if (compilerConfig) { - platformDirectivesFromAppProviders = compilerConfig.platformDirectives; - platformPipesFromAppProviders = compilerConfig.platformPipes; + platformDirectivesFromAppProviders = compilerConfig.deprecatedPlatformDirectives; + platformPipesFromAppProviders = compilerConfig.deprecatedPlatformPipes; useJitFromAppProviders = compilerConfig.useJit; useDebugFromAppProviders = compilerConfig.genDebugInfo; defaultEncapsulationFromAppProviders = compilerConfig.defaultEncapsulation; @@ -133,9 +133,9 @@ export class _RuntimeCompilerFactory extends CompilerFactory { provide: CompilerConfig, useFactory: (platformDirectives: any[], platformPipes: any[]) => { return new CompilerConfig({ - platformDirectives: + deprecatedPlatformDirectives: _mergeArrays(platformDirectivesFromAppProviders, platformDirectives), - platformPipes: _mergeArrays(platformPipesFromAppProviders, platformPipes), + deprecatedPlatformPipes: _mergeArrays(platformPipesFromAppProviders, platformPipes), // let explicit values from the compiler options overwrite options // from the app providers. E.g. important for the testing platform. genDebugInfo: _firstDefined(options.useDebug, useDebugFromAppProviders, isDevMode()), diff --git a/modules/@angular/compiler/src/config.ts b/modules/@angular/compiler/src/config.ts index fd2ca6a774..4e7f74ae00 100644 --- a/modules/@angular/compiler/src/config.ts +++ b/modules/@angular/compiler/src/config.ts @@ -19,28 +19,38 @@ export class CompilerConfig { private _genDebugInfo: boolean; private _logBindingUpdate: boolean; public useJit: boolean; - public platformDirectives: any[]; - public platformPipes: any[]; + /** + * @deprecated Providing platform directives via the {@link CompilerConfig} deprecated. Provide + * platform + * directives via an {@link AppModule} instead. + */ + public deprecatedPlatformDirectives: any[]; + /** + * @deprecated Providing platform pipes via the {@link CompilerConfig} deprecated. Provide + * platform pipes + * via an {@link AppModule} instead. + */ + public deprecatedPlatformPipes: any[]; constructor( {renderTypes = new DefaultRenderTypes(), defaultEncapsulation = ViewEncapsulation.Emulated, - genDebugInfo, logBindingUpdate, useJit = true, platformDirectives = [], - platformPipes = []}: { + genDebugInfo, logBindingUpdate, useJit = true, deprecatedPlatformDirectives = [], + deprecatedPlatformPipes = []}: { renderTypes?: RenderTypes, defaultEncapsulation?: ViewEncapsulation, genDebugInfo?: boolean, logBindingUpdate?: boolean, useJit?: boolean, - platformDirectives?: any[], - platformPipes?: any[] + deprecatedPlatformDirectives?: any[], + deprecatedPlatformPipes?: any[] } = {}) { this.renderTypes = renderTypes; this.defaultEncapsulation = defaultEncapsulation; this._genDebugInfo = genDebugInfo; this._logBindingUpdate = logBindingUpdate; this.useJit = useJit; - this.platformDirectives = platformDirectives; - this.platformPipes = platformPipes; + this.deprecatedPlatformDirectives = deprecatedPlatformDirectives; + this.deprecatedPlatformPipes = deprecatedPlatformPipes; } get genDebugInfo(): boolean { diff --git a/modules/@angular/compiler/src/metadata_resolver.ts b/modules/@angular/compiler/src/metadata_resolver.ts index eb2623491e..8f226ce607 100644 --- a/modules/@angular/compiler/src/metadata_resolver.ts +++ b/modules/@angular/compiler/src/metadata_resolver.ts @@ -301,7 +301,7 @@ export class CompileMetadataResolver { getViewDirectivesMetadata(component: Type): cpl.CompileDirectiveMetadata[] { var view = this._viewResolver.resolve(component); - var directives = flattenDirectives(view, this._config.platformDirectives); + var directives = flattenDirectives(view, this._config.deprecatedPlatformDirectives); for (var i = 0; i < directives.length; i++) { if (!isValidType(directives[i])) { throw new BaseException( @@ -313,7 +313,7 @@ export class CompileMetadataResolver { getViewPipesMetadata(component: Type): cpl.CompilePipeMetadata[] { var view = this._viewResolver.resolve(component); - var pipes = flattenPipes(view, this._config.platformPipes); + var pipes = flattenPipes(view, this._config.deprecatedPlatformPipes); for (var i = 0; i < pipes.length; i++) { if (!isValidType(pipes[i])) { throw new BaseException( diff --git a/modules/@angular/compiler/src/runtime_compiler.ts b/modules/@angular/compiler/src/runtime_compiler.ts index 5ff7f3f308..abd7182daf 100644 --- a/modules/@angular/compiler/src/runtime_compiler.ts +++ b/modules/@angular/compiler/src/runtime_compiler.ts @@ -7,6 +7,7 @@ */ import {AppModuleFactory, AppModuleMetadata, Compiler, ComponentFactory, ComponentResolver, ComponentStillLoadingError, Injectable, Injector, OptionalMetadata, Provider, SkipSelfMetadata} from '@angular/core'; +import {Console} from '../core_private'; import {BaseException} from '../src/facade/exceptions'; import {ConcreteType, IS_DART, Type, isBlank, isString, stringify} from '../src/facade/lang'; @@ -42,11 +43,28 @@ export class RuntimeCompiler implements ComponentResolver, Compiler { private _compiledHostTemplateCache = new Map(); private _compiledAppModuleCache = new Map>(); + private _warnOnComponentResolver = true; + constructor( private _injector: Injector, private _metadataResolver: CompileMetadataResolver, private _templateNormalizer: DirectiveNormalizer, private _templateParser: TemplateParser, private _styleCompiler: StyleCompiler, private _viewCompiler: ViewCompiler, - private _appModuleCompiler: AppModuleCompiler, private _genConfig: CompilerConfig) {} + 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)); + } + } get injector(): Injector { return this._injector; } @@ -55,6 +73,10 @@ export class RuntimeCompiler implements ComponentResolver, Compiler { return PromiseWrapper.reject( new BaseException(`Cannot resolve component using '${component}'.`), null); } + if (this._warnOnComponentResolver) { + this._console.warn(ComponentResolver.DynamicCompilationDeprecationMsg); + this._warnOnComponentResolver = false; + } return this.compileComponentAsync(>component); } diff --git a/modules/@angular/compiler/test/metadata_resolver_spec.ts b/modules/@angular/compiler/test/metadata_resolver_spec.ts index e7eaf97f39..d4d8b350c8 100644 --- a/modules/@angular/compiler/test/metadata_resolver_spec.ts +++ b/modules/@angular/compiler/test/metadata_resolver_spec.ts @@ -115,8 +115,8 @@ export function main() { configureCompiler({ providers: [{ provide: CompilerConfig, - useValue: - new CompilerConfig({genDebugInfo: true, platformDirectives: [ADirective]}) + useValue: new CompilerConfig( + {genDebugInfo: true, deprecatedPlatformDirectives: [ADirective]}) }] }); }); diff --git a/modules/@angular/core/src/application_ref.ts b/modules/@angular/core/src/application_ref.ts index 45c2a14b11..11e607cf3a 100644 --- a/modules/@angular/core/src/application_ref.ts +++ b/modules/@angular/core/src/application_ref.ts @@ -235,10 +235,12 @@ export function bootstrapModule( * Shortcut for ApplicationRef.bootstrap. * Requires a platform to be created first. * - * @experimental APIs related to application bootstrap are currently under review. + * @deprecated Use {@link bootstrapModuleFactory} instead. */ export function coreBootstrap( componentFactory: ComponentFactory, injector: Injector): ComponentRef { + let console = injector.get(Console); + console.warn('coreBootstrap is deprecated. Use bootstrapModuleFactory instead.'); var appRef: ApplicationRef = injector.get(ApplicationRef); return appRef.bootstrap(componentFactory); } @@ -248,10 +250,12 @@ export function coreBootstrap( * waits for asynchronous initializers and bootstraps the component. * Requires a platform to be created first. * - * @experimental APIs related to application bootstrap are currently under review. + * @deprecated Use {@link bootstrapModule} instead. */ export function coreLoadAndBootstrap( componentType: Type, injector: Injector): Promise> { + let console = injector.get(Console); + console.warn('coreLoadAndBootstrap is deprecated. Use bootstrapModule instead.'); var appRef: ApplicationRef = injector.get(ApplicationRef); return appRef.run(() => { var componentResolver: ComponentResolver = injector.get(ComponentResolver); diff --git a/modules/@angular/core/src/linker/component_resolver.ts b/modules/@angular/core/src/linker/component_resolver.ts index 996656fcd1..2e44565fb6 100644 --- a/modules/@angular/core/src/linker/component_resolver.ts +++ b/modules/@angular/core/src/linker/component_resolver.ts @@ -6,6 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ +import {Console} from '../console'; import {Injectable} from '../di/decorators'; import {PromiseWrapper} from '../facade/async'; import {BaseException} from '../facade/exceptions'; @@ -18,9 +19,19 @@ import {ComponentFactory} from './component_factory'; /** * Low-level service for loading {@link ComponentFactory}s, which * can later be used to create and render a Component instance. - * @experimental + * + * @deprecated Use {@link ComponentFactoryResolver} together with {@link + * AppModule}.precompile}/{@link Component}.precompile or + * {@link ANALYZE_FOR_PRECOMPILE} provider for dynamic component creation. + * Use {@link AppModuleFactoryLoader} for lazy loading. */ export abstract class ComponentResolver { + static DynamicCompilationDeprecationMsg = + 'ComponentResolver is deprecated for dynamic compilation. Use ComponentFactoryResolver together with @AppModule/@Component.precompile or ANALYZE_FOR_PRECOMPILE provider instead.'; + static LazyLoadingDeprecationMsg = + 'ComponentResolver is deprecated for lazy loading. Use AppModuleFactoryLoader instead.'; + + abstract resolveComponent(component: Type|string): Promise>; abstract clearCache(): void; } @@ -31,11 +42,13 @@ function _isComponentFactory(type: any): boolean { @Injectable() export class ReflectorComponentResolver extends ComponentResolver { + constructor(private _console: Console) { super(); } resolveComponent(component: Type|string): Promise> { if (isString(component)) { return PromiseWrapper.reject( new BaseException(`Cannot resolve component using '${component}'.`), null); } + this._console.warn(ComponentResolver.DynamicCompilationDeprecationMsg); var metadatas = reflector.annotations(component); var componentFactory = metadatas.find(_isComponentFactory); diff --git a/modules/@angular/core/src/linker/systemjs_component_resolver.ts b/modules/@angular/core/src/linker/systemjs_component_resolver.ts index 7a47a9c1f6..e32feadf34 100644 --- a/modules/@angular/core/src/linker/systemjs_component_resolver.ts +++ b/modules/@angular/core/src/linker/systemjs_component_resolver.ts @@ -6,6 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ +import {Console} from '../console'; +import {Injectable} from '../di'; import {Type, global, isString} from '../facade/lang'; import {ComponentFactory} from './component_factory'; @@ -15,13 +17,18 @@ const _SEPARATOR = '#'; /** * Component resolver that can load components lazily - * @experimental + * + * @deprecated Lazy loading of components is deprecated. Use {@link SystemJsAppModuleLoader} to lazy + * load + * {@link AppModuleFactory}s instead. */ +@Injectable() export class SystemJsComponentResolver implements ComponentResolver { - constructor(private _resolver: ComponentResolver) {} + constructor(private _resolver: ComponentResolver, private _console: Console) {} resolveComponent(componentType: string|Type): Promise> { if (isString(componentType)) { + this._console.warn(ComponentResolver.LazyLoadingDeprecationMsg); let [module, component] = componentType.split(_SEPARATOR); if (component === void(0)) { @@ -45,11 +52,17 @@ const FACTORY_CLASS_SUFFIX = 'NgFactory'; /** * Component resolver that can load component factories lazily - * @experimental + * + * @deprecated Lazy loading of components is deprecated. Use {@link SystemJsAppModuleFactoryLoader} + * to lazy + * load {@link AppModuleFactory}s instead. */ +@Injectable() export class SystemJsCmpFactoryResolver implements ComponentResolver { + constructor(private _console: Console) {} resolveComponent(componentType: string|Type): Promise> { if (isString(componentType)) { + this._console.warn(ComponentResolver.LazyLoadingDeprecationMsg); let [module, factory] = componentType.split(_SEPARATOR); return (global) .System.import(module + FACTORY_MODULE_SUFFIX) diff --git a/modules/@angular/core/src/platform_directives_and_pipes.ts b/modules/@angular/core/src/platform_directives_and_pipes.ts index c754764b4c..984c749923 100644 --- a/modules/@angular/core/src/platform_directives_and_pipes.ts +++ b/modules/@angular/core/src/platform_directives_and_pipes.ts @@ -9,7 +9,7 @@ import {OpaqueToken} from './di'; /** - A token that can be provided when bootstrapping an application to make an array of directives + * A token that can be provided when bootstrapping an application to make an array of directives * available in every component of the application. * * ### Example @@ -32,9 +32,10 @@ import {OpaqueToken} from './di'; * bootstrap(MyComponent, [{provide: PLATFORM_DIRECTIVES, useValue: [OtherDirective], multi:true}]); * ``` - * @stable + * + * @deprecated Providing platform directives via a provider is deprecated. Provide platform + * directives via an {@link AppModule} instead. */ - export const PLATFORM_DIRECTIVES: OpaqueToken = /*@ts2dart_const*/ new OpaqueToken('Platform Directives'); @@ -60,7 +61,8 @@ export const PLATFORM_DIRECTIVES: OpaqueToken = * * bootstrap(MyComponent, [{provide: PLATFORM_PIPES, useValue: [OtherPipe], multi:true}]); * ``` - * @stable + * + * @deprecated Providing platform pipes via a provider is deprecated. Provide platform pipes via an + * {@link AppModule} instead. */ - export const PLATFORM_PIPES: OpaqueToken = /*@ts2dart_const*/ new OpaqueToken('Platform Pipes'); \ No newline at end of file diff --git a/modules/@angular/core/test/linker/reflector_component_resolver_spec.ts b/modules/@angular/core/test/linker/reflector_component_resolver_spec.ts index f48c178d9b..226442f5a9 100644 --- a/modules/@angular/core/test/linker/reflector_component_resolver_spec.ts +++ b/modules/@angular/core/test/linker/reflector_component_resolver_spec.ts @@ -12,6 +12,12 @@ import {ComponentResolver, ReflectorComponentResolver} from '@angular/core/src/l import {ReflectionInfo, reflector} from '@angular/core/src/reflection/reflection'; import {afterEach, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; import {AsyncTestCompleter} from '@angular/core/testing/testing_internal'; +import {Console} from '../../src/console'; + +class DummyConsole implements Console { + log(message: string) {} + warn(message: string) {} +} export function main() { describe('Compiler', () => { @@ -21,7 +27,7 @@ export function main() { beforeEach(() => { someCompFactory = new ComponentFactory(null, null, null); reflector.registerType(SomeComponent, new ReflectionInfo([someCompFactory])); - compiler = new ReflectorComponentResolver(); + compiler = new ReflectorComponentResolver(new DummyConsole()); }); it('should read the template from an annotation', diff --git a/modules/@angular/platform-browser-dynamic/index.ts b/modules/@angular/platform-browser-dynamic/index.ts index c1626c6427..ba825514b8 100644 --- a/modules/@angular/platform-browser-dynamic/index.ts +++ b/modules/@angular/platform-browser-dynamic/index.ts @@ -19,13 +19,17 @@ import {CachedXHR} from './src/xhr/xhr_cache'; import {XHRImpl} from './src/xhr/xhr_impl'; /** - * @experimental + * @deprecated The compiler providers are already included in the {@link CompilerFactory} that is + * contained the {@link browserDynamicPlatform}()`. */ export const BROWSER_APP_COMPILER_PROVIDERS: Array = [ COMPILER_PROVIDERS, { provide: CompilerConfig, useFactory: (platformDirectives: any[], platformPipes: any[]) => { - return new CompilerConfig({platformDirectives, platformPipes}); + return new CompilerConfig({ + deprecatedPlatformDirectives: platformDirectives, + deprecatedPlatformPipes: platformPipes + }); }, deps: [PLATFORM_DIRECTIVES, PLATFORM_PIPES] }, @@ -208,11 +212,15 @@ export function bootstrap( } /** - * @experimental + * @deprecated Create an {@link AppModule} that includes the {@link WorkerUiModule} and use {@link + * bootstrapModule} + * with the {@link workerUiPlatform}() instead. */ export function bootstrapWorkerUi( workerScriptUri: string, customProviders?: Array): Promise { + console.warn( + 'bootstrapWorkerUi is deprecated. Create an @AppModule that includes the `WorkerUiModule` and use `bootstrapModule` with the `workerUiPlatform()` instead.'); var app = ReflectiveInjector.resolveAndCreate( [ WORKER_UI_APPLICATION_PROVIDERS, BROWSER_APP_COMPILER_PROVIDERS, @@ -227,13 +235,17 @@ export function bootstrapWorkerUi( } /** - * @experimental + * @deprecated The compiler providers are already included in the {@link CompilerFactory} that is + * contained the {@link workerAppPlatform}(). */ const WORKER_APP_COMPILER_PROVIDERS: Array = [ COMPILER_PROVIDERS, { provide: CompilerConfig, useFactory: (platformDirectives: any[], platformPipes: any[]) => { - return new CompilerConfig({platformDirectives, platformPipes}); + return new CompilerConfig({ + deprecatedPlatformDirectives: platformDirectives, + deprecatedPlatformPipes: platformPipes + }); }, deps: [PLATFORM_DIRECTIVES, PLATFORM_PIPES] }, @@ -244,11 +256,15 @@ const WORKER_APP_COMPILER_PROVIDERS: Array = [ /** - * @experimental + * @deprecated Create an {@link AppModule} that includes the {@link WorkerAppModule} and use {@link + * bootstrapModule} + * with the {@link workerAppPlatform}() instead. */ export function bootstrapWorkerApp( appComponentType: Type, customProviders?: Array): Promise> { + console.warn( + 'bootstrapWorkerApp is deprecated. Create an @AppModule that includes the `WorkerAppModule` and use `bootstrapModule` with the `workerAppPlatform()` instead.'); var appInjector = ReflectiveInjector.resolveAndCreate( [ WORKER_APP_APPLICATION_PROVIDERS, WORKER_APP_COMPILER_PROVIDERS, diff --git a/modules/@angular/platform-browser/test/browser/bootstrap_spec.ts b/modules/@angular/platform-browser/test/browser/bootstrap_spec.ts index a65dc5d2da..a0f3a0c745 100644 --- a/modules/@angular/platform-browser/test/browser/bootstrap_spec.ts +++ b/modules/@angular/platform-browser/test/browser/bootstrap_spec.ts @@ -325,7 +325,9 @@ export function main() { expect(compilerConsole.warnings).toEqual([ 'Passing PLATFORM_DIRECTIVES to "bootstrap()" as provider is deprecated. Use the new parameter "directives" of "bootstrap()" instead.', - 'Passing PLATFORM_PIPES to "bootstrap()" as provider is deprecated. Use the new parameter "pipes" of "bootstrap()" instead.' + 'Passing PLATFORM_PIPES to "bootstrap()" as provider is deprecated. Use the new parameter "pipes" of "bootstrap()" instead.', + `Providing platform directives via the PLATFORM_DIRECTIVES provider or the "CompilerConfig" is deprecated. Provide platform directives via an @AppModule instead. Directives: ${stringify(SomeDirective)}`, + `Providing platform pipes via the PLATFORM_PIPES provider or the "CompilerConfig" is deprecated. Provide platform pipes via an @AppModule instead. Pipes: ${stringify(SomePipe)}` ]); async.done(); }); diff --git a/modules/@angular/platform-server/src/server.ts b/modules/@angular/platform-server/src/server.ts index f1793a0582..6bc7b4fbf3 100644 --- a/modules/@angular/platform-server/src/server.ts +++ b/modules/@angular/platform-server/src/server.ts @@ -81,11 +81,15 @@ export const serverDynamicPlatform = * serverBootstrap(..., [BROWSER_APP_PROVIDERS, BROWSER_APP_COMPILER_PROVIDERS]) * ``` * - * @experimental + * @deprecated create an {@link AppModule} and use {@link bootstrapModule} with the {@link + * serverDynamicPlatform}() + * instead. */ export function serverBootstrap( appComponentType: Type, providers: Array): Promise> { + console.warn( + 'serverBootstrap is deprecated. Create an @AppModule and use `bootstrapModule` with the `serverDynamicPlatform()` instead.'); reflector.reflectionCapabilities = new ReflectionCapabilities(); var appInjector = ReflectiveInjector.resolveAndCreate(providers, serverPlatform().injector); return coreLoadAndBootstrap(appComponentType, appInjector); diff --git a/modules/@angular/upgrade/src/upgrade_adapter.ts b/modules/@angular/upgrade/src/upgrade_adapter.ts index 033c552df4..fa4860633a 100644 --- a/modules/@angular/upgrade/src/upgrade_adapter.ts +++ b/modules/@angular/upgrade/src/upgrade_adapter.ts @@ -6,9 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ -import {ApplicationRef, ComponentFactory, ComponentResolver, Injector, NgZone, PlatformRef, Provider, ReflectiveInjector, Testability, Type, provide} from '@angular/core'; -import {BROWSER_APP_PROVIDERS, browserPlatform} from '@angular/platform-browser'; -import {BROWSER_APP_COMPILER_PROVIDERS} from '@angular/platform-browser-dynamic'; +import {AppModule, ApplicationRef, Compiler, CompilerFactory, ComponentFactory, ComponentResolver, Injector, NgZone, PlatformRef, Provider, ReflectiveInjector, Testability, Type, bootstrapModuleFactory, provide} from '@angular/core'; +import {BrowserModule} from '@angular/platform-browser'; +import {browserDynamicPlatform} from '@angular/platform-browser-dynamic'; import * as angular from './angular_js'; import {NG1_COMPILE, NG1_INJECTOR, NG1_PARSE, NG1_ROOT_SCOPE, NG1_TESTABILITY, NG2_COMPILER, NG2_COMPONENT_FACTORY_REF_MAP, NG2_INJECTOR, NG2_ZONE, REQUIRE_INJECTOR} from './constants'; @@ -278,21 +278,22 @@ export class UpgradeAdapter { UpgradeAdapterRef { var upgrade = new UpgradeAdapterRef(); var ng1Injector: angular.IInjectorService = null; - var platformRef: PlatformRef = browserPlatform(); - var applicationRef: ApplicationRef = - ReflectiveInjector - .resolveAndCreate( - [ - BROWSER_APP_PROVIDERS, BROWSER_APP_COMPILER_PROVIDERS, - {provide: NG1_INJECTOR, useFactory: () => ng1Injector}, - {provide: NG1_COMPILE, useFactory: () => ng1Injector.get(NG1_COMPILE)}, - this.providers - ], - platformRef.injector) - .get(ApplicationRef); + var platformRef: PlatformRef = browserDynamicPlatform(); + var compiler: Compiler = platformRef.injector.get(CompilerFactory).createCompiler(); + var providers = [ + {provide: NG1_INJECTOR, useFactory: () => ng1Injector}, + {provide: NG1_COMPILE, useFactory: () => ng1Injector.get(NG1_COMPILE)}, this.providers + ]; + + @AppModule({providers: providers, modules: [BrowserModule]}) + class DynamicModule { + } + + var moduleRef = + bootstrapModuleFactory(compiler.compileAppModuleSync(DynamicModule), platformRef); + var applicationRef: ApplicationRef = moduleRef.injector.get(ApplicationRef); var injector: Injector = applicationRef.injector; var ngZone: NgZone = injector.get(NgZone); - var compiler: ComponentResolver = injector.get(ComponentResolver); var delayApplyExps: Function[] = []; var original$applyFn: Function; var rootScopePrototype: any; @@ -510,13 +511,12 @@ export class UpgradeAdapter { } /* @internal */ - private compileNg2Components( - compiler: ComponentResolver, - componentFactoryRefMap: ComponentFactoryRefMap): Promise { + private compileNg2Components(compiler: Compiler, componentFactoryRefMap: ComponentFactoryRefMap): + Promise { var promises: Array>> = []; var types = this.upgradedComponents; for (var i = 0; i < types.length; i++) { - promises.push(compiler.resolveComponent(types[i])); + promises.push(compiler.compileComponentAsync(types[i])); } return Promise.all(promises).then((componentFactories: Array>) => { var types = this.upgradedComponents; diff --git a/modules/@angular/upgrade/test/upgrade_spec.ts b/modules/@angular/upgrade/test/upgrade_spec.ts index a2a27e025e..f21f3cc377 100644 --- a/modules/@angular/upgrade/test/upgrade_spec.ts +++ b/modules/@angular/upgrade/test/upgrade_spec.ts @@ -7,7 +7,7 @@ */ import {Class, Component, EventEmitter, Testability, disposePlatform, provide} from '@angular/core'; -import {AsyncTestCompleter, describe, expect, iit, inject, it} from '@angular/core/testing/testing_internal'; +import {AsyncTestCompleter, ddescribe, describe, expect, iit, inject, it} from '@angular/core/testing/testing_internal'; import {UpgradeAdapter} from '@angular/upgrade'; import * as angular from '@angular/upgrade/src/angular_js'; diff --git a/tools/public_api_guard/core/index.d.ts b/tools/public_api_guard/core/index.d.ts index 7d25839ebb..d83d740187 100644 --- a/tools/public_api_guard/core/index.d.ts +++ b/tools/public_api_guard/core/index.d.ts @@ -471,10 +471,12 @@ export declare abstract class ComponentRef { abstract onDestroy(callback: Function): void; } -/** @experimental */ +/** @deprecated */ export declare abstract class ComponentResolver { abstract clearCache(): void; abstract resolveComponent(component: Type | string): Promise>; + static DynamicCompilationDeprecationMsg: string; + static LazyLoadingDeprecationMsg: string; } /** @stable */ @@ -526,10 +528,10 @@ export interface ContentChildrenMetadataFactory { }): ContentChildrenMetadata; } -/** @experimental */ +/** @deprecated */ export declare function coreBootstrap(componentFactory: ComponentFactory, injector: Injector): ComponentRef; -/** @experimental */ +/** @deprecated */ export declare function coreLoadAndBootstrap(componentType: Type, injector: Injector): Promise>; /** @experimental */ @@ -1057,13 +1059,13 @@ export interface PipeTransform { /** @experimental */ export declare const PLATFORM_COMMON_PROVIDERS: Array; -/** @stable */ +/** @deprecated */ export declare const PLATFORM_DIRECTIVES: OpaqueToken; /** @experimental */ export declare const PLATFORM_INITIALIZER: any; -/** @stable */ +/** @deprecated */ export declare const PLATFORM_PIPES: OpaqueToken; /** @experimental */ @@ -1338,15 +1340,16 @@ export declare class SystemJsAppModuleLoader implements AppModuleFactoryLoader { load(path: string): Promise>; } -/** @experimental */ +/** @deprecated */ export declare class SystemJsCmpFactoryResolver implements ComponentResolver { + constructor(_console: Console); clearCache(): void; resolveComponent(componentType: string | Type): Promise>; } -/** @experimental */ +/** @deprecated */ export declare class SystemJsComponentResolver implements ComponentResolver { - constructor(_resolver: ComponentResolver); + constructor(_resolver: ComponentResolver, _console: Console); clearCache(): void; resolveComponent(componentType: string | Type): Promise>; } diff --git a/tools/public_api_guard/platform-browser-dynamic/index.d.ts b/tools/public_api_guard/platform-browser-dynamic/index.d.ts index def0cbedbe..03d689070b 100644 --- a/tools/public_api_guard/platform-browser-dynamic/index.d.ts +++ b/tools/public_api_guard/platform-browser-dynamic/index.d.ts @@ -1,13 +1,13 @@ /** @experimental */ export declare function bootstrap(appComponentType: ConcreteType, customProviders?: Array): Promise>; -/** @experimental */ +/** @deprecated */ export declare function bootstrapWorkerApp(appComponentType: Type, customProviders?: Array): Promise>; -/** @experimental */ +/** @deprecated */ export declare function bootstrapWorkerUi(workerScriptUri: string, customProviders?: Array): Promise; -/** @experimental */ +/** @deprecated */ export declare const BROWSER_APP_COMPILER_PROVIDERS: Array; /** @experimental */ diff --git a/tools/public_api_guard/platform-server/index.d.ts b/tools/public_api_guard/platform-server/index.d.ts index 89a2abc719..4f9be412ea 100644 --- a/tools/public_api_guard/platform-server/index.d.ts +++ b/tools/public_api_guard/platform-server/index.d.ts @@ -1,7 +1,7 @@ /** @experimental */ export declare const SERVER_PLATFORM_PROVIDERS: Array; -/** @experimental */ +/** @deprecated */ export declare function serverBootstrap(appComponentType: Type, providers: Array): Promise>; /** @experimental */