From 5effc330edbedd7ececedb1fea1e22db00522c53 Mon Sep 17 00:00:00 2001 From: Karl Seamon Date: Tue, 11 Oct 2016 18:48:08 -0400 Subject: [PATCH] feat(upgrade): compilerOptions in bootstrap (#10575) --- .../@angular/upgrade/src/upgrade_adapter.ts | 8 ++--- modules/@angular/upgrade/test/upgrade_spec.ts | 32 +++++++++++++++++++ tools/public_api_guard/upgrade/index.d.ts | 2 +- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/modules/@angular/upgrade/src/upgrade_adapter.ts b/modules/@angular/upgrade/src/upgrade_adapter.ts index 5abc226c59..45f133eeb9 100644 --- a/modules/@angular/upgrade/src/upgrade_adapter.ts +++ b/modules/@angular/upgrade/src/upgrade_adapter.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {Compiler, ComponentFactory, Injector, NgModule, NgModuleRef, NgZone, Provider, Testability, Type} from '@angular/core'; +import {Compiler, CompilerOptions, ComponentFactory, Injector, NgModule, NgModuleRef, NgZone, Provider, Testability, Type} from '@angular/core'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; import * as angular from './angular_js'; @@ -58,7 +58,7 @@ var upgradeCount: number = 0; * ### Example * * ``` - * var adapter = new UpgradeAdapter(forwardRef(() => MyNg2Module)); + * var adapter = new UpgradeAdapter(forwardRef(() => MyNg2Module), myCompilerOptions); * var module = angular.module('myExample', []); * module.directive('ng2Comp', adapter.downgradeNg2Component(Ng2Component)); * @@ -114,7 +114,7 @@ export class UpgradeAdapter { /* @internal */ private providers: Provider[] = []; - constructor(private ng2AppModule: Type) { + constructor(private ng2AppModule: Type, private compilerOptions?: CompilerOptions) { if (!ng2AppModule) { throw new Error( 'UpgradeAdapter cannot be instantiated without an NgModule of the Angular 2 app.'); @@ -399,7 +399,7 @@ export class UpgradeAdapter { (platformBrowserDynamic() as any) ._bootstrapModuleWithZone( - DynamicNgUpgradeModule, undefined, ngZone, + DynamicNgUpgradeModule, this.compilerOptions, ngZone, (componentFactories: ComponentFactory[]) => { componentFactories.forEach((componentFactory: ComponentFactory) => { var type: Type = componentFactory.componentType; diff --git a/modules/@angular/upgrade/test/upgrade_spec.ts b/modules/@angular/upgrade/test/upgrade_spec.ts index 489f5e9ef3..9ff21974d2 100644 --- a/modules/@angular/upgrade/test/upgrade_spec.ts +++ b/modules/@angular/upgrade/test/upgrade_spec.ts @@ -9,6 +9,7 @@ import {Class, Component, EventEmitter, NO_ERRORS_SCHEMA, NgModule, Testability, destroyPlatform, forwardRef} from '@angular/core'; import {async} from '@angular/core/testing'; import {BrowserModule} from '@angular/platform-browser'; +import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; import {UpgradeAdapter} from '@angular/upgrade'; import * as angular from '@angular/upgrade/src/angular_js'; @@ -69,6 +70,37 @@ export function main() { ref.dispose(); }); })); + + it('supports the compilerOptions argument', async(() => { + const platformRef = platformBrowserDynamic(); + spyOn(platformRef, '_bootstrapModuleWithZone').and.callThrough(); + + const ng1Module = angular.module('ng1', []); + const Ng2 = Component({ + selector: 'ng2', + template: `{{ 'NG2' }}()` + }).Class({constructor: function() {}}); + + const element = + html('
{{ \'ng1[\' }}~{{ \'ng-content\' }}~{{ \']\' }}
'); + + const Ng2AppModule = + NgModule({ + declarations: [Ng2], + imports: [BrowserModule], + }).Class({constructor: function Ng2AppModule() {}, ngDoBootstrap: function() {}}); + + const adapter: UpgradeAdapter = new UpgradeAdapter(Ng2AppModule, {providers: []}); + ng1Module.directive('ng2', adapter.downgradeNg2Component(Ng2)); + adapter.bootstrap(element, ['ng1']).ready((ref) => { + expect((platformRef as any)._bootstrapModuleWithZone) + .toHaveBeenCalledWith( + jasmine.any(Function), {providers: []}, jasmine.any(Object), + jasmine.any(Function)); + ref.dispose(); + }); + })); + describe('scope/component change-detection', () => { it('should interleave scope and component expressions', async(() => { const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => Ng2Module)); diff --git a/tools/public_api_guard/upgrade/index.d.ts b/tools/public_api_guard/upgrade/index.d.ts index 29844bc800..33ef4ab993 100644 --- a/tools/public_api_guard/upgrade/index.d.ts +++ b/tools/public_api_guard/upgrade/index.d.ts @@ -1,6 +1,6 @@ /** @stable */ export declare class UpgradeAdapter { - constructor(ng2AppModule: Type); + constructor(ng2AppModule: Type, compilerOptions?: CompilerOptions); bootstrap(element: Element, modules?: any[], config?: angular.IAngularBootstrapConfig): UpgradeAdapterRef; downgradeNg2Component(type: Type): Function; downgradeNg2Provider(token: any): Function;