Merge branch 'sourcemaps-wip' into 1.5.0-wip

Conflicts:
	bin/lessc
	lib/less/env.js
	lib/less/tree/color.js
	package.json
This commit is contained in:
Luke Page
2013-07-31 22:21:44 +01:00
63 changed files with 1095 additions and 624 deletions

View File

@@ -1,13 +1,12 @@
var path = require('path'),
fs = require('fs'),
sys = require('util');
fs = require('fs');
var readDirFilesSync = function(dir, regex, callback) {
fs.readdirSync(dir).forEach(function (file) {
if (! regex.test(file)) { return; }
callback(file);
});
}
};
var createTestRunnerPage = function(dir, exclude, testSuiteName, dir2) {
var output = '<html><head>\n';
@@ -33,7 +32,7 @@ var removeFiles = function(dir, regex) {
console.log("Failed to delete " + file);
});
});
}
};
removeFiles("test/browser", /test-runner-[a-zA-Z-]*\.htm$/);
createTestRunnerPage("", /javascript|urls/, "main");

View File

@@ -1,5 +1,4 @@
@import "https://www.github.com/cloudhead/imports/modify-this.css";
@import "https://www.github.com/cloudhead/imports/modify-again.css";
.modify {
my-url: url("https://www.github.com/cloudhead/imports/a.png");

View File

@@ -1,5 +1,4 @@
@import "http://localhost:8081/browser/less/modify-this.css";
@import "http://localhost:8081/browser/less/modify-again.css";
.modify {
my-url: url("http://localhost:8081/browser/less/a.png");

View File

@@ -32,7 +32,6 @@
color: red;
/* A C-style comment */
/* A C-style comment */
background-color: orange;
font-size: 12px;
/* lost comment */
@@ -59,7 +58,12 @@
#last {
color: #0000ff;
}
/* *//* { *//* *//* *//* */#div {
/* */
/* { */
/* */
/* */
/* */
#div {
color: #A33;
}
/* } */

View File

@@ -1,5 +1,4 @@
#colours{color1:#fea;color2:#fea;color3:rgba(255,238,170,0.1);string:"#ffeeaa";/*! but not this type
Note preserved whitespace
*/
}
*/}
dimensions{val:.1px;val:0;val:4cm;val:.2;val:5;angles-must-have-unit:0deg;width:auto\9}

View File

@@ -52,9 +52,9 @@ div.ext7,
.c.replace + .replace .replace,
.replace.replace .c,
.c.replace + .replace .c,
.rep_ace .rep_ace .rep_ace,
.rep_ace.rep_ace .rep_ace,
.c.rep_ace + .rep_ace .rep_ace,
.rep_ace .rep_ace .c,
.rep_ace.rep_ace .c,
.c.rep_ace + .rep_ace .c {
prop: copy-paste-replace;
}

View File

@@ -1,3 +1,5 @@
this isn't very valid CSS. @media (min-width: 600px) {
this isn't very valid CSS.
@media (min-width: 600px) {
#css { color: yellow; }
}

2
test/css/import.css vendored
View File

