Skip to content

Commit fa03f0a

Browse files
thePunderWomanalxhub
authored andcommitted
fix(migrations): Ensure control flow migration ignores new block syntax (angular#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 angular#52402
1 parent 6c58034 commit fa03f0a

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

packages/core/schematics/ng-generate/control-flow-migration/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export function migrateTemplate(template: string): {migrated: string|null, error
101101
// Allows for ICUs to be parsed.
102102
tokenizeExpansionForms: true,
103103
// Explicitly disable blocks so that their characters are treated as plain text.
104-
tokenizeBlocks: false,
104+
tokenizeBlocks: true,
105105
preserveLineEndings: true,
106106
});
107107

packages/core/schematics/test/control_flow_migration_spec.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,5 +2085,45 @@ describe('control flow migration', () => {
20852085

20862086
expect(content).toContain('template: `<div><span>shrug</span></div>`');
20872087
});
2088+
2089+
it('should do nothing with already present updated control flow', async () => {
2090+
writeFile('/comp.ts', `
2091+
import {Component} from '@angular/core';
2092+
import {NgIf} from '@angular/common';
2093+
2094+
@Component({
2095+
imports: [NgIf],
2096+
template: \`<div>@if (toggle) {<span>shrug</span>}</div>\`
2097+
})
2098+
class Comp {
2099+
toggle = false;
2100+
}
2101+
`);
2102+
2103+
await runMigration();
2104+
const content = tree.readContent('/comp.ts');
2105+
expect(content).toContain('template: `<div>@if (toggle) {<span>shrug</span>}</div>`');
2106+
});
2107+
2108+
it('should migrate an ngif inside a block', async () => {
2109+
writeFile('/comp.ts', `
2110+
import {Component} from '@angular/core';
2111+
import {NgIf} from '@angular/common';
2112+
2113+
@Component({
2114+
imports: [NgIf],
2115+
template: \`<div>@if (toggle) {<div><span *ngIf="show">shrug</span></div>}</div>\`
2116+
})
2117+
class Comp {
2118+
toggle = false;
2119+
show = false;
2120+
}
2121+
`);
2122+
2123+
await runMigration();
2124+
const content = tree.readContent('/comp.ts');
2125+
expect(content).toContain(
2126+
'template: `<div>@if (toggle) {<div>@if (show) {<span>shrug</span>}</div>}</div>`');
2127+
});
20882128
});
20892129
});

0 commit comments

Comments
 (0)