Skip to content

Commit b5ef68f

Browse files
crisbetoalxhub
authored andcommitted
fix(compiler): compilation error when for loop block expression contains new line (angular#52447)
Fixes that the regex which captures the expression of a `@for` loop block wasn't accounting for line breaks. Fixes angular#52446. PR Close angular#52447
1 parent a3028e2 commit b5ef68f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/compiler/src/render3/r3_control_flow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {BindingParser} from '../template_parser/binding_parser';
1414
import * as t from './r3_ast';
1515

1616
/** Pattern for the expression in a for loop block. */
17-
const FOR_LOOP_EXPRESSION_PATTERN = /^\s*([0-9A-Za-z_$]*)\s+of\s+(.*)/;
17+
const FOR_LOOP_EXPRESSION_PATTERN = /^\s*([0-9A-Za-z_$]*)\s+of\s+([\S\s]*)/;
1818

1919
/** Pattern for the tracking expression in a for loop block. */
2020
const FOR_LOOP_TRACK_PATTERN = /^track\s+([\S\s]*)/;

packages/compiler/test/render3/r3_template_transform_spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,21 @@ describe('R3 template transform', () => {
15941594
`).toEqual(expectedResult);
15951595
});
15961596

1597+
it('should parse for loop block expression containing new lines', () => {
1598+
expectFromHtml(`
1599+
@for (item of [
1600+
{ id: 1 },
1601+
{ id: 2 }
1602+
]; track item.id) {
1603+
{{ item }}
1604+
}
1605+
`).toEqual([
1606+
['ForLoopBlock', '[{id: 1}, {id: 2}]', 'item.id'],
1607+
['Variable', 'item', '$implicit'],
1608+
['BoundText', ' {{ item }} '],
1609+
]);
1610+
});
1611+
15971612
describe('validations', () => {
15981613
it('should report if for loop does not have an expression', () => {
15991614
expect(() => parse(`@for {hello}`)).toThrowError(/@for loop does not have an expression/);

0 commit comments

Comments
 (0)