[Pkg-javascript-commits] [less.js] 25/38: Fix an issue with the import visitor that can cause the parse callback to be called multiple times
Jonas Smedegaard
dr at jones.dk
Mon Oct 26 23:27:27 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag v2.2.0
in repository less.js.
commit 64382de11b6d620632359e4f0f93a9cbf1ae0333
Author: Luke Page <luke.a.page at gmail.com>
Date: Sat Jan 3 14:56:55 2015 +0000
Fix an issue with the import visitor that can cause the parse callback to be called multiple times
---
lib/less/visitors/import-sequencer.js | 40 ++++++++++++++++++++---------------
lib/less/visitors/import-visitor.js | 22 ++++++++++---------
2 files changed, 35 insertions(+), 27 deletions(-)
diff --git a/lib/less/visitors/import-sequencer.js b/lib/less/visitors/import-sequencer.js
index 779faf9..b9e27e9 100644
--- a/lib/less/visitors/import-sequencer.js
+++ b/lib/less/visitors/import-sequencer.js
@@ -2,6 +2,7 @@ function ImportSequencer(onSequencerEmpty) {
this.imports = [];
this.variableImports = [];
this._onSequencerEmpty = onSequencerEmpty;
+ this._currentDepth = 0;
}
ImportSequencer.prototype.addImport = function(callback) {
@@ -24,23 +25,28 @@ ImportSequencer.prototype.addVariableImport = function(callback) {
};
ImportSequencer.prototype.tryRun = function() {
- while(true) {
- while(this.imports.length > 0) {
- var importItem = this.imports[0];
- if (!importItem.isReady) {
- return;
- }
- this.imports = this.imports.slice(1);
- importItem.callback.apply(null, importItem.args);
- }
- if (this.variableImports.length === 0) {
- break;
- }
- var variableImport = this.variableImports[0];
- this.variableImports = this.variableImports.slice(1);
- variableImport();
- }
- if (this._onSequencerEmpty) {
+ this._currentDepth++;
+ try {
+ while(true) {
+ while(this.imports.length > 0) {
+ var importItem = this.imports[0];
+ if (!importItem.isReady) {
+ return;
+ }
+ this.imports = this.imports.slice(1);
+ importItem.callback.apply(null, importItem.args);
+ }
+ if (this.variableImports.length === 0) {
+ break;
+ }
+ var variableImport = this.variableImports[0];
+ this.variableImports = this.variableImports.slice(1);
+ variableImport();
+ }
+ } finally {
+ this._currentDepth--;
+ }
+ if (this._currentDepth === 0 && this._onSequencerEmpty) {
this._onSequencerEmpty();
}
};
diff --git a/lib/less/visitors/import-visitor.js b/lib/less/visitors/import-visitor.js
index a1a0516..f7e3070 100644
--- a/lib/less/visitors/import-visitor.js
+++ b/lib/less/visitors/import-visitor.js
@@ -11,27 +11,29 @@ var ImportVisitor = function(importer, finish) {
this.importCount = 0;
this.onceFileDetectionMap = {};
this.recursionDetector = {};
- this._sequencer = new ImportSequencer();
+ this._sequencer = new ImportSequencer(this._onSequencerEmpty.bind(this));
};
ImportVisitor.prototype = {
isReplacing: false,
run: function (root) {
- var error;
try {
// process the contents
this._visitor.visit(root);
}
catch(e) {
- error = e;
+ this.error = e;
}
this.isFinished = true;
this._sequencer.tryRun();
- if (this.importCount === 0) {
- this._finish(error || this.error);
- }
},
+ _onSequencerEmpty: function() {
+ if (!this.isFinished) {
+ return;
+ }
+ this._finish(this.error);
+ },
visitImport: function (importNode, visitArgs) {
var inlineCSS = importNode.options.inline;
@@ -85,6 +87,9 @@ ImportVisitor.prototype = {
this._importer.push(evaldImportNode.getPath(), tryAppendLessExtension, evaldImportNode.currentFileInfo, evaldImportNode.options, sequencedOnImported);
} else {
this.importCount--;
+ if (this.isFinished) {
+ this._sequencer.tryRun();
+ }
}
},
onImported: function (importNode, context, e, root, importedAtRoot, fullPath) {
@@ -134,10 +139,7 @@ ImportVisitor.prototype = {
importVisitor.importCount--;
if (importVisitor.isFinished) {
- this._sequencer.tryRun();
- if (importVisitor.importCount === 0) {
- importVisitor._finish(importVisitor.error);
- }
+ importVisitor._sequencer.tryRun();
}
},
visitRule: function (ruleNode, visitArgs) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git
More information about the Pkg-javascript-commits
mailing list