Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Propage TreeScope into the shadow trees too.
Browse files Browse the repository at this point in the history
  • Loading branch information
arv committed Mar 13, 2014
1 parent afd4552 commit ce71c44
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/TreeScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
function setTreeScope(node, treeScope) {
if (node.treeScope_ !== treeScope) {
node.treeScope_ = treeScope;
for (var sr = node.shadowRoot; sr; sr = sr.olderShadowRoot) {
sr.treeScope_.parent = treeScope;
}
for (var child = node.firstChild; child; child = child.nextSibling) {
setTreeScope(child, treeScope);
}
Expand Down
37 changes: 37 additions & 0 deletions test/js/TreeScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,41 @@ suite('TreeScope', function() {
assert.equal(getTreeScope(d), srTs);
});

test('change parent in shadow', function() {
var div = document.createElement('div');
div.innerHTML = '<a></a>';
var a = div.firstChild;

var sr = a.createShadowRoot();
sr.innerHTML = '<b></b>';
var b = sr.firstChild;

var sr2 = b.createShadowRoot();
sr2.innerHTML = '<c></c>';
var c = sr2.firstChild;

var sr3 = a.createShadowRoot();
sr3.innerHTML = '<d></d>';
var d = sr3.firstChild;

var ts1 = getTreeScope(a);
var ts2 = getTreeScope(b);
var ts3 = getTreeScope(c);
var ts4 = getTreeScope(d);

assert.equal(ts1.parent, null);
assert.equal(ts2.parent, ts1);
assert.equal(ts3.parent, ts2);
assert.equal(ts4.parent, ts1);

var div2 = document.createElement('div');
div2.appendChild(a);

var ts5 = getTreeScope(a);
assert.notEqual(ts1, ts5);
assert.equal(ts2.parent, ts5);
assert.equal(ts3.parent, ts2);
assert.equal(ts4.parent, ts5);
});

});

0 comments on commit ce71c44

Please sign in to comment.