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 2d38619a6eb4a..ff13d77dc49f9 100644 --- a/packages/core/schematics/ng-generate/control-flow-migration/util.ts +++ b/packages/core/schematics/ng-generate/control-flow-migration/util.ts @@ -101,7 +101,7 @@ export function migrateTemplate(template: string): {migrated: string|null, error // Allows for ICUs to be parsed. tokenizeExpansionForms: true, // Explicitly disable blocks so that their characters are treated as plain text. - tokenizeBlocks: false, + tokenizeBlocks: true, preserveLineEndings: true, }); diff --git a/packages/core/schematics/test/control_flow_migration_spec.ts b/packages/core/schematics/test/control_flow_migration_spec.ts index 822a659626975..79da0a927e2e0 100644 --- a/packages/core/schematics/test/control_flow_migration_spec.ts +++ b/packages/core/schematics/test/control_flow_migration_spec.ts @@ -2085,5 +2085,45 @@ describe('control flow migration', () => { expect(content).toContain('template: `
shrug
`'); }); + + it('should do nothing with already present updated control flow', async () => { + writeFile('/comp.ts', ` + import {Component} from '@angular/core'; + import {NgIf} from '@angular/common'; + + @Component({ + imports: [NgIf], + template: \`
@if (toggle) {shrug}
\` + }) + class Comp { + toggle = false; + } + `); + + await runMigration(); + const content = tree.readContent('/comp.ts'); + expect(content).toContain('template: `
@if (toggle) {shrug}
`'); + }); + + it('should migrate an ngif inside a block', async () => { + writeFile('/comp.ts', ` + import {Component} from '@angular/core'; + import {NgIf} from '@angular/common'; + + @Component({ + imports: [NgIf], + template: \`
@if (toggle) {
shrug
}
\` + }) + class Comp { + toggle = false; + show = false; + } + `); + + await runMigration(); + const content = tree.readContent('/comp.ts'); + expect(content).toContain( + 'template: `
@if (toggle) {
@if (show) {shrug}
}
`'); + }); }); });