diff --git a/src/Parser.js b/src/Parser.js index 2f00e05..93c9c8c 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -23,16 +23,27 @@ var importParser = { script: 'parseScript', style: 'parseGeneric' }, - parse: function(inDocument) { - if (!inDocument.__importParsed) { + parse: function(document) { + if (!document.__importParsed) { // only parse once - inDocument.__importParsed = true; + document.__importParsed = true; // all parsable elements in inDocument (depth-first pre-order traversal) - var elts = inDocument.querySelectorAll(importParser.selectors); + var elts = document.querySelectorAll(importParser.selectors); + // memoize the number of scripts + var scriptCount = document.scripts.length; // for each parsable node type, call the mapped parsing method - forEach(elts, function(e) { + for (var i=0, e; i