Skip to content

Commit

Permalink
fix(migrations): Ensure control flow migration ignores new block synt…
Browse files Browse the repository at this point in the history
…ax (#52402)

This fix ensures that the control flow migration does not encounter any problems when new block sytax already exists in a template.

PR Close #52402
  • Loading branch information
jessicajaniuk authored and alxhub committed Oct 27, 2023
1 parent e40e55d commit d7397fb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Expand Up @@ -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,
});

Expand Down
40 changes: 40 additions & 0 deletions packages/core/schematics/test/control_flow_migration_spec.ts
Expand Up @@ -2085,5 +2085,45 @@ describe('control flow migration', () => {

expect(content).toContain('template: `<div><span>shrug</span></div>`');
});

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: \`<div>@if (toggle) {<span>shrug</span>}</div>\`
})
class Comp {
toggle = false;
}
`);

await runMigration();
const content = tree.readContent('/comp.ts');
expect(content).toContain('template: `<div>@if (toggle) {<span>shrug</span>}</div>`');
});

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: \`<div>@if (toggle) {<div><span *ngIf="show">shrug</span></div>}</div>\`
})
class Comp {
toggle = false;
show = false;
}
`);

await runMigration();
const content = tree.readContent('/comp.ts');
expect(content).toContain(
'template: `<div>@if (toggle) {<div>@if (show) {<span>shrug</span>}</div>}</div>`');
});
});
});

0 comments on commit d7397fb

Please sign in to comment.