[Pkg-javascript-commits] [less.js] 92/285: move import manager creation out of parser

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:23:42 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag v2.0.0
in repository less.js.

commit a46de448a3aebabb7b871febd0c4ac9566e61d9a
Author: Luke Page <luke.a.page at gmail.com>
Date:   Thu Sep 4 18:35:56 2014 +0100

    move import manager creation out of parser
---
 lib/less/{parser => }/imports.js |  8 ++++----
 lib/less/non-node-index.js       |  2 +-
 lib/less/parser/parser.js        | 11 +++--------
 lib/less/render.js               | 16 +++++++++++-----
 4 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/lib/less/parser/imports.js b/lib/less/imports.js
similarity index 92%
rename from lib/less/parser/imports.js
rename to lib/less/imports.js
index b45e533..e31a375 100644
--- a/lib/less/parser/imports.js
+++ b/lib/less/imports.js
@@ -1,5 +1,5 @@
-var contexts = require("../contexts.js");
-module.exports = function(environment, env, Parser) {
+var contexts = require("./contexts.js");
+var getImportManager = module.exports = function(environment, env, Parser) {
     var rootFilename = env && env.filename;
     return {
         paths: env.paths || [],  // Search paths, when importing
@@ -68,9 +68,9 @@ module.exports = function(environment, env, Parser) {
                 if (importOptions.inline) {
                     fileParsedFunc(null, contents, resolvedFilename);
                 } else {
-                    new(Parser)(newEnv).parse(contents, function (e, root) {
+                    new(Parser)(newEnv, getImportManager(environment, env, Parser)).parse(contents, function (e, root) {
                         fileParsedFunc(e, root, resolvedFilename);
-                    }, null, true);
+                    });
                 }
             });
         }
diff --git a/lib/less/non-node-index.js b/lib/less/non-node-index.js
index 0e43bc0..7abfc1b 100644
--- a/lib/less/non-node-index.js
+++ b/lib/less/non-node-index.js
@@ -9,7 +9,7 @@ module.exports = function(environment) {
         contexts: require("./contexts.js"),
         environment: environment
     };
-    less.render = require("./render.js")(less.Parser);
+    less.render = require("./render.js")(less.Parser, environment);
 
     return less;
 };
diff --git a/lib/less/parser/parser.js b/lib/less/parser/parser.js
index 5c323ab..c2c2ed1 100644
--- a/lib/less/parser/parser.js
+++ b/lib/less/parser/parser.js
@@ -1,12 +1,10 @@
 var LessError = require('../less-error.js'),
     tree = require("../tree/index.js"),
     visitor = require("../visitor/index.js"),
-    getImportManager = require("./imports.js"),
     getParserInput = require("./parser-input.js"),
     utils = require("../utils.js");
 
 module.exports = function(environment) {
-    var ParseTree = require("../parse-tree.js")(environment);
 //
 // less.js - parser
 //
@@ -40,12 +38,10 @@ module.exports = function(environment) {
 //    It also takes care of moving all the indices forwards.
 //
 //
-var Parser = function Parser(env) {
+var Parser = function Parser(env, imports) {
     var parsers,
         parserInput = getParserInput();
 
-    var imports = getImportManager(environment, env, Parser);
-
     function expect(arg, msg, index) {
         // some older browsers return typeof 'function' for RegExp
         var result = (Object.prototype.toString.call(arg) === '[object Function]') ? arg.call(parsers) : parserInput.$(arg);
@@ -97,7 +93,7 @@ var Parser = function Parser(env) {
         // @param callback call `callback` when done.
         // @param [additionalData] An optional map which can contains vars - a map (key, value) of variables to apply
         //
-        parse: function (str, callback, additionalData, returnSubParseTree) {
+        parse: function (str, callback, additionalData) {
             var root, error = null, globalVars, modifyVars, preText = "";
 
             globalVars = (additionalData && additionalData.globalVars) ? Parser.serializeVars(additionalData.globalVars) + '\n' : '';
@@ -170,8 +166,7 @@ var Parser = function Parser(env) {
                     return callback(e);
                 }
                 else {
-                    return callback(null,
-                        returnSubParseTree ? root : new ParseTree(root, imports));
+                    return callback(null, root);
                 }
             };
 
diff --git a/lib/less/render.js b/lib/less/render.js
index df31b37..fcce382 100644
--- a/lib/less/render.js
+++ b/lib/less/render.js
@@ -1,7 +1,9 @@
 var PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise,
-    contexts = require("./contexts.js");
+    contexts = require("./contexts.js"),
+    getImportManager = require("./imports.js");
 
-var render = function(Parser) {
+var render = function(Parser, environment) {
+    var ParseTree = require("./parse-tree.js")(environment);
     return function (input, options, callback) {
         options = options || {};
 
@@ -19,14 +21,18 @@ var render = function(Parser) {
                     callback(error);
                 });
         } else {
-            var env = new contexts.parseEnv(options);
+            var env = new contexts.parseEnv(options),
+                imports = getImportManager(environment, env, Parser);
 
-            var parser = new(Parser)(env);
+            var parser = new(Parser)(env, imports);
 
             return new PromiseConstructor(function (resolve, reject) {
                 parser.parse(input, function (e, root) {
                     if (e) { return reject(e); }
-                    try { resolve(root.toCSS(options)); }
+                    try {
+                        var parseTree = new ParseTree(root, imports);
+                        resolve(parseTree.toCSS(options));
+                    }
                     catch (err) { reject( err); }
                 }, options);
             });

-- 
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