[Pkg-javascript-commits] [less.js] 79/285: Merge remote-tracking branch 'origin/master' into 2_0_0
Jonas Smedegaard
dr at jones.dk
Mon Oct 26 23:23:40 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 8fc964dc3449437bbfdc7f078cc9566cfacf2834
Merge: ca72b4d 6f7676a
Author: Luke Page <luke.a.page at gmail.com>
Date: Wed Sep 3 07:36:20 2014 +0100
Merge remote-tracking branch 'origin/master' into 2_0_0
Conflicts:
lib/less/index.js
lib/less/parser/parser.js
lib/less/tree/rule.js
test/less/property-name-interp.less
lib/less/index.js | 4 ++--
lib/less/parser/parser.js | 3 +++
lib/less/tree/rule.js | 11 +++++++----
test/css/comments.css | 6 ++++++
test/css/property-name-interp.css | 1 +
test/less/comments.less | 8 +++++++-
test/less/property-name-interp.less | 3 +++
test/modify-vars.js | 17 +++++++++++++++++
8 files changed, 46 insertions(+), 7 deletions(-)
diff --cc lib/less/index.js
index c83153c,5ddfa4c..f764f66
--- a/lib/less/index.js
+++ b/lib/less/index.js
@@@ -1,91 -1,264 +1,91 @@@
-var path = require('path'),
- url = require('url'),
- request,
- fs = require('./fs');
+var PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise;
+var environment = require("./environment/node");
+var less = require("./non-node-index.js")(environment);
-var less = {
- version: [1, 7, 4],
- Parser: require('./parser').Parser,
- tree: require('./tree'),
- render: function (input, options, callback) {
- options = options || {};
+less.render = function (input, options, callback) {
+ options = options || {};
- if (typeof(options) === 'function') {
- callback = options;
- options = {};
- }
+ if (typeof(options) === 'function') {
+ callback = options;
+ options = {};
+ }
- var parser = new(less.Parser)(options),
- ee;
+ var parser = new(less.Parser)(options);
- if (callback) {
- parser.parse(input, function (e, root) {
- if (e) { callback(e); return; }
- var css;
- try {
- css = root && root.toCSS && root.toCSS(options);
- }
- catch (err) { callback(err); return; }
- callback(null, css);
+ if (callback) {
+ parser.parse(input, function (e, root) {
+ if (e) { callback(e); return; }
+ var css;
+ try {
+ css = root && root.toCSS && root.toCSS(options);
+ }
+ catch (err) { callback(err); return; }
+ callback(null, css);
- });
+ }, options);
- } else {
- ee = new (require('events').EventEmitter)();
-
- process.nextTick(function () {
- parser.parse(input, function (e, root) {
- if (e) { return ee.emit('error', e); }
- try { ee.emit('success', root.toCSS(options)); }
- catch (err) { ee.emit('error', err); }
+ } else {
+ return new PromiseConstructor(function (resolve, reject) {
+ parser.parse(input, function (e, root) {
+ if (e) { return reject(e); }
+ try { resolve(root.toCSS(options)); }
+ catch (err) { reject( err); }
- });
+ }, options);
- });
- return ee;
- }
- },
- formatError: function(ctx, options) {
- options = options || {};
-
- var message = "";
- var extract = ctx.extract;
- var error = [];
- 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.hasOwnProperty('index') || !extract) {
- return ctx.stack || ctx.message;
- }
-
- if (typeof(extract[0]) === 'string') {
- error.push(stylize((ctx.line - 1) + ' ' + extract[0], 'grey'));
- }
-
- if (typeof(extract[1]) === 'string') {
- var errorTxt = ctx.line + ' ';
- if (extract[1]) {
- errorTxt += extract[1].slice(0, ctx.column) +
- stylize(stylize(stylize(extract[1][ctx.column], 'bold') +
- extract[1].slice(ctx.column + 1), 'red'), 'inverse');
- }
- error.push(errorTxt);
- }
-
- if (typeof(extract[2]) === 'string') {
- error.push(stylize((ctx.line + 1) + ' ' + extract[2], 'grey'));
- }
- error = error.join('\n') + stylize('', 'reset') + '\n';
-
- message += stylize(ctx.type + 'Error: ' + ctx.message, 'red');
- if (ctx.filename) {
- message += stylize(' in ', 'red') + ctx.filename +
- stylize(' on line ' + ctx.line + ', column ' + (ctx.column + 1) + ':', 'grey');
- }
-
- message += '\n' + error;
-
- if (ctx.callLine) {
- message += stylize('from ', 'red') + (ctx.filename || '') + '/n';
- message += stylize(ctx.callLine, 'grey') + ' ' + ctx.callExtract + '/n';
- }
-
- return message;
- },
- writeError: function (ctx, options) {
- options = options || {};
- if (options.silent) { return; }
- console.error(less.formatError(ctx, options));
+ });
}
};
+less.formatError = function(ctx, options) {
+ options = options || {};
-require('./tree/color');
-require('./tree/directive');
-require('./tree/detached-ruleset');
-require('./tree/operation');
-require('./tree/dimension');
-require('./tree/keyword');
-require('./tree/variable');
-require('./tree/ruleset');
-require('./tree/element');
-require('./tree/selector');
-require('./tree/quoted');
-require('./tree/expression');
-require('./tree/rule');
-require('./tree/call');
-require('./tree/url');
-require('./tree/alpha');
-require('./tree/import');
-require('./tree/mixin');
-require('./tree/comment');
-require('./tree/anonymous');
-require('./tree/value');
-require('./tree/javascript');
-require('./tree/assignment');
-require('./tree/condition');
-require('./tree/paren');
-require('./tree/media');
-require('./tree/unicode-descriptor');
-require('./tree/negative');
-require('./tree/extend');
-require('./tree/ruleset-call');
+ var message = "";
+ var extract = ctx.extract;
+ var error = [];
+ 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'); }
-var isUrlRe = /^(?:https?:)?\/\//i;
-
-less.Parser.fileLoader = function (file, currentFileInfo, callback, env) {
- var pathname, dirname, data,
- newFileInfo = {
- relativeUrls: env.relativeUrls,
- entryPath: currentFileInfo.entryPath,
- rootpath: currentFileInfo.rootpath,
- rootFilename: currentFileInfo.rootFilename
- };
-
- function handleDataAndCallCallback(data) {
- var j = file.lastIndexOf('/');
-
- // Pass on an updated rootpath if path of imported file is relative and file
- // is in a (sub|sup) directory
- //
- // Examples:
- // - If path of imported file is 'module/nav/nav.less' and rootpath is 'less/',
- // then rootpath should become 'less/module/nav/'
- // - If path of imported file is '../mixins.less' and rootpath is 'less/',
- // then rootpath should become 'less/../'
- if(newFileInfo.relativeUrls && !/^(?:[a-z-]+:|\/)/.test(file) && j != -1) {
- var relativeSubDirectory = file.slice(0, j+1);
- newFileInfo.rootpath = newFileInfo.rootpath + relativeSubDirectory; // append (sub|sup) directory path of imported file
- }
- newFileInfo.currentDirectory = pathname.replace(/[^\\\/]*$/, "");
- newFileInfo.filename = pathname;
-
- callback(null, data, pathname, newFileInfo);
+ if (!ctx.hasOwnProperty('index') || !extract) {
+ return ctx.stack || ctx.message;
}
- var isUrl = isUrlRe.test( file );
- if (isUrl || isUrlRe.test(currentFileInfo.currentDirectory)) {
- if (request === undefined) {
- try { request = require('request'); }
- catch(e) { request = null; }
- }
- if (!request) {
- callback({ type: 'File', message: "optional dependency 'request' required to import over http(s)\n" });
- return;
- }
-
- var urlStr = isUrl ? file : url.resolve(currentFileInfo.currentDirectory, file),
- urlObj = url.parse(urlStr);
+ if (typeof(extract[0]) === 'string') {
+ error.push(stylize((ctx.line - 1) + ' ' + extract[0], 'grey'));
+ }
- if (!urlObj.protocol) {
- urlObj.protocol = "http";
- urlStr = urlObj.format();
+ if (typeof(extract[1]) === 'string') {
+ var errorTxt = ctx.line + ' ';
+ if (extract[1]) {
+ errorTxt += extract[1].slice(0, ctx.column) +
+ stylize(stylize(stylize(extract[1].substr(ctx.column, 1), 'bold') +
+ extract[1].slice(ctx.column + 1), 'red'), 'inverse');
}
+ error.push(errorTxt);
+ }
- request.get({uri: urlStr, strictSSL: !env.insecure }, function (error, res, body) {
- if (error) {
- callback({ type: 'File', message: "resource '" + urlStr + "' gave this Error:\n "+ error +"\n" });
- return;
- }
- if (res.statusCode === 404) {
- callback({ type: 'File', message: "resource '" + urlStr + "' was not found\n" });
- return;
- }
- if (!body) {
- console.error( 'Warning: Empty body (HTTP '+ res.statusCode + ') returned by "' + urlStr +'"' );
- }
- pathname = urlStr;
- dirname = urlObj.protocol +'//'+ urlObj.host + urlObj.pathname.replace(/[^\/]*$/, '');
- handleDataAndCallCallback(body);
- });
- } else {
-
- var paths = [currentFileInfo.currentDirectory];
- if (env.paths) paths.push.apply(paths, env.paths);
- if (paths.indexOf('.') === -1) paths.push('.');
-
- if (env.syncImport) {
- for (var i = 0; i < paths.length; i++) {
- try {
- pathname = path.join(paths[i], file);
- fs.statSync(pathname);
- break;
- } catch (e) {
- pathname = null;
- }
- }
+ if (typeof(extract[2]) === 'string') {
+ error.push(stylize((ctx.line + 1) + ' ' + extract[2], 'grey'));
+ }
+ error = error.join('\n') + stylize('', 'reset') + '\n';
- if (!pathname) {
- callback({ type: 'File', message: "'" + file + "' wasn't found" });
- return;
- }
+ message += stylize(ctx.type + 'Error: ' + ctx.message, 'red');
+ if (ctx.filename) {
+ message += stylize(' in ', 'red') + ctx.filename +
+ stylize(' on line ' + ctx.line + ', column ' + (ctx.column + 1) + ':', 'grey');
+ }
- try {
- data = fs.readFileSync(pathname, 'utf-8');
- handleDataAndCallCallback(data);
- } catch (e) {
- callback(e);
- }
- } else {
- (function tryPathIndex(i) {
- if (i < paths.length) {
- pathname = path.join(paths[i], file);
- fs.stat(pathname, function (err) {
- if (err) {
- tryPathIndex(i + 1);
- } else {
- fs.readFile(pathname, 'utf-8', function(e, data) {
- if (e) { callback(e); return; }
+ message += '\n' + error;
- // do processing in the next tick to allow
- // file handling to dispose
- process.nextTick(function() {
- handleDataAndCallCallback(data);
- });
- });
- }
- });
- } else {
- callback({ type: 'File', message: "'" + file + "' wasn't found" });
- }
- }(0));
- }
+ if (ctx.callLine) {
+ message += stylize('from ', 'red') + (ctx.filename || '') + '/n';
+ message += stylize(ctx.callLine, 'grey') + ' ' + ctx.callExtract + '/n';
}
+
+ return message;
};
-require('./env');
-require('./functions');
-require('./colors');
-require('./visitor.js');
-require('./import-visitor.js');
-require('./extend-visitor.js');
-require('./join-selector-visitor.js');
-require('./to-css-visitor.js');
-require('./source-map-output.js');
+less.writeError = function (ctx, options) {
+ options = options || {};
+ if (options.silent) { return; }
+ console.error(less.formatError(ctx, options));
+};
-for (var k in less) { if (less.hasOwnProperty(k)) { exports[k] = less[k]; }}
+module.exports = less;
diff --cc lib/less/parser/parser.js
index 8691ec5,7e0e55d..dfc6ace
--- a/lib/less/parser/parser.js
+++ b/lib/less/parser/parser.js
@@@ -1173,7 -1578,16 +1173,8 @@@ var Parser = function Parser(env)
value = this.detachedRuleset();
}
- this.comments();
++ parserInput.commentStore.length = 0;
if (!value) {
- // prefer to try to parse first if its a variable or we are compressing
- // but always fallback on the other one
- value = !tryAnonymous && (env.compress || isVariable) ?
- (this.value() || this.anonymousValue()) :
- (this.anonymousValue() || this.value());
-
- important = this.important();
-
// a name returned by this.ruleProperty() is always an array of the form:
// [string-1, ..., string-n, ""] or [string-1, ..., string-n, "+"]
// where each item is a tree.Keyword or tree.Variable
@@@ -1433,6 -1823,8 +1434,8 @@@
break;
}
- this.comments();
++ parserInput.commentStore.length = 0;
+
if (hasIdentifier) {
value = this.entity();
if (!value) {
diff --cc lib/less/tree/rule.js
index ec09dcf,8e62c40..521a2f0
--- a/lib/less/tree/rule.js
+++ b/lib/less/tree/rule.js
@@@ -1,18 -1,86 +1,19 @@@
-(function (tree) {
+var Node = require("./node.js"),
+ Value = require("./value.js"),
+ Keyword = require("./keyword.js");
- var Rule = function (name, value, important, merge, index, currentFileInfo, inline) {
-tree.Rule = function (name, value, important, merge, index, currentFileInfo, inline, variable) {
++var Rule = function (name, value, important, merge, index, currentFileInfo, inline, variable) {
this.name = name;
- this.value = (value instanceof tree.Value || value instanceof tree.Ruleset) ? value : new(tree.Value)([value]);
+ this.value = (value instanceof Node) ? value : new(Value)([value]); //value instanceof tree.Value || value instanceof tree.Ruleset ??
this.important = important ? ' ' + important.trim() : '';
this.merge = merge;
this.index = index;
this.currentFileInfo = currentFileInfo;
this.inline = inline || false;
- this.variable = name.charAt && (name.charAt(0) === '@');
+ this.variable = (variable !== undefined) ? variable
+ : (name.charAt && (name.charAt(0) === '@'));
};
-tree.Rule.prototype = {
- type: "Rule",
- accept: function (visitor) {
- this.value = visitor.visit(this.value);
- },
- genCSS: function (env, output) {
- output.add(this.name + (env.compress ? ':' : ': '), this.currentFileInfo, this.index);
- try {
- this.value.genCSS(env, output);
- }
- catch(e) {
- e.index = this.index;
- e.filename = this.currentFileInfo.filename;
- throw e;
- }
- output.add(this.important + ((this.inline || (env.lastRule && env.compress)) ? "" : ";"), this.currentFileInfo, this.index);
- },
- toCSS: tree.toCSS,
- eval: function (env) {
- var strictMathBypass = false, name = this.name, variable = this.variable, evaldValue;
- if (typeof name !== "string") {
- // expand 'primitive' name directly to get
- // things faster (~10% for benchmark.less):
- name = (name.length === 1)
- && (name[0] instanceof tree.Keyword)
- ? name[0].value : evalName(env, name);
- variable = false; // never treat expanded interpolation as new variable name
- }
- if (name === "font" && !env.strictMath) {
- strictMathBypass = true;
- env.strictMath = true;
- }
- try {
- evaldValue = this.value.eval(env);
-
- if (!this.variable && evaldValue.type === "DetachedRuleset") {
- throw { message: "Rulesets cannot be evaluated on a property.",
- index: this.index, filename: this.currentFileInfo.filename };
- }
-
- return new(tree.Rule)(name,
- evaldValue,
- this.important,
- this.merge,
- this.index, this.currentFileInfo, this.inline,
- variable);
- }
- catch(e) {
- if (typeof e.index !== 'number') {
- e.index = this.index;
- e.filename = this.currentFileInfo.filename;
- }
- throw e;
- }
- finally {
- if (strictMathBypass) {
- env.strictMath = false;
- }
- }
- },
- makeImportant: function () {
- return new(tree.Rule)(this.name,
- this.value,
- "!important",
- this.merge,
- this.index, this.currentFileInfo, this.inline);
- }
-};
-
function evalName(env, name) {
var value = "", i, n = name.length,
output = {add: function (s) {value += s;}};
@@@ -22,66 -90,4 +23,68 @@@
return value;
}
-})(require('../tree'));
+Rule.prototype = new Node();
+Rule.prototype.type = "Rule";
+Rule.prototype.genCSS = function (env, output) {
+ output.add(this.name + (env.compress ? ':' : ': '), this.currentFileInfo, this.index);
+ try {
+ this.value.genCSS(env, output);
+ }
+ catch(e) {
+ e.index = this.index;
+ e.filename = this.currentFileInfo.filename;
+ throw e;
+ }
+ output.add(this.important + ((this.inline || (env.lastRule && env.compress)) ? "" : ";"), this.currentFileInfo, this.index);
+};
+Rule.prototype.eval = function (env) {
- var strictMathBypass = false, name = this.name, evaldValue;
++ var strictMathBypass = false, name = this.name, evaldValue, variable = this.variable;
+ if (typeof name !== "string") {
+ // expand 'primitive' name directly to get
+ // things faster (~10% for benchmark.less):
+ name = (name.length === 1)
+ && (name[0] instanceof Keyword)
+ ? name[0].value : evalName(env, name);
++ variable = false; // never treat expanded interpolation as new variable name
+ }
+ if (name === "font" && !env.strictMath) {
+ strictMathBypass = true;
+ env.strictMath = true;
+ }
+ try {
+ evaldValue = this.value.eval(env);
+
+ if (!this.variable && evaldValue.type === "DetachedRuleset") {
+ throw { message: "Rulesets cannot be evaluated on a property.",
+ index: this.index, filename: this.currentFileInfo.filename };
+ }
+
+ return new(Rule)(name,
+ evaldValue,
+ this.important,
+ this.merge,
- this.index, this.currentFileInfo, this.inline);
++ this.index, this.currentFileInfo, this.inline,
++ variable);
+ }
+ catch(e) {
+ if (typeof e.index !== 'number') {
+ e.index = this.index;
+ e.filename = this.currentFileInfo.filename;
+ }
+ throw e;
+ }
+ finally {
+ if (strictMathBypass) {
+ env.strictMath = false;
+ }
+ }
+};
+Rule.prototype.makeImportant = function () {
+ return new(Rule)(this.name,
+ this.value,
+ "!important",
+ this.merge,
+ this.index, this.currentFileInfo, this.inline);
+};
+
+module.exports = Rule;
diff --cc test/css/comments.css
index a18ab80,d3c57b4..31e23f7
--- a/test/css/comments.css
+++ b/test/css/comments.css
@@@ -58,8 -58,13 +58,14 @@@
.sr-only-focusable {
clip: auto;
}
+ @-webkit-keyframes hover {
++ /* and Chrome */
+ 0% {
+ color: red;
+ }
+ }
#last {
- color: #0000ff;
+ color: blue;
}
/* */
/* { */
--
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