[Pkg-javascript-commits] [less.js] 127/285: initial work to allow post process plugins to work with sourcemaps
Jonas Smedegaard
dr at jones.dk
Mon Oct 26 23:23:46 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 d9a6b462348c8fbb2fbed52650b91d6b3ada1685
Author: Luke Page <luke.a.page at gmail.com>
Date: Fri Sep 19 14:45:41 2014 +0100
initial work to allow post process plugins to work with sourcemaps
---
bin/lessc | 6 +++++-
lib/less/parse-tree.js | 2 +-
lib/less/source-map-builder.js | 25 +++++++++++++++++++++----
lib/less/source-map-output.js | 13 +++++++------
test/less-test.js | 6 +-----
5 files changed, 35 insertions(+), 17 deletions(-)
diff --git a/bin/lessc b/bin/lessc
index f1931ea..e42aac6 100755
--- a/bin/lessc
+++ b/bin/lessc
@@ -338,9 +338,9 @@ var parseLessFile = function (e, data) {
if (options.lint) {
options.sourceMap = false;
}
- options.writeSourceMap = writeSourceMap;
options.sourceMapFilename = options.sourceMap;
options.sourceMapRootpath = options.sourceMapRootpath || "";
+ options.sourceMapFileInline = sourceMapFileInline;
if (options.sourceMap) {
// todo seperate options - no need to send them to less any more?
@@ -361,6 +361,10 @@ var parseLessFile = function (e, data) {
} else {
process.stdout.write(css);
}
+ if (options.sourceMap && !sourceMapFileInline) {
+ // TODO change to return object instead of css.. so much simpler and can also return metrics
+ writeSourceMap(options.sourceMap.getExternalSourceMap());
+ }
}
},
function(err) {
diff --git a/lib/less/parse-tree.js b/lib/less/parse-tree.js
index e1aeeae..baa4d93 100644
--- a/lib/less/parse-tree.js
+++ b/lib/less/parse-tree.js
@@ -35,7 +35,7 @@ ParseTree.prototype.toCSS = function(options) {
for(var i = 0; i < postProcessors.length; i++) {
// TODO - pass source maps
// TODO - async
- css = postProcessors[i].process(css, options);
+ css = postProcessors[i].process(css, options, this.imports);
}
}
return css;
diff --git a/lib/less/source-map-builder.js b/lib/less/source-map-builder.js
index 5cd6f91..68df618 100644
--- a/lib/less/source-map-builder.js
+++ b/lib/less/source-map-builder.js
@@ -5,10 +5,9 @@ module.exports = function (SourceMapOutput) {
};
SourceMapBuilder.prototype.toCSS = function(rootNode, options, imports) {
- this.sourceMapOutput = new SourceMapOutput(
+ var sourceMapOutput = new SourceMapOutput(
{
contentsIgnoredCharsMap: imports.contentsIgnoredChars,
- writeSourceMap: this.options.writeSourceMap,
rootNode: rootNode,
contentsMap: imports.contents,
sourceMapFilename: this.options.sourceMapFilename,
@@ -17,10 +16,28 @@ module.exports = function (SourceMapOutput) {
sourceMapBasepath: this.options.sourceMapBasepath,
sourceMapRootpath: this.options.sourceMapRootpath,
outputSourceFiles: this.options.outputSourceFiles,
- sourceMapGenerator: this.options.sourceMapGenerator
+ sourceMapGenerator: this.options.sourceMapGenerator,
+ sourceMapFileInline: this.options.sourceMapFileInline
});
- return this.sourceMapOutput.toCSS(options);
+ var css = sourceMapOutput.toCSS(options);
+ this.sourceMap = sourceMapOutput.sourceMap;
+ this.sourceMapURL = sourceMapOutput.sourceMapURL;
+ return css;
+ };
+
+ SourceMapBuilder.prototype.getExternalSourceMap = function() {
+ return this.sourceMap;
+ };
+ SourceMapBuilder.prototype.setExternalSourceMap = function(sourceMap) {
+ this.sourceMap = sourceMap;
+ };
+
+ SourceMapBuilder.prototype.isInline = function() {
+ return this.options.sourceMapFileInline;
+ };
+ SourceMapBuilder.prototype.getSourceMapURL = function() {
+ return this.sourceMapURL;
};
return SourceMapBuilder;
diff --git a/lib/less/source-map-output.js b/lib/less/source-map-output.js
index a70889b..5f4c9de 100644
--- a/lib/less/source-map-output.js
+++ b/lib/less/source-map-output.js
@@ -3,18 +3,18 @@ module.exports = function (environment) {
var SourceMapOutput = function (options) {
this._css = [];
this._rootNode = options.rootNode;
- this._writeSourceMap = options.writeSourceMap;
this._contentsMap = options.contentsMap;
this._contentsIgnoredCharsMap = options.contentsIgnoredCharsMap;
this._sourceMapFilename = options.sourceMapFilename;
this._outputFilename = options.outputFilename;
- this._sourceMapURL = options.sourceMapURL;
+ this.sourceMapURL = options.sourceMapURL;
if (options.sourceMapBasepath) {
this._sourceMapBasepath = options.sourceMapBasepath.replace(/\\/g, '/');
}
this._sourceMapRootpath = options.sourceMapRootpath;
this._outputSourceFiles = options.outputSourceFiles;
this._sourceMapGeneratorConstructor = environment.getSourceMapGenerator();
+ this._sourceMapFileInline = options.sourceMapFileInline;
if (this._sourceMapRootpath && this._sourceMapRootpath.charAt(this._sourceMapRootpath.length-1) !== '/') {
this._sourceMapRootpath += '/';
@@ -118,14 +118,15 @@ module.exports = function (environment) {
var sourceMapURL,
sourceMapContent = JSON.stringify(this._sourceMapGenerator.toJSON());
- if (this._sourceMapURL) {
- sourceMapURL = this._sourceMapURL;
+ if (this.sourceMapURL) {
+ sourceMapURL = this.sourceMapURL;
} else if (this._sourceMapFilename) {
sourceMapURL = this.normalizeFilename(this._sourceMapFilename);
}
+ this.sourceMapURL = sourceMapURL;
- if (this._writeSourceMap) {
- this._writeSourceMap(sourceMapContent);
+ if (!this._sourceMapFileInline) {
+ this.sourceMap = sourceMapContent;
} else {
sourceMapURL = "data:application/json;base64," + environment.encodeBase64(sourceMapContent);
}
diff --git a/test/less-test.js b/test/less-test.js
index fbb1d99..f00582e 100644
--- a/test/less-test.js
+++ b/test/less-test.js
@@ -110,10 +110,6 @@ module.exports = function() {
totalTests++;
if (options.sourceMap) {
- var sourceMapOutput;
- options.writeSourceMap = function(output) {
- sourceMapOutput = output;
- };
options.sourceMapOutputFilename = name + ".css";
options.sourceMapBasepath = path.join(process.cwd(), "test/less");
options.sourceMapRootpath = "testweb/";
@@ -128,7 +124,7 @@ module.exports = function() {
toCSS(options, path.join('test/less/', foldername + file), function (err, less) {
if (verifyFunction) {
- return verifyFunction(name, err, less, doReplacements, sourceMapOutput);
+ return verifyFunction(name, err, less, doReplacements, options.sourceMap.getExternalSourceMap());
}
var css_name = name;
if(nameModifier) { css_name = nameModifier(name); }
--
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