feat(upgrade): compilerOptions in bootstrap (#10575)
This commit is contained in:
parent
3df00828d7
commit
5effc330ed
|
@ -6,7 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* 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 {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||||
|
|
||||||
import * as angular from './angular_js';
|
import * as angular from './angular_js';
|
||||||
|
@ -58,7 +58,7 @@ var upgradeCount: number = 0;
|
||||||
* ### Example
|
* ### Example
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
* var adapter = new UpgradeAdapter(forwardRef(() => MyNg2Module));
|
* var adapter = new UpgradeAdapter(forwardRef(() => MyNg2Module), myCompilerOptions);
|
||||||
* var module = angular.module('myExample', []);
|
* var module = angular.module('myExample', []);
|
||||||
* module.directive('ng2Comp', adapter.downgradeNg2Component(Ng2Component));
|
* module.directive('ng2Comp', adapter.downgradeNg2Component(Ng2Component));
|
||||||
*
|
*
|
||||||
|
@ -114,7 +114,7 @@ export class UpgradeAdapter {
|
||||||
/* @internal */
|
/* @internal */
|
||||||
private providers: Provider[] = [];
|
private providers: Provider[] = [];
|
||||||
|
|
||||||
constructor(private ng2AppModule: Type<any>) {
|
constructor(private ng2AppModule: Type<any>, private compilerOptions?: CompilerOptions) {
|
||||||
if (!ng2AppModule) {
|
if (!ng2AppModule) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'UpgradeAdapter cannot be instantiated without an NgModule of the Angular 2 app.');
|
'UpgradeAdapter cannot be instantiated without an NgModule of the Angular 2 app.');
|
||||||
|
@ -399,7 +399,7 @@ export class UpgradeAdapter {
|
||||||
|
|
||||||
(platformBrowserDynamic() as any)
|
(platformBrowserDynamic() as any)
|
||||||
._bootstrapModuleWithZone(
|
._bootstrapModuleWithZone(
|
||||||
DynamicNgUpgradeModule, undefined, ngZone,
|
DynamicNgUpgradeModule, this.compilerOptions, ngZone,
|
||||||
(componentFactories: ComponentFactory<any>[]) => {
|
(componentFactories: ComponentFactory<any>[]) => {
|
||||||
componentFactories.forEach((componentFactory: ComponentFactory<any>) => {
|
componentFactories.forEach((componentFactory: ComponentFactory<any>) => {
|
||||||
var type: Type<any> = componentFactory.componentType;
|
var type: Type<any> = componentFactory.componentType;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
import {Class, Component, EventEmitter, NO_ERRORS_SCHEMA, NgModule, Testability, destroyPlatform, forwardRef} from '@angular/core';
|
import {Class, Component, EventEmitter, NO_ERRORS_SCHEMA, NgModule, Testability, destroyPlatform, forwardRef} from '@angular/core';
|
||||||
import {async} from '@angular/core/testing';
|
import {async} from '@angular/core/testing';
|
||||||
import {BrowserModule} from '@angular/platform-browser';
|
import {BrowserModule} from '@angular/platform-browser';
|
||||||
|
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||||
import {UpgradeAdapter} from '@angular/upgrade';
|
import {UpgradeAdapter} from '@angular/upgrade';
|
||||||
import * as angular from '@angular/upgrade/src/angular_js';
|
import * as angular from '@angular/upgrade/src/angular_js';
|
||||||
|
|
||||||
|
@ -69,6 +70,37 @@ export function main() {
|
||||||
ref.dispose();
|
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' }}(<ng-content></ng-content>)`
|
||||||
|
}).Class({constructor: function() {}});
|
||||||
|
|
||||||
|
const element =
|
||||||
|
html('<div>{{ \'ng1[\' }}<ng2>~{{ \'ng-content\' }}~</ng2>{{ \']\' }}</div>');
|
||||||
|
|
||||||
|
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', () => {
|
describe('scope/component change-detection', () => {
|
||||||
it('should interleave scope and component expressions', async(() => {
|
it('should interleave scope and component expressions', async(() => {
|
||||||
const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => Ng2Module));
|
const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => Ng2Module));
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/** @stable */
|
/** @stable */
|
||||||
export declare class UpgradeAdapter {
|
export declare class UpgradeAdapter {
|
||||||
constructor(ng2AppModule: Type<any>);
|
constructor(ng2AppModule: Type<any>, compilerOptions?: CompilerOptions);
|
||||||
bootstrap(element: Element, modules?: any[], config?: angular.IAngularBootstrapConfig): UpgradeAdapterRef;
|
bootstrap(element: Element, modules?: any[], config?: angular.IAngularBootstrapConfig): UpgradeAdapterRef;
|
||||||
downgradeNg2Component(type: Type<any>): Function;
|
downgradeNg2Component(type: Type<any>): Function;
|
||||||
downgradeNg2Provider(token: any): Function;
|
downgradeNg2Provider(token: any): Function;
|
||||||
|
|
Loading…
Reference in New Issue