@@ -1,7 +1,5 @@
@import url(http://fonts.googleapis.com/css?family=Open+Sans);
@import url(/absolute/something.css) screen and (color) and (max-width: 600px);
@import url("//ha.com/file.css") (min-width: 100px);
#import-test {
height: 10px;

View File

@@ -118,7 +118,8 @@
margin: 1cm;
}
@page :first {
size: 8.5in 11in;@top-left {
size: 8.5in 11in;
@top-left {
margin: 1cm;
}
@top-left-corner {

View File

@@ -1,5 +1,4 @@
@import "folder (1)/../css/background.css";
@import "folder (1)/import-test-d.css";
@font-face {
src: url("/fonts/garamond-pro.ttf");

View File

@@ -1,7 +1,5 @@
@import "import/../css/background.css";
@import "import/import-test-d.css";
@import "file.css";
@font-face {
src: url("/fonts/garamond-pro.ttf");

View File

@@ -9,6 +9,8 @@ var globals = Object.keys(global);
var oneTestOnly = process.argv[2];
var isVerbose = process.env.npm_config_loglevel === 'verbose';
var totalTests = 0,
failedTests = 0,
passedTests = 0;
@@ -20,7 +22,7 @@ less.tree.functions.increment = function (a) {
return new(less.tree.Dimension)(a.value + 1);
};
less.tree.functions._color = function (str) {
if (str.value === "evil red") { return new(less.tree.Color)("600") }
if (str.value === "evil red") { return new(less.tree.Color)("600"); }
};
sys.puts("\n" + stylize("LESS", 'underline') + "\n");
@@ -39,6 +41,8 @@ runTestSet({strictMath: true, dumpLineNumbers: 'all'}, "debug/", null,
runTestSet({strictMath: true, relativeUrls: false, rootpath: "folder (1)/"}, "static-urls/");
runTestSet({strictMath: true, compress: true}, "compression/");
runTestSet({}, "legacy/");
runTestSet({strictMath: true, strictUnits: true, sourceMap: true }, "sourcemaps/",
testSourcemap, null, null, function(filename) { return path.join('test/sourcemaps', filename) + '.json'; });
testNoOptions();
@@ -53,6 +57,24 @@ function getErrorPathReplacementFunction(dir) {
};
}
function testSourcemap(name, err, compiledLess, doReplacements, sourcemap) {
fs.readFile(path.join('test/', name) + '.json', 'utf8', function (e, expectedSourcemap) {
sys.print("- " + name + ": ");
if (sourcemap === expectedSourcemap) {
ok('OK');
} else if (err) {
fail("ERROR: " + (err && err.message));
if (isVerbose) {
console.error();
console.error(err.stack);
}
} else {
difference("FAIL", expectedSourcemap, sourcemap);
}
sys.puts("");
});
}
function testErrors(name, err, compiledLess, doReplacements) {
fs.readFile(path.join('test/less/', name) + '.txt', 'utf8', function (e, expectedErr) {
sys.print("- " + name + ": ");
@@ -94,14 +116,14 @@ function checkGlobalLeaks() {
});
}
function runTestSet(options, foldername, verifyFunction, nameModifier, doReplacements) {
function runTestSet(options, foldername, verifyFunction, nameModifier, doReplacements, getFilename) {
foldername = foldername || "";
if(!doReplacements)
doReplacements = globalReplacements;
fs.readdirSync(path.join('test/less/', foldername)).forEach(function (file) {
if (! /\.less/.test(file)) { return }
if (! /\.less/.test(file)) { return; }
var name = foldername + path.basename(file, '.less');
@@ -109,20 +131,34 @@ function runTestSet(options, foldername, verifyFunction, nameModifier, doReplace
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/";
}
toCSS(options, path.join('test/less/', foldername + file), function (err, less) {
if (verifyFunction) {
return verifyFunction(name, err, less, doReplacements);
return verifyFunction(name, err, less, doReplacements, sourceMapOutput);
}
var css_name = name;
if(nameModifier) css_name=nameModifier(name);
if(nameModifier) { css_name = nameModifier(name); }
fs.readFile(path.join('test/css', css_name) + '.css', 'utf8', function (e, css) {
sys.print("- " + css_name + ": ")
sys.print("- " + css_name + ": ");
css = css && doReplacements(css, 'test/less/' + foldername);
if (less === css) { ok('OK'); }
else if (err) {
fail("ERROR: " + (err && err.message));
if (isVerbose) {
console.error();
console.error(err.stack);
}
} else {
difference("FAIL", css, less);
}
@@ -136,7 +172,8 @@ function diff(left, right) {
sys.puts("");
require('diff').diffLines(left, right).forEach(function(item) {
if(item.added || item.removed) {
sys.print(stylize(item.value, item.added ? 'green' : 'red'));
var text = item.value.replace("\n", String.fromCharCode(182) + "\n");
sys.print(stylize(text, item.added ? 'green' : 'red'));
} else {
sys.print(item.value);
}
@@ -186,10 +223,10 @@ function endTest() {
}
function toCSS(options, path, callback) {
var tree, css;
var css;
options = options || {};
fs.readFile(path, 'utf8', function (e, str) {
if (e) { return callback(e) }
if (e) { return callback(e); }
options.paths = [require('path').dirname(path)];
options.filename = require('path').resolve(process.cwd(), path);
@@ -214,7 +251,7 @@ function testNoOptions() {
totalTests++;
try {
sys.print("- Integration - creating parser without options: ");
new(less.Parser);
new(less.Parser)();
} catch(e) {
fail(stylize("FAIL\n", "red"));
return;

View File

@@ -1 +1 @@
this isn't very valid CSS.
this isn't very valid CSS.

View File

@@ -0,0 +1,26 @@
@var: black;
.a() {
color: red;
}
.b {
color: green;
.a();
color: blue;
background: @var;
}
.a, .b {
background: green;
.c, .d {
background: gray;
& + & {
color: red;
}
}
}
.extend:extend(.a all) {
color: pink;
}

View File

@@ -0,0 +1 @@
{"version":3,"file":"sourcemaps/basic.css","sources":["testweb/sourcemaps/basic.less"],"names":[],"mappings":"AAMG;EACD,YAAA;EAJA,UAAA;EAWA,iBAAA;EALA,WAAA;EACA,mBAAA;;AAJC,EASC;AATD,EASM;EACL,gBAAA;;AACE,EAFF,GAEM,KAFN;AAEE,EAFF,GAEM,KAFD;AAEH,EAFG,GAEC,KAFN;AAEE,EAFG,GAEC,KAFD;EAGH,UAAA;;AALJ;AAAK;AAUA;EATL,iBAAA;;AADA,EAEE;AAFG,EAEH;AAFF,EAEO;AAFF,EAEE;AAQF,OARH;AAQG,OARE;EACL,gBAAA;;AACE,EAFF,GAEM,KAFN;AAEE,EAFF,GAEM,KAFN;AAEE,EAFF,GAEM,KAFD;AAEH,EAFF,GAEM,KAFD;AAEH,EAFF,GAEM,KAFN;AAEE,EAFF,GAEM,KAFN;AAEE,EAFF,GAEM,KAFD;AAEH,EAFF,GAEM,KAFD;AAEH,EAFG,GAEC,KAFN;AAEE,EAFG,GAEC,KAFN;AAEE,EAFG,GAEC,KAFD;AAEH,EAFG,GAEC,KAFD;AAEH,EAFG,GAEC,KAFN;AAEE,EAFG,GAEC,KAFN;AAEE,EAFG,GAEC,KAFD;AAEH,EAFG,GAEC,KAFD;AAQF,OARH,GAQG,UARH;AAQG,OARH,GAEM,KAFN;AAQG,OARH,GAQG,UARE;AAQF,OARH,GAEM,KAFD;AAEH,EAFF,GAQG,UARH;AAEE,EAFF,GAQG,UARE;AAQF,OARE,GAQF,UARH;AAQG,OARE,GAEC,KAFN;AAQG,OARE,GAQF,UARE;AAQF,OARE,GAEC,KAFD;AAEH,EAFG,GAQF,UARH;AAEE,EAFG,GAQF,UARE;EAGH,UAAA;;AAKC;EACL,WAAA"}

View File

@@ -0,0 +1,16 @@
<html>
<link type="text/css" rel="stylesheet" media="all" href="import.css">
<link type="text/css" rel="stylesheet" media="all" href="basic.css">
<head>
</head>
<body>
<div id="import-test">id import-test</div>
<div id="import">id import-test</div>
<div id="mixin">class mixin</div>
<div class="a">class a</div>
<div class="b">class b</div>
<div class="b">class b<div class="c">class c</div></div>
<div class="a">class a<div class="d">class d</div></div>
<div class="extend">class extend<div class="c">class c</div></div>
</body>
</html>