mirror of
https://github.com/less/less.js.git
synced 2026-05-01 03:00:22 -04:00
implement log to console and fix browser tests
This commit is contained in:
@@ -124,7 +124,9 @@ less.refresh = function (reload, newVars) {
|
||||
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');
|
||||
if (env.remaining === 0) {
|
||||
log("css generated in " + (new Date() - startTime) + 'ms');
|
||||
}
|
||||
endTime = new Date();
|
||||
}, reload, newVars);
|
||||
|
||||
@@ -280,7 +282,7 @@ function loadStyleSheet(sheet, callback, reload, remaining, newVars) {
|
||||
}
|
||||
|
||||
//TODO add tests around how this behaves when reloading
|
||||
removeNode(document.getElementById('less-error-message:' + extractId(path)));
|
||||
removeError(path);
|
||||
|
||||
if (data) {
|
||||
env.currentFileInfo = newFileInfo;
|
||||
@@ -485,15 +487,70 @@ function getXMLHttpRequest() {
|
||||
}
|
||||
}
|
||||
|
||||
function removeNode(node) {
|
||||
return node && node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
function log(str) {
|
||||
if (less.env == 'development' && typeof(console) !== "undefined") { console.log('less: ' + str); }
|
||||
}
|
||||
|
||||
function error(e, rootHref) {
|
||||
if (!less.errorReporting || less.errorReporting === "html") {
|
||||
errorHTML(e, rootHref);
|
||||
} else if (less.errorReporting === "console") {
|
||||
errorConsole(e, rootHref);
|
||||
} else if (typeof less.errorReporting === 'function') {
|
||||
less.errorReporting("add", e, rootHref);
|
||||
}
|
||||
}
|
||||
|
||||
function removeError(path) {
|
||||
if (!less.errorReporting || less.errorReporting === "html") {
|
||||
removeErrorHTML(path);
|
||||
} else if (less.errorReporting === "console") {
|
||||
removeErrorConsole(path);
|
||||
} else if (typeof less.errorReporting === 'function') {
|
||||
less.errorReporting("remove", path);
|
||||
}
|
||||
}
|
||||
|
||||
function removeErrorHTML(path) {
|
||||
var node = document.getElementById('less-error-message:' + extractId(path));
|
||||
if (node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
}
|
||||
|
||||
function removeErrorConsole(path) {
|
||||
//no action
|
||||
}
|
||||
|
||||
function errorConsole(e, rootHref) {
|
||||
var template = '{line}\n{content}';
|
||||
var filename = e.filename || rootHref;
|
||||
var filenameNoPath = filename.match(/([^\/]+(\?.*)?)$/)[1];
|
||||
|
||||
content = (e.type || "Syntax") + "Error: " + (e.message || 'There is an error in your .less file') +
|
||||
"'" + filename + "'";
|
||||
|
||||
var errorline = function (e, i, classname) {
|
||||
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]));
|
||||
}
|
||||
};
|
||||
|
||||
if (e.extract) {
|
||||
errorline(e, 0, '');
|
||||
errorline(e, 1, 'line');
|
||||
errorline(e, 2, '');
|
||||
content += 'on line ' + e.line + ', column ' + (e.column + 1) + ':\n' +
|
||||
errors.join('\n');
|
||||
} else if (e.stack) {
|
||||
content += e.stack;
|
||||
}
|
||||
log(content);
|
||||
}
|
||||
|
||||
function errorHTML(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, errors = [];
|
||||
|
||||
Reference in New Issue
Block a user