diff --git a/packages/core/schematics/ng-generate/control-flow-migration/util.ts b/packages/core/schematics/ng-generate/control-flow-migration/util.ts index fd0d362d865de..7eb271756c8af 100644 --- a/packages/core/schematics/ng-generate/control-flow-migration/util.ts +++ b/packages/core/schematics/ng-generate/control-flow-migration/util.ts @@ -315,7 +315,7 @@ function buildIfThenElseBlock( } function migrateNgFor(etm: ElementToMigrate, tmpl: string, offset: number): Result { - const aliasWithEqualRegexp = /=\s+(count|index|first|last|even|odd)/gm; + const aliasWithEqualRegexp = /=\s*(count|index|first|last|even|odd)/gm; const aliasWithAsRegexp = /(count|index|first|last|even|odd)\s+as/gm; const aliases = []; const lbString = etm.hasLineBreaks ? lb : ''; diff --git a/packages/core/schematics/test/control_flow_migration_spec.ts b/packages/core/schematics/test/control_flow_migration_spec.ts index 93886eb2bab76..7c89d6343bb70 100644 --- a/packages/core/schematics/test/control_flow_migration_spec.ts +++ b/packages/core/schematics/test/control_flow_migration_spec.ts @@ -869,7 +869,6 @@ describe('control flow migration', () => { 'template: ``'); }); - it('should migrate with an index alias', async () => { writeFile('/comp.ts', ` import {Component} from '@angular/core'; @@ -895,6 +894,31 @@ describe('control flow migration', () => { 'template: ``'); }); + it('should migrate with an index alias with no spaces', async () => { + writeFile('/comp.ts', ` + import {Component} from '@angular/core'; + import {NgFor} from '@angular/common'; + interface Item { + id: number; + text: string; + } + + @Component({ + imports: [NgFor], + template: \`\` + }) + class Comp { + items: Item[] = [{id: 1, text: 'blah'},{id: 2, text: 'stuff'}]; + } + `); + + await runMigration(); + const content = tree.readContent('/comp.ts'); + + expect(content).toContain( + 'template: ``'); + }); + it('should migrate with alias declared with as', async () => { writeFile('/comp.ts', ` import {Component} from '@angular/core';