diff --git a/packages/core/schematics/test/dynamic_queries_migration_spec.ts b/packages/core/schematics/test/dynamic_queries_migration_spec.ts
index 31644d345f..19b23c951e 100644
--- a/packages/core/schematics/test/dynamic_queries_migration_spec.ts
+++ b/packages/core/schematics/test/dynamic_queries_migration_spec.ts
@@ -160,6 +160,6 @@ describe('dynamic queries migration', () => {
}
function runMigration() {
- runner.runSchematicAsync('migration-v9-dynamic-queries', {}, tree).toPromise();
+ return runner.runSchematicAsync('migration-v9-dynamic-queries', {}, tree).toPromise();
}
});
diff --git a/packages/core/schematics/test/missing_injectable_migration_spec.ts b/packages/core/schematics/test/missing_injectable_migration_spec.ts
index 3aab813149..762989f4a8 100644
--- a/packages/core/schematics/test/missing_injectable_migration_spec.ts
+++ b/packages/core/schematics/test/missing_injectable_migration_spec.ts
@@ -63,8 +63,8 @@ describe('Missing injectable migration', () => {
host.sync.write(normalize(filePath), virtualFs.stringToFileBuffer(contents));
}
- async function runMigration() {
- await runner.runSchematicAsync('migration-v9-missing-injectable', {}, tree).toPromise();
+ function runMigration() {
+ return runner.runSchematicAsync('migration-v9-missing-injectable', {}, tree).toPromise();
}
describe('NgModule', () => createTests('NgModule', 'providers'));
@@ -79,10 +79,10 @@ describe('Missing injectable migration', () => {
async() => {
writeFile('/index.ts', `
import {Component} from '@angular/core';
-
+
export class MyService {}
export class MySecondService {}
-
+
@Component({
providers: [MyService],
viewProviders: [MySecondService],
@@ -106,9 +106,9 @@ describe('Missing injectable migration', () => {
it(`should migrate type provider in ${type}`, async() => {
writeFile('/index.ts', `
import {${type}} from '@angular/core';
-
+
export class MyService {}
-
+
@${type}({${propName}: [MyService]})
export class TestClass {}
`);
@@ -124,9 +124,9 @@ describe('Missing injectable migration', () => {
it(`should migrate object literal provider in ${type} to explicit value provider`, async() => {
writeFile('/index.ts', `
import {${type}} from '@angular/core';
-
+
export class MyService {}
-
+
@${type}({${propName}: [{provide: MyService}]})
export class TestClass {}
`);
@@ -143,7 +143,7 @@ describe('Missing injectable migration', () => {
it(`should migrate object literal provider with forwardRef in ${type}`, async() => {
writeFile('/index.ts', `
import {${type}, forwardRef} from '@angular/core';
-
+
@${type}({${propName}: [forwardRef(() => MyService)]})
export class TestClass {}
@@ -161,9 +161,9 @@ describe('Missing injectable migration', () => {
it(`should not migrate object literal provider with "useValue" in ${type}`, async() => {
writeFile('/index.ts', `
import {${type}} from '@angular/core';
-
+
export class MyService {}
-
+
@${type}({${propName}: [{provide: MyService, useValue: null }]})
export class TestClass {}
`);
@@ -177,9 +177,9 @@ describe('Missing injectable migration', () => {
it(`should not migrate provider with "useClass" and "deps" in ${type}`, async() => {
writeFile('/index.ts', `
import {${type}} from '@angular/core';
-
+
export class MyService {}
-
+
@${type}({${propName}: [{provide: MyService, deps: []}]})
export class TestClass {}
`);
@@ -193,9 +193,9 @@ describe('Missing injectable migration', () => {
it(`should not migrate object literal provider with "useFactory" in ${type}`, async() => {
writeFile('/index.ts', `
import {${type}} from '@angular/core';
-
+
export class MyService {}
-
+
@${type}({${propName}: [{provide: MyService, useFactory: () => null }]})
export class TestClass {}
`);
@@ -209,10 +209,10 @@ describe('Missing injectable migration', () => {
it(`should not migrate object literal provider with "useExisting" in ${type}`, async() => {
writeFile('/index.ts', `
import {${type}} from '@angular/core';
-
+
export class MyService {}
export class MyToken {}
-
+
@${type}({${propName}: [
{provide: MyService: useValue: null},
{provide: MyToken, useExisting: MyService},
@@ -229,10 +229,10 @@ describe('Missing injectable migration', () => {
it(`should migrate object literal provider with "useClass" in ${type}`, async() => {
writeFile('/index.ts', `
import {${type}} from '@angular/core';
-
+
export class MyService {}
export class MyToken {}
-
+
@${type}({${propName}: [{provide: MyToken, useClass: MyService}]})
export class TestClass {}
`);
@@ -251,10 +251,10 @@ describe('Missing injectable migration', () => {
async() => {
writeFile('/index.ts', `
import {${type}} from '@angular/core';
-
+
export class MyService {}
export class MyToken {}
-
+
@${type}({
${propName}: [
{provide: MyToken, useExisting: MyService},
@@ -266,7 +266,7 @@ describe('Missing injectable migration', () => {
writeFile('/other.ts', `
import {${type} from '@angular/core';
import {MyService} from './index';
-
+
export @${type}({
${propName}: [{provide: MyService, useClass: MyService}],
})
@@ -284,10 +284,10 @@ describe('Missing injectable migration', () => {
it('should not migrate provider which is already decorated with @Injectable', async() => {
writeFile('/index.ts', `
import {Injectable, ${type}} from '@angular/core';
-
+
@Injectable()
export class MyService {}
-
+
@${type}({${propName}: [MyService]})
export class TestClass {}
`);
@@ -302,10 +302,10 @@ describe('Missing injectable migration', () => {
it('should not migrate provider which is already decorated with @Directive', async() => {
writeFile('/index.ts', `
import {Directive, ${type}} from '@angular/core';
-
+
@Directive()
export class MyService {}
-
+
@${type}({${propName}: [MyService]})
export class TestClass {}
`);
@@ -319,10 +319,10 @@ describe('Missing injectable migration', () => {
it('should not migrate provider which is already decorated with @Component', async() => {
writeFile('/index.ts', `
import {Component, ${type}} from '@angular/core';
-
+
@Component()
export class MyService {}
-
+
@${type}({${propName}: [MyService]})
export class TestClass {}
`);
@@ -336,10 +336,10 @@ describe('Missing injectable migration', () => {
it('should not migrate provider which is already decorated with @Pipe', async() => {
writeFile('/index.ts', `
import {Pipe, ${type}} from '@angular/core';
-
+
@Pipe()
export class MyService {}
-
+
@${type}({${propName}: [MyService]})
export class TestClass {}
`);
@@ -353,10 +353,10 @@ describe('Missing injectable migration', () => {
it(`should migrate multiple providers in same ${type}`, async() => {
writeFile('/index.ts', `
import {${type}} from '@angular/core';
-
+
export class ServiceA {}
export class ServiceB {}
-
+
@${type}({${propName}: [ServiceA, ServiceB]})
export class TestClass {}
`);
@@ -373,11 +373,11 @@ describe('Missing injectable migration', () => {
it(`should migrate multiple mixed providers in same ${type}`, async() => {
writeFile('/index.ts', `
import {${type}} from '@angular/core';
-
+
export class ServiceA {}
export class ServiceB {}
export class ServiceC {}
-
+
@${type}({
${propName}: [
ServiceA,
@@ -402,12 +402,12 @@ describe('Missing injectable migration', () => {
it(`should migrate multiple nested providers in same ${type}`, async() => {
writeFile('/index.ts', `
import {${type}} from '@angular/core';
-
+
export class ServiceA {}
export class ServiceB {}
export class ServiceC {}
export class ServiceD {}
-
+
@${type}({
${propName}: [
ServiceA,
@@ -436,11 +436,11 @@ describe('Missing injectable migration', () => {
it('should migrate providers referenced through identifier', async() => {
writeFile('/index.ts', `
import {${type}} from '@angular/core';
-
+
export class ServiceA {}
export class ServiceB {}
export class ServiceC {}
-
+
const PROVIDERS = [
ServiceA,
ServiceB,
@@ -448,7 +448,7 @@ describe('Missing injectable migration', () => {
// an invalid object literal.
{provide: ServiceC, },
];
-
+
@${type}({
${propName}: PROVIDERS,
})
@@ -470,15 +470,15 @@ describe('Missing injectable migration', () => {
it('should migrate providers created through static analyzable function call', async() => {
writeFile('/index.ts', `
import {${type}} from '@angular/core';
-
+
export class ServiceA {}
export class ServiceB {}
export class ServiceC {}
-
+
export function createProviders(x: any, b: any) {
return [ServiceA, x, b]
}
-
+
@${type}({
${propName}: createProviders(ServiceB, {provide: ServiceC}),
})
@@ -500,13 +500,13 @@ describe('Missing injectable migration', () => {
it('should migrate providers which are computed through spread operator', async() => {
writeFile('/index.ts', `
import {${type}} from '@angular/core';
-
+
export class ServiceA {}
export class ServiceB {}
export class ServiceC {}
-
+
const otherServices = [ServiceB, {provide: ServiceC}];
-
+
@${type}({
${propName}: [ServiceA, ...otherServices],
})
@@ -528,9 +528,9 @@ describe('Missing injectable migration', () => {
it(`should migrate provider once if referenced in multiple ${type} definitions`, async() => {
writeFile('/index.ts', `
import {${type}} from '@angular/core';
-
+
export class ServiceA {}
-
+
@${type}({${propName}: [ServiceA]})
export class TestClassA {}
`);
@@ -538,9 +538,9 @@ describe('Missing injectable migration', () => {
writeFile('/second.ts', `
import {${type}} from '@angular/core';
import {ServiceA} from './index';
-
+
export class ServiceB {}
-
+
@${type}({${propName}: [ServiceA, ServiceB]})
export class TestClassB {}
`);
@@ -562,14 +562,14 @@ describe('Missing injectable migration', () => {
async() => {
writeFile('/provider.ts', `
export class MyService {}
-
+
export const PROVIDER = {provide: MyService};
`);
writeFile('/index.ts', `
import {${type}} from '@angular/core';
import {PROVIDER} from './provider';
-
+
@${type}({${propName}: [PROVIDER]})
export class TestClassA {}
`);
@@ -577,9 +577,9 @@ describe('Missing injectable migration', () => {
writeFile('/second.ts', `
import {${type}} from '@angular/core';
import {PROVIDER} from './provider';
-
- export class ServiceB {}
-
+
+ export class ServiceB {}
+
@${type}({${propName}: [PROVIDER, ServiceB]})
export class TestClassB {}
`);
@@ -596,13 +596,13 @@ describe('Missing injectable migration', () => {
writeFile('/index.ts', `
import {${type}} from '@angular/core';
import {MyService, MySecondService} from './service';
-
+
@${type}({${propName}: [MyService, MySecondService]})
export class TestClass {}
`);
writeFile('/service.ts', `export class MyService {}
-
+
export class MySecondService {}
`);
@@ -620,7 +620,7 @@ describe('Missing injectable migration', () => {
async() => {
writeFile('/index.ts', `
import * as core from '@angular/core';
-
+
export class MyService {
constructor() {
console.log(core.isDevMode());
@@ -631,7 +631,7 @@ describe('Missing injectable migration', () => {
writeFile('/app.module.ts', `
import {${type}} from '@angular/core';
import {MyService} from './index';
-
+
@${type}({${propName}: [MyService]})
export class TestClass {}
`);
@@ -646,7 +646,7 @@ describe('Missing injectable migration', () => {
it('should warn if a referenced individual provider could not be resolved', async() => {
writeFile('/index.ts', `
import {${type}} from '@angular/core';
-
+
@${type}({${propName}: [NotPresent]})
export class TestClass {}
`);
@@ -662,7 +662,7 @@ describe('Missing injectable migration', () => {
it(`should warn if ${propName} value could not be resolved`, async() => {
writeFile('/index.ts', `
import {${type}} from '@angular/core';
-
+
@${type}({${propName}: NOT_ANALYZABLE)
export class TestClass {}
`);
@@ -678,7 +678,7 @@ describe('Missing injectable migration', () => {
it(`should not throw if an empty @${type} is analyzed`, async() => {
writeFile('/index.ts', `
import {${type}} from '@angular/core';
-
+
@${type}()
export class MyModule {}
`);
@@ -697,7 +697,7 @@ describe('Missing injectable migration', () => {
writeFile('/index.ts', `
import {${type}} from '@angular/core';
import {MyService} from './service';
-
+
@${type}({${propName}: [MyService]})
export class TestClass {}
`);
@@ -705,7 +705,7 @@ describe('Missing injectable migration', () => {
writeFile('/service.ts', `
import * as a from 'a';
import * as a from 'b'; // some comment
-
+
export class MyService {}
`);
@@ -722,7 +722,7 @@ describe('Missing injectable migration', () => {
writeFile('/index.ts', `
import {${type}} from '@angular/core';
import {MyService} from './service';
-
+
@${type}({${propName}: [MyService]})
export class TestClass {}
`);
@@ -743,14 +743,14 @@ describe('Missing injectable migration', () => {
writeFile('/index.ts', `
import {${type}} from '@angular/core';
import {MyService} from './service';
-
+
@${type}({${propName}: [MyService]})
export class TestClass {}
`);
writeFile('/service.ts', `
import {Inject} from '@angular/core';
-
+
@Inject()
export class MyService {}
`);
@@ -774,7 +774,7 @@ describe('Missing injectable migration', () => {
writeFile('/index.ts', `
import {MyService} from 'my-lib';
import {Pipe, ${type}} from '@angular/core';
-
+
@${type}({${propName}: [MyService]})
export class TestClass {}
`);
diff --git a/packages/core/schematics/test/module_with_providers_migration_spec.ts b/packages/core/schematics/test/module_with_providers_migration_spec.ts
index 170ed9e351..089753a633 100644
--- a/packages/core/schematics/test/module_with_providers_migration_spec.ts
+++ b/packages/core/schematics/test/module_with_providers_migration_spec.ts
@@ -49,14 +49,14 @@ describe('ModuleWithProviders migration', () => {
it('should add generic type for function return', async() => {
writeFile('/index.ts', `
import {NgModule, ModuleWithProviders} from '@angular/core';
-
+
@NgModule({})
export class BaseModule {}
-
+
export function getProvider() {
return {ngModule: BaseModule}
}
-
+
@NgModule({})
export class TestModule {
static forRoot(): ModuleWithProviders {
@@ -72,18 +72,18 @@ describe('ModuleWithProviders migration', () => {
it('should add generic type for function return; external file', async() => {
writeFile('/module.ts', `
import {NgModule} from '@angular/core';
-
+
@NgModule({})
export class BaseModule {}
`);
writeFile('/index.ts', `
import {NgModule, ModuleWithProviders} from '@angular/core';
import {BaseModule} from './module';
-
+
export function getProvider() {
return {ngModule: BaseModule}
}
-
+
@NgModule({})
export class TestModule {
static forRoot(): ModuleWithProviders {
@@ -99,14 +99,14 @@ describe('ModuleWithProviders migration', () => {
it('should add generic type for function return without explicit type', async() => {
writeFile('/index.ts', `
import {NgModule} from '@angular/core';
-
+
@NgModule({})
export class BaseModule {}
-
+
export function getProvider() {
return {ngModule: BaseModule}
}
-
+
@NgModule({})
export class TestModule {
static forRoot() {
@@ -122,12 +122,12 @@ describe('ModuleWithProviders migration', () => {
it('should add generic type for const variable', async() => {
writeFile('/index.ts', `
import {ModuleWithProviders, NgModule} from '@angular/core';
-
+
@NgModule({})
export class BaseModule {}
-
+
export const myModuleWithProviders = {ngModule: BaseModule};
-
+
@NgModule({})
export class TestModule {
static forRoot(): ModuleWithProviders {
@@ -143,12 +143,12 @@ describe('ModuleWithProviders migration', () => {
it('should add generic type for const variable without explicit type', async() => {
writeFile('/index.ts', `
import {NgModule} from '@angular/core';
-
+
@NgModule({})
export class BaseModule {}
-
+
export const myModuleWithProviders = {ngModule: BaseModule};
-
+
@NgModule({})
export class TestModule {
static forRoot() {
@@ -164,12 +164,12 @@ describe('ModuleWithProviders migration', () => {
it('should not add generic type for const variable with invalid base object', async() => {
writeFile('/index.ts', `
import {NgModule} from '@angular/core';
-
+
@NgModule({})
export class BaseModule {}
-
+
export const myModuleWithProviders = {ngModule: BaseModule, otherKey: 'a'};
-
+
@NgModule({})
export class TestModule {
static forRoot() {
@@ -185,24 +185,24 @@ describe('ModuleWithProviders migration', () => {
it('should add generic type for const variables and functions with incomplete type', async() => {
writeFile('/index.ts', `
import {ModuleWithProviders, NgModule} from '@angular/core';
-
+
@NgModule({})
export class BaseModule {}
-
+
export const myModuleWithProviders: ModuleWithProviders = {ngModule: BaseModule};
-
+
export function mwpFunction(): ModuleWithProviders {
return myModuleWithProviders;
}
-
+
export class MwpClass {
mwp: ModuleWithProviders = myModuleWithProviders;
private _mwp: ModuleWithProviders = myModuleWithProviders;
-
+
getMwp(): ModuleWithProviders {
return myModuleWithProviders;
}
-
+
static initMwp(): ModuleWithProviders {
return myModuleWithProviders;
}
@@ -217,7 +217,7 @@ describe('ModuleWithProviders migration', () => {
it('should not add generic type for const variables without initialization', async() => {
writeFile('/index.ts', `
import {ModuleWithProviders} from '@angular/core';
-
+
export const myModuleWithProviders: ModuleWithProviders;
`);
@@ -230,6 +230,6 @@ describe('ModuleWithProviders migration', () => {
}
function runMigration() {
- runner.runSchematicAsync('migration-v9-module-with-providers', {}, tree).toPromise();
+ return runner.runSchematicAsync('migration-v9-module-with-providers', {}, tree).toPromise();
}
});
diff --git a/packages/core/schematics/test/move_document_migration_spec.ts b/packages/core/schematics/test/move_document_migration_spec.ts
index 267848d35d..46aefc9e01 100644
--- a/packages/core/schematics/test/move_document_migration_spec.ts
+++ b/packages/core/schematics/test/move_document_migration_spec.ts
@@ -165,6 +165,6 @@ describe('move-document migration', () => {
}
function runMigration() {
- runner.runSchematicAsync('migration-v8-move-document', {}, tree).toPromise();
+ return runner.runSchematicAsync('migration-v8-move-document', {}, tree).toPromise();
}
});
diff --git a/packages/core/schematics/test/static_queries_migration_template_spec.ts b/packages/core/schematics/test/static_queries_migration_template_spec.ts
index cce1b34bee..341bb27866 100644
--- a/packages/core/schematics/test/static_queries_migration_template_spec.ts
+++ b/packages/core/schematics/test/static_queries_migration_template_spec.ts
@@ -100,8 +100,8 @@ describe('static-queries migration with template strategy', () => {
host.sync.write(normalize(filePath), virtualFs.stringToFileBuffer(contents));
}
- async function runMigration() {
- await runner.runSchematicAsync('migration-v8-static-queries', {}, tree).toPromise();
+ function runMigration() {
+ return runner.runSchematicAsync('migration-v8-static-queries', {}, tree).toPromise();
}
describe('ViewChild', () => {
@@ -533,13 +533,13 @@ describe('static-queries migration with template strategy', () => {
read?: any;
}): any;
}
-
+
export declare const ViewChild: ViewChildDecorator;
`);
writeFile('/index.ts', `
import {NgModule, Component, ViewChild} from '@angular/core';
-
+
@Component({
template: '
{{myVar.hello()}}
' }) @@ -576,7 +576,7 @@ describe('static-queries migration with template strategy', () => { // This causes a type checking exception as the template // tries to call a function called "hello()" on this variable. myVar: boolean = false; - + @ViewChild('myRef') query: any; } `); @@ -584,7 +584,7 @@ describe('static-queries migration with template strategy', () => { writeFile('/my-module.ts', ` import {NgModule} from '@angular/core'; import {MyComp} from './index'; - + @NgModule({declarations: [MyComp]}) export class MyModule {} `); @@ -599,7 +599,7 @@ describe('static-queries migration with template strategy', () => { it('should notify user if project has syntax errors which can affect analysis', async() => { writeFile('/index.ts', ` import {Component, ViewChild} from '@angular/core'; - + @Component({ template: '' }) @@ -608,7 +608,7 @@ describe('static-queries migration with template strategy', () => { } `); - writeFile('/file-with-syntax-error.ts', ` + writeFile('/file-with-syntax-error.ts', ` export classX ClassWithSyntaxError { // ... } @@ -617,7 +617,7 @@ describe('static-queries migration with template strategy', () => { writeFile('/my-module.ts', ` import {NgModule} from '@angular/core'; import {MyComp} from './index'; - + @NgModule({declarations: [MyComp]}) export class MyModule {} `); @@ -716,7 +716,7 @@ describe('static-queries migration with template strategy', () => { it('should add a todo if query options cannot be migrated inline', async() => { writeFile('/index.ts', ` import {Component, NgModule, ViewChild} from '@angular/core'; - + const myOptionsVar = {}; @Component({template: ''}) diff --git a/packages/core/schematics/test/static_queries_migration_usage_spec.ts b/packages/core/schematics/test/static_queries_migration_usage_spec.ts index 2069948c63..1ec9616648 100644 --- a/packages/core/schematics/test/static_queries_migration_usage_spec.ts +++ b/packages/core/schematics/test/static_queries_migration_usage_spec.ts @@ -172,8 +172,8 @@ describe('static-queries migration with usage strategy', () => { host.sync.write(normalize(filePath), virtualFs.stringToFileBuffer(contents)); } - async function runMigration() { - await runner.runSchematicAsync('migration-v8-static-queries', {}, tree).toPromise(); + function runMigration() { + return runner.runSchematicAsync('migration-v8-static-queries', {}, tree).toPromise(); } function createQueryTests(queryType: 'ViewChild' | 'ContentChild') { @@ -686,12 +686,12 @@ describe('static-queries migration with usage strategy', () => { resolve(): Promise; reject(): Promise; } - + interface Promise { then(cb: Function): Promise; catch(cb: Function): Promise; } - + declare var Promise: PromiseConstructor; `); writeFile('/index.ts', ` @@ -1437,15 +1437,15 @@ describe('static-queries migration with usage strategy', () => { writeFile('/index.ts', ` import {Component, ${queryType}} from '@angular/core'; import {thirdPartySync} from 'my-lib'; - + @Component({template: 'Template'}) export class MyComponent { @${queryType}('test') query: any; @${queryType}('test') query2: any; - + ngOnInit() { const myVarFn = () => this.query2.doSomething(); - + thirdPartySync(() => this.query.doSomething()); thirdPartySync(myVarFn); } @@ -1473,12 +1473,12 @@ describe('static-queries migration with usage strategy', () => { writeFile('/index.ts', ` import {Component, ${queryType}} from '@angular/core'; import {ThirdParty} from 'my-lib'; - + @Component({template: 'Template'}) export class MyComponent { @${queryType}('test') query: any; - - ngOnInit() { + + ngOnInit() { new ThirdParty(() => this.query.doSomething()); } } @@ -1533,11 +1533,11 @@ describe('static-queries migration with usage strategy', () => { @Component({template: 'Test'}) export class MyComponent { @${queryType}('test') query: any; - + ngOnInit() { this.myFunction(); } - + myFunction(unused?: string, cb = () => this.query.doSomething) { cb(); } diff --git a/packages/core/schematics/test/undecorated_classes_with_di_migration_spec.ts b/packages/core/schematics/test/undecorated_classes_with_di_migration_spec.ts index beebaf81b4..b39a8ae74a 100644 --- a/packages/core/schematics/test/undecorated_classes_with_di_migration_spec.ts +++ b/packages/core/schematics/test/undecorated_classes_with_di_migration_spec.ts @@ -68,13 +68,12 @@ describe('Undecorated classes with DI migration', () => { host.sync.write(normalize(filePath), virtualFs.stringToFileBuffer(contents)); } - async function runMigration() { + function runMigration() { return runner.runSchematicAsync('migration-v9-undecorated-classes-with-di', {}, tree) .toPromise(); } - function - writeFakeAngular() { + function writeFakeAngular() { writeFile('/node_modules/@angular/core/index.d.ts', ` export declare class PipeTransform {} export declare class NgZone {} @@ -92,7 +91,7 @@ describe('Undecorated classes with DI migration', () => { })); writeFile('/node_modules/my-lib/index.d.ts', ` import {NgZone} from '@angular/core'; - + export declare class SuperBaseClass { constructor(zone: NgZone); } @@ -101,12 +100,12 @@ describe('Undecorated classes with DI migration', () => { writeFile('/index.ts', ` import {Component, NgModule} from '@angular/core'; import {SuperBaseClass} from 'my-lib'; - + export class BaseClass extends SuperBaseClass {} - + @Component({template: ''}) export class MyComponent extends BaseClass {} - + @NgModule({declarations: [MyComponent]}) export class MyModule {} `); @@ -125,21 +124,21 @@ describe('Undecorated classes with DI migration', () => { it('should add @Directive() decorator to extended base class', async() => { writeFile('/index.ts', ` import {Component, NgModule, NgZone} from '@angular/core'; - + export class BaseClass { constructor(zone: NgZone) {} } - + export class BaseClass2 { constructor(zone: NgZone) {} } - + @Component({template: ''}) export class MyComponent extends BaseClass {} - + @Component({template: ''}) export class MyComponent2 extends BaseClass2 {} - + @NgModule({declarations: [MyComponent, MyComponent2]}) export class AppModule {} `); @@ -153,17 +152,17 @@ describe('Undecorated classes with DI migration', () => { it('not decorated base class multiple times if extended multiple times', async() => { writeFile('/index.ts', dedent ` import {Component, NgModule, NgZone} from '@angular/core'; - + export class BaseClass { constructor(zone: NgZone) {} } - + @Component({template: ''}) export class MyComponent extends BaseClass {} - + @Component({template: ''}) export class MyComponent2 extends BaseClass {} - + @NgModule({declarations: [MyComponent, MyComponent2]}) export class AppModule {} `); @@ -171,7 +170,7 @@ describe('Undecorated classes with DI migration', () => { await runMigration(); expect(tree.readContent('/index.ts')).toContain(dedent ` - + @Directive() export class BaseClass { constructor(zone: NgZone) {} @@ -181,14 +180,14 @@ describe('Undecorated classes with DI migration', () => { it('should add @Injectable() decorator to extended base class', async() => { writeFile('/index.ts', ` import {Injectable, NgModule, NgZone} from '@angular/core'; - + export class BaseClass { constructor(zone: NgZone) {} } @Injectable({template: ''}) export class MyService extends BaseClass {} - + @NgModule({providers: [MyService]}) export class AppModule {} `); @@ -201,10 +200,10 @@ describe('Undecorated classes with DI migration', () => { it('should not decorate base class for decorated pipe', async() => { writeFile('/index.ts', dedent ` import {Component, NgModule, Pipe, PipeTransform} from '@angular/core'; - + @Pipe({name: 'test'}) export class MyPipe extends PipeTransform {} - + @NgModule({declarations: [MyPipe]}) export class AppModule {} `); @@ -256,29 +255,29 @@ describe('Undecorated classes with DI migration', () => { async() => { writeFile('/index.ts', dedent ` import {Component, Injectable, NgModule, NgZone} from '@angular/core'; - + export class BaseClass { constructor(zone: NgZone) {} } - + export class BaseClass { constructor(zone: NgZone) {} } - + @Component({template: ''}) export class MyComponent extends BaseClass { constructor(zone: NgZone) { super(zone); } } - + @Injectable() export class MyService extends BaseClass { constructor(zone: NgZone) { super(zone); } } - + @NgModule({declarations: [MyComponent], providers: [MyService]}) export class AppModule {} `); @@ -295,18 +294,18 @@ describe('Undecorated classes with DI migration', () => { it('should not decorate base class if it already has decorator', async() => { writeFile('/index.ts', dedent ` import {Component, Directive, NgModule, NgZone} from '@angular/core'; - + @Directive({selector: 'base-class'}) export class BaseClass { constructor(zone: NgZone) {} } - + @Component({template: ''}) export class MyComponent extends BaseClass {} - + @NgModule({declarations: [MyComponent]}) export class AppModule {} - + @NgModule({declarations: [BaseClass]}) export class LibModule {} `); @@ -314,7 +313,7 @@ describe('Undecorated classes with DI migration', () => { await runMigration(); expect(tree.readContent('/index.ts')).toContain(dedent ` - + @Directive({selector: 'base-class'}) export class BaseClass {`); }); @@ -327,7 +326,7 @@ describe('Undecorated classes with DI migration', () => { })); writeFile('/node_modules/my-lib/index.d.ts', ` import {NgZone} from '@angular/core'; - + export declare class SuperBaseClass { constructor(zone: NgZone); } @@ -336,30 +335,30 @@ describe('Undecorated classes with DI migration', () => { writeFile('/index.ts', dedent ` import {Component, Injectable, NgModule} from '@angular/core'; import {SuperBaseClass} from 'my-lib'; - + export class BaseClass extends SuperBaseClass {} - + export class BaseClass2 extends SuperBaseClass {} - + export class PassThroughClass extends BaseClass {} - + // should cause "BaseClass" to get a todo comment. @Component({template: ''}) export class MyComponent extends PassThroughClass {} - + // should cause "BaseClass2" to get a todo comment. @Injectable() export class MyService extends BaseClass2 {} - + // should cause "BaseClass" to get a todo comment. @Component({template: ''}) export class MyComponent2 extends BaseClass {} - + // should get a todo comment because there are no base classes // in between. @Component({template: ''}) export class MyComponent3 extends SuperBaseClass {} - + @NgModule({declarations: [MyComponent, MyComponent2, MyComponent3], providers: [MyService]}) export class MyModule {} `); @@ -404,10 +403,10 @@ describe('Undecorated classes with DI migration', () => { writeFile('/index.ts', dedent ` import {Component, NgModule} from '@angular/core'; import {BaseComponent} from 'my-lib'; - + @Component({template: ''}) export class MyComponent extends BaseComponent {} - + @NgModule({declarations: [MyComponent]}) export class MyModule {} `); @@ -424,10 +423,10 @@ describe('Undecorated classes with DI migration', () => { writeFile('/index.ts', dedent ` import {Component, NgModule} from '@angular/core'; import {BaseDirective} from 'my-lib'; - + @Component({template: ''}) export class MyComponent extends BaseDirective {} - + @NgModule({declarations: [MyComponent]}) export class MyModule {} `); @@ -446,10 +445,10 @@ describe('Undecorated classes with DI migration', () => { writeFile('/index.ts', dedent ` import {Component, NgModule} from '@angular/core'; import {BaseComponent} from 'my-lib'; - + @Component({template: ''}) export class MyComponent extends BaseComponent {} - + @NgModule({declarations: [MyComponent]}) export class MyModule {} `); @@ -466,16 +465,16 @@ describe('Undecorated classes with DI migration', () => { it('should decorate all undecorated directives of inheritance chain', async() => { writeFile('/index.ts', ` import {Component, NgModule, NgZone} from '@angular/core'; - + export class SuperBaseClass { constructor(zone: NgZone) {} } - + export class BaseClass extends SuperBaseClass {} - + @Component({template: ''}) export class MyComponent extends BaseClass {} - + @NgModule({declarations: [MyComponent]}) export class MyModule {} `); @@ -490,16 +489,16 @@ describe('Undecorated classes with DI migration', () => { it('should decorate all undecorated providers of inheritance chain', async() => { writeFile('/index.ts', ` import {Injectable, NgModule, NgZone} from '@angular/core'; - + export class SuperBaseClass { constructor(zone: NgZone) {} } - + export class BaseClass extends SuperBaseClass {} - + @Injectable() export class MyService extends BaseClass {} - + @NgModule({providers: [MyService]}) export class MyModule {} `); @@ -516,17 +515,17 @@ describe('Undecorated classes with DI migration', () => { writeFile('/index.ts', ` import {Component, NgModule, NgZone} from '@angular/core'; import {BaseClass} from './base'; - + @Component({template: ''}) export class A extends BaseClass {} - + @NgModule({declarations: [A]}) export class MyModule {} `); writeFile('/base.ts', ` import * as core from '@angular/core'; - + export class BaseClass { constructor(zone: core.NgZone) {} } @@ -542,14 +541,14 @@ describe('Undecorated classes with DI migration', () => { writeFile('/index.ts', ` import {Component, NgModule, NgZone} from '@angular/core'; import {Directive} from './third_party_directive'; - + export class BaseClass { constructor(zone: NgZone) {} } - + @Component({template: ''}) export class MyComponent extends BaseClass {} - + @NgModule({declarations: [MyComponent]}) export class AppModule {} `); @@ -566,19 +565,19 @@ describe('Undecorated classes with DI migration', () => { writeFile('/index.ts', ` import {Component, NgModule, NgZone} from '@angular/core'; import {BaseClass} from './base'; - + @Component({template: ''}) export class A extends BaseClass {} - + @NgModule({declarations: [A]}) export class MyModule {} `); writeFile('/base.ts', ` import {Directive} from './external'; - + export class MyService {} - + export class BaseClass { constructor(zone: MyService) {} } @@ -595,17 +594,17 @@ describe('Undecorated classes with DI migration', () => { writeFile('/index.ts', ` import {Component, NgModule} from '@angular/core'; import {BaseClass} from './base'; - + @Component({template: ''}) export class A extends BaseClass {} - + @NgModule({declarations: [A]}) export class MyModule {} `); writeFile('/base.ts', ` import {Directive as AliasedDir, NgZone} from '@angular/core'; - + export class BaseClass { constructor(zone: NgZone) {} } @@ -637,7 +636,7 @@ describe('Undecorated classes with DI migration', () => { templateUrl: './my-dir.html', }) export class BaseClass {} - + @NgModule({declarations: [BaseClass]}) export class LibModule {} `); @@ -667,14 +666,14 @@ describe('Undecorated classes with DI migration', () => { writeFile('/lib/base.ts', dedent ` import {Directive, NgModule} from '@angular/core'; - + /** my comment */ @Directive({ selector: 'my-dir', styleUrls: ['./my-dir.css'], }) export class BaseClass {} - + @NgModule({declarations: [BaseClass]}) export class LibModule {} `); @@ -683,7 +682,7 @@ describe('Undecorated classes with DI migration', () => { expect(tree.readContent('/index.ts')).toContain(dedent ` import {BaseClass} from './lib/base'; - + @Directive({ selector: 'my-dir', styleUrls: ['./my-dir.css'] @@ -704,10 +703,10 @@ describe('Undecorated classes with DI migration', () => { writeFile('/lib/base.ts', dedent ` import {Pipe, NgModule} from '@angular/core'; - + @Pipe({name: 'my-pipe-name'}) export class BasePipe {} - + @NgModule({declarations: [BasePipe]}) export class LibModule {} `); @@ -728,7 +727,7 @@ describe('Undecorated classes with DI migration', () => { writeFile('/index.ts', dedent ` import {NgModule, Component} from '@angular/core'; import {CDK_TABLE_TEMPLATE} from '@angular/cdk/table'; - + const A = 'hello'; @Component({ @@ -777,16 +776,16 @@ describe('Undecorated classes with DI migration', () => { import {Component, NgModule} from '@angular/core'; import {CDK_TABLE_TEMPLATE as tableTmpl} from '@angular/cdk/table'; import {STYLE_THROUGH_VAR} from '../styles'; - - export const LOCAL_STYLE = 'local_style'; - + + export const LOCAL_STYLE = 'local_style'; + @Component({ selector: 'my-dir', template: tableTmpl, styles: [STYLE_THROUGH_VAR, LOCAL_STYLE] }) export class BaseClass {} - + @NgModule({declarations: [BaseClass]}) export class LibModule {} `); @@ -822,23 +821,23 @@ describe('Undecorated classes with DI migration', () => { writeFile('/second-module.ts', dedent ` import {NgModule, Directive} from '@angular/core'; import {MyComp} from './index'; - + @Directive({selector: 'other-dir'}) export class OtherDir {} - + @NgModule({declarations: [OtherDir, [MyComp]], entryComponents: [MyComp]}) export class MySecondModule {} `); writeFile('/lib/base.ts', dedent ` import {Component, NgModule} from '@angular/core'; - + @Component({ selector: 'my-dir', template: '', }) export class BaseClass {} - + @NgModule({declarations: [BaseClass]}) export class LibModule {} `); @@ -859,7 +858,7 @@ describe('Undecorated classes with DI migration', () => { writeFile('/index.ts', dedent ` import {NgModule} from '@angular/core'; import {BaseClass} from './lib/base'; - + // this will conflict if "MY_TEMPLATE" from the base class is imported. The // import to that export from base class should be aliased to avoid the collision. const MY_TEMPLATE = ''; @@ -872,15 +871,15 @@ describe('Undecorated classes with DI migration', () => { writeFile('/lib/base.ts', dedent ` import {Component, NgModule} from '@angular/core'; - + export const MY_TEMPLATE = ''; - + @Component({ selector: 'my-dir', template: MY_TEMPLATE, }) export class BaseClass {} - + @NgModule({declarations: [BaseClass]}) export class LibModule {} `); @@ -910,7 +909,7 @@ describe('Undecorated classes with DI migration', () => { writeFile('/lib/base.ts', dedent ` import {Component, NgModule, Document} from '@angular/core'; - + // this variable cannot be imported automatically. const someProviders = [{provide: Document, useValue: null}] @@ -920,7 +919,7 @@ describe('Undecorated classes with DI migration', () => { providers: [...someProviders], }) export class BaseClass {} - + @NgModule({declarations: [BaseClass]}) export class LibModule {} `); @@ -954,7 +953,7 @@ describe('Undecorated classes with DI migration', () => { writeFile('/lib/base.ts', dedent ` import {Component, NgModule} from '@angular/core'; - + export const metadataThroughVar = { styleUrls: ['./test.css'], } @@ -965,7 +964,7 @@ describe('Undecorated classes with DI migration', () => { ...metadataThroughVar, }) export class BaseClass {} - + @NgModule({declarations: [BaseClass]}) export class LibModule {} `); @@ -1002,7 +1001,7 @@ describe('Undecorated classes with DI migration', () => { writeFile('/lib/my-tmpl.html', ''); writeFile('/lib/base.ts', dedent ` import {Component, NgModule} from '@angular/core'; - + export const host = {}; export const templateUrl = './my-tmpl.html'; const styleUrls = ["hello.css"]; @@ -1014,7 +1013,7 @@ describe('Undecorated classes with DI migration', () => { host, }) export class BaseClass {} - + @NgModule({declarations: [BaseClass]}) export class LibModule {} `); @@ -1043,14 +1042,14 @@ describe('Undecorated classes with DI migration', () => { writeFile('/index.ts', dedent ` import {NgModule} from '@angular/core'; import {BaseComponent, BasePipe} from 'my-lib'; - + export class PassThrough extends BaseComponent {} - + @NgModule({declarations: [PassThrough]}) export class MyPassThroughMod {} export class MyComp extends PassThrough {} - + export class MyPipe extends BasePipe {} @NgModule({declarations: [MyComp, MyPipe]}) @@ -1110,7 +1109,7 @@ describe('Undecorated classes with DI migration', () => { writeFile('/index.ts', dedent ` import {NgModule} from '@angular/core'; import {BaseComponent} from 'my-lib'; - + export class MyComp extends BaseComponent {} @NgModule({declarations: [MyComp]}) @@ -1172,7 +1171,7 @@ describe('Undecorated classes with DI migration', () => { @NgModule({declarations: [MyDir]}) export class MyModule {} - + export {LOCAL_NAME as PUBLIC_NAME}; `); @@ -1186,7 +1185,7 @@ describe('Undecorated classes with DI migration', () => { styleUrls: [PUBLIC_NAME] }) export class BaseClass {} - + @NgModule({declarations: [BaseClass]}) export class LibModule {} `); @@ -1220,7 +1219,7 @@ describe('Undecorated classes with DI migration', () => { writeFile('/node_modules/my-lib/index.d.ts', `export * from './public-api';`); writeFile('/node_modules/my-lib/public-api.d.ts', ` import {NgZone} from '@angular/core'; - + export const testValidators: any; export declare class BasePipe {} export declare class BaseDirective {} @@ -1328,7 +1327,7 @@ describe('Undecorated classes with DI migration', () => { writeFile('/node_modules/my-lib/index.d.ts', `export * from './public-api';`); writeFile('/node_modules/my-lib/public-api.d.ts', ` import {NgZone} from '@angular/core'; - + export declare class BaseComponent { constructor(zone: NgZone); } @@ -1407,7 +1406,7 @@ describe('Undecorated classes with DI migration', () => { writeFile('/src/app.component.ts', ` import {Component} from '@angular/core'; - + @Component({template: ''}) export class AppComponent {} `); @@ -1415,7 +1414,7 @@ describe('Undecorated classes with DI migration', () => { writeFile('/src/app.module.ts', ` import {NgModule} from '@angular/core'; import {AppComponent} from './app.component'; - + @NgModule({declarations: [AppComponent]}) export class AppModule {} `); @@ -1434,10 +1433,10 @@ describe('Undecorated classes with DI migration', () => { it('should gracefully exit migration if project fails with structural diagnostic', async() => { writeFile('/index.ts', ` import {Component, NgModule} from '@angular/core'; - + @Component({template: ''}) export class TestComp {} - + @NgModule({declarations: [/* TestComp not added */]}) export class MyModule {} `); @@ -1477,13 +1476,13 @@ describe('Undecorated classes with DI migration', () => { it('should not throw if resources could not be read', async() => { writeFile('/index.ts', ` import {Component, NgModule} from '@angular/core'; - + @Component({ templateUrl: './my-template.pug', styleUrls: ["./test.scss", "./some-special-file.custom"], }) export class TestComp {} - + @NgModule({declarations: [TestComp]}) export class MyModule {} `); diff --git a/packages/core/schematics/utils/typescript/compiler_host.ts b/packages/core/schematics/utils/typescript/compiler_host.ts index 25f4f083ab..5103890dfe 100644 --- a/packages/core/schematics/utils/typescript/compiler_host.ts +++ b/packages/core/schematics/utils/typescript/compiler_host.ts @@ -22,7 +22,7 @@ export function createMigrationCompilerHost( const treeRelativePath = relative(basePath, fileName); const fakeOutput = fakeRead ? fakeRead(treeRelativePath) : null; const buffer = fakeOutput === null ? tree.read(treeRelativePath) : fakeOutput; - // Strip BOM as otherwise TSC methods (Ex: getWidth) will return an offset which + // Strip BOM as otherwise TSC methods (Ex: getWidth) will return an offset, // which breaks the CLI UpdateRecorder. // See: https://github.com/angular/angular/pull/30719 return buffer ? buffer.toString().replace(/^\uFEFF/, '') : undefined;