[Pkg-javascript-commits] [less.js] 86/285: Remove duplication in render function

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:23:41 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 20025f10b1079acedc75d3b28d43ab093e6ae985
Author: Luke Page <luke.a.page at gmail.com>
Date:   Thu Sep 4 15:57:20 2014 +0100

    Remove duplication in render function
---
 lib/less/render.js | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/lib/less/render.js b/lib/less/render.js
index d4ea7cc..4893f94 100644
--- a/lib/less/render.js
+++ b/lib/less/render.js
@@ -1,6 +1,6 @@
 var PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise;
 
-module.exports = function(Parser) {
+var render = function(Parser) {
     return function (input, options, callback) {
         options = options || {};
 
@@ -9,19 +9,17 @@ module.exports = function(Parser) {
             options = {};
         }
 
-        var parser = new(Parser)(options);
-
         if (callback) {
-            parser.parse(input, function (e, root) {
-                if (e) { callback(e); return; }
-                var css;
-                try {
-                    css = root && root.toCSS && root.toCSS(options);
-                }
-                catch (err) { callback(err); return; }
-                callback(null, css);
-            }, options);
+            render(input.options)
+                .then(function(css) {
+                    callback(null, css);
+                },
+                function(error) {
+                    callback(error);
+                });
         } else {
+            var parser = new(Parser)(options);
+
             return new PromiseConstructor(function (resolve, reject) {
                 parser.parse(input, function (e, root) {
                     if (e) { return reject(e); }
@@ -32,3 +30,4 @@ module.exports = function(Parser) {
         }
     };
 };
+module.exports = render;

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