Skip to content
This repository was archived by the owner on Sep 20, 2019. It is now read-only.

Commit 1e1b111

Browse files
author
John Messerly
committed
Merge pull request #270 from edrachev/forDocumentTree_recursive
Added possibility for recursive calls via callback for forDocumentTree function
2 parents 58c8709 + edde6bb commit 1e1b111

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

src/CustomElements/traverse.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,12 @@ function forRoots(node, cb) {
5858
}
5959
}
6060

61-
/*
62-
Note that the import tree can consume itself and therefore special care
63-
must be taken to avoid recursion.
64-
*/
65-
var processingDocuments;
6661
function forDocumentTree(doc, cb) {
67-
processingDocuments = [];
68-
_forDocumentTree(doc, cb);
69-
processingDocuments = null;
62+
_forDocumentTree(doc, cb, []);
7063
}
7164

7265

73-
function _forDocumentTree(doc, cb) {
66+
function _forDocumentTree(doc, cb, processingDocuments) {
7467
doc = wrap(doc);
7568
if (processingDocuments.indexOf(doc) >= 0) {
7669
return;
@@ -79,7 +72,7 @@ function _forDocumentTree(doc, cb) {
7972
var imports = doc.querySelectorAll('link[rel=' + IMPORT_LINK_TYPE + ']');
8073
for (var i=0, l=imports.length, n; (i<l) && (n=imports[i]); i++) {
8174
if (n.import) {
82-
_forDocumentTree(n.import, cb);
75+
_forDocumentTree(n.import, cb, processingDocuments);
8376
}
8477
}
8578
cb(doc);

0 commit comments

Comments
 (0)