From 485214edb20e76fce48fc63b1b18fa4eef7b38ab Mon Sep 17 00:00:00 2001 From: "Scott J. Miles" Date: Fri, 8 Nov 2013 19:22:34 -0800 Subject: [PATCH] implement node re-querying when a document acquires new scripts nodes in the middle of parsing; probably impairs performance, brittle wrt node injections above the current parser point --- src/Parser.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) 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