Skip to content

Commit a6a6273

Browse files
committed
fix(compiler): fix nextSibling iterator in compiler.
Due to DOM manipulations happening during compilation, it is not correct to call nextSibling after compilation steps.
1 parent ef20b70 commit a6a6273

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

modules/core/src/compiler/pipeline/compile_pipeline.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ export class CompilePipeline {
2525
_process(results, parent:CompileElement, current:CompileElement) {
2626
var additionalChildren = this._control.internalProcess(results, 0, parent, current);
2727
var node = DOM.templateAwareRoot(current.element).firstChild;
28-
while (isPresent(node)){
29-
if(node.nodeType === Node.ELEMENT_NODE) {
28+
while (isPresent(node)) {
29+
// compiliation can potentially move the node, so we need to store the
30+
// next sibling before recursing.
31+
var nextNode = DOM.nextSibling(node);
32+
if (node.nodeType === Node.ELEMENT_NODE) {
3033
this._process(results, current, new CompileElement(node));
3134
}
32-
node = DOM.nextSibling(node);
35+
node = nextNode;
3336
}
3437

3538
if (isPresent(additionalChildren)) {

modules/core/test/compiler/pipeline/view_splitter_spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ export function main() {
7979
expect(results[1].variableBindings).toBe(null);
8080
});
8181

82+
it('should iterate properly after a template dom modification', () => {
83+
var rootElement = createElement('<div><div template></div><after></after></div>');
84+
var results = createPipeline().process(rootElement);
85+
// 1 root + 2 initial + 1 generated template elements
86+
expect(results.length).toEqual(4);
87+
});
88+
8289
});
8390

8491
});

0 commit comments

Comments
 (0)