mirror of
https://github.com/less/less.js.git
synced 2026-01-22 21:58:14 -05:00
Merge remote-tracking branch 'evocateur/all-sourcemap-patches' into sourcemaps-wip
This commit is contained in:
5
.jshintignore
Normal file
5
.jshintignore
Normal file
@@ -0,0 +1,5 @@
|
||||
benchmark/
|
||||
build/
|
||||
dist/
|
||||
node_modules/
|
||||
test/browser/
|
||||
7
.jshintrc
Normal file
7
.jshintrc
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"evil": true,
|
||||
"boss": true,
|
||||
"expr": true,
|
||||
"laxbreak": true,
|
||||
"node": true
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
//
|
||||
// browser.js - client-side engine
|
||||
//
|
||||
/*global less */
|
||||
|
||||
var isFileProtocol = /^(file|chrome(-extension)?|resource|qrc|app):/.test(location.protocol);
|
||||
|
||||
@@ -43,7 +44,7 @@ less.watch = function () {
|
||||
less.env = 'development';
|
||||
initRunningMode();
|
||||
}
|
||||
return this.watchMode = true
|
||||
return this.watchMode = true;
|
||||
};
|
||||
|
||||
less.unwatch = function () {clearInterval(less.watchTimer); return this.watchMode = false; };
|
||||
@@ -105,12 +106,12 @@ less.modifyVars = function(record) {
|
||||
newVars += ((name.slice(0,1) === '@')? '' : '@') + name +': '+
|
||||
((record[name].slice(-1) === ';')? record[name] : record[name] +';');
|
||||
}
|
||||
less.refresh(false, newVars)
|
||||
less.refresh(false, newVars);
|
||||
};
|
||||
|
||||
less.refresh = function (reload, newVars) {
|
||||
var startTime, endTime;
|
||||
startTime = endTime = new(Date);
|
||||
startTime = endTime = new Date();
|
||||
|
||||
loadStyleSheets(function (e, root, _, sheet, env) {
|
||||
if (e) {
|
||||
@@ -122,9 +123,9 @@ less.refresh = function (reload, newVars) {
|
||||
log("parsed " + sheet.href + " successfully.");
|
||||
createCSS(root.toCSS(less), sheet, env.lastModified);
|
||||
}
|
||||
log("css for " + sheet.href + " generated in " + (new(Date) - endTime) + 'ms');
|
||||
(env.remaining === 0) && log("css generated in " + (new(Date) - startTime) + 'ms');
|
||||
endTime = new(Date);
|
||||
log("css for " + sheet.href + " generated in " + (new Date() - endTime) + 'ms');
|
||||
(env.remaining === 0) && log("css generated in " + (new Date() - startTime) + 'ms');
|
||||
endTime = new Date();
|
||||
}, reload, newVars);
|
||||
|
||||
loadStyles(newVars);
|
||||
@@ -145,6 +146,7 @@ function loadStyles(newVars) {
|
||||
lessText += "\n" + newVars;
|
||||
}
|
||||
|
||||
/*jshint loopfunc:true */
|
||||
// use closure to store current value of i
|
||||
var callback = (function(style) {
|
||||
return function (e, cssAST) {
|
||||
@@ -158,7 +160,7 @@ function loadStyles(newVars) {
|
||||
} else {
|
||||
style.innerHTML = css;
|
||||
}
|
||||
}
|
||||
};
|
||||
})(style);
|
||||
new(less.Parser)(env).parse(lessText, callback);
|
||||
}
|
||||
@@ -337,20 +339,20 @@ function loadFile(originalHref, currentFileInfo, callback, env, newVars) {
|
||||
if (newVars) {
|
||||
lessText += "\n" + newVars;
|
||||
}
|
||||
callback(null, lessText, href, newFileInfo, { lastModified: new Date() })
|
||||
callback(null, lessText, href, newFileInfo, { lastModified: new Date() });
|
||||
} catch (e) {
|
||||
callback(e, null, href);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
xhr(href, env.mime, function (data, lastModified) {
|
||||
doXHR(href, env.mime, function (data, lastModified) {
|
||||
// per file cache
|
||||
fileCache[href] = data;
|
||||
|
||||
// Use remote copy (re-parse)
|
||||
try {
|
||||
callback(null, data, href, newFileInfo, { lastModified: lastModified })
|
||||
callback(null, data, href, newFileInfo, { lastModified: lastModified });
|
||||
} catch (e) {
|
||||
callback(e, null, href);
|
||||
}
|
||||
@@ -406,7 +408,7 @@ function createCSS(styles, sheet, lastModified) {
|
||||
|
||||
// If there is no oldCss, just append; otherwise, only append if we need
|
||||
// to replace oldCss with an updated stylesheet
|
||||
if (oldCss == null || keepOldCss === false) {
|
||||
if (oldCss === null || keepOldCss === false) {
|
||||
var nextEl = sheet && sheet.nextSibling || null;
|
||||
(nextEl || document.getElementsByTagName('head')[0]).parentNode.insertBefore(css, nextEl);
|
||||
}
|
||||
@@ -427,7 +429,7 @@ function createCSS(styles, sheet, lastModified) {
|
||||
}
|
||||
}
|
||||
|
||||
function xhr(url, type, callback, errback) {
|
||||
function doXHR(url, type, callback, errback) {
|
||||
var xhr = getXMLHttpRequest();
|
||||
var async = isFileProtocol ? less.fileAsync : less.async;
|
||||
|
||||
@@ -467,10 +469,11 @@ function xhr(url, type, callback, errback) {
|
||||
|
||||
function getXMLHttpRequest() {
|
||||
if (window.XMLHttpRequest) {
|
||||
return new(XMLHttpRequest);
|
||||
return new XMLHttpRequest();
|
||||
} else {
|
||||
try {
|
||||
return new(ActiveXObject)("MSXML2.XMLHTTP.3.0");
|
||||
/*global ActiveXObject */
|
||||
return new ActiveXObject("MSXML2.XMLHTTP.3.0");
|
||||
} catch (e) {
|
||||
log("browser doesn't support AJAX.");
|
||||
return null;
|
||||
@@ -483,13 +486,13 @@ function removeNode(node) {
|
||||
}
|
||||
|
||||
function log(str) {
|
||||
if (less.env == 'development' && typeof(console) !== "undefined") { console.log('less: ' + str) }
|
||||
if (less.env == 'development' && typeof(console) !== "undefined") { console.log('less: ' + str); }
|
||||
}
|
||||
|
||||
function error(e, rootHref) {
|
||||
var id = 'less-error-message:' + extractId(rootHref || "");
|
||||
var template = '<li><label>{line}</label><pre class="{class}">{content}</pre></li>';
|
||||
var elem = document.createElement('div'), timer, content, error = [];
|
||||
var elem = document.createElement('div'), timer, content, errors = [];
|
||||
var filename = e.filename || rootHref;
|
||||
var filenameNoPath = filename.match(/([^\/]+(\?.*)?)$/)[1];
|
||||
|
||||
@@ -500,8 +503,8 @@ function error(e, rootHref) {
|
||||
'</h3>' + '<p>in <a href="' + filename + '">' + filenameNoPath + "</a> ";
|
||||
|
||||
var errorline = function (e, i, classname) {
|
||||
if (e.extract[i] != undefined) {
|
||||
error.push(template.replace(/\{line\}/, (parseInt(e.line) || 0) + (i - 1))
|
||||
if (e.extract[i] !== undefined) {
|
||||
errors.push(template.replace(/\{line\}/, (parseInt(e.line, 10) || 0) + (i - 1))
|
||||
.replace(/\{class\}/, classname)
|
||||
.replace(/\{content\}/, e.extract[i]));
|
||||
}
|
||||
@@ -512,7 +515,7 @@ function error(e, rootHref) {
|
||||
errorline(e, 1, 'line');
|
||||
errorline(e, 2, '');
|
||||
content += 'on line ' + e.line + ', column ' + (e.column + 1) + ':</p>' +
|
||||
'<ul>' + error.join('') + '</ul>';
|
||||
'<ul>' + errors.join('') + '</ul>';
|
||||
} else if (e.stack) {
|
||||
content += '<br/>' + e.stack.split('\n').slice(1).join('<br/>');
|
||||
}
|
||||
|
||||
@@ -98,5 +98,6 @@
|
||||
destination[propertiesToCopy[i]] = original[propertiesToCopy[i]];
|
||||
}
|
||||
}
|
||||
}
|
||||
})(require('./tree'));
|
||||
};
|
||||
|
||||
})(require('./tree'));
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
(function (tree) {
|
||||
/*jshint loopfunc:true */
|
||||
|
||||
tree.extendFinderVisitor = function() {
|
||||
this._visitor = new tree.visitor(this);
|
||||
this.contexts = [];
|
||||
@@ -246,7 +248,7 @@
|
||||
haystackElement = hackstackSelector.elements[hackstackElementIndex];
|
||||
|
||||
// if we allow elements before our match we can add a potential match every time. otherwise only at the first element.
|
||||
if (extend.allowBefore || (haystackSelectorIndex == 0 && hackstackElementIndex == 0)) {
|
||||
if (extend.allowBefore || (haystackSelectorIndex === 0 && hackstackElementIndex === 0)) {
|
||||
potentialMatches.push({pathIndex: haystackSelectorIndex, index: hackstackElementIndex, matched: 0, initialCombinator: haystackElement.combinator});
|
||||
}
|
||||
|
||||
@@ -257,7 +259,7 @@
|
||||
// then each selector in haystackSelectorPath has a space before it added in the toCSS phase. so we need to work out
|
||||
// what the resulting combinator will be
|
||||
targetCombinator = haystackElement.combinator.value;
|
||||
if (targetCombinator == '' && hackstackElementIndex === 0) {
|
||||
if (targetCombinator === '' && hackstackElementIndex === 0) {
|
||||
targetCombinator = ' ';
|
||||
}
|
||||
|
||||
@@ -388,4 +390,4 @@
|
||||
}
|
||||
};
|
||||
|
||||
})(require('./tree'));
|
||||
})(require('./tree'));
|
||||
|
||||
@@ -26,10 +26,10 @@ tree.functions = {
|
||||
|
||||
function hue(h) {
|
||||
h = h < 0 ? h + 1 : (h > 1 ? h - 1 : h);
|
||||
if (h * 6 < 1) return m1 + (m2 - m1) * h * 6;
|
||||
else if (h * 2 < 1) return m2;
|
||||
else if (h * 3 < 2) return m1 + (m2 - m1) * (2/3 - h) * 6;
|
||||
else return m1;
|
||||
if (h * 6 < 1) { return m1 + (m2 - m1) * h * 6; }
|
||||
else if (h * 2 < 1) { return m2; }
|
||||
else if (h * 3 < 2) { return m1 + (m2 - m1) * (2/3 - h) * 6; }
|
||||
else { return m1; }
|
||||
}
|
||||
},
|
||||
|
||||
@@ -223,6 +223,7 @@ tree.functions = {
|
||||
str = quoted.value;
|
||||
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
/*jshint loopfunc:true */
|
||||
str = str.replace(/%[sda]/i, function(token) {
|
||||
var value = token.match(/s/i) ? args[i].value : args[i].toCSS();
|
||||
return token.match(/[A-Z]$/) ? encodeURIComponent(value) : value;
|
||||
@@ -259,6 +260,7 @@ tree.functions = {
|
||||
},
|
||||
_math: function (fn, unit, n) {
|
||||
if (n instanceof tree.Dimension) {
|
||||
/*jshint eqnull:true */
|
||||
return new(tree.Dimension)(fn(parseFloat(n.value)), unit == null ? n.unit : unit);
|
||||
} else if (typeof(n) === 'number') {
|
||||
return fn(n);
|
||||
@@ -463,10 +465,10 @@ tree.functions = {
|
||||
// use base 64 unless it's an ASCII or UTF-8 format
|
||||
var charset = mime.charsets.lookup(mimetype);
|
||||
useBase64 = ['US-ASCII', 'UTF-8'].indexOf(charset) < 0;
|
||||
if (useBase64) mimetype += ';base64';
|
||||
if (useBase64) { mimetype += ';base64'; }
|
||||
}
|
||||
else {
|
||||
useBase64 = /;base64$/.test(mimetype)
|
||||
useBase64 = /;base64$/.test(mimetype);
|
||||
}
|
||||
|
||||
var buf = fs.readFileSync(filePath);
|
||||
@@ -532,7 +534,7 @@ tree.functions = {
|
||||
gradientType = "radial";
|
||||
gradientDirectionSvg = 'cx="50%" cy="50%" r="75%"';
|
||||
rectangleDimension = 'x="-50" y="-50" width="101" height="101"';
|
||||
break
|
||||
break;
|
||||
default:
|
||||
throw { type: "Argument", message: "svg-gradient direction must be 'to bottom', 'to right', 'to bottom right', 'to top right' or 'radial'" };
|
||||
}
|
||||
@@ -607,6 +609,7 @@ var mathFunctions = [{name:"ceil"}, {name:"floor"}, {name: "sqrt"}, {name:"abs"}
|
||||
{name:"atan", unit: "rad"}, {name:"asin", unit: "rad"}, {name:"acos", unit: "rad"}],
|
||||
createMathFunction = function(name, unit) {
|
||||
return function(n) {
|
||||
/*jshint eqnull:true */
|
||||
if (unit != null) {
|
||||
n = n.unify();
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ var less = {
|
||||
catch (err) { callback(err); }
|
||||
});
|
||||
} else {
|
||||
ee = new(require('events').EventEmitter);
|
||||
ee = new (require('events').EventEmitter)();
|
||||
|
||||
process.nextTick(function () {
|
||||
parser.parse(input, function (e, root) {
|
||||
@@ -42,10 +42,10 @@ var less = {
|
||||
var message = "";
|
||||
var extract = ctx.extract;
|
||||
var error = [];
|
||||
var stylize = options.color ? require('./lessc_helper').stylize : function (str) { return str };
|
||||
var stylize = options.color ? require('./lessc_helper').stylize : function (str) { return str; };
|
||||
|
||||
// only output a stack if it isn't a less error
|
||||
if (ctx.stack && !ctx.type) { return stylize(ctx.stack, 'red') }
|
||||
if (ctx.stack && !ctx.type) { return stylize(ctx.stack, 'red'); }
|
||||
|
||||
if (!ctx.hasOwnProperty('index') || !extract) {
|
||||
return ctx.stack || ctx.message;
|
||||
@@ -132,7 +132,7 @@ less.Parser.fileLoader = function (file, currentFileInfo, callback, env) {
|
||||
newFileInfo.filename = pathname;
|
||||
|
||||
callback(null, data, pathname, newFileInfo);
|
||||
};
|
||||
}
|
||||
|
||||
var isUrl = isUrlRe.test( file );
|
||||
if (isUrl || isUrlRe.test(currentFileInfo.currentDirectory)) {
|
||||
@@ -205,7 +205,7 @@ less.Parser.fileLoader = function (file, currentFileInfo, callback, env) {
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
require('./env');
|
||||
require('./functions');
|
||||
|
||||
@@ -66,4 +66,4 @@ var lessc_helper = {
|
||||
};
|
||||
|
||||
// Exports helper functions
|
||||
for (var h in lessc_helper) { exports[h] = lessc_helper[h] }
|
||||
for (var h in lessc_helper) { exports[h] = lessc_helper[h]; }
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
var less, tree;
|
||||
|
||||
/*global environment */
|
||||
// Node.js does not have a header file added which defines less
|
||||
if (less === undefined) {
|
||||
less = exports;
|
||||
@@ -104,7 +105,7 @@ less.Parser = function Parser(env) {
|
||||
fileParsedFunc(e, root, fullPath);
|
||||
});
|
||||
}
|
||||
}, env)
|
||||
}, env);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -176,13 +177,13 @@ less.Parser = function Parser(env) {
|
||||
mem = i += length;
|
||||
|
||||
while (i < endIndex) {
|
||||
if (! isWhitespace(input.charAt(i))) { break }
|
||||
if (! isWhitespace(input.charAt(i))) { break; }
|
||||
i++;
|
||||
}
|
||||
chunks[j] = chunks[j].slice(length + (i - mem));
|
||||
current = i;
|
||||
|
||||
if (chunks[j].length === 0 && j < chunks.length - 1) { j++ }
|
||||
if (chunks[j].length === 0 && j < chunks.length - 1) { j++; }
|
||||
|
||||
return oldi !== i || oldj !== j;
|
||||
}
|
||||
@@ -222,13 +223,23 @@ less.Parser = function Parser(env) {
|
||||
}
|
||||
}
|
||||
|
||||
function getLocation(index, input) {
|
||||
for (var n = index, column = -1;
|
||||
n >= 0 && input.charAt(n) !== '\n';
|
||||
n--) { column++ }
|
||||
function getLocation(index, inputStream) {
|
||||
var n = index + 1,
|
||||
line = null,
|
||||
column = -1;
|
||||
|
||||
return { line: typeof(index) === 'number' ? (input.slice(0, index).match(/\n/g) || "").length : null,
|
||||
column: column };
|
||||
while (--n >= 0 && inputStream.charAt(n) !== '\n') {
|
||||
column++;
|
||||
}
|
||||
|
||||
if (typeof index === 'number') {
|
||||
line = (inputStream.slice(0, index).match(/\n/g) || "").length;
|
||||
}
|
||||
|
||||
return {
|
||||
line: line,
|
||||
column: column
|
||||
};
|
||||
}
|
||||
|
||||
function getDebugInfo(index, inputStream, env) {
|
||||
@@ -248,6 +259,7 @@ less.Parser = function Parser(env) {
|
||||
loc = getLocation(e.index, input),
|
||||
line = loc.line,
|
||||
col = loc.column,
|
||||
callLine = e.call && getLocation(e.call, input).line,
|
||||
lines = input.split('\n');
|
||||
|
||||
this.type = e.type || 'Syntax';
|
||||
@@ -255,8 +267,8 @@ less.Parser = function Parser(env) {
|
||||
this.filename = e.filename || env.currentFileInfo.filename;
|
||||
this.index = e.index;
|
||||
this.line = typeof(line) === 'number' ? line + 1 : null;
|
||||
this.callLine = e.call && (getLocation(e.call, input).line + 1);
|
||||
this.callExtract = lines[getLocation(e.call, input).line];
|
||||
this.callLine = callLine + 1;
|
||||
this.callExtract = lines[callLine];
|
||||
this.stack = e.stack;
|
||||
this.column = col;
|
||||
this.extract = [
|
||||
@@ -340,16 +352,42 @@ less.Parser = function Parser(env) {
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
case '{': if (! inParam) { level ++; chunk.push(c); break }
|
||||
case '}': if (! inParam) { level --; chunk.push(c); chunks[++j] = chunk = []; break }
|
||||
case '(': if (! inParam) { inParam = true; chunk.push(c); break }
|
||||
case ')': if ( inParam) { inParam = false; chunk.push(c); break }
|
||||
default: chunk.push(c);
|
||||
case '{':
|
||||
if (!inParam) {
|
||||
level++;
|
||||
chunk.push(c);
|
||||
break;
|
||||
}
|
||||
/* falls through */
|
||||
case '}':
|
||||
if (!inParam) {
|
||||
level--;
|
||||
chunk.push(c);
|
||||
chunks[++j] = chunk = [];
|
||||
break;
|
||||
}
|
||||
/* falls through */
|
||||
case '(':
|
||||
if (!inParam) {
|
||||
inParam = true;
|
||||
chunk.push(c);
|
||||
break;
|
||||
}
|
||||
/* falls through */
|
||||
case ')':
|
||||
if (inParam) {
|
||||
inParam = false;
|
||||
chunk.push(c);
|
||||
break;
|
||||
}
|
||||
/* falls through */
|
||||
default:
|
||||
chunk.push(c);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
if (level != 0) {
|
||||
if (level !== 0) {
|
||||
error = new(LessError)({
|
||||
index: i-1,
|
||||
type: 'Parse',
|
||||
@@ -358,7 +396,7 @@ less.Parser = function Parser(env) {
|
||||
}, env);
|
||||
}
|
||||
|
||||
return chunks.map(function (c) { return c.join('') });
|
||||
return chunks.map(function (c) { return c.join(''); });
|
||||
})([[]]);
|
||||
|
||||
if (error) {
|
||||
@@ -383,6 +421,8 @@ less.Parser = function Parser(env) {
|
||||
return function (options, variables) {
|
||||
options = options || {};
|
||||
var importError,
|
||||
evaldRoot,
|
||||
css,
|
||||
evalEnv = new tree.evalEnv(options);
|
||||
|
||||
//
|
||||
@@ -414,7 +454,7 @@ less.Parser = function Parser(env) {
|
||||
}
|
||||
|
||||
try {
|
||||
var evaldRoot = evaluate.call(this, evalEnv);
|
||||
evaldRoot = evaluate.call(this, evalEnv);
|
||||
|
||||
new(tree.joinSelectorVisitor)()
|
||||
.run(evaldRoot);
|
||||
@@ -425,7 +465,7 @@ less.Parser = function Parser(env) {
|
||||
new(tree.toCSSVisitor)({compress: Boolean(options.compress)})
|
||||
.run(evaldRoot);
|
||||
|
||||
var css = evaldRoot.toCSS({
|
||||
css = evaldRoot.toCSS({
|
||||
compress: Boolean(options.compress),
|
||||
dumpLineNumbers: env.dumpLineNumbers,
|
||||
strictUnits: Boolean(options.strictUnits)});
|
||||
@@ -453,10 +493,9 @@ less.Parser = function Parser(env) {
|
||||
// and the part which didn't), so we can color them differently.
|
||||
if (i < input.length - 1) {
|
||||
i = furthest;
|
||||
var loc = getLocation(i, input);
|
||||
lines = input.split('\n');
|
||||
line = (input.slice(0, i).match(/\n/g) || "").length + 1;
|
||||
|
||||
for (var n = i, column = -1; n >= 0 && input.charAt(n) !== '\n'; n--) { column++ }
|
||||
line = loc.line + 1;
|
||||
|
||||
error = {
|
||||
type: "Parse",
|
||||
@@ -464,7 +503,7 @@ less.Parser = function Parser(env) {
|
||||
index: i,
|
||||
filename: env.currentFileInfo.filename,
|
||||
line: line,
|
||||
column: column,
|
||||
column: loc.column,
|
||||
extract: [
|
||||
lines[line - 2],
|
||||
lines[line - 1],
|
||||
@@ -558,7 +597,7 @@ less.Parser = function Parser(env) {
|
||||
comment: function () {
|
||||
var comment;
|
||||
|
||||
if (input.charAt(i) !== '/') return;
|
||||
if (input.charAt(i) !== '/') { return; }
|
||||
|
||||
if (input.charAt(i + 1) === '/') {
|
||||
return new(tree.Comment)($(/^\/\/.*/), true, i, env.currentFileInfo);
|
||||
@@ -589,8 +628,8 @@ less.Parser = function Parser(env) {
|
||||
quoted: function () {
|
||||
var str, j = i, e, index = i;
|
||||
|
||||
if (input.charAt(j) === '~') { j++, e = true } // Escaped strings
|
||||
if (input.charAt(j) !== '"' && input.charAt(j) !== "'") return;
|
||||
if (input.charAt(j) === '~') { j++, e = true; } // Escaped strings
|
||||
if (input.charAt(j) !== '"' && input.charAt(j) !== "'") { return; }
|
||||
|
||||
e && $('~');
|
||||
|
||||
@@ -630,13 +669,13 @@ less.Parser = function Parser(env) {
|
||||
call: function () {
|
||||
var name, nameLC, args, alpha_ret, index = i;
|
||||
|
||||
if (! (name = /^([\w-]+|%|progid:[\w\.]+)\(/.exec(chunks[j]))) return;
|
||||
if (! (name = /^([\w-]+|%|progid:[\w\.]+)\(/.exec(chunks[j]))) { return; }
|
||||
|
||||
name = name[1];
|
||||
nameLC = name.toLowerCase();
|
||||
|
||||
if (nameLC === 'url') { return null }
|
||||
else { i += name.length }
|
||||
if (nameLC === 'url') { return null; }
|
||||
else { i += name.length; }
|
||||
|
||||
if (nameLC === 'alpha') {
|
||||
alpha_ret = $(this.alpha);
|
||||
@@ -660,7 +699,9 @@ less.Parser = function Parser(env) {
|
||||
|
||||
while (arg = $(this.entities.assignment) || $(this.expression)) {
|
||||
args.push(arg);
|
||||
if (! $(',')) { break }
|
||||
if (! $(',')) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return args;
|
||||
},
|
||||
@@ -694,12 +735,16 @@ less.Parser = function Parser(env) {
|
||||
url: function () {
|
||||
var value;
|
||||
|
||||
if (input.charAt(i) !== 'u' || !$(/^url\(/)) return;
|
||||
if (input.charAt(i) !== 'u' || !$(/^url\(/)) {
|
||||
return;
|
||||
}
|
||||
|
||||
value = $(this.entities.quoted) || $(this.entities.variable) ||
|
||||
$(/^(?:(?:\\[\(\)'"])|[^\(\)'"])+/) || "";
|
||||
|
||||
expect(')');
|
||||
|
||||
/*jshint eqnull:true */
|
||||
return new(tree.URL)((value.value != null || value instanceof tree.Variable)
|
||||
? value : new(tree.Anonymous)(value), env.currentFileInfo);
|
||||
},
|
||||
@@ -752,7 +797,9 @@ less.Parser = function Parser(env) {
|
||||
dimension: function () {
|
||||
var value, c = input.charCodeAt(i);
|
||||
//Is the first char of the dimension 0-9, '.', '+' or '-'
|
||||
if ((c > 57 || c < 43) || c === 47 || c == 44) return;
|
||||
if ((c > 57 || c < 43) || c === 47 || c == 44) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (value = $(/^([+-]?\d*\.?\d+)(%|[a-z]+)?/)) {
|
||||
return new(tree.Dimension)(value[1], value[2]);
|
||||
@@ -802,7 +849,7 @@ less.Parser = function Parser(env) {
|
||||
variable: function () {
|
||||
var name;
|
||||
|
||||
if (input.charAt(i) === '@' && (name = $(/^(@[\w-]+)\s*:/))) { return name[1] }
|
||||
if (input.charAt(i) === '@' && (name = $(/^(@[\w-]+)\s*:/))) { return name[1]; }
|
||||
},
|
||||
|
||||
//
|
||||
@@ -828,7 +875,7 @@ less.Parser = function Parser(env) {
|
||||
|
||||
extendList.push(new(tree.Extend)(new(tree.Selector)(elements), option, index));
|
||||
|
||||
} while($(","))
|
||||
} while($(","));
|
||||
|
||||
expect(/^\)/);
|
||||
|
||||
@@ -864,7 +911,7 @@ less.Parser = function Parser(env) {
|
||||
call: function () {
|
||||
var elements = [], e, c, args, delim, arg, index = i, s = input.charAt(i), important = false;
|
||||
|
||||
if (s !== '.' && s !== '#') { return }
|
||||
if (s !== '.' && s !== '#') { return; }
|
||||
|
||||
save(); // stop us absorbing part of an invalid selector
|
||||
|
||||
@@ -924,7 +971,7 @@ less.Parser = function Parser(env) {
|
||||
if (isCall) {
|
||||
// Variable
|
||||
if (arg.value.length == 1) {
|
||||
var val = arg.value[0];
|
||||
val = arg.value[0];
|
||||
}
|
||||
} else {
|
||||
val = arg;
|
||||
@@ -973,7 +1020,7 @@ less.Parser = function Parser(env) {
|
||||
isSemiColonSeperated = true;
|
||||
|
||||
if (expressions.length > 1) {
|
||||
value = new (tree.Value)(expressions);
|
||||
value = new(tree.Value)(expressions);
|
||||
}
|
||||
argsSemiColon.push({ name:name, value:value });
|
||||
|
||||
@@ -1008,7 +1055,9 @@ less.Parser = function Parser(env) {
|
||||
definition: function () {
|
||||
var name, params = [], match, ruleset, param, value, cond, variadic = false;
|
||||
if ((input.charAt(i) !== '.' && input.charAt(i) !== '#') ||
|
||||
peek(/^[^{]*\}/)) return;
|
||||
peek(/^[^{]*\}/)) {
|
||||
return;
|
||||
}
|
||||
|
||||
save();
|
||||
|
||||
@@ -1070,7 +1119,7 @@ less.Parser = function Parser(env) {
|
||||
alpha: function () {
|
||||
var value;
|
||||
|
||||
if (! $(/^\(opacity=/i)) return;
|
||||
if (! $(/^\(opacity=/i)) { return; }
|
||||
if (value = $(/^\d+/) || $(this.entities.variable)) {
|
||||
expect(')');
|
||||
return new(tree.Alpha)(value);
|
||||
@@ -1106,7 +1155,7 @@ less.Parser = function Parser(env) {
|
||||
}
|
||||
}
|
||||
|
||||
if (e) { return new(tree.Element)(c, e, i) }
|
||||
if (e) { return new(tree.Element)(c, e, i); }
|
||||
},
|
||||
|
||||
//
|
||||
@@ -1123,7 +1172,7 @@ less.Parser = function Parser(env) {
|
||||
|
||||
if (c === '>' || c === '+' || c === '~' || c === '|') {
|
||||
i++;
|
||||
while (input.charAt(i).match(/\s/)) { i++ }
|
||||
while (input.charAt(i).match(/\s/)) { i++; }
|
||||
return new(tree.Combinator)(c);
|
||||
} else if (input.charAt(i - 1).match(/\s/)) {
|
||||
return new(tree.Combinator)(" ");
|
||||
@@ -1161,10 +1210,12 @@ less.Parser = function Parser(env) {
|
||||
error("Extend can only be used at the end of selector");
|
||||
}
|
||||
c = input.charAt(i);
|
||||
elements.push(e)
|
||||
elements.push(e);
|
||||
e = null;
|
||||
}
|
||||
if (c === '{' || c === '}' || c === ';' || c === ',' || c === ')') { break }
|
||||
if (c === '{' || c === '}' || c === ';' || c === ',' || c === ')') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (elements.length > 0) { return new(tree.Selector)(elements, extendList, condition, i, env.currentFileInfo); }
|
||||
@@ -1173,7 +1224,7 @@ less.Parser = function Parser(env) {
|
||||
attribute: function () {
|
||||
var attr = '', key, val, op;
|
||||
|
||||
if (! $('[')) return;
|
||||
if (! $('[')) { return; }
|
||||
|
||||
if (!(key = $(this.entities.variableCurly))) {
|
||||
key = expect(/^(?:[_A-Za-z0-9-\*]*\|)?(?:[_A-Za-z0-9-]|\\.)+/);
|
||||
@@ -1207,8 +1258,9 @@ less.Parser = function Parser(env) {
|
||||
|
||||
save();
|
||||
|
||||
if (env.dumpLineNumbers)
|
||||
if (env.dumpLineNumbers) {
|
||||
debugInfo = getDebugInfo(i, input, env);
|
||||
}
|
||||
|
||||
while (s = $(this.lessSelector)) {
|
||||
selectors.push(s);
|
||||
@@ -1222,8 +1274,9 @@ less.Parser = function Parser(env) {
|
||||
|
||||
if (selectors.length > 0 && (rules = $(this.block))) {
|
||||
var ruleset = new(tree.Ruleset)(selectors, rules, env.strictImports);
|
||||
if (env.dumpLineNumbers)
|
||||
if (env.dumpLineNumbers) {
|
||||
ruleset.debugInfo = debugInfo;
|
||||
}
|
||||
return ruleset;
|
||||
} else {
|
||||
// Backtrack
|
||||
@@ -1235,7 +1288,7 @@ less.Parser = function Parser(env) {
|
||||
var name, value, c = input.charAt(i), important, merge = false;
|
||||
save();
|
||||
|
||||
if (c === '.' || c === '#' || c === '&') { return }
|
||||
if (c === '.' || c === '#' || c === '&') { return; }
|
||||
|
||||
if (name = $(this.variable) || $(this.ruleProperty)) {
|
||||
// prefer to try to parse first if its a variable or we are compressing
|
||||
@@ -1320,7 +1373,7 @@ less.Parser = function Parser(env) {
|
||||
break;
|
||||
}
|
||||
options[optionName] = value;
|
||||
if (! $(',')) { break }
|
||||
if (! $(',')) { break; }
|
||||
}
|
||||
} while (o);
|
||||
expect(')');
|
||||
@@ -1351,7 +1404,7 @@ less.Parser = function Parser(env) {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else { return null }
|
||||
} else { return null; }
|
||||
}
|
||||
} while (e);
|
||||
|
||||
@@ -1366,10 +1419,10 @@ less.Parser = function Parser(env) {
|
||||
do {
|
||||
if (e = $(this.mediaFeature)) {
|
||||
features.push(e);
|
||||
if (! $(',')) { break }
|
||||
if (! $(',')) { break; }
|
||||
} else if (e = $(this.entities.variable)) {
|
||||
features.push(e);
|
||||
if (! $(',')) { break }
|
||||
if (! $(',')) { break; }
|
||||
}
|
||||
} while (e);
|
||||
|
||||
@@ -1379,16 +1432,18 @@ less.Parser = function Parser(env) {
|
||||
media: function () {
|
||||
var features, rules, media, debugInfo;
|
||||
|
||||
if (env.dumpLineNumbers)
|
||||
if (env.dumpLineNumbers) {
|
||||
debugInfo = getDebugInfo(i, input, env);
|
||||
}
|
||||
|
||||
if ($(/^@media/)) {
|
||||
features = $(this.mediaFeatures);
|
||||
|
||||
if (rules = $(this.block)) {
|
||||
media = new(tree.Media)(rules, features, i, env.currentFileInfo);
|
||||
if(env.dumpLineNumbers)
|
||||
if (env.dumpLineNumbers) {
|
||||
media.debugInfo = debugInfo;
|
||||
}
|
||||
return media;
|
||||
}
|
||||
}
|
||||
@@ -1403,7 +1458,7 @@ less.Parser = function Parser(env) {
|
||||
var name, value, rules, identifier, e, nodes, nonVendorSpecificName,
|
||||
hasBlock, hasIdentifier, hasExpression;
|
||||
|
||||
if (input.charAt(i) !== '@') return;
|
||||
if (input.charAt(i) !== '@') { return; }
|
||||
|
||||
if (value = $(this['import']) || $(this.media)) {
|
||||
return value;
|
||||
@@ -1413,7 +1468,7 @@ less.Parser = function Parser(env) {
|
||||
|
||||
name = $(/^@[a-z-]+/);
|
||||
|
||||
if (!name) return;
|
||||
if (!name) { return; }
|
||||
|
||||
nonVendorSpecificName = name;
|
||||
if (name.charAt(1) == '-' && name.indexOf('-', 2) > 0) {
|
||||
@@ -1490,7 +1545,7 @@ less.Parser = function Parser(env) {
|
||||
|
||||
while (e = $(this.expression)) {
|
||||
expressions.push(e);
|
||||
if (! $(',')) { break }
|
||||
if (! $(',')) { break; }
|
||||
}
|
||||
|
||||
if (expressions.length > 0) {
|
||||
@@ -1558,7 +1613,7 @@ less.Parser = function Parser(env) {
|
||||
condition: function () {
|
||||
var a, b, c, op, index = i, negate = false;
|
||||
|
||||
if ($(/^not/)) { negate = true }
|
||||
if ($(/^not/)) { negate = true; }
|
||||
expect('(');
|
||||
if (a = $(this.addition) || $(this.entities.keyword) || $(this.entities.quoted)) {
|
||||
if (op = $(/^(?:>=|=<|[<=>])/)) {
|
||||
@@ -1582,7 +1637,7 @@ less.Parser = function Parser(env) {
|
||||
operand: function () {
|
||||
var negate, p = input.charAt(i + 1);
|
||||
|
||||
if (input.charAt(i) === '-' && (p === '@' || p === '(')) { negate = $('-') }
|
||||
if (input.charAt(i) === '-' && (p === '@' || p === '(')) { negate = $('-'); }
|
||||
var o = $(this.sub) || $(this.entities.dimension) ||
|
||||
$(this.entities.color) || $(this.entities.variable) ||
|
||||
$(this.entities.call);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/*jshint rhino:true */
|
||||
/*global name:true, less */
|
||||
var name;
|
||||
|
||||
function loadStyleSheet(sheet, callback, reload, remaining) {
|
||||
@@ -61,7 +63,7 @@ function writeFile(filename, content) {
|
||||
print('No files present in the fileset; Check your pattern match in build.xml');
|
||||
quit(1);
|
||||
}
|
||||
path = name.split("/");path.pop();path=path.join("/")
|
||||
path = name.split("/");path.pop();path=path.join("/");
|
||||
|
||||
var input = readFile(name);
|
||||
|
||||
@@ -109,7 +111,7 @@ function error(e, filename) {
|
||||
var errorline = function (e, i, classname) {
|
||||
if (e.extract[i]) {
|
||||
content +=
|
||||
String(parseInt(e.line) + (i - 1)) +
|
||||
String(parseInt(e.line, 10) + (i - 1)) +
|
||||
":" + e.extract[i] + "\n";
|
||||
}
|
||||
};
|
||||
@@ -123,4 +125,4 @@ function error(e, filename) {
|
||||
errorline(e, 2);
|
||||
}
|
||||
print(content);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,20 +24,25 @@ tree.debugInfo.asComment = function(ctx) {
|
||||
|
||||
tree.debugInfo.asMediaQuery = function(ctx) {
|
||||
return '@media -sass-debug-info{filename{font-family:' +
|
||||
('file://' + ctx.debugInfo.fileName).replace(/([.:/\\])/g, function(a){if(a=='\\') a = '\/'; return '\\' + a}) +
|
||||
('file://' + ctx.debugInfo.fileName).replace(/([.:/\\])/g, function (a) {
|
||||
if (a == '\\') {
|
||||
a = '\/';
|
||||
}
|
||||
return '\\' + a;
|
||||
}) +
|
||||
'}line{font-family:\\00003' + ctx.debugInfo.lineNumber + '}}\n';
|
||||
};
|
||||
|
||||
tree.find = function (obj, fun) {
|
||||
for (var i = 0, r; i < obj.length; i++) {
|
||||
if (r = fun.call(obj, obj[i])) { return r }
|
||||
if (r = fun.call(obj, obj[i])) { return r; }
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
tree.jsify = function (obj) {
|
||||
if (Array.isArray(obj.value) && (obj.value.length > 1)) {
|
||||
return '[' + obj.value.map(function (v) { return v.toCSS(false) }).join(', ') + ']';
|
||||
return '[' + obj.value.map(function (v) { return v.toCSS(false); }).join(', ') + ']';
|
||||
} else {
|
||||
return obj.toCSS(false);
|
||||
}
|
||||
|
||||
@@ -26,4 +26,4 @@ tree.Assignment.prototype = {
|
||||
toCSS: tree.toCSS
|
||||
};
|
||||
|
||||
})(require('../tree'));
|
||||
})(require('../tree'));
|
||||
|
||||
@@ -36,6 +36,7 @@ tree.Call.prototype = {
|
||||
try {
|
||||
func = new tree.functionCall(env, this.currentFileInfo);
|
||||
result = func[nameLC].apply(func, args);
|
||||
/*jshint eqnull:true */
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ tree.Condition.prototype = {
|
||||
|
||||
var i = this.index, result;
|
||||
|
||||
var result = (function (op) {
|
||||
result = (function (op) {
|
||||
switch (op) {
|
||||
case 'and':
|
||||
return a && b;
|
||||
|
||||
@@ -55,6 +55,7 @@ tree.Dimension.prototype = {
|
||||
// we default to the first Dimension's unit,
|
||||
// so `1px + 2` will yield `3px`.
|
||||
operate: function (env, op, other) {
|
||||
/*jshint noempty:false */
|
||||
var value = tree.operate(env, op, this.value, other.value),
|
||||
unit = this.unit.clone();
|
||||
|
||||
@@ -62,7 +63,7 @@ tree.Dimension.prototype = {
|
||||
if (unit.numerator.length === 0 && unit.denominator.length === 0) {
|
||||
unit.numerator = other.unit.numerator.slice(0);
|
||||
unit.denominator = other.unit.denominator.slice(0);
|
||||
} else if (other.unit.numerator.length == 0 && unit.denominator.length == 0) {
|
||||
} else if (other.unit.numerator.length === 0 && unit.denominator.length === 0) {
|
||||
// do nothing
|
||||
} else {
|
||||
other = other.convertTo(this.unit.usedUnits());
|
||||
@@ -124,6 +125,7 @@ tree.Dimension.prototype = {
|
||||
conversions = derivedConversions;
|
||||
}
|
||||
applyUnit = function (atomicUnit, denominator) {
|
||||
/*jshint loopfunc:true */
|
||||
if (group.hasOwnProperty(atomicUnit)) {
|
||||
if (denominator) {
|
||||
value = value / (group[atomicUnit] / group[targetUnit]);
|
||||
@@ -222,11 +224,11 @@ tree.Unit.prototype = {
|
||||
},
|
||||
|
||||
isEmpty: function () {
|
||||
return this.numerator.length == 0 && this.denominator.length == 0;
|
||||
return this.numerator.length === 0 && this.denominator.length === 0;
|
||||
},
|
||||
|
||||
isSingular: function() {
|
||||
return this.numerator.length <= 1 && this.denominator.length == 0;
|
||||
return this.numerator.length <= 1 && this.denominator.length === 0;
|
||||
},
|
||||
|
||||
map: function(callback) {
|
||||
@@ -245,6 +247,7 @@ tree.Unit.prototype = {
|
||||
var group, groupName, result = {}, mapUnit;
|
||||
|
||||
mapUnit = function (atomicUnit) {
|
||||
/*jshint loopfunc:true */
|
||||
if (group.hasOwnProperty(atomicUnit) && !result[groupName]) {
|
||||
result[groupName] = atomicUnit;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ tree.Element.prototype = {
|
||||
},
|
||||
toCSS: function (env) {
|
||||
var value = (this.value.toCSS ? this.value.toCSS(env) : this.value);
|
||||
if (value == '' && this.combinator.value.charAt(0) == '&') {
|
||||
if (value === '' && this.combinator.value.charAt(0) === '&') {
|
||||
return '';
|
||||
} else {
|
||||
return this.combinator.toCSS(env || {}) + value;
|
||||
|
||||
@@ -24,6 +24,7 @@ tree.JavaScript.prototype = {
|
||||
}
|
||||
|
||||
for (var k in env.frames[0].variables()) {
|
||||
/*jshint loopfunc:true */
|
||||
context[k.slice(1)] = {
|
||||
value: env.frames[0].variables()[k].value,
|
||||
toJS: function () {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(function (tree) {
|
||||
|
||||
tree.Keyword = function (value) { this.value = value };
|
||||
tree.Keyword = function (value) { this.value = value; };
|
||||
tree.Keyword.prototype = {
|
||||
type: "Keyword",
|
||||
eval: function () { return this; },
|
||||
|
||||
@@ -74,7 +74,7 @@ tree.Media.prototype = {
|
||||
env.mediaPath.pop();
|
||||
|
||||
return env.mediaPath.length === 0 ? media.evalTop(env) :
|
||||
media.evalNested(env)
|
||||
media.evalNested(env);
|
||||
},
|
||||
variable: function (name) { return tree.Ruleset.prototype.variable.call(this.rules[0], name); },
|
||||
find: function () { return tree.Ruleset.prototype.find.apply(this.rules[0], arguments); },
|
||||
|
||||
@@ -96,8 +96,8 @@ tree.mixin.Definition = function (name, params, rules, condition, variadic) {
|
||||
this.rules = rules;
|
||||
this._lookups = {};
|
||||
this.required = params.reduce(function (count, p) {
|
||||
if (!p.name || (p.name && !p.value)) { return count + 1 }
|
||||
else { return count }
|
||||
if (!p.name || (p.name && !p.value)) { return count + 1; }
|
||||
else { return count; }
|
||||
}, 0);
|
||||
this.parent = tree.Ruleset.prototype;
|
||||
this.frames = [];
|
||||
@@ -116,6 +116,7 @@ tree.mixin.Definition.prototype = {
|
||||
rulesets: function () { return this.parent.rulesets.apply(this); },
|
||||
|
||||
evalParams: function (env, mixinEnv, args, evaldArguments) {
|
||||
/*jshint boss:true */
|
||||
var frame = new(tree.Ruleset)(null, []),
|
||||
varargs, arg,
|
||||
params = this.params.slice(0),
|
||||
@@ -151,7 +152,7 @@ tree.mixin.Definition.prototype = {
|
||||
}
|
||||
argIndex = 0;
|
||||
for (i = 0; i < params.length; i++) {
|
||||
if (evaldArguments[i]) continue;
|
||||
if (evaldArguments[i]) { continue; }
|
||||
|
||||
arg = args && args[argIndex];
|
||||
|
||||
@@ -219,9 +220,9 @@ tree.mixin.Definition.prototype = {
|
||||
var argsLength = (args && args.length) || 0, len, frame;
|
||||
|
||||
if (! this.variadic) {
|
||||
if (argsLength < this.required) { return false }
|
||||
if (argsLength > this.params.length) { return false }
|
||||
if ((this.required > 0) && (argsLength > this.params.length)) { return false }
|
||||
if (argsLength < this.required) { return false; }
|
||||
if (argsLength > this.params.length) { return false; }
|
||||
if ((this.required > 0) && (argsLength > this.params.length)) { return false; }
|
||||
}
|
||||
|
||||
len = Math.min(argsLength, this.arity);
|
||||
|
||||
@@ -19,9 +19,11 @@ tree.Ruleset.prototype = {
|
||||
this.rules = visitor.visit(this.rules);
|
||||
},
|
||||
eval: function (env) {
|
||||
var selectors = this.selectors && this.selectors.map(function (s) { return s.eval(env) });
|
||||
var selectors = this.selectors && this.selectors.map(function (s) { return s.eval(env); });
|
||||
var ruleset = new(tree.Ruleset)(selectors, this.rules.slice(0), this.strictImports);
|
||||
var rules;
|
||||
var rule;
|
||||
var i;
|
||||
|
||||
ruleset.originalRuleset = this;
|
||||
ruleset.root = this.root;
|
||||
@@ -48,7 +50,7 @@ tree.Ruleset.prototype = {
|
||||
|
||||
// Store the frames around mixin definitions,
|
||||
// so they can be evaluated like closures when the time comes.
|
||||
for (var i = 0; i < ruleset.rules.length; i++) {
|
||||
for (i = 0; i < ruleset.rules.length; i++) {
|
||||
if (ruleset.rules[i] instanceof tree.mixin.Definition) {
|
||||
ruleset.rules[i].frames = env.frames.slice(0);
|
||||
}
|
||||
@@ -57,8 +59,9 @@ tree.Ruleset.prototype = {
|
||||
var mediaBlockCount = (env.mediaBlocks && env.mediaBlocks.length) || 0;
|
||||
|
||||
// Evaluate mixin calls.
|
||||
for (var i = 0; i < ruleset.rules.length; i++) {
|
||||
for (i = 0; i < ruleset.rules.length; i++) {
|
||||
if (ruleset.rules[i] instanceof tree.mixin.Call) {
|
||||
/*jshint loopfunc:true */
|
||||
rules = ruleset.rules[i].eval(env).filter(function(r) {
|
||||
if ((r instanceof tree.Rule) && r.variable) {
|
||||
// do not pollute the scope if the variable is
|
||||
@@ -75,7 +78,7 @@ tree.Ruleset.prototype = {
|
||||
}
|
||||
|
||||
// Evaluate everything else
|
||||
for (var i = 0, rule; i < ruleset.rules.length; i++) {
|
||||
for (i = 0; i < ruleset.rules.length; i++) {
|
||||
rule = ruleset.rules[i];
|
||||
|
||||
if (! (rule instanceof tree.mixin.Definition)) {
|
||||
@@ -88,7 +91,7 @@ tree.Ruleset.prototype = {
|
||||
env.selectors.shift();
|
||||
|
||||
if (env.mediaBlocks) {
|
||||
for(var i = mediaBlockCount; i < env.mediaBlocks.length; i++) {
|
||||
for (i = mediaBlockCount; i < env.mediaBlocks.length; i++) {
|
||||
env.mediaBlocks[i].bubbleSelectors(selectors);
|
||||
}
|
||||
}
|
||||
@@ -138,7 +141,7 @@ tree.Ruleset.prototype = {
|
||||
this._lookups = {};
|
||||
},
|
||||
variables: function () {
|
||||
if (this._variables) { return this._variables }
|
||||
if (this._variables) { return this._variables; }
|
||||
else {
|
||||
return this._variables = this.rules.reduce(function (hash, r) {
|
||||
if (r instanceof tree.Rule && r.variable === true) {
|
||||
@@ -303,7 +306,7 @@ tree.Ruleset.prototype = {
|
||||
|
||||
if (!hasParentSelector) {
|
||||
if (context.length > 0) {
|
||||
for(i = 0; i < context.length; i++) {
|
||||
for (i = 0; i < context.length; i++) {
|
||||
paths.push(context[i].concat(selector));
|
||||
}
|
||||
}
|
||||
@@ -347,11 +350,11 @@ tree.Ruleset.prototype = {
|
||||
}
|
||||
|
||||
// loop through our current selectors
|
||||
for(j = 0; j < newSelectors.length; j++) {
|
||||
for (j = 0; j < newSelectors.length; j++) {
|
||||
sel = newSelectors[j];
|
||||
// if we don't have any parent paths, the & might be in a mixin so that it can be used
|
||||
// whether there are parents or not
|
||||
if (context.length == 0) {
|
||||
if (context.length === 0) {
|
||||
// the combinator used on el should now be applied to the next element instead so that
|
||||
// it is not lost
|
||||
if (sel.length > 0) {
|
||||
@@ -362,7 +365,7 @@ tree.Ruleset.prototype = {
|
||||
}
|
||||
else {
|
||||
// and the parent selectors
|
||||
for(k = 0; k < context.length; k++) {
|
||||
for (k = 0; k < context.length; k++) {
|
||||
parentSel = context[k];
|
||||
// We need to put the current selectors
|
||||
// then join the last selector's elements on to the parents selectors
|
||||
@@ -424,7 +427,7 @@ tree.Ruleset.prototype = {
|
||||
this.mergeElementsOnToSelectors(currentElements, newSelectors);
|
||||
}
|
||||
|
||||
for(i = 0; i < newSelectors.length; i++) {
|
||||
for (i = 0; i < newSelectors.length; i++) {
|
||||
if (newSelectors[i].length > 0) {
|
||||
paths.push(newSelectors[i]);
|
||||
}
|
||||
@@ -434,12 +437,12 @@ tree.Ruleset.prototype = {
|
||||
mergeElementsOnToSelectors: function(elements, selectors) {
|
||||
var i, sel, extendList;
|
||||
|
||||
if (selectors.length == 0) {
|
||||
if (selectors.length === 0) {
|
||||
selectors.push([ new(tree.Selector)(elements) ]);
|
||||
return;
|
||||
}
|
||||
|
||||
for(i = 0; i < selectors.length; i++) {
|
||||
for (i = 0; i < selectors.length; i++) {
|
||||
sel = selectors[i];
|
||||
|
||||
// if the previous thing in sel is a parent this needs to join on to it
|
||||
|
||||
@@ -18,6 +18,7 @@ tree.Selector.prototype = {
|
||||
this.condition = visitor.visit(this.condition);
|
||||
},
|
||||
createDerived: function(elements, extendList, evaldCondition) {
|
||||
/*jshint eqnull:true */
|
||||
evaldCondition = evaldCondition != null ? evaldCondition : this.evaldCondition;
|
||||
var newSelector = new(tree.Selector)(elements, extendList || this.extendList, this.condition, this.index, this.currentFileInfo, this.isReferenced);
|
||||
newSelector.evaldCondition = evaldCondition;
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
(function (tree) {
|
||||
|
||||
tree.Variable = function (name, index, currentFileInfo) { this.name = name, this.index = index, this.currentFileInfo = currentFileInfo };
|
||||
tree.Variable = function (name, index, currentFileInfo) {
|
||||
this.name = name;
|
||||
this.index = index;
|
||||
this.currentFileInfo = currentFileInfo;
|
||||
};
|
||||
tree.Variable.prototype = {
|
||||
type: "Variable",
|
||||
eval: function (env) {
|
||||
var variable, v, name = this.name;
|
||||
|
||||
if (name.indexOf('@@') == 0) {
|
||||
if (name.indexOf('@@') === 0) {
|
||||
name = '@' + new(tree.Variable)(name.slice(1)).eval(env).value;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
"node": ">=0.4.2"
|
||||
},
|
||||
"scripts": {
|
||||
"pretest": "./node_modules/.bin/jshint --config ./.jshintrc .",
|
||||
"test": "make test"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
@@ -38,7 +39,8 @@
|
||||
"source-map": "0.1.x"
|
||||
},
|
||||
"devDependencies": {
|
||||
"diff": "~1.0"
|
||||
"diff": "~1.0",
|
||||
"jshint": "~2.1.4"
|
||||
},
|
||||
"keywords": [
|
||||
"compile less",
|
||||
|
||||
@@ -7,7 +7,7 @@ var readDirFilesSync = function(dir, regex, callback) {
|
||||
if (! regex.test(file)) { return; }
|
||||
callback(file);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var createTestRunnerPage = function(dir, exclude, testSuiteName, dir2) {
|
||||
var output = '<html><head>\n';
|
||||
@@ -33,7 +33,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");
|
||||
|
||||
@@ -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");
|
||||
@@ -101,7 +103,7 @@ function runTestSet(options, foldername, verifyFunction, nameModifier, doReplace
|
||||
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');
|
||||
|
||||
@@ -117,12 +119,16 @@ function runTestSet(options, foldername, verifyFunction, nameModifier, doReplace
|
||||
var css_name = 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);
|
||||
}
|
||||
@@ -190,7 +196,7 @@ function toCSS(options, path, callback) {
|
||||
var tree, 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);
|
||||
@@ -215,7 +221,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;
|
||||
|
||||
Reference in New Issue
Block a user