Skip to content

Commit

Permalink
Merge pull request #2439 from OhJeez/sourcemaps-empty-fix
Browse files Browse the repository at this point in the history
Fix empty sourcemaps
  • Loading branch information
lukeapage committed Feb 6, 2015
2 parents 054d88a + 5fac1f0 commit 00c862f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib/less/source-map-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ module.exports = function (SourceMapOutput, environment) {
};

SourceMapBuilder.prototype.getCSSAppendage = function() {

var sourceMapURL = this.sourceMapURL;
if (this.options.sourceMapFileInline) {
if (this.sourceMap === undefined) {
return "";
}
sourceMapURL = "data:application/json;base64," + environment.encodeBase64(this.sourceMap);
}

Expand Down
3 changes: 2 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ lessTester.runTestSet({strictMath: true, strictUnits: true, sourceMap: true, glo
}
return path.join('test/sourcemaps', filename) + '.json';
});
lessTester.runTestSet({strictMath: true, strictUnits: true, sourceMap: {sourceMapFileInline: true}}, "sourcemaps-empty/", lessTester.testEmptySourcemap);
lessTester.runTestSet({globalVars: true, banner: "/**\n * Test\n */\n"}, "globalVars/",
null, null, null, function(name, type, baseFolder) { return path.join(baseFolder, name) + '.json'; });
lessTester.runTestSet({modifyVars: true}, "modifyVars/",
Expand All @@ -49,4 +50,4 @@ lessTester.runTestSet({paths: ['test/data/', 'test/less/import/']}, "include-pat
lessTester.testSyncronous({syncImport: true}, "import");
lessTester.testSyncronous({syncImport: true}, "css");
lessTester.testNoOptions();
lessTester.finished();
lessTester.finished();
24 changes: 21 additions & 3 deletions test/less-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@ module.exports = function() {
});
}

function testEmptySourcemap(name, err, compiledLess, doReplacements, sourcemap, baseFolder) {
process.stdout.write("- " + path.join(baseFolder, name) + ": ");
if (err) {
fail("ERROR: " + (err && err.message));
} else {
var expectedSourcemap = undefined;
if ( compiledLess !== "" ) {
difference("\nCompiledLess must be empty", "", compiledLess);

} else if (sourcemap !== expectedSourcemap) {
fail("Sourcemap must be undefined");
} else {
ok('OK');
}
}
}

function testErrors(name, err, compiledLess, doReplacements, sourcemap, baseFolder) {
fs.readFile(path.join(baseFolder, name) + '.txt', 'utf8', function (e, expectedErr) {
process.stdout.write("- " + path.join(baseFolder, name) + ": ");
Expand Down Expand Up @@ -189,7 +206,7 @@ module.exports = function() {

totalTests++;

if (options.sourceMap) {
if (options.sourceMap && !options.sourceMap.sourceMapFileInline) {
options.sourceMapOutputFilename = name + ".css";
options.sourceMapBasepath = path.join(process.cwd(), baseFolder);
options.sourceMapRootpath = "testweb/";
Expand Down Expand Up @@ -247,10 +264,10 @@ module.exports = function() {
function diff(left, right) {
require('diff').diffLines(left, right).forEach(function(item) {
if (item.added || item.removed) {
var text = item.value.replace("\n", String.fromCharCode(182) + "\n").replace('\ufeff', '[[BOM]]');
var text = item.value && item.value.replace("\n", String.fromCharCode(182) + "\n").replace('\ufeff', '[[BOM]]');
process.stdout.write(stylize(text, item.added ? 'green' : 'red'));
} else {
process.stdout.write(item.value.replace('\ufeff', '[[BOM]]'));
process.stdout.write(item.value && item.value.replace('\ufeff', '[[BOM]]'));
}
});
process.stdout.write("\n");
Expand Down Expand Up @@ -352,6 +369,7 @@ module.exports = function() {
testSyncronous: testSyncronous,
testErrors: testErrors,
testSourcemap: testSourcemap,
testEmptySourcemap: testEmptySourcemap,
testNoOptions: testNoOptions,
prepBomTest: prepBomTest,
finished: finished
Expand Down
Empty file.
1 change: 1 addition & 0 deletions test/less/sourcemaps-empty/var-defs.less
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@test-var: 'something';

0 comments on commit 00c862f

Please sign in to comment.