[Pkg-javascript-commits] [less.js] 129/285: Do not require users to construct a source map builder

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:23:47 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 5dbae366422917152faca4f4c2d93d0cebbd7d06
Author: Luke Page <luke.a.page at gmail.com>
Date:   Sat Sep 20 00:43:02 2014 +0100

    Do not require users to construct a source map builder
---
 bin/lessc              |  2 +-
 lib/less/index.js      | 11 +++++------
 lib/less/parse-tree.js | 14 ++++++++------
 lib/less/render.js     |  5 ++---
 test/less-test.js      |  2 +-
 5 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/bin/lessc b/bin/lessc
index 3f1b327..18b42f7 100755
--- a/bin/lessc
+++ b/bin/lessc
@@ -344,7 +344,7 @@ var parseLessFile = function (e, data) {
 
     if (options.sourceMap) {
         // todo seperate options - no need to send them to less any more?
-        options.sourceMap = new less.SourceMapBuilder(options);
+        options.sourceMap = options;
     }
 
     options.plugins = pluginManager;
diff --git a/lib/less/index.js b/lib/less/index.js
index bd259b2..5b45e65 100644
--- a/lib/less/index.js
+++ b/lib/less/index.js
@@ -1,6 +1,5 @@
 module.exports = function(environment) {
-    var SourceMapOutput = require('./source-map-output.js')(environment),
-        SourceMapBuilder = require('./source-map-builder.js')(SourceMapOutput);
+    var SourceMapOutput, SourceMapBuilder, ParseTree;
 
     var less = {
         version: [2, 0, 0],
@@ -11,10 +10,10 @@ module.exports = function(environment) {
         functions: require('./functions')(environment),
         contexts: require("./contexts"),
         environment: environment,
-        render: require("./render")(environment),
-        ParseTree: require('./parse-tree'),
-        SourceMapOutput: SourceMapOutput,
-        SourceMapBuilder: SourceMapBuilder,
+        SourceMapOutput: (SourceMapOutput = require('./source-map-output.js')(environment)),
+        SourceMapBuilder: (SourceMapBuilder = require('./source-map-builder.js')(SourceMapOutput)),
+        ParseTree: (ParseTree = require('./parse-tree')(SourceMapBuilder)),
+        render: require("./render")(environment, ParseTree),
         getImportManager: require('./imports'), // TODO: change to class? add static ways of replacing file-manager?
         LessError: require('./less-error'),
         transformTree: require('./transform-tree'),
diff --git a/lib/less/parse-tree.js b/lib/less/parse-tree.js
index c0ade10..f04749f 100644
--- a/lib/less/parse-tree.js
+++ b/lib/less/parse-tree.js
@@ -1,13 +1,14 @@
 var LessError = require('./less-error'),
     transformTree = require("./transform-tree");
 
+module.exports = function(SourceMapBuilder) {
 var ParseTree = function(root, imports) {
     this.root = root;
     this.imports = imports;
 };
 
 ParseTree.prototype.toCSS = function(options) {
-    var evaldRoot, result = {};
+    var evaldRoot, result = {}, sourceMapBuilder;
     try {
         evaldRoot = transformTree(this.root, options);
     } catch (e) {
@@ -22,7 +23,8 @@ ParseTree.prototype.toCSS = function(options) {
             numPrecision: 8};
 
         if (options.sourceMap) {
-            result.css = options.sourceMap.toCSS(evaldRoot, toCSSOptions, this.imports);
+            sourceMapBuilder = new SourceMapBuilder(options.sourceMap);
+            result.css = sourceMapBuilder.toCSS(evaldRoot, toCSSOptions, this.imports);
         } else {
             result.css = evaldRoot.toCSS(toCSSOptions);
         }
@@ -33,14 +35,14 @@ ParseTree.prototype.toCSS = function(options) {
     if (options.plugins) {
         var postProcessors = options.plugins.getPostProcessors();
         for(var i = 0; i < postProcessors.length; i++) {
-            // TODO - pass source maps
             // TODO - async
-            result.css = postProcessors[i].process(result.css, options, this.imports);
+            result.css = postProcessors[i].process(result.css, { sourceMap: sourceMapBuilder, options: options, imports: this.imports });
         }
     }
     if (options.sourceMap) {
-        result.map = options.sourceMap.getExternalSourceMap();
+        result.map = sourceMapBuilder.getExternalSourceMap();
     }
     return result;
 };
-module.exports = ParseTree;
+return ParseTree;
+};
diff --git a/lib/less/render.js b/lib/less/render.js
index ad98a19..182e91b 100644
--- a/lib/less/render.js
+++ b/lib/less/render.js
@@ -1,10 +1,9 @@
 var PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise,
     contexts = require("./contexts"),
     getImportManager = require("./imports"),
-    Parser = require('./parser/parser'),
-    ParseTree = require("./parse-tree");
+    Parser = require('./parser/parser');
 
-module.exports = function(environment) {
+module.exports = function(environment, ParseTree) {
     var render = function (input, options, callback) {
         options = options || {};
 
diff --git a/test/less-test.js b/test/less-test.js
index 8719ac9..8ea848a 100644
--- a/test/less-test.js
+++ b/test/less-test.js
@@ -114,7 +114,7 @@ module.exports = function() {
                 options.sourceMapBasepath = path.join(process.cwd(), "test/less");
                 options.sourceMapRootpath = "testweb/";
                 // TODO seperate options?
-                options.sourceMap = new less.SourceMapBuilder(options);
+                options.sourceMap = options;
             }
 
             options.getVars = function(file) {

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