Skip to content

Commit da36ca7

Browse files
authored
fix(material/schematics): avoid mutating the AST when traversing (#25964)
The `visitElements` function was calling `reverse` on the node's `children` which reverses it in place. We shouldn't be mutating the AST just to traverse it in reverse order. These changes switch to using a reverse loop instead.
1 parent 09e44f0 commit da36ca7

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/material/schematics/ng-generate/mdc-migration/rules/tree-traversal.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ export function visitElements(
3030
preorderCallback: (node: TmplAstElement) => void = () => {},
3131
postorderCallback: (node: TmplAstElement) => void = () => {},
3232
): void {
33-
nodes.reverse();
34-
for (let i = 0; i < nodes.length; i++) {
33+
for (let i = nodes.length - 1; i > -1; i--) {
3534
const node = nodes[i];
3635
const isElement = node instanceof TmplAstElement;
3736

0 commit comments

Comments
 (0)