From e7a4d79890508d7c0b1399b5d9af33046c5f815b Mon Sep 17 00:00:00 2001 From: James Leigh Date: Mon, 4 Jun 2012 10:18:34 -0400 Subject: [PATCH 1/3] Assume Object/Array prototypes are sealed --- Makefile | 2 - build/ecma-5.js | 120 ----------- dist/less-1.3.0.js | 394 +++++++++++++++++++----------------- dist/less-1.3.0.min.js | 4 +- lib/less/functions.js | 2 +- lib/less/index.js | 3 +- lib/less/parser.js | 8 +- lib/less/tree.js | 91 ++++++++- lib/less/tree/call.js | 4 +- lib/less/tree/color.js | 12 +- lib/less/tree/condition.js | 2 +- lib/less/tree/directive.js | 4 +- lib/less/tree/element.js | 4 +- lib/less/tree/expression.js | 4 +- lib/less/tree/javascript.js | 2 +- lib/less/tree/media.js | 8 +- lib/less/tree/mixin.js | 12 +- lib/less/tree/operation.js | 2 +- lib/less/tree/rule.js | 2 +- lib/less/tree/ruleset.js | 14 +- lib/less/tree/selector.js | 6 +- lib/less/tree/value.js | 4 +- 22 files changed, 348 insertions(+), 356 deletions(-) delete mode 100644 build/ecma-5.js diff --git a/Makefile b/Makefile index 32d7cc044..4e708a45f 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,6 @@ less: @@echo "(function (window, undefined) {" >> ${DIST} @@cat build/require.js\ build/amd.js\ - build/ecma-5.js\ ${SRC}/parser.js\ ${SRC}/functions.js\ ${SRC}/colors.js\ @@ -42,7 +41,6 @@ rhino: @@mkdir -p dist @@touch ${RHINO} @@cat build/require-rhino.js\ - build/ecma-5.js\ ${SRC}/parser.js\ ${SRC}/functions.js\ ${SRC}/tree/*.js\ diff --git a/build/ecma-5.js b/build/ecma-5.js deleted file mode 100644 index 420bd8859..000000000 --- a/build/ecma-5.js +++ /dev/null @@ -1,120 +0,0 @@ - -// ecma-5.js -// -// -- kriskowal Kris Kowal Copyright (C) 2009-2010 MIT License -// -- tlrobinson Tom Robinson -// dantman Daniel Friesen - -// -// Array -// -if (!Array.isArray) { - Array.isArray = function(obj) { - return Object.prototype.toString.call(obj) === "[object Array]" || - (obj instanceof Array); - }; -} -if (!Array.prototype.forEach) { - Array.prototype.forEach = function(block, thisObject) { - var len = this.length >>> 0; - for (var i = 0; i < len; i++) { - if (i in this) { - block.call(thisObject, this[i], i, this); - } - } - }; -} -if (!Array.prototype.map) { - Array.prototype.map = function(fun /*, thisp*/) { - var len = this.length >>> 0; - var res = new Array(len); - var thisp = arguments[1]; - - for (var i = 0; i < len; i++) { - if (i in this) { - res[i] = fun.call(thisp, this[i], i, this); - } - } - return res; - }; -} -if (!Array.prototype.filter) { - Array.prototype.filter = function (block /*, thisp */) { - var values = []; - var thisp = arguments[1]; - for (var i = 0; i < this.length; i++) { - if (block.call(thisp, this[i])) { - values.push(this[i]); - } - } - return values; - }; -} -if (!Array.prototype.reduce) { - Array.prototype.reduce = function(fun /*, initial*/) { - var len = this.length >>> 0; - var i = 0; - - // no value to return if no initial value and an empty array - if (len === 0 && arguments.length === 1) throw new TypeError(); - - if (arguments.length >= 2) { - var rv = arguments[1]; - } else { - do { - if (i in this) { - rv = this[i++]; - break; - } - // if array contains no values, no initial value to return - if (++i >= len) throw new TypeError(); - } while (true); - } - for (; i < len; i++) { - if (i in this) { - rv = fun.call(null, rv, this[i], i, this); - } - } - return rv; - }; -} -if (!Array.prototype.indexOf) { - Array.prototype.indexOf = function (value /*, fromIndex */ ) { - var length = this.length; - var i = arguments[1] || 0; - - if (!length) return -1; - if (i >= length) return -1; - if (i < 0) i += length; - - for (; i < length; i++) { - if (!Object.prototype.hasOwnProperty.call(this, i)) { continue } - if (value === this[i]) return i; - } - return -1; - }; -} - -// -// Object -// -if (!Object.keys) { - Object.keys = function (object) { - var keys = []; - for (var name in object) { - if (Object.prototype.hasOwnProperty.call(object, name)) { - keys.push(name); - } - } - return keys; - }; -} - -// -// String -// -if (!String.prototype.trim) { - String.prototype.trim = function () { - return String(this).replace(/^\s\s*/, '').replace(/\s\s*$/, ''); - }; -} diff --git a/dist/less-1.3.0.js b/dist/less-1.3.0.js index fce5fb590..c23e9cf93 100644 --- a/dist/less-1.3.0.js +++ b/dist/less-1.3.0.js @@ -19,126 +19,6 @@ function require(arg) { if (typeof define === "function" && define.amd) { define("less", [], function () { return less; } ); } - -// ecma-5.js -// -// -- kriskowal Kris Kowal Copyright (C) 2009-2010 MIT License -// -- tlrobinson Tom Robinson -// dantman Daniel Friesen - -// -// Array -// -if (!Array.isArray) { - Array.isArray = function(obj) { - return Object.prototype.toString.call(obj) === "[object Array]" || - (obj instanceof Array); - }; -} -if (!Array.prototype.forEach) { - Array.prototype.forEach = function(block, thisObject) { - var len = this.length >>> 0; - for (var i = 0; i < len; i++) { - if (i in this) { - block.call(thisObject, this[i], i, this); - } - } - }; -} -if (!Array.prototype.map) { - Array.prototype.map = function(fun /*, thisp*/) { - var len = this.length >>> 0; - var res = new Array(len); - var thisp = arguments[1]; - - for (var i = 0; i < len; i++) { - if (i in this) { - res[i] = fun.call(thisp, this[i], i, this); - } - } - return res; - }; -} -if (!Array.prototype.filter) { - Array.prototype.filter = function (block /*, thisp */) { - var values = []; - var thisp = arguments[1]; - for (var i = 0; i < this.length; i++) { - if (block.call(thisp, this[i])) { - values.push(this[i]); - } - } - return values; - }; -} -if (!Array.prototype.reduce) { - Array.prototype.reduce = function(fun /*, initial*/) { - var len = this.length >>> 0; - var i = 0; - - // no value to return if no initial value and an empty array - if (len === 0 && arguments.length === 1) throw new TypeError(); - - if (arguments.length >= 2) { - var rv = arguments[1]; - } else { - do { - if (i in this) { - rv = this[i++]; - break; - } - // if array contains no values, no initial value to return - if (++i >= len) throw new TypeError(); - } while (true); - } - for (; i < len; i++) { - if (i in this) { - rv = fun.call(null, rv, this[i], i, this); - } - } - return rv; - }; -} -if (!Array.prototype.indexOf) { - Array.prototype.indexOf = function (value /*, fromIndex */ ) { - var length = this.length; - var i = arguments[1] || 0; - - if (!length) return -1; - if (i >= length) return -1; - if (i < 0) i += length; - - for (; i < length; i++) { - if (!Object.prototype.hasOwnProperty.call(this, i)) { continue } - if (value === this[i]) return i; - } - return -1; - }; -} - -// -// Object -// -if (!Object.keys) { - Object.keys = function (object) { - var keys = []; - for (var name in object) { - if (Object.prototype.hasOwnProperty.call(object, name)) { - keys.push(name); - } - } - return keys; - }; -} - -// -// String -// -if (!String.prototype.trim) { - String.prototype.trim = function () { - return String(this).replace(/^\s\s*/, '').replace(/\s\s*$/, ''); - }; -} var less, tree; if (typeof environment === "object" && ({}).toString.call(environment) === "[object Environment]") { @@ -226,11 +106,15 @@ less.Parser = function Parser(env) { // less.Parser.importer(path, this.paths, function (e, root, contents) { that.queue.splice(that.queue.indexOf(path), 1); // Remove the path from the queue + + var imported = path in that.files; + that.files[path] = root; // Store the root that.contents[path] = contents; if (e && !that.error) { that.error = e } - callback(e, root); + + callback(e, root, imported); if (that.queue.length === 0) { finish() } // Call `finish` if we're done importing }, env); @@ -466,7 +350,7 @@ less.Parser = function Parser(env) { }, env); } - return chunks.map(function (c) { return c.join('') });; + return tree.map.call(chunks, function (c) { return c.join('') });; })([[]]); if (error) { @@ -504,8 +388,8 @@ less.Parser = function Parser(env) { // ]) // ) // - if (typeof(variables) === 'object' && !Array.isArray(variables)) { - variables = Object.keys(variables).map(function (k) { + if (typeof(variables) === 'object' && !tree.isArray(variables)) { + variables = tree.map.call(tree.keys(variables), function (k) { var value = variables[k]; if (! (value instanceof tree.Value)) { @@ -821,7 +705,7 @@ less.Parser = function Parser(env) { var value, c = input.charCodeAt(i); if ((c > 57 || c < 45) || c === 47) return; - if (value = $(/^(-?\d*\.?\d+)(px|%|em|rem|pc|ex|in|deg|s|ms|pt|cm|mm|rad|grad|turn)?/)) { + if (value = $(/^(-?\d*\.?\d+)(px|%|em|rem|pc|ex|in|deg|s|ms|pt|cm|mm|rad|grad|turn|dpi)?/)) { return new(tree.Dimension)(value[1], value[2]); } }, @@ -889,7 +773,7 @@ less.Parser = function Parser(env) { // selector for now. // call: function () { - var elements = [], e, c, args, index = i, s = input.charAt(i), important = false; + var elements = [], e, c, args = [], arg, index = i, s = input.charAt(i), name, value, important = false; if (s !== '.' && s !== '#') { return } @@ -897,14 +781,38 @@ less.Parser = function Parser(env) { elements.push(new(tree.Element)(c, e, i)); c = $('>'); } - $('(') && (args = $(this.entities.arguments)) && $(')'); + if ($('(')) { + while (arg = $(this.expression)) { + value = arg; + name = null; + + // Variable + if (arg.value.length == 1) { + var val = arg.value[0]; + if (val instanceof tree.Variable) { + if ($(':')) { + if (value = $(this.expression)) { + name = val.name; + } else { + throw new(Error)("Expected value"); + } + } + } + } + + args.push({ name: name, value: value }); + + if (! $(',')) { break } + } + if (! $(')')) throw new(Error)("Expected )"); + } if ($(this.important)) { important = true; } if (elements.length > 0 && ($(';') || peek('}'))) { - return new(tree.mixin.Call)(elements, args || [], index, env.filename, important); + return new(tree.mixin.Call)(elements, args, index, env.filename, important); } }, @@ -1192,11 +1100,12 @@ less.Parser = function Parser(env) { // "import": function () { var path, features, index = i; - if ($(/^@import\s+/) && - (path = $(this.entities.quoted) || $(this.entities.url))) { + var dir = $(/^@import(?:-(once))?\s+/); + + if (dir && (path = $(this.entities.quoted) || $(this.entities.url))) { features = $(this.mediaFeatures); if ($(';')) { - return new(tree.Import)(path, imports, features, index); + return new(tree.Import)(path, imports, features, (dir[1] === 'once'), index); } } }, @@ -1268,7 +1177,7 @@ less.Parser = function Parser(env) { if (value = $(this['import']) || $(this.media)) { return value; } else if (name = $(/^@page|@keyframes/) || $(/^@(?:-webkit-|-moz-|-o-|-ms-)[a-z0-9-]+/)) { - types = ($(/^[^{]+/) || '').trim(); + types = tree.trim.call($(/^[^{]+/) || ''); if (rules = $(this.block)) { return new(tree.Directive)(name + " " + types, rules); } @@ -1451,7 +1360,7 @@ tree.functions = { return this.rgba(r, g, b, 1.0); }, rgba: function (r, g, b, a) { - var rgb = [r, g, b].map(function (c) { return number(c) }), + var rgb = tree.map.call([r, g, b], function (c) { return number(c) }), a = number(a); return new(tree.Color)(rgb, a); }, @@ -1814,6 +1723,7 @@ function clamp(val) { 'teal':'#008080', 'thistle':'#d8bfd8', 'tomato':'#ff6347', + 'transparent':'rgba(0,0,0,0)', 'turquoise':'#40e0d0', 'violet':'#ee82ee', 'wheat':'#f5deb3', @@ -1894,7 +1804,7 @@ tree.Call.prototype = { // The function should receive the value, not the variable. // eval: function (env) { - var args = this.args.map(function (a) { return a.eval(env) }); + var args = tree.map.call(this.args, function (a) { return a.eval(env) }); if (this.name in tree.functions) { // 1. try { @@ -1907,7 +1817,7 @@ tree.Call.prototype = { } } else { // 2. return new(tree.Anonymous)(this.name + - "(" + args.map(function (a) { return a.toCSS() }).join(', ') + ")"); + "(" + tree.map.call(args, function (a) { return a.toCSS() }).join(', ') + ")"); } }, @@ -1928,14 +1838,14 @@ tree.Color = function (rgb, a) { // // This facilitates operations and conversions. // - if (Array.isArray(rgb)) { + if (tree.isArray(rgb)) { this.rgb = rgb; } else if (rgb.length == 6) { - this.rgb = rgb.match(/.{2}/g).map(function (c) { + this.rgb = tree.map.call(rgb.match(/.{2}/g), function (c) { return parseInt(c, 16); }); } else { - this.rgb = rgb.split('').map(function (c) { + this.rgb = tree.map.call(rgb.split(''), function (c) { return parseInt(c + c, 16); }); } @@ -1952,11 +1862,11 @@ tree.Color.prototype = { // toCSS: function () { if (this.alpha < 1.0) { - return "rgba(" + this.rgb.map(function (c) { + return "rgba(" + tree.map.call(this.rgb, function (c) { return Math.round(c); }).concat(this.alpha).join(', ') + ")"; } else { - return '#' + this.rgb.map(function (i) { + return '#' + tree.map.call(this.rgb, function (i) { i = Math.round(i); i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16); return i.length === 1 ? '0' + i : i; @@ -2008,7 +1918,7 @@ tree.Color.prototype = { }, toARGB: function () { var argb = [Math.round(this.alpha * 255)].concat(this.rgb); - return '#' + argb.map(function (i) { + return '#' + tree.map.call(argb, function (i) { i = Math.round(i); i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16); return i.length === 1 ? '0' + i : i; @@ -2035,7 +1945,7 @@ tree.Comment.prototype = { (function (tree) { tree.Condition = function (op, l, r, i, negate) { - this.op = op.trim(); + this.op = tree.trim.call(op); this.lvalue = l; this.rvalue = r; this.index = i; @@ -2128,7 +2038,7 @@ tree.Dimension.prototype = { tree.Directive = function (name, value, features) { this.name = name; - if (Array.isArray(value)) { + if (tree.isArray(value)) { this.ruleset = new(tree.Ruleset)([], value); this.ruleset.allowImports = true; } else { @@ -2140,7 +2050,7 @@ tree.Directive.prototype = { if (this.ruleset) { this.ruleset.root = true; return this.name + (env.compress ? '{' : ' {\n ') + - this.ruleset.toCSS(ctx, env).trim().replace(/\n/g, '\n ') + + tree.trim.call(this.ruleset.toCSS(ctx, env)).replace(/\n/g, '\n ') + (env.compress ? '}': '\n}\n'); } else { return this.name + ' ' + this.value.toCSS() + ';\n'; @@ -2165,7 +2075,7 @@ tree.Element = function (combinator, value, index) { combinator : new(tree.Combinator)(combinator); if (typeof(value) === 'string') { - this.value = value.trim(); + this.value = tree.trim.call(value); } else if (value) { this.value = value; } else { @@ -2179,7 +2089,12 @@ tree.Element.prototype.eval = function (env) { this.index); }; tree.Element.prototype.toCSS = function (env) { - return this.combinator.toCSS(env || {}) + (this.value.toCSS ? this.value.toCSS(env) : this.value); + var value = (this.value.toCSS ? this.value.toCSS(env) : this.value); + if (value == '' && this.combinator.value.charAt(0) == '&') { + return ''; + } else { + return this.combinator.toCSS(env || {}) + value; + } }; tree.Combinator = function (value) { @@ -2188,7 +2103,7 @@ tree.Combinator = function (value) { } else if (value === '& ') { this.value = '& '; } else { - this.value = value ? value.trim() : ""; + this.value = value ? tree.trim.call(value) : ""; } }; tree.Combinator.prototype.toCSS = function (env) { @@ -2211,7 +2126,7 @@ tree.Expression = function (value) { this.value = value }; tree.Expression.prototype = { eval: function (env) { if (this.value.length > 1) { - return new(tree.Expression)(this.value.map(function (e) { + return new(tree.Expression)(tree.map.call(this.value, function (e) { return e.eval(env); })); } else if (this.value.length === 1) { @@ -2221,7 +2136,7 @@ tree.Expression.prototype = { } }, toCSS: function (env) { - return this.value.map(function (e) { + return tree.map.call(this.value, function (e) { return e.toCSS ? e.toCSS(env) : ''; }).join(' '); } @@ -2241,9 +2156,10 @@ tree.Expression.prototype = { // `import,push`, we also pass it a callback, which it'll call once // the file has been fetched, and parsed. // -tree.Import = function (path, imports, features, index) { +tree.Import = function (path, imports, features, once, index) { var that = this; + this.once = once; this.index = index; this._path = path; this.features = features && new(tree.Value)(features); @@ -2259,8 +2175,9 @@ tree.Import = function (path, imports, features, index) { // Only pre-compile .less files if (! this.css) { - imports.push(this.path, function (e, root) { + imports.push(this.path, function (e, root, imported) { if (e) { e.index = index } + if (imported && that.once) that.skip = imported; that.root = root || new(tree.Ruleset)([], []); }); } @@ -2288,6 +2205,8 @@ tree.Import.prototype = { eval: function (env) { var ruleset, features = this.features && this.features.eval(env); + if (this.skip) return []; + if (this.css) { return this; } else { @@ -2348,7 +2267,7 @@ tree.JavaScript.prototype = { } if (typeof(result) === 'string') { return new(tree.Quoted)('"' + result + '"', result, this.escaped, this.index); - } else if (Array.isArray(result)) { + } else if (tree.isArray(result)) { return new(tree.Anonymous)(result.join(', ')); } else { return new(tree.Anonymous)(result); @@ -2393,7 +2312,7 @@ tree.Media.prototype = { this.ruleset.root = (ctx.length === 0 || ctx[0].multiMedia); return '@media ' + features + (env.compress ? '{' : ' {\n ') + - this.ruleset.toCSS(ctx, env).trim().replace(/\n/g, '\n ') + + tree.trim.call(this.ruleset.toCSS(ctx, env)).replace(/\n/g, '\n ') + (env.compress ? '}': '\n}\n'); }, eval: function (env) { @@ -2447,7 +2366,7 @@ tree.Media.prototype = { for (i = 0; i < path.length; i++) { value = path[i].features instanceof tree.Value ? path[i].features.value : path[i].features; - path[i] = Array.isArray(value) ? value : [value]; + path[i] = tree.isArray(value) ? value : [value]; } // Trace all permutations to generate the resulting media-query. @@ -2457,8 +2376,8 @@ tree.Media.prototype = { // a and e // b and c and d // b and c and e - this.features = new(tree.Value)(this.permute(path).map(function (path) { - path = path.map(function (fragment) { + this.features = new(tree.Value)(tree.map.call(this.permute(path), function (path) { + path = tree.map.call(path, function (fragment) { return fragment.toCSS ? fragment : new(tree.Anonymous)(fragment); }); @@ -2507,7 +2426,9 @@ tree.mixin.Call.prototype = { for (var i = 0; i < env.frames.length; i++) { if ((mixins = env.frames[i].find(this.selector)).length > 0) { - args = this.arguments && this.arguments.map(function (a) { return a.eval(env) }); + args = this.arguments && tree.map.call(this.arguments, function (a) { + return { name: a.name, value: a.value.eval(env) }; + }); for (var m = 0; m < mixins.length; m++) { if (mixins[m].match(args, env)) { try { @@ -2524,8 +2445,8 @@ tree.mixin.Call.prototype = { } else { throw { type: 'Runtime', message: 'No matching definition was found for `' + - this.selector.toCSS().trim() + '(' + - this.arguments.map(function (a) { + tree.trim.call(this.selector.toCSS()) + '(' + + tree.map.call(this.arguments, function (a) { return a.toCSS(); }).join(', ') + ")`", index: this.index, filename: this.filename }; @@ -2533,7 +2454,7 @@ tree.mixin.Call.prototype = { } } throw { type: 'Name', - message: this.selector.toCSS().trim() + " is undefined", + message: tree.trim.call(this.selector.toCSS()) + " is undefined", index: this.index, filename: this.filename }; } }; @@ -2547,7 +2468,7 @@ tree.mixin.Definition = function (name, params, rules, condition, variadic) { this.arity = params.length; this.rules = rules; this._lookups = {}; - this.required = params.reduce(function (count, p) { + this.required = tree.reduce.call(params, function (count, p) { if (!p.name || (p.name && !p.value)) { return count + 1 } else { return count } }, 0); @@ -2562,17 +2483,26 @@ tree.mixin.Definition.prototype = { rulesets: function () { return this.parent.rulesets.apply(this) }, evalParams: function (env, args) { - var frame = new(tree.Ruleset)(null, []), varargs; + var frame = new(tree.Ruleset)(null, []), varargs, arg; for (var i = 0, val, name; i < this.params.length; i++) { + arg = args && args[i] + + if (arg && arg.name) { + frame.rules.unshift(new(tree.Rule)(arg.name, arg.value.eval(env))); + args.splice(i, 1); + i--; + continue; + } + if (name = this.params[i].name) { if (this.params[i].variadic && args) { varargs = []; for (var j = i; j < args.length; j++) { - varargs.push(args[j].eval(env)); + varargs.push(args[j].value.eval(env)); } frame.rules.unshift(new(tree.Rule)(name, new(tree.Expression)(varargs).eval(env))); - } else if (val = (args && args[i]) || this.params[i].value) { + } else if (val = (arg && arg.value) || this.params[i].value) { frame.rules.unshift(new(tree.Rule)(name, val.eval(env))); } else { throw { type: 'Runtime', message: "wrong number of arguments for " + this.name + @@ -2586,12 +2516,12 @@ tree.mixin.Definition.prototype = { var frame = this.evalParams(env, args), context, _arguments = [], rules, start; for (var i = 0; i < Math.max(this.params.length, args && args.length); i++) { - _arguments.push(args[i] || this.params[i].value); + _arguments.push((args[i] && args[i].value) || this.params[i].value); } frame.rules.unshift(new(tree.Rule)('@arguments', new(tree.Expression)(_arguments).eval(env))); rules = important ? - this.rules.map(function (r) { + tree.map.call(this.rules, function (r) { return new(tree.Rule)(r.name, r.value, '!important', r.index); }) : this.rules.slice(0); @@ -2616,7 +2546,7 @@ tree.mixin.Definition.prototype = { for (var i = 0; i < len; i++) { if (!this.params[i].name) { - if (args[i].eval(env).toCSS() != this.params[i].value.eval(env).toCSS()) { + if (args[i].value.eval(env).toCSS() != this.params[i].value.eval(env).toCSS()) { return false; } } @@ -2629,7 +2559,7 @@ tree.mixin.Definition.prototype = { (function (tree) { tree.Operation = function (op, operands) { - this.op = op.trim(); + this.op = tree.trim.call(op); this.operands = operands; }; tree.Operation.prototype.eval = function (env) { @@ -2708,7 +2638,7 @@ tree.Quoted.prototype = { tree.Rule = function (name, value, important, index, inline) { this.name = name; this.value = (value instanceof tree.Value) ? value : new(tree.Value)([value]); - this.important = important ? ' ' + important.trim() : ''; + this.important = important ? ' ' + tree.trim.call(important) : ''; this.index = index; this.inline = inline || false; @@ -2755,7 +2685,7 @@ tree.Ruleset = function (selectors, rules, strictImports) { }; tree.Ruleset.prototype = { eval: function (env) { - var selectors = this.selectors && this.selectors.map(function (s) { return s.eval(env) }); + var selectors = this.selectors && tree.map.call(this.selectors, function (s) { return s.eval(env) }); var ruleset = new(tree.Ruleset)(selectors, this.rules.slice(0), this.strictImports); ruleset.root = this.root; @@ -2810,7 +2740,7 @@ tree.Ruleset.prototype = { variables: function () { if (this._variables) { return this._variables } else { - return this._variables = this.rules.reduce(function (hash, r) { + return this._variables = tree.reduce.call(this.rules, function (hash, r) { if (r instanceof tree.Rule && r.variable === true) { hash[r.name] = r; } @@ -2824,7 +2754,7 @@ tree.Ruleset.prototype = { rulesets: function () { if (this._rulesets) { return this._rulesets } else { - return this._rulesets = this.rules.filter(function (r) { + return this._rulesets = tree.filter.call(this.rules, function (r) { return (r instanceof tree.Ruleset) || (r instanceof tree.mixin.Definition); }); } @@ -2836,7 +2766,7 @@ tree.Ruleset.prototype = { if (key in this._lookups) { return this._lookups[key] } - this.rulesets().forEach(function (rule) { + tree.forEach.call(this.rulesets(), function (rule) { if (rule !== self) { for (var j = 0; j < rule.selectors.length; j++) { if (match = selector.match(rule.selectors[j])) { @@ -2861,6 +2791,7 @@ tree.Ruleset.prototype = { toCSS: function (context, env) { var css = [], // The CSS output rules = [], // node.Rule instances + _rules = [], // rulesets = [], // node.Ruleset instances paths = [], // Current selectors selector, // The fully rendered selector @@ -2868,7 +2799,7 @@ tree.Ruleset.prototype = { if (! this.root) { if (context.length === 0) { - paths = this.selectors.map(function (s) { return [s] }); + paths = tree.map.call(this.selectors, function (s) { return [s] }); } else { this.joinSelectors(paths, context, this.selectors); } @@ -2906,11 +2837,19 @@ tree.Ruleset.prototype = { css.push(rules.join(env.compress ? '' : '\n')); } else { if (rules.length > 0) { - selector = paths.map(function (p) { - return p.map(function (s) { + selector = tree.map.call(paths, function (p) { + return tree.map.call(p, function (s) { return s.toCSS(env); }).join('').trim(); - }).join( env.compress ? ',' : ',\n'); + }).join(env.compress ? ',' : ',\n'); + + // Remove duplicates + for (var i = rules.length - 1; i >= 0; i--) { + if (_rules.indexOf(rules[i]) === -1) { + _rules.unshift(rules[i]); + } + } + rules = _rules; css.push(selector, (env.compress ? '{' : ' {\n ') + @@ -2986,16 +2925,16 @@ tree.Selector.prototype.match = function (other) { return true; }; tree.Selector.prototype.eval = function (env) { - return new(tree.Selector)(this.elements.map(function (e) { + return new(tree.Selector)(tree.map.call(this.elements, function (e) { return e.eval(env); })); }; tree.Selector.prototype.toCSS = function (env) { if (this._css) { return this._css } - return this._css = this.elements.map(function (e) { + return this._css = tree.map.call(this.elements, function (e) { if (typeof(e) === 'string') { - return ' ' + e.trim(); + return ' ' + tree.trim.call(e); } else { return e.toCSS(env); } @@ -3039,13 +2978,13 @@ tree.Value.prototype = { if (this.value.length === 1) { return this.value[0].eval(env); } else { - return new(tree.Value)(this.value.map(function (v) { + return new(tree.Value)(tree.map.call(this.value, function (v) { return v.eval(env); })); } }, toCSS: function (env) { - return this.value.map(function (e) { + return tree.map.call(this.value, function (e) { return e.toCSS(env); }).join(env.compress ? ',' : ', '); } @@ -3080,6 +3019,93 @@ tree.Variable.prototype = { })(require('../tree')); (function (tree) { +tree.isArray = Array.isArray ? Array.isArray : function(obj) { + return Object.prototype.toString.call(obj) === "[object Array]" || + (obj instanceof Array); +}; +tree.forEach = Array.prototype.forEach ? Array.prototype.forEach : function(block, thisObject) { + var len = this.length >>> 0; + for (var i = 0; i < len; i++) { + if (i in this) { + block.call(thisObject, this[i], i, this); + } + } +}; +tree.map = Array.prototype.map ? Array.prototype.map : Array.prototype.map = function(fun /*, thisp*/) { + var len = this.length >>> 0; + var res = new Array(len); + var thisp = arguments[1]; + + for (var i = 0; i < len; i++) { + if (i in this) { + res[i] = fun.call(thisp, this[i], i, this); + } + } + return res; +}; +tree.filter = Array.prototype.filter ? Array.prototype.filter : function (block /*, thisp */) { + var values = []; + var thisp = arguments[1]; + for (var i = 0; i < this.length; i++) { + if (block.call(thisp, this[i])) { + values.push(this[i]); + } + } + return values; +}; +tree.reduce = Array.prototype.reduce ? Array.prototype.reduce : function(fun /*, initial*/) { + var len = this.length >>> 0; + var i = 0; + + // no value to return if no initial value and an empty array + if (len === 0 && arguments.length === 1) throw new TypeError(); + + if (arguments.length >= 2) { + var rv = arguments[1]; + } else { + do { + if (i in this) { + rv = this[i++]; + break; + } + // if array contains no values, no initial value to return + if (++i >= len) throw new TypeError(); + } while (true); + } + for (; i < len; i++) { + if (i in this) { + rv = fun.call(null, rv, this[i], i, this); + } + } + return rv; +}; +tree.indexOf = Array.prototype.indexOf ? Array.prototype.indexOf : function (value /*, fromIndex */ ) { + var length = this.length; + var i = arguments[1] || 0; + + if (!length) return -1; + if (i >= length) return -1; + if (i < 0) i += length; + + for (; i < length; i++) { + if (!Object.prototype.hasOwnProperty.call(this, i)) { continue } + if (value === this[i]) return i; + } + return -1; +}; +tree.keys = Object.keys ? Object.keys : function (object) { + var keys = []; + for (var name in object) { + if (Object.prototype.hasOwnProperty.call(object, name)) { + keys.push(name); + } + } + return keys; +}; +tree.trim = String.prototype.trim ? String.prototype.trim : function () { + return String(this).replace(/^\s\s*/, '').replace(/\s\s*$/, ''); +}; + tree.find = function (obj, fun) { for (var i = 0, r; i < obj.length; i++) { if (r = fun.call(obj, obj[i])) { return r } @@ -3087,8 +3113,8 @@ tree.find = function (obj, fun) { 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(', ') + ']'; + if (tree.isArray(obj.value) && (obj.value.length > 1)) { + return '[' + tree.map.call(obj.value, function (v) { return v.toCSS(false) }).join(', ') + ']'; } else { return obj.toCSS(false); } diff --git a/dist/less-1.3.0.min.js b/dist/less-1.3.0.min.js index 309bf550d..9dcf5606a 100644 --- a/dist/less-1.3.0.min.js +++ b/dist/less-1.3.0.min.js @@ -5,5 +5,5 @@ // Copyright (c) 2009-2011, Alexis Sellier // Licensed under the Apache 2.0 License. // -(function(a,b){function c(b){return a.less[b.split("/")[1]]}function l(){var a=document.getElementsByTagName("style");for(var b=0;b0?d.firstChild.nodeValue!==a.nodeValue&&d.replaceChild(a,d.firstChild):d.appendChild(a)})(document.createTextNode(a));c&&g&&(t("saving "+e+" to cache."),g.setItem(e,a),g.setItem(e+":timestamp",c))}function q(a,b,c,e){function i(b,c,d){b.status>=200&&b.status<300?c(b.responseText,b.getResponseHeader("Last-Modified")):typeof d=="function"&&d(b.status,a)}var g=r(),h=f?!1:d.async;typeof g.overrideMimeType=="function"&&g.overrideMimeType("text/css"),g.open("GET",a,h),g.setRequestHeader("Accept",b||"text/x-less, text/css; q=0.9, */*; q=0.5"),g.send(null),f?g.status===0||g.status>=200&&g.status<300?c(g.responseText):e(g.status,a):h?g.onreadystatechange=function(){g.readyState==4&&i(g,c,e)}:i(g,c,e)}function r(){if(a.XMLHttpRequest)return new XMLHttpRequest;try{return new ActiveXObject("MSXML2.XMLHTTP.3.0")}catch(b){return t("browser doesn't support AJAX."),null}}function s(a){return a&&a.parentNode.removeChild(a)}function t(a){d.env=="development"&&typeof console!="undefined"&&console.log("less: "+a)}function u(a,b){var c="less-error-message:"+o(b),e='
  • {content}
  • ',f=document.createElement("div"),g,h,i=[],j=a.filename||b;f.id=c,f.className="less-error-message",h="

    "+(a.message||"There is an error in your .less file")+"

    "+'

    in '+j+" ";var k=function(a,b,c){a.extract[b]&&i.push(e.replace(/\{line\}/,parseInt(a.line)+(b-1)).replace(/\{class\}/,c).replace(/\{content\}/,a.extract[b]))};a.stack?h+="
    "+a.stack.split("\n").slice(1).join("
    "):a.extract&&(k(a,0,""),k(a,1,"line"),k(a,2,""),h+="on line "+a.line+", column "+(a.column+1)+":

    "+""),f.innerHTML=h,p([".less-error-message ul, .less-error-message li {","list-style-type: none;","margin-right: 15px;","padding: 4px 0;","margin: 0;","}",".less-error-message label {","font-size: 12px;","margin-right: 15px;","padding: 4px 0;","color: #cc7777;","}",".less-error-message pre {","color: #dd6666;","padding: 4px 0;","margin: 0;","display: inline-block;","}",".less-error-message pre.line {","color: #ff0000;","}",".less-error-message h3 {","font-size: 20px;","font-weight: bold;","padding: 15px 0 5px 0;","margin: 0;","}",".less-error-message a {","color: #10a","}",".less-error-message .error {","color: red;","font-weight: bold;","padding-bottom: 2px;","border-bottom: 1px dashed red;","}"].join("\n"),{title:"error-message"}),f.style.cssText=["font-family: Arial, sans-serif","border: 1px solid #e00","background-color: #eee","border-radius: 5px","-webkit-border-radius: 5px","-moz-border-radius: 5px","color: #e00","padding: 15px","margin-bottom: 15px"].join(";"),d.env=="development"&&(g=setInterval(function(){document.body&&(document.getElementById(c)?document.body.replaceChild(f,document.getElementById(c)):document.body.insertBefore(f,document.body.firstChild),clearInterval(g))},10))}typeof define=="function"&&define.amd&&define("less",[],function(){return d}),Array.isArray||(Array.isArray=function(a){return Object.prototype.toString.call(a)==="[object Array]"||a instanceof Array}),Array.prototype.forEach||(Array.prototype.forEach=function(a,b){var c=this.length>>>0;for(var d=0;d>>0,c=new Array(b),d=arguments[1];for(var e=0;e>>0,c=0;if(b===0&&arguments.length===1)throw new TypeError;if(arguments.length>=2)var d=arguments[1];else do{if(c in this){d=this[c++];break}if(++c>=b)throw new TypeError}while(!0);for(;c=b)return-1;c<0&&(c+=b);for(;cl&&(k[g]=k[g].slice(f-l),l=f)}function t(a){var c,d,e,h,i,j,n,o;if(a instanceof Function)return a.call(m.parsers);if(typeof a=="string")c=b.charAt(f)===a?a:null,e=1,s();else{s();if(c=a.exec(k[g]))e=c[0].length;else return null}if(c){o=f+=e,j=f+k[g].length-e;while(f=0&&b.charAt(c)!=="\n";c--)d++;return{line:typeof a=="number"?(b.slice(0,a).match(/\n/g)||"").length:null,column:d}}function A(a,b){var c=y(a,b),d=z(a.index,c),e=d.line,f=d.column,g=c.split("\n");this.type=a.type||"Syntax",this.message=a.message,this.filename=a.filename||b.filename,this.index=a.index,this.line=typeof e=="number"?e+1:null,this.callLine=a.call&&z(a.call,c).line+1,this.callExtract=g[z(a.call,c).line],this.stack=a.stack,this.column=f,this.extract=[g[e-1],g[e],g[e+1]]}var b,f,g,h,i,j,k,l,m,n=this,o=function(){},p=this.imports={paths:a&&a.paths||[],queue:[],files:{},contents:{},mime:a&&a.mime,error:null,push:function(b,c){var e=this;this.queue.push(b),d.Parser.importer(b,this.paths,function(a,d,f){e.queue.splice(e.queue.indexOf(b),1),e.files[b]=d,e.contents[b]=f,a&&!e.error&&(e.error=a),c(a,d),e.queue.length===0&&o()},a)}};return this.env=a=a||{},this.optimization="optimization"in this.env?this.env.optimization:1,this.env.filename=this.env.filename||null,m={imports:p,parse:function(h,i){var n,p,q,r,s,u,v=[],w,x=null;f=g=l=j=0,b=h.replace(/\r\n/g,"\n"),k=function(c){var d=0,e=/[^"'`\{\}\/\(\)\\]+/g,f=/\/\*(?:[^*]|\*+[^\/*])*\*+\/|\/\/.*/g,g=/"((?:[^"\\\r\n]|\\.)*)"|'((?:[^'\\\r\n]|\\.)*)'|`((?:[^`\\\r\n]|\\.)*)`/g,h=0,i,j=c[0],k;for(var l=0,m,n;l0&&(x=new A({index:l,type:"Parse",message:"missing closing `}`",filename:a.filename},a)),c.map(function(a){return a.join("")})}([[]]);if(x)return i(x);try{n=new e.Ruleset([],t(this.parsers.primary)),n.root=!0}catch(y){return i(new A(y,a))}n.toCSS=function(b){var f,g,h;return function(f,g){var h=[],i;f=f||{},typeof g=="object"&&!Array.isArray(g)&&(g=Object.keys(g).map(function(a){var b=g[a];return b instanceof e.Value||(b instanceof e.Expression||(b=new e.Expression([b])),b=new e.Value([b])),new e.Rule("@"+a,b,!1,0)}),h=[new e.Ruleset(null,g)]);try{var j=b.call(this,{frames:h}).toCSS([],{compress:f.compress||!1})}catch(k){throw new A(k,a)}if(i=m.imports.error)throw i instanceof A?i:new A(i,a);return f.yuicompress&&d.mode==="node"?c("./cssmin").compressor.cssmin(j):f.compress?j.replace(/(\s)+/g,"$1"):j}}(n.eval);if(f=0&&b.charAt(z)!=="\n";z--)B++;x={type:"Parse",message:"Syntax Error on line "+s,index:f,filename:a.filename,line:s,column:B,extract:[u[s-2],u[s-1],u[s]]}}this.imports.queue.length>0?o=function(){i(x,n)}:i(x,n)},parsers:{primary:function(){var a,b=[];while((a=t(this.mixin.definition)||t(this.rule)||t(this.ruleset)||t(this.mixin.call)||t(this.comment)||t(this.directive))||t(/^[\s\n]+/))a&&b.push(a);return b},comment:function(){var a;if(b.charAt(f)!=="/")return;if(b.charAt(f+1)==="/")return new e.Comment(t(/^\/\/.*/),!0);if(a=t(/^\/\*(?:[^*]|\*+[^\/*])*\*+\/\n?/))return new e.Comment(a)},entities:{quoted:function(){var a,c=f,d;b.charAt(c)==="~"&&(c++,d=!0);if(b.charAt(c)!=='"'&&b.charAt(c)!=="'")return;d&&t("~");if(a=t(/^"((?:[^"\\\r\n]|\\.)*)"|'((?:[^'\\\r\n]|\\.)*)'/))return new e.Quoted(a[0],a[1]||a[2],d)},keyword:function(){var a;if(a=t(/^[_A-Za-z-][_A-Za-z0-9-]*/))return e.colors.hasOwnProperty(a)?new e.Color(e.colors[a].slice(1)):new e.Keyword(a)},call:function(){var b,c,d=f;if(!(b=/^([\w-]+|%|progid:[\w\.]+)\(/.exec(k[g])))return;b=b[1].toLowerCase();if(b==="url")return null;f+=b.length;if(b==="alpha")return t(this.alpha);t("("),c=t(this.entities.arguments);if(!t(")"))return;if(b)return new e.Call(b,c,d,a.filename)},arguments:function(){var a=[],b;while(b=t(this.entities.assignment)||t(this.expression)){a.push(b);if(!t(","))break}return a},literal:function(){return t(this.entities.dimension)||t(this.entities.color)||t(this.entities.quoted)},assignment:function(){var a,b;if((a=t(/^\w+(?=\s?=)/i))&&t("=")&&(b=t(this.entity)))return new e.Assignment(a,b)},url:function(){var a;if(b.charAt(f)!=="u"||!t(/^url\(/))return;return a=t(this.entities.quoted)||t(this.entities.variable)||t(this.entities.dataURI)||t(/^[-\w%@$\/.&=:;#+?~]+/)||"",u(")"),new e.URL(a.value||a.data||a instanceof e.Variable?a:new e.Anonymous(a),p.paths)},dataURI:function(){var a;if(t(/^data:/)){a={},a.mime=t(/^[^\/]+\/[^,;)]+/)||"",a.charset=t(/^;\s*charset=[^,;)]+/)||"",a.base64=t(/^;\s*base64/)||"",a.data=t(/^,\s*[^)]+/);if(a.data)return a}},variable:function(){var c,d=f;if(b.charAt(f)==="@"&&(c=t(/^@@?[\w-]+/)))return new e.Variable(c,d,a.filename)},color:function(){var a;if(b.charAt(f)==="#"&&(a=t(/^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})/)))return new e.Color(a[1])},dimension:function(){var a,c=b.charCodeAt(f);if(c>57||c<45||c===47)return;if(a=t(/^(-?\d*\.?\d+)(px|%|em|rem|pc|ex|in|deg|s|ms|pt|cm|mm|rad|grad|turn)?/))return new e.Dimension(a[1],a[2])},javascript:function(){var a,c=f,d;b.charAt(c)==="~"&&(c++,d=!0);if(b.charAt(c)!=="`")return;d&&t("~");if(a=t(/^`([^`]*)`/))return new e.JavaScript(a[1],f,d)}},variable:function(){var a;if(b.charAt(f)==="@"&&(a=t(/^(@[\w-]+)\s*:/)))return a[1]},shorthand:function(){var a,b;if(!w(/^[@\w.%-]+\/[@\w.-]+/))return;if((a=t(this.entity))&&t("/")&&(b=t(this.entity)))return new e.Shorthand(a,b)},mixin:{call:function(){var c=[],d,g,h,i=f,j=b.charAt(f),k=!1;if(j!=="."&&j!=="#")return;while(d=t(/^[#.](?:[\w-]|\\(?:[a-fA-F0-9]{1,6} ?|[^a-fA-F0-9]))+/))c.push(new e.Element(g,d,f)),g=t(">");t("(")&&(h=t(this.entities.arguments))&&t(")"),t(this.important)&&(k=!0);if(c.length>0&&(t(";")||w("}")))return new e.mixin.Call(c,h||[],i,a.filename,k)},definition:function(){var a,c=[],d,g,h,i,j,k=!1;if(b.charAt(f)!=="."&&b.charAt(f)!=="#"||w(/^[^{]*(;|})/))return;q();if(d=t(/^([#.](?:[\w-]|\\(?:[a-fA-F0-9]{1,6} ?|[^a-fA-F0-9]))+)\s*\(/)){a=d[1];do{if(b.charAt(f)==="."&&t(/^\.{3}/)){k=!0;break}if(!(h=t(this.entities.variable)||t(this.entities.literal)||t(this.entities.keyword)))break;if(h instanceof e.Variable)if(t(":"))i=u(this.expression,"expected expression"),c.push({name:h.name,value:i});else{if(t(/^\.{3}/)){c.push({name:h.name,variadic:!0}),k=!0;break}c.push({name:h.name})}else c.push({value:h})}while(t(","));u(")"),t(/^when/)&&(j=u(this.conditions,"expected condition")),g=t(this.block);if(g)return new e.mixin.Definition(a,c,g,j,k);r()}}},entity:function(){return t(this.entities.literal)||t(this.entities.variable)||t(this.entities.url)||t(this.entities.call)||t(this.entities.keyword)||t(this.entities.javascript)||t(this.comment)},end:function(){return t(";")||w("}")},alpha:function(){var a;if(!t(/^\(opacity=/i))return;if(a=t(/^\d+/)||t(this.entities.variable))return u(")"),new e.Alpha(a)},element:function(){var a,b,c,d;c=t(this.combinator),a=t(/^(?:\d+\.\d+|\d+)%/)||t(/^(?:[.#]?|:*)(?:[\w-]|\\(?:[a-fA-F0-9]{1,6} ?|[^a-fA-F0-9]))+/)||t("*")||t(this.attribute)||t(/^\([^)@]+\)/),a||t("(")&&(d=t(this.entities.variable))&&t(")")&&(a=new e.Paren(d));if(a)return new e.Element(c,a,f);if(c.value&&c.value.charAt(0)==="&")return new e.Element(c,null,f)},combinator:function(){var a,c=b.charAt(f);if(c===">"||c==="+"||c==="~"){f++;while(b.charAt(f)===" ")f++;return new e.Combinator(c)}if(c==="&"){a="&",f++,b.charAt(f)===" "&&(a="& ");while(b.charAt(f)===" ")f++;return new e.Combinator(a)}return b.charAt(f-1)===" "?new e.Combinator(" "):new e.Combinator(null)},selector:function(){var a,c,d=[],g,h;if(t("("))return a=t(this.entity),u(")"),new e.Selector([new e.Element("",a,f)]);while(c=t(this.element)){g=b.charAt(f),d.push(c);if(g==="{"||g==="}"||g===";"||g===",")break}if(d.length>0)return new e.Selector(d)},tag:function(){return t(/^[a-zA-Z][a-zA-Z-]*[0-9]?/)||t("*")},attribute:function(){var a="",b,c,d;if(!t("["))return;if(b=t(/^[a-zA-Z-]+/)||t(this.entities.quoted))(d=t(/^[|~*$^]?=/))&&(c=t(this.entities.quoted)||t(/^[\w-]+/))?a=[b,d,c.toCSS?c.toCSS():c].join(""):a=b;if(!t("]"))return;if(a)return"["+a+"]"},block:function(){var a;if(t("{")&&(a=t(this.primary))&&t("}"))return a},ruleset:function(){var b=[],c,d,g;q();while(c=t(this.selector)){b.push(c),t(this.comment);if(!t(","))break;t(this.comment)}if(b.length>0&&(d=t(this.block)))return new e.Ruleset(b,d,a.strictImports);j=f,r()},rule:function(){var a,c,d=b.charAt(f),h,l;q();if(d==="."||d==="#"||d==="&")return;if(a=t(this.variable)||t(this.property)){a.charAt(0)!="@"&&(l=/^([^@+\/'"*`(;{}-]*);/.exec(k[g]))?(f+=l[0].length-1,c=new e.Anonymous(l[1])):a==="font"?c=t(this.font):c=t(this.value),h=t(this.important);if(c&&t(this.end))return new e.Rule(a,c,h,i);j=f,r()}},"import":function(){var a,b,c=f;if(t(/^@import\s+/)&&(a=t(this.entities.quoted)||t(this.entities.url))){b=t(this.mediaFeatures);if(t(";"))return new e.Import(a,p,b,c)}},mediaFeature:function(){var a,b,c=[];do if(a=t(this.entities.keyword))c.push(a);else if(t("(")){b=t(this.property),a=t(this.entity);if(!t(")"))return null;if(b&&a)c.push(new e.Paren(new e.Rule(b,a,null,f,!0)));else if(a)c.push(new e.Paren(a));else return null}while(a);if(c.length>0)return new e.Expression(c)},mediaFeatures:function(){var a,b=[];do if(a=t(this.mediaFeature)){b.push(a);if(!t(","))break}else if(a=t(this.entities.variable)){b.push(a);if(!t(","))break}while(a);return b.length>0?b:null},media:function(){var a,b;if(t(/^@media/)){a=t(this.mediaFeatures);if(b=t(this.block))return new e.Media(b,a)}},directive:function(){var a,c,d,g,h,i;if(b.charAt(f)!=="@")return;if(c=t(this["import"])||t(this.media))return c;if(a=t(/^@page|@keyframes/)||t(/^@(?:-webkit-|-moz-|-o-|-ms-)[a-z0-9-]+/)){g=(t(/^[^{]+/)||"").trim();if(d=t(this.block))return new e.Directive(a+" "+g,d)}else if(a=t(/^@[-a-z]+/))if(a==="@font-face"){if(d=t(this.block))return new e.Directive(a,d)}else if((c=t(this.entity))&&t(";"))return new e.Directive(a,c)},font:function(){var a=[],b=[],c,d,f,g;while(g=t(this.shorthand)||t(this.entity))b.push(g);a.push(new e.Expression(b));if(t(","))while(g=t(this.expression)){a.push(g);if(!t(","))break}return new e.Value(a)},value:function(){var a,b=[],c;while(a=t(this.expression)){b.push(a);if(!t(","))break}if(b.length>0)return new e.Value(b)},important:function(){if(b.charAt(f)==="!")return t(/^! *important/)},sub:function(){var a;if(t("(")&&(a=t(this.expression))&&t(")"))return a},multiplication:function(){var a,b,c,d;if(a=t(this.operand)){while(!w(/^\/\*/)&&(c=t("/")||t("*"))&&(b=t(this.operand)))d=new e.Operation(c,[d||a,b]);return d||a}},addition:function(){var a,c,d,g;if(a=t(this.multiplication)){while((d=t(/^[-+]\s+/)||b.charAt(f-1)!=" "&&(t("+")||t("-")))&&(c=t(this.multiplication)))g=new e.Operation(d,[g||a,c]);return g||a}},conditions:function(){var a,b,c=f,d;if(a=t(this.condition)){while(t(",")&&(b=t(this.condition)))d=new e.Condition("or",d||a,b,c);return d||a}},condition:function(){var a,b,c,d,g=f,h=!1;t(/^not/)&&(h=!0),u("(");if(a=t(this.addition)||t(this.entities.keyword)||t(this.entities.quoted))return(d=t(/^(?:>=|=<|[<=>])/))?(b=t(this.addition)||t(this.entities.keyword)||t(this.entities.quoted))?c=new e.Condition(d,a,b,g,h):v("expected expression"):c=new e.Condition("=",a,new e.Keyword("true"),g,h),u(")"),t(/^and/)?new e.Condition("and",c,t(this.condition)):c},operand:function(){var a,c=b.charAt(f+1);b.charAt(f)==="-"&&(c==="@"||c==="(")&&(a=t("-"));var d=t(this.sub)||t(this.entities.dimension)||t(this.entities.color)||t(this.entities.variable)||t(this.entities.call);return a?new e.Operation("*",[new e.Dimension(-1),d]):d},expression:function(){var a,b,c=[],d;while(a=t(this.addition)||t(this.entity))c.push(a);if(c.length>0)return new e.Expression(c)},property:function(){var a;if(a=t(/^(\*?-?[-a-z_0-9]+)\s*:/))return a[1]}}}};if(d.mode==="browser"||d.mode==="rhino")d.Parser.importer=function(a,b,c,d){!/^([a-z]+:)?\//.test(a)&&b.length>0&&(a=b[0]+a),n({href:a,title:a,type:d.mime},function(e){e&&typeof d.errback=="function"?d.errback.call(null,a,b,c,d):c.apply(null,arguments)},!0)};(function(a){function b(b){return a.functions.hsla(b.h,b.s,b.l,b.a)}function c(b){if(b instanceof a.Dimension)return parseFloat(b.unit=="%"?b.value/100:b.value);if(typeof b=="number")return b;throw{error:"RuntimeError",message:"color functions take numbers as parameters"}}function d(a){return Math.min(1,Math.max(0,a))}a.functions={rgb:function(a,b,c){return this.rgba(a,b,c,1)},rgba:function(b,d,e,f){var g=[b,d,e].map(function(a){return c(a)}),f=c(f);return new a.Color(g,f)},hsl:function(a,b,c){return this.hsla(a,b,c,1)},hsla:function(a,b,d,e){function h(a){return a=a<0?a+1:a>1?a-1:a,a*6<1?g+(f-g)*a*6:a*2<1?f:a*3<2?g+(f-g)*(2/3-a)*6:g}a=c(a)%360/360,b=c(b),d=c(d),e=c(e);var f=d<=.5?d*(b+1):d+b-d*b,g=d*2-f;return this.rgba(h(a+1/3)*255,h(a)*255,h(a-1/3)*255,e)},hue:function(b){return new a.Dimension(Math.round(b.toHSL().h))},saturation:function(b){return new a.Dimension(Math.round(b.toHSL().s*100),"%")},lightness:function(b){return new a.Dimension(Math.round(b.toHSL().l*100),"%")},alpha:function(b){return new a.Dimension(b.toHSL().a)},saturate:function(a,c){var e=a.toHSL();return e.s+=c.value/100,e.s=d(e.s),b(e)},desaturate:function(a,c){var e=a.toHSL();return e.s-=c.value/100,e.s=d(e.s),b(e)},lighten:function(a,c){var e=a.toHSL();return e.l+=c.value/100,e.l=d(e.l),b(e)},darken:function(a,c){var e=a.toHSL();return e.l-=c.value/100,e.l=d(e.l),b(e)},fadein:function(a,c){var e=a.toHSL();return e.a+=c.value/100,e.a=d(e.a),b(e)},fadeout:function(a,c){var e=a.toHSL();return e.a-=c.value/100,e.a=d(e.a),b(e)},fade:function(a,c){var e=a.toHSL();return e.a=c.value/100,e.a=d(e.a),b(e)},spin:function(a,c){var d=a.toHSL(),e=(d.h+c.value)%360;return d.h=e<0?360+e:e,b(d)},mix:function(b,c,d){var e=d.value/100,f=e*2-1,g=b.toHSL().a-c.toHSL().a,h=((f*g==-1?f:(f+g)/(1+f*g))+1)/2,i=1-h,j=[b.rgb[0]*h+c.rgb[0]*i,b.rgb[1]*h+c.rgb[1]*i,b.rgb[2]*h+c.rgb[2]*i],k=b.alpha*e+c.alpha*(1-e);return new a.Color(j,k)},greyscale:function(b){return this.desaturate(b,new a.Dimension(100))},e:function(b){return new a.Anonymous(b instanceof a.JavaScript?b.evaluated:b)},escape:function(b){return new a.Anonymous(encodeURI(b.value).replace(/=/g,"%3D").replace(/:/g,"%3A").replace(/#/g,"%23").replace(/;/g,"%3B").replace(/\(/g,"%28").replace(/\)/g,"%29"))},"%":function(b){var c=Array.prototype.slice.call(arguments,1),d=b.value;for(var e=0;e255?255:a<0?0:a).toString(16),a.length===1?"0"+a:a}).join("")},operate:function(b,c){var d=[];c instanceof a.Color||(c=c.toColor());for(var e=0;e<3;e++)d[e]=a.operate(b,this.rgb[e],c.rgb[e]);return new a.Color(d,this.alpha+c.alpha)},toHSL:function(){var a=this.rgb[0]/255,b=this.rgb[1]/255,c=this.rgb[2]/255,d=this.alpha,e=Math.max(a,b,c),f=Math.min(a,b,c),g,h,i=(e+f)/2,j=e-f;if(e===f)g=h=0;else{h=i>.5?j/(2-e-f):j/(e+f);switch(e){case a:g=(b-c)/j+(b255?255:a<0?0:a).toString(16),a.length===1?"0"+a:a}).join("")}}}(c("../tree")),function(a){a.Comment=function(a,b){this.value=a,this.silent=!!b},a.Comment.prototype={toCSS:function(a){return a.compress?"":this.value},eval:function(){return this}}}(c("../tree")),function(a){a.Condition=function(a,b,c,d,e){this.op=a.trim(),this.lvalue=b,this.rvalue=c,this.index=d,this.negate=e},a.Condition.prototype.eval=function(a){var b=this.lvalue.eval(a),c=this.rvalue.eval(a),d=this.index,e,e=function(a){switch(a){case"and":return b&&c;case"or":return b||c;default:if(b.compare)e=b.compare(c);else if(c.compare)e=c.compare(b);else throw{type:"Type",message:"Unable to perform comparison",index:d};switch(e){case-1:return a==="<"||a==="=<";case 0:return a==="="||a===">="||a==="=<";case 1:return a===">"||a===">="}}}(this.op);return this.negate?!e:e}}(c("../tree")),function(a){a.Dimension=function(a,b){this.value=parseFloat(a),this.unit=b||null},a.Dimension.prototype={eval:function(){return this},toColor:function(){return new a.Color([this.value,this.value,this.value])},toCSS:function(){var a=this.value+this.unit;return a},operate:function(b,c){return new a.Dimension(a.operate(b,this.value,c.value),this.unit||c.unit)},compare:function(b){return b instanceof a.Dimension?b.value>this.value?-1:b.value":a.compress?">":" > "}[this.value]}}(c("../tree")),function(a){a.Expression=function(a){this.value=a},a.Expression.prototype={eval:function(b){return this.value.length>1?new a.Expression(this.value.map(function(a){return a.eval(b)})):this.value.length===1?this.value[0].eval(b):this},toCSS:function(a){return this.value.map(function(b){return b.toCSS?b.toCSS(a):""}).join(" ")}}}(c("../tree")),function(a){a.Import=function(b,c,d,e){var f=this;this.index=e,this._path=b,this.features=d&&new a.Value(d),b instanceof a.Quoted?this.path=/\.(le?|c)ss(\?.*)?$/.test(b.value)?b.value:b.value+".less":this.path=b.value.value||b.value,this.css=/css(\?.*)?$/.test(this.path),this.css||c.push(this.path,function(b,c){b&&(b.index=e),f.root=c||new a.Ruleset([],[])})},a.Import.prototype={toCSS:function(a){var b=this.features?" "+this.features.toCSS(a):"";return this.css?"@import "+this._path.toCSS()+b+";\n":""},eval:function(b){var c,d=this.features&&this.features.eval(b);if(this.css)return this;c=new a.Ruleset([],this.root.rules.slice(0));for(var e=0;e1){var d=new a.Element("&",null,0),e=[new a.Selector([d])];c=new a.Ruleset(e,b.mediaBlocks),c.multiMedia=!0}return delete b.mediaBlocks,delete b.mediaPath,c},evalNested:function(b){var c,d,e=b.mediaPath.concat([this]);for(c=0;c0;c--)b.splice(c,0,new a.Anonymous("and"));return new a.Expression(b)})),new a.Ruleset([],[])},permute:function(a){if(a.length===0)return[];if(a.length===1)return a[0];var b=[],c=this.permute(a.slice(1));for(var d=0;d0){c=this.arguments&&this.arguments.map(function(b){return b.eval(a)});for(var g=0;gthis.params.length)return!1;if(this.required>0&&c>this.params.length)return!1}if(this.condition&&!this.condition.eval({frames:[this.evalParams(b,a)].concat(b.frames)}))return!1;d=Math.min(c,this.arity);for(var f=0;fe.selectors[g].elements.length?Array.prototype.push.apply(d,e.find(new a.Selector(b.elements.slice(1)),c)):d.push(e);break}}),this._lookups[g]=d)},toCSS:function(b,c){var d=[],e=[],f=[],g=[],h,i;this.root||(b.length===0?g=this.selectors.map(function(a){return[a]}):this.joinSelectors(g,b,this.selectors));for(var j=0;j0&&(h=g.map(function(a){return a.map(function(a){return a.toCSS(c)}).join("").trim()}).join(c.compress?",":",\n"),d.push(h,(c.compress?"{":" {\n ")+e.join(c.compress?"":"\n ")+(c.compress?"}":"\n}\n"))),d.push(f),d.join("")+(c.compress?"\n":"")},joinSelectors:function(a,b,c){for(var d=0;d0&&e.push(new a.Selector(g)),h.length>0&&f.push(new a.Selector(h));for(var l=0;l0&&(b.value=c[0]+(b.value.charAt(0)==="/"?b.value.slice(1):b.value)),this.value=b,this.paths=c)},b.URL.prototype={toCSS:function(){return"url("+(this.attrs?"data:"+this.attrs.mime+this.attrs.charset+this.attrs.base64+this.attrs.data:this.value.toCSS())+")"},eval:function(a){return this.attrs?this:new b.URL(this.value.eval(a),this.paths)}}}(c("../tree")),function(a){a.Value=function(a){this.value=a,this.is="value"},a.Value.prototype={eval:function(b){return this.value.length===1?this.value[0].eval(b):new a.Value(this.value.map(function(a){return a.eval(b)}))},toCSS:function(a){return this.value.map(function(b){return b.toCSS(a)}).join(a.compress?",":", ")}}}(c("../tree")),function(a){a.Variable=function(a,b,c){this.name=a,this.index=b,this.file=c},a.Variable.prototype={eval:function(b){var c,d,e=this.name;e.indexOf("@@")==0&&(e="@"+(new a.Variable(e.slice(1))).eval(b).value);if(c=a.find(b.frames,function(a){if(d=a.variable(e))return d.value.eval(b)}))return c;throw{type:"Name",message:"variable "+e+" is undefined",filename:this.file,index:this.index}}}}(c("../tree")),function(a){a.find=function(a,b){for(var c=0,d;c1?"["+a.value.map(function(a){return a.toCSS(!1)}).join(", ")+"]":a.toCSS(!1)}}(c("./tree"));var f=location.protocol==="file:"||location.protocol==="chrome:"||location.protocol==="chrome-extension:"||location.protocol==="resource:";d.env=d.env||(location.hostname=="127.0.0.1"||location.hostname=="0.0.0.0"||location.hostname=="localhost"||location.port.length>0||f?"development":"production"),d.async=!1,d.poll=d.poll||(f?1e3:1500),d.watch=function(){return this.watchMode=!0},d.unwatch=function(){return this.watchMode=!1},d.env==="development"?(d.optimization=0,/!watch/.test(location.hash)&&d.watch(),d.watchTimer=setInterval(function(){d.watchMode&&m(function(a,b,c,d,e){b&&p(b.toCSS(),d,e.lastModified)})},d.poll)):d.optimization=3;var g;try{g=typeof a.localStorage=="undefined"?null:a.localStorage}catch(h){g=null}var i=document.getElementsByTagName("link"),j=/^text\/(x-)?less$/;d.sheets=[];for(var k=0;k0?d.firstChild.nodeValue!==a.nodeValue&&d.replaceChild(a,d.firstChild):d.appendChild(a)})(document.createTextNode(a));c&&g&&(t("saving "+e+" to cache."),g.setItem(e,a),g.setItem(e+":timestamp",c))}function q(a,b,c,e){function i(b,c,d){b.status>=200&&b.status<300?c(b.responseText,b.getResponseHeader("Last-Modified")):typeof d=="function"&&d(b.status,a)}var g=r(),h=f?!1:d.async;typeof g.overrideMimeType=="function"&&g.overrideMimeType("text/css"),g.open("GET",a,h),g.setRequestHeader("Accept",b||"text/x-less, text/css; q=0.9, */*; q=0.5"),g.send(null),f?g.status===0||g.status>=200&&g.status<300?c(g.responseText):e(g.status,a):h?g.onreadystatechange=function(){g.readyState==4&&i(g,c,e)}:i(g,c,e)}function r(){if(a.XMLHttpRequest)return new XMLHttpRequest;try{return new ActiveXObject("MSXML2.XMLHTTP.3.0")}catch(b){return t("browser doesn't support AJAX."),null}}function s(a){return a&&a.parentNode.removeChild(a)}function t(a){d.env=="development"&&typeof console!="undefined"&&console.log("less: "+a)}function u(a,b){var c="less-error-message:"+o(b),e='
  • {content}
  • ',f=document.createElement("div"),g,h,i=[],j=a.filename||b;f.id=c,f.className="less-error-message",h="

    "+(a.message||"There is an error in your .less file")+"

    "+'

    in '+j+" ";var k=function(a,b,c){a.extract[b]&&i.push(e.replace(/\{line\}/,parseInt(a.line)+(b-1)).replace(/\{class\}/,c).replace(/\{content\}/,a.extract[b]))};a.stack?h+="
    "+a.stack.split("\n").slice(1).join("
    "):a.extract&&(k(a,0,""),k(a,1,"line"),k(a,2,""),h+="on line "+a.line+", column "+(a.column+1)+":

    "+"
      "+i.join("")+"
    "),f.innerHTML=h,p([".less-error-message ul, .less-error-message li {","list-style-type: none;","margin-right: 15px;","padding: 4px 0;","margin: 0;","}",".less-error-message label {","font-size: 12px;","margin-right: 15px;","padding: 4px 0;","color: #cc7777;","}",".less-error-message pre {","color: #dd6666;","padding: 4px 0;","margin: 0;","display: inline-block;","}",".less-error-message pre.line {","color: #ff0000;","}",".less-error-message h3 {","font-size: 20px;","font-weight: bold;","padding: 15px 0 5px 0;","margin: 0;","}",".less-error-message a {","color: #10a","}",".less-error-message .error {","color: red;","font-weight: bold;","padding-bottom: 2px;","border-bottom: 1px dashed red;","}"].join("\n"),{title:"error-message"}),f.style.cssText=["font-family: Arial, sans-serif","border: 1px solid #e00","background-color: #eee","border-radius: 5px","-webkit-border-radius: 5px","-moz-border-radius: 5px","color: #e00","padding: 15px","margin-bottom: 15px"].join(";"),d.env=="development"&&(g=setInterval(function(){document.body&&(document.getElementById(c)?document.body.replaceChild(f,document.getElementById(c)):document.body.insertBefore(f,document.body.firstChild),clearInterval(g))},10))}typeof define=="function"&&define.amd&&define("less",[],function(){return d});var d,e;typeof environment=="object"&&{}.toString.call(environment)==="[object Environment]"?(typeof a=="undefined"?d={}:d=a.less={},e=d.tree={},d.mode="rhino"):typeof a=="undefined"?(d=exports,e=c("./tree"),d.mode="node"):(typeof a.less=="undefined"&&(a.less={}),d=a.less,e=a.less.tree={},d.mode="browser"),d.Parser=function(b){function r(){i=l[h],j=g,m=g}function s(){l[h]=i,g=j,m=g}function t(){g>m&&(l[h]=l[h].slice(g-m),m=g)}function u(a){var b,c,d,e,i,j,k,o;if(a instanceof Function)return a.call(n.parsers);if(typeof a=="string")b=f.charAt(g)===a?a:null,d=1,t();else{t();if(b=a.exec(l[h]))d=b[0].length;else return null}if(b){o=g+=d,j=g+l[h].length-d;while(g=0&&b.charAt(c)!=="\n";c--)d++;return{line:typeof a=="number"?(b.slice(0,a).match(/\n/g)||"").length:null,column:d}}function B(a,b){var c=z(a,b),d=A(a.index,c),e=d.line,f=d.column,g=c.split("\n");this.type=a.type||"Syntax",this.message=a.message,this.filename=a.filename||b.filename,this.index=a.index,this.line=typeof e=="number"?e+1:null,this.callLine=a.call&&A(a.call,c).line+1,this.callExtract=g[A(a.call,c).line],this.stack=a.stack,this.column=f,this.extract=[g[e-1],g[e],g[e+1]]}var f,g,h,i,j,k,l,m,n,o=this,p=function(){},q=this.imports={paths:b&&b.paths||[],queue:[],files:{},contents:{},mime:b&&b.mime,error:null,push:function(a,c){var e=this;this.queue.push(a),d.Parser.importer(a,this.paths,function(b,d,f){e.queue.splice(e.queue.indexOf(a),1);var g=a in e.files;e.files[a]=d,e.contents[a]=f,b&&!e.error&&(e.error=b),c(b,d,g),e.queue.length===0&&p()},b)}};return this.env=b=b||{},this.optimization="optimization"in this.env?this.env.optimization:1,this.env.filename=this.env.filename||null,n={imports:q,parse:function(a,i){var j,o,q,r,s,t,v=[],w,x=null;g=h=m=k=0,f=a.replace(/\r\n/g,"\n"),l=function(a){var c=0,d=/[^"'`\{\}\/\(\)\\]+/g,g=/\/\*(?:[^*]|\*+[^\/*])*\*+\/|\/\/.*/g,h=/"((?:[^"\\\r\n]|\\.)*)"|'((?:[^'\\\r\n]|\\.)*)'|`((?:[^`\\\r\n]|\\.)*)`/g,i=0,j,k=a[0],l;for(var m=0,n,o;m0&&(x=new B({index:m,type:"Parse",message:"missing closing `}`",filename:b.filename},b)),e.map.call(a,function(a){return a.join("")})}([[]]);if(x)return i(x);try{j=new e.Ruleset([],u(this.parsers.primary)),j.root=!0}catch(y){return i(new B(y,b))}j.toCSS=function(a){var f,g,h;return function(f,g){var h=[],i;f=f||{},typeof g=="object"&&!e.isArray(g)&&(g=e.map.call(e.keys(g),function(a){var b=g[a];return b instanceof e.Value||(b instanceof e.Expression||(b=new e.Expression([b])),b=new e.Value([b])),new e.Rule("@"+a,b,!1,0)}),h=[new e.Ruleset(null,g)]);try{var j=a.call(this,{frames:h}).toCSS([],{compress:f.compress||!1})}catch(k){throw new B(k,b)}if(i=n.imports.error)throw i instanceof B?i:new B(i,b);return f.yuicompress&&d.mode==="node"?c("./cssmin").compressor.cssmin(j):f.compress?j.replace(/(\s)+/g,"$1"):j}}(j.eval);if(g=0&&f.charAt(z)!=="\n";z--)A++;x={type:"Parse",message:"Syntax Error on line "+s,index:g,filename:b.filename,line:s,column:A,extract:[t[s-2],t[s-1],t[s]]}}this.imports.queue.length>0?p=function(){i(x,j)}:i(x,j)},parsers:{primary:function(){var a,b=[];while((a=u(this.mixin.definition)||u(this.rule)||u(this.ruleset)||u(this.mixin.call)||u(this.comment)||u(this.directive))||u(/^[\s\n]+/))a&&b.push(a);return b},comment:function(){var a;if(f.charAt(g)!=="/")return;if(f.charAt(g+1)==="/")return new e.Comment(u(/^\/\/.*/),!0);if(a=u(/^\/\*(?:[^*]|\*+[^\/*])*\*+\/\n?/))return new e.Comment(a)},entities:{quoted:function(){var a,b=g,c;f.charAt(b)==="~"&&(b++,c=!0);if(f.charAt(b)!=='"'&&f.charAt(b)!=="'")return;c&&u("~");if(a=u(/^"((?:[^"\\\r\n]|\\.)*)"|'((?:[^'\\\r\n]|\\.)*)'/))return new e.Quoted(a[0],a[1]||a[2],c)},keyword:function(){var a;if(a=u(/^[_A-Za-z-][_A-Za-z0-9-]*/))return e.colors.hasOwnProperty(a)?new e.Color(e.colors[a].slice(1)):new e.Keyword(a)},call:function(){var a,c,d=g;if(!(a=/^([\w-]+|%|progid:[\w\.]+)\(/.exec(l[h])))return;a=a[1].toLowerCase();if(a==="url")return null;g+=a.length;if(a==="alpha")return u(this.alpha);u("("),c=u(this.entities.arguments);if(!u(")"))return;if(a)return new e.Call(a,c,d,b.filename)},arguments:function(){var a=[],b;while(b=u(this.entities.assignment)||u(this.expression)){a.push(b);if(!u(","))break}return a},literal:function(){return u(this.entities.dimension)||u(this.entities.color)||u(this.entities.quoted)},assignment:function(){var a,b;if((a=u(/^\w+(?=\s?=)/i))&&u("=")&&(b=u(this.entity)))return new e.Assignment(a,b)},url:function(){var a;if(f.charAt(g)!=="u"||!u(/^url\(/))return;return a=u(this.entities.quoted)||u(this.entities.variable)||u(this.entities.dataURI)||u(/^[-\w%@$\/.&=:;#+?~]+/)||"",v(")"),new e.URL(a.value||a.data||a instanceof e.Variable?a:new e.Anonymous(a),q.paths)},dataURI:function(){var a;if(u(/^data:/)){a={},a.mime=u(/^[^\/]+\/[^,;)]+/)||"",a.charset=u(/^;\s*charset=[^,;)]+/)||"",a.base64=u(/^;\s*base64/)||"",a.data=u(/^,\s*[^)]+/);if(a.data)return a}},variable:function(){var a,c=g;if(f.charAt(g)==="@"&&(a=u(/^@@?[\w-]+/)))return new e.Variable(a,c,b.filename)},color:function(){var a;if(f.charAt(g)==="#"&&(a=u(/^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})/)))return new e.Color(a[1])},dimension:function(){var a,b=f.charCodeAt(g);if(b>57||b<45||b===47)return;if(a=u(/^(-?\d*\.?\d+)(px|%|em|rem|pc|ex|in|deg|s|ms|pt|cm|mm|rad|grad|turn|dpi)?/))return new e.Dimension(a[1],a[2])},javascript:function(){var a,b=g,c;f.charAt(b)==="~"&&(b++,c=!0);if(f.charAt(b)!=="`")return;c&&u("~");if(a=u(/^`([^`]*)`/))return new e.JavaScript(a[1],g,c)}},variable:function(){var a;if(f.charAt(g)==="@"&&(a=u(/^(@[\w-]+)\s*:/)))return a[1]},shorthand:function(){var a,b;if(!x(/^[@\w.%-]+\/[@\w.-]+/))return;if((a=u(this.entity))&&u("/")&&(b=u(this.entity)))return new e.Shorthand(a,b)},mixin:{call:function(){var a=[],c,d,h=[],i,j=g,k=f.charAt(g),l,m,n=!1;if(k!=="."&&k!=="#")return;while(c=u(/^[#.](?:[\w-]|\\(?:[a-fA-F0-9]{1,6} ?|[^a-fA-F0-9]))+/))a.push(new e.Element(d,c,g)),d=u(">");if(u("(")){while(i=u(this.expression)){m=i,l=null;if(i.value.length==1){var o=i.value[0];if(o instanceof e.Variable&&u(":"))if(m=u(this.expression))l=o.name;else throw new Error("Expected value")}h.push({name:l,value:m});if(!u(","))break}if(!u(")"))throw new Error("Expected )")}u(this.important)&&(n=!0);if(a.length>0&&(u(";")||x("}")))return new e.mixin.Call(a,h,j,b.filename,n)},definition:function(){var a,b=[],c,d,h,i,j,k=!1;if(f.charAt(g)!=="."&&f.charAt(g)!=="#"||x(/^[^{]*(;|})/))return;r();if(c=u(/^([#.](?:[\w-]|\\(?:[a-fA-F0-9]{1,6} ?|[^a-fA-F0-9]))+)\s*\(/)){a=c[1];do{if(f.charAt(g)==="."&&u(/^\.{3}/)){k=!0;break}if(!(h=u(this.entities.variable)||u(this.entities.literal)||u(this.entities.keyword)))break;if(h instanceof e.Variable)if(u(":"))i=v(this.expression,"expected expression"),b.push({name:h.name,value:i});else{if(u(/^\.{3}/)){b.push({name:h.name,variadic:!0}),k=!0;break}b.push({name:h.name})}else b.push({value:h})}while(u(","));v(")"),u(/^when/)&&(j=v(this.conditions,"expected condition")),d=u(this.block);if(d)return new e.mixin.Definition(a,b,d,j,k);s()}}},entity:function(){return u(this.entities.literal)||u(this.entities.variable)||u(this.entities.url)||u(this.entities.call)||u(this.entities.keyword)||u(this.entities.javascript)||u(this.comment)},end:function(){return u(";")||x("}")},alpha:function(){var a;if(!u(/^\(opacity=/i))return;if(a=u(/^\d+/)||u(this.entities.variable))return v(")"),new e.Alpha(a)},element:function(){var a,b,c,d;c=u(this.combinator),a=u(/^(?:\d+\.\d+|\d+)%/)||u(/^(?:[.#]?|:*)(?:[\w-]|\\(?:[a-fA-F0-9]{1,6} ?|[^a-fA-F0-9]))+/)||u("*")||u(this.attribute)||u(/^\([^)@]+\)/),a||u("(")&&(d=u(this.entities.variable))&&u(")")&&(a=new e.Paren(d));if(a)return new e.Element(c,a,g);if(c.value&&c.value.charAt(0)==="&")return new e.Element(c,null,g)},combinator:function(){var a,b=f.charAt(g);if(b===">"||b==="+"||b==="~"){g++;while(f.charAt(g)===" ")g++;return new e.Combinator(b)}if(b==="&"){a="&",g++,f.charAt(g)===" "&&(a="& ");while(f.charAt(g)===" ")g++;return new e.Combinator(a)}return f.charAt(g-1)===" "?new e.Combinator(" "):new e.Combinator(null)},selector:function(){var a,b,c=[],d,h;if(u("("))return a=u(this.entity),v(")"),new e.Selector([new e.Element("",a,g)]);while(b=u(this.element)){d=f.charAt(g),c.push(b);if(d==="{"||d==="}"||d===";"||d===",")break}if(c.length>0)return new e.Selector(c)},tag:function(){return u(/^[a-zA-Z][a-zA-Z-]*[0-9]?/)||u("*")},attribute:function(){var a="",b,c,d;if(!u("["))return;if(b=u(/^[a-zA-Z-]+/)||u(this.entities.quoted))(d=u(/^[|~*$^]?=/))&&(c=u(this.entities.quoted)||u(/^[\w-]+/))?a=[b,d,c.toCSS?c.toCSS():c].join(""):a=b;if(!u("]"))return;if(a)return"["+a+"]"},block:function(){var a;if(u("{")&&(a=u(this.primary))&&u("}"))return a},ruleset:function(){var a=[],c,d,f;r();while(c=u(this.selector)){a.push(c),u(this.comment);if(!u(","))break;u(this.comment)}if(a.length>0&&(d=u(this.block)))return new e.Ruleset(a,d,b.strictImports);k=g,s()},rule:function(){var a,b,c=f.charAt(g),d,i;r();if(c==="."||c==="#"||c==="&")return;if(a=u(this.variable)||u(this.property)){a.charAt(0)!="@"&&(i=/^([^@+\/'"*`(;{}-]*);/.exec(l[h]))?(g+=i[0].length-1,b=new e.Anonymous(i[1])):a==="font"?b=u(this.font):b=u(this.value),d=u(this.important);if(b&&u(this.end))return new e.Rule(a,b,d,j);k=g,s()}},"import":function(){var a,b,c=g,d=u(/^@import(?:-(once))?\s+/);if(d&&(a=u(this.entities.quoted)||u(this.entities.url))){b=u(this.mediaFeatures);if(u(";"))return new e.Import(a,q,b,d[1]==="once",c)}},mediaFeature:function(){var a,b,c=[];do if(a=u(this.entities.keyword))c.push(a);else if(u("(")){b=u(this.property),a=u(this.entity);if(!u(")"))return null;if(b&&a)c.push(new e.Paren(new e.Rule(b,a,null,g,!0)));else if(a)c.push(new e.Paren(a));else return null}while(a);if(c.length>0)return new e.Expression(c)},mediaFeatures:function(){var a,b=[];do if(a=u(this.mediaFeature)){b.push(a);if(!u(","))break}else if(a=u(this.entities.variable)){b.push(a);if(!u(","))break}while(a);return b.length>0?b:null},media:function(){var a,b;if(u(/^@media/)){a=u(this.mediaFeatures);if(b=u(this.block))return new e.Media(b,a)}},directive:function(){var a,b,c,d,h,i;if(f.charAt(g)!=="@")return;if(b=u(this["import"])||u(this.media))return b;if(a=u(/^@page|@keyframes/)||u(/^@(?:-webkit-|-moz-|-o-|-ms-)[a-z0-9-]+/)){d=e.trim.call(u(/^[^{]+/)||"");if(c=u(this.block))return new e.Directive(a+" "+d,c)}else if(a=u(/^@[-a-z]+/))if(a==="@font-face"){if(c=u(this.block))return new e.Directive(a,c)}else if((b=u(this.entity))&&u(";"))return new e.Directive(a,b)},font:function(){var a=[],b=[],c,d,f,g;while(g=u(this.shorthand)||u(this.entity))b.push(g);a.push(new e.Expression(b));if(u(","))while(g=u(this.expression)){a.push(g);if(!u(","))break}return new e.Value(a)},value:function(){var a,b=[],c;while(a=u(this.expression)){b.push(a);if(!u(","))break}if(b.length>0)return new e.Value(b)},important:function(){if(f.charAt(g)==="!")return u(/^! *important/)},sub:function(){var a;if(u("(")&&(a=u(this.expression))&&u(")"))return a},multiplication:function(){var a,b,c,d;if(a=u(this.operand)){while(!x(/^\/\*/)&&(c=u("/")||u("*"))&&(b=u(this.operand)))d=new e.Operation(c,[d||a,b]);return d||a}},addition:function(){var a,b,c,d;if(a=u(this.multiplication)){while((c=u(/^[-+]\s+/)||f.charAt(g-1)!=" "&&(u("+")||u("-")))&&(b=u(this.multiplication)))d=new e.Operation(c,[d||a,b]);return d||a}},conditions:function(){var a,b,c=g,d;if(a=u(this.condition)){while(u(",")&&(b=u(this.condition)))d=new e.Condition("or",d||a,b,c);return d||a}},condition:function(){var a,b,c,d,f=g,h=!1;u(/^not/)&&(h=!0),v("(");if(a=u(this.addition)||u(this.entities.keyword)||u(this.entities.quoted))return(d=u(/^(?:>=|=<|[<=>])/))?(b=u(this.addition)||u(this.entities.keyword)||u(this.entities.quoted))?c=new e.Condition(d,a,b,f,h):w("expected expression"):c=new e.Condition("=",a,new e.Keyword("true"),f,h),v(")"),u(/^and/)?new e.Condition("and",c,u(this.condition)):c},operand:function(){var a,b=f.charAt(g+1);f.charAt(g)==="-"&&(b==="@"||b==="(")&&(a=u("-"));var c=u(this.sub)||u(this.entities.dimension)||u(this.entities.color)||u(this.entities.variable)||u(this.entities.call);return a?new e.Operation("*",[new e.Dimension(-1),c]):c},expression:function(){var a,b,c=[],d;while(a=u(this.addition)||u(this.entity))c.push(a);if(c.length>0)return new e.Expression(c)},property:function(){var a;if(a=u(/^(\*?-?[-a-z_0-9]+)\s*:/))return a[1]}}}};if(d.mode==="browser"||d.mode==="rhino")d.Parser.importer=function(a,b,c,d){!/^([a-z]+:)?\//.test(a)&&b.length>0&&(a=b[0]+a),n({href:a,title:a,type:d.mime},function(e){e&&typeof d.errback=="function"?d.errback.call(null,a,b,c,d):c.apply(null,arguments)},!0)};(function(a){function b(b){return a.functions.hsla(b.h,b.s,b.l,b.a)}function c(b){if(b instanceof a.Dimension)return parseFloat(b.unit=="%"?b.value/100:b.value);if(typeof b=="number")return b;throw{error:"RuntimeError",message:"color functions take numbers as parameters"}}function d(a){return Math.min(1,Math.max(0,a))}a.functions={rgb:function(a,b,c){return this.rgba(a,b,c,1)},rgba:function(b,d,e,f){var g=a.map.call([b,d,e],function(a){return c(a)}),f=c(f);return new a.Color(g,f)},hsl:function(a,b,c){return this.hsla(a,b,c,1)},hsla:function(a,b,d,e){function h(a){return a=a<0?a+1:a>1?a-1:a,a*6<1?g+(f-g)*a*6:a*2<1?f:a*3<2?g+(f-g)*(2/3-a)*6:g}a=c(a)%360/360,b=c(b),d=c(d),e=c(e);var f=d<=.5?d*(b+1):d+b-d*b,g=d*2-f;return this.rgba(h(a+1/3)*255,h(a)*255,h(a-1/3)*255,e)},hue:function(b){return new a.Dimension(Math.round(b.toHSL().h))},saturation:function(b){return new a.Dimension(Math.round(b.toHSL().s*100),"%")},lightness:function(b){return new a.Dimension(Math.round(b.toHSL().l*100),"%")},alpha:function(b){return new a.Dimension(b.toHSL().a)},saturate:function(a,c){var e=a.toHSL();return e.s+=c.value/100,e.s=d(e.s),b(e)},desaturate:function(a,c){var e=a.toHSL();return e.s-=c.value/100,e.s=d(e.s),b(e)},lighten:function(a,c){var e=a.toHSL();return e.l+=c.value/100,e.l=d(e.l),b(e)},darken:function(a,c){var e=a.toHSL();return e.l-=c.value/100,e.l=d(e.l),b(e)},fadein:function(a,c){var e=a.toHSL();return e.a+=c.value/100,e.a=d(e.a),b(e)},fadeout:function(a,c){var e=a.toHSL();return e.a-=c.value/100,e.a=d(e.a),b(e)},fade:function(a,c){var e=a.toHSL();return e.a=c.value/100,e.a=d(e.a),b(e)},spin:function(a,c){var d=a.toHSL(),e=(d.h+c.value)%360;return d.h=e<0?360+e:e,b(d)},mix:function(b,c,d){var e=d.value/100,f=e*2-1,g=b.toHSL().a-c.toHSL().a,h=((f*g==-1?f:(f+g)/(1+f*g))+1)/2,i=1-h,j=[b.rgb[0]*h+c.rgb[0]*i,b.rgb[1]*h+c.rgb[1]*i,b.rgb[2]*h+c.rgb[2]*i],k=b.alpha*e+c.alpha*(1-e);return new a.Color(j,k)},greyscale:function(b){return this.desaturate(b,new a.Dimension(100))},e:function(b){return new a.Anonymous(b instanceof a.JavaScript?b.evaluated:b)},escape:function(b){return new a.Anonymous(encodeURI(b.value).replace(/=/g,"%3D").replace(/:/g,"%3A").replace(/#/g,"%23").replace(/;/g,"%3B").replace(/\(/g,"%28").replace(/\)/g,"%29"))},"%":function(b){var c=Array.prototype.slice.call(arguments,1),d=b.value;for(var e=0;e255?255:a<0?0:a).toString(16),a.length===1?"0"+a:a}).join("")},operate:function(b,c){var d=[];c instanceof a.Color||(c=c.toColor());for(var e=0;e<3;e++)d[e]=a.operate(b,this.rgb[e],c.rgb[e]);return new a.Color(d,this.alpha+c.alpha)},toHSL:function(){var a=this.rgb[0]/255,b=this.rgb[1]/255,c=this.rgb[2]/255,d=this.alpha,e=Math.max(a,b,c),f=Math.min(a,b,c),g,h,i=(e+f)/2,j=e-f;if(e===f)g=h=0;else{h=i>.5?j/(2-e-f):j/(e+f);switch(e){case a:g=(b-c)/j+(b255?255:a<0?0:a).toString(16),a.length===1?"0"+a:a}).join("")}}}(c("../tree")),function(a){a.Comment=function(a,b){this.value=a,this.silent=!!b},a.Comment.prototype={toCSS:function(a){return a.compress?"":this.value},eval:function(){return this}}}(c("../tree")),function(a){a.Condition=function(b,c,d,e,f){this.op=a.trim.call(b),this.lvalue=c,this.rvalue=d,this.index=e,this.negate=f},a.Condition.prototype.eval=function(a){var b=this.lvalue.eval(a),c=this.rvalue.eval(a),d=this.index,e,e=function(a){switch(a){case"and":return b&&c;case"or":return b||c;default:if(b.compare)e=b.compare(c);else if(c.compare)e=c.compare(b);else throw{type:"Type",message:"Unable to perform comparison",index:d};switch(e){case-1:return a==="<"||a==="=<";case 0:return a==="="||a===">="||a==="=<";case 1:return a===">"||a===">="}}}(this.op);return this.negate?!e:e}}(c("../tree")),function(a){a.Dimension=function(a,b){this.value=parseFloat(a),this.unit=b||null},a.Dimension.prototype={eval:function(){return this},toColor:function(){return new a.Color([this.value,this.value,this.value])},toCSS:function(){var a=this.value+this.unit;return a},operate:function(b,c){return new a.Dimension(a.operate(b,this.value,c.value),this.unit||c.unit)},compare:function(b){return b instanceof a.Dimension?b.value>this.value?-1:b.value":a.compress?">":" > "}[this.value]}}(c("../tree")),function(a){a.Expression=function(a){this.value=a},a.Expression.prototype={eval:function(b){return this.value.length>1?new a.Expression(a.map.call(this.value,function(a){return a.eval(b)})):this.value.length===1?this.value[0].eval(b):this},toCSS:function(b){return a.map.call(this.value,function(a){return a.toCSS?a.toCSS(b):""}).join(" ")}}}(c("../tree")),function(a){a.Import=function(b,c,d,e,f){var g=this;this.once=e,this.index=f,this._path=b,this.features=d&&new a.Value(d),b instanceof a.Quoted?this.path=/\.(le?|c)ss(\?.*)?$/.test(b.value)?b.value:b.value+".less":this.path=b.value.value||b.value,this.css=/css(\?.*)?$/.test(this.path),this.css||c.push(this.path,function(b,c,d){b&&(b.index=f),d&&g.once&&(g.skip=d),g.root=c||new a.Ruleset([],[])})},a.Import.prototype={toCSS:function(a){var b=this.features?" "+this.features.toCSS(a):"";return this.css?"@import "+this._path.toCSS()+b+";\n":""},eval:function(b){var c,d=this.features&&this.features.eval(b);if(this.skip)return[];if(this.css)return this;c=new a.Ruleset([],this.root.rules.slice(0));for(var e=0;e1){var d=new a.Element("&",null,0),e=[new a.Selector([d])];c=new a.Ruleset(e,b.mediaBlocks),c.multiMedia=!0}return delete b.mediaBlocks,delete b.mediaPath,c},evalNested:function(b){var c,d,e=b.mediaPath.concat([this]);for(c=0;c0;c--)b.splice(c,0,new a.Anonymous("and"));return new a.Expression(b)})),new a.Ruleset([],[])},permute:function(a){if(a.length===0)return[];if(a.length===1)return a[0];var b=[],c=this.permute(a.slice(1));for(var d=0;d0){d=this.arguments&&a.map.call(this.arguments,function(a){return{name:a.name,value:a.value.eval(b)}});for(var h=0;hthis.params.length)return!1;if(this.required>0&&c>this.params.length)return!1}if(this.condition&&!this.condition.eval({frames:[this.evalParams(b,a)].concat(b.frames)}))return!1;d=Math.min(c,this.arity);for(var f=0;fe.selectors[g].elements.length?Array.prototype.push.apply(d,e.find(new a.Selector(b.elements.slice(1)),c)):d.push(e);break}}),this._lookups[g]=d)},toCSS:function(b,c){var d=[],e=[],f=[],g=[],h=[],i,j;this.root||(b.length===0?h=a.map.call(this.selectors,function(a){return[a]}):this.joinSelectors(h,b,this.selectors));for(var k=0;k0){i=a.map.call(h,function(b){return a.map.call(b,function(a){return a.toCSS(c)}).join("").trim()}).join(c.compress?",":",\n");for(var k=e.length-1;k>=0;k--)f.indexOf(e[k])===-1&&f.unshift(e[k]);e=f,d.push(i,(c.compress?"{":" {\n ")+e.join(c.compress?"":"\n ")+(c.compress?"}":"\n}\n"))}return d.push(g),d.join("")+(c.compress?"\n":"")},joinSelectors:function(a,b,c){for(var d=0;d0&&e.push(new a.Selector(g)),h.length>0&&f.push(new a.Selector(h));for(var l=0;l0&&(b.value=c[0]+(b.value.charAt(0)==="/"?b.value.slice(1):b.value)),this.value=b,this.paths=c)},b.URL.prototype={toCSS:function(){return"url("+(this.attrs?"data:"+this.attrs.mime+this.attrs.charset+this.attrs.base64+this.attrs.data:this.value.toCSS())+")"},eval:function(a){return this.attrs?this:new b.URL(this.value.eval(a),this.paths)}}}(c("../tree")),function(a){a.Value=function(a){this.value=a,this.is="value"},a.Value.prototype={eval:function(b){return this.value.length===1?this.value[0].eval(b):new a.Value(a.map.call(this.value,function(a){return a.eval(b)}))},toCSS:function(b){return a.map.call(this.value,function(a){return a.toCSS(b)}).join(b.compress?",":", ")}}}(c("../tree")),function(a){a.Variable=function(a,b,c){this.name=a,this.index=b,this.file=c},a.Variable.prototype={eval:function(b){var c,d,e=this.name;e.indexOf("@@")==0&&(e="@"+(new a.Variable(e.slice(1))).eval(b).value);if(c=a.find(b.frames,function(a){if(d=a.variable(e))return d.value.eval(b)}))return c;throw{type:"Name",message:"variable "+e+" is undefined",filename:this.file,index:this.index}}}}(c("../tree")),function(a){a.isArray=Array.isArray?Array.isArray:function(a){return Object.prototype.toString.call(a)==="[object Array]"||a instanceof Array},a.forEach=Array.prototype.forEach?Array.prototype.forEach:function(a,b){var c=this.length>>>0;for(var d=0;d>>0,c=new Array(b),d=arguments[1];for(var e=0;e>>0,c=0;if(b===0&&arguments.length===1)throw new TypeError;if(arguments.length>=2)var d=arguments[1];else do{if(c in this){d=this[c++];break}if(++c>=b)throw new TypeError}while(!0);for(;c=b)return-1;c<0&&(c+=b);for(;c1?"["+a.map.call(b.value,function(a){return a.toCSS(!1)}).join(", ")+"]":b.toCSS(!1)}}(c("./tree"));var f=location.protocol==="file:"||location.protocol==="chrome:"||location.protocol==="chrome-extension:"||location.protocol==="resource:";d.env=d.env||(location.hostname=="127.0.0.1"||location.hostname=="0.0.0.0"||location.hostname=="localhost"||location.port.length>0||f?"development":"production"),d.async=!1,d.poll=d.poll||(f?1e3:1500),d.watch=function(){return this.watchMode=!0},d.unwatch=function(){return this.watchMode=!1},d.env==="development"?(d.optimization=0,/!watch/.test(location.hash)&&d.watch(),d.watchTimer=setInterval(function(){d.watchMode&&m(function(a,b,c,d,e){b&&p(b.toCSS(),d,e.lastModified)})},d.poll)):d.optimization=3;var g;try{g=typeof a.localStorage=="undefined"?null:a.localStorage}catch(h){g=null}var i=document.getElementsByTagName("link"),j=/^text\/(x-)?less$/;d.sheets=[];for(var k=0;k>> 0; + for (var i = 0; i < len; i++) { + if (i in this) { + block.call(thisObject, this[i], i, this); + } + } +}; +tree.map = Array.prototype.map ? Array.prototype.map : Array.prototype.map = function(fun /*, thisp*/) { + var len = this.length >>> 0; + var res = new Array(len); + var thisp = arguments[1]; + + for (var i = 0; i < len; i++) { + if (i in this) { + res[i] = fun.call(thisp, this[i], i, this); + } + } + return res; +}; +tree.filter = Array.prototype.filter ? Array.prototype.filter : function (block /*, thisp */) { + var values = []; + var thisp = arguments[1]; + for (var i = 0; i < this.length; i++) { + if (block.call(thisp, this[i])) { + values.push(this[i]); + } + } + return values; +}; +tree.reduce = Array.prototype.reduce ? Array.prototype.reduce : function(fun /*, initial*/) { + var len = this.length >>> 0; + var i = 0; + + // no value to return if no initial value and an empty array + if (len === 0 && arguments.length === 1) throw new TypeError(); + + if (arguments.length >= 2) { + var rv = arguments[1]; + } else { + do { + if (i in this) { + rv = this[i++]; + break; + } + // if array contains no values, no initial value to return + if (++i >= len) throw new TypeError(); + } while (true); + } + for (; i < len; i++) { + if (i in this) { + rv = fun.call(null, rv, this[i], i, this); + } + } + return rv; +}; +tree.indexOf = Array.prototype.indexOf ? Array.prototype.indexOf : function (value /*, fromIndex */ ) { + var length = this.length; + var i = arguments[1] || 0; + + if (!length) return -1; + if (i >= length) return -1; + if (i < 0) i += length; + + for (; i < length; i++) { + if (!Object.prototype.hasOwnProperty.call(this, i)) { continue } + if (value === this[i]) return i; + } + return -1; +}; +tree.keys = Object.keys ? Object.keys : function (object) { + var keys = []; + for (var name in object) { + if (Object.prototype.hasOwnProperty.call(object, name)) { + keys.push(name); + } + } + return keys; +}; +tree.trim = String.prototype.trim ? String.prototype.trim : function () { + return String(this).replace(/^\s\s*/, '').replace(/\s\s*$/, ''); +}; + tree.find = function (obj, fun) { for (var i = 0, r; i < obj.length; i++) { if (r = fun.call(obj, obj[i])) { return r } @@ -7,8 +94,8 @@ tree.find = function (obj, fun) { 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(', ') + ']'; + if (tree.isArray(obj.value) && (obj.value.length > 1)) { + return '[' + tree.map.call(obj.value, function (v) { return v.toCSS(false) }).join(', ') + ']'; } else { return obj.toCSS(false); } diff --git a/lib/less/tree/call.js b/lib/less/tree/call.js index c1465dd47..ec31d2e52 100644 --- a/lib/less/tree/call.js +++ b/lib/less/tree/call.js @@ -23,7 +23,7 @@ tree.Call.prototype = { // The function should receive the value, not the variable. // eval: function (env) { - var args = this.args.map(function (a) { return a.eval(env) }); + var args = tree.map.call(this.args, function (a) { return a.eval(env) }); if (this.name in tree.functions) { // 1. try { @@ -36,7 +36,7 @@ tree.Call.prototype = { } } else { // 2. return new(tree.Anonymous)(this.name + - "(" + args.map(function (a) { return a.toCSS() }).join(', ') + ")"); + "(" + tree.map.call(args, function (a) { return a.toCSS() }).join(', ') + ")"); } }, diff --git a/lib/less/tree/color.js b/lib/less/tree/color.js index 37ce1781d..aac033b95 100644 --- a/lib/less/tree/color.js +++ b/lib/less/tree/color.js @@ -9,14 +9,14 @@ tree.Color = function (rgb, a) { // // This facilitates operations and conversions. // - if (Array.isArray(rgb)) { + if (tree.isArray(rgb)) { this.rgb = rgb; } else if (rgb.length == 6) { - this.rgb = rgb.match(/.{2}/g).map(function (c) { + this.rgb = tree.map.call(rgb.match(/.{2}/g), function (c) { return parseInt(c, 16); }); } else { - this.rgb = rgb.split('').map(function (c) { + this.rgb = tree.map.call(rgb.split(''), function (c) { return parseInt(c + c, 16); }); } @@ -33,11 +33,11 @@ tree.Color.prototype = { // toCSS: function () { if (this.alpha < 1.0) { - return "rgba(" + this.rgb.map(function (c) { + return "rgba(" + tree.map.call(this.rgb, function (c) { return Math.round(c); }).concat(this.alpha).join(', ') + ")"; } else { - return '#' + this.rgb.map(function (i) { + return '#' + tree.map.call(this.rgb, function (i) { i = Math.round(i); i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16); return i.length === 1 ? '0' + i : i; @@ -89,7 +89,7 @@ tree.Color.prototype = { }, toARGB: function () { var argb = [Math.round(this.alpha * 255)].concat(this.rgb); - return '#' + argb.map(function (i) { + return '#' + tree.map.call(argb, function (i) { i = Math.round(i); i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16); return i.length === 1 ? '0' + i : i; diff --git a/lib/less/tree/condition.js b/lib/less/tree/condition.js index 6b79dc960..38c7e0062 100644 --- a/lib/less/tree/condition.js +++ b/lib/less/tree/condition.js @@ -1,7 +1,7 @@ (function (tree) { tree.Condition = function (op, l, r, i, negate) { - this.op = op.trim(); + this.op = tree.trim.call(op); this.lvalue = l; this.rvalue = r; this.index = i; diff --git a/lib/less/tree/directive.js b/lib/less/tree/directive.js index 27538332a..b6e8911a3 100644 --- a/lib/less/tree/directive.js +++ b/lib/less/tree/directive.js @@ -3,7 +3,7 @@ tree.Directive = function (name, value, features) { this.name = name; - if (Array.isArray(value)) { + if (tree.isArray(value)) { this.ruleset = new(tree.Ruleset)([], value); this.ruleset.allowImports = true; } else { @@ -15,7 +15,7 @@ tree.Directive.prototype = { if (this.ruleset) { this.ruleset.root = true; return this.name + (env.compress ? '{' : ' {\n ') + - this.ruleset.toCSS(ctx, env).trim().replace(/\n/g, '\n ') + + tree.trim.call(this.ruleset.toCSS(ctx, env)).replace(/\n/g, '\n ') + (env.compress ? '}': '\n}\n'); } else { return this.name + ' ' + this.value.toCSS() + ';\n'; diff --git a/lib/less/tree/element.js b/lib/less/tree/element.js index 14b08d2ea..20706739c 100644 --- a/lib/less/tree/element.js +++ b/lib/less/tree/element.js @@ -5,7 +5,7 @@ tree.Element = function (combinator, value, index) { combinator : new(tree.Combinator)(combinator); if (typeof(value) === 'string') { - this.value = value.trim(); + this.value = tree.trim.call(value); } else if (value) { this.value = value; } else { @@ -33,7 +33,7 @@ tree.Combinator = function (value) { } else if (value === '& ') { this.value = '& '; } else { - this.value = value ? value.trim() : ""; + this.value = value ? tree.trim.call(value) : ""; } }; tree.Combinator.prototype.toCSS = function (env) { diff --git a/lib/less/tree/expression.js b/lib/less/tree/expression.js index fbfa9c5b7..3ad5e0a50 100644 --- a/lib/less/tree/expression.js +++ b/lib/less/tree/expression.js @@ -4,7 +4,7 @@ tree.Expression = function (value) { this.value = value }; tree.Expression.prototype = { eval: function (env) { if (this.value.length > 1) { - return new(tree.Expression)(this.value.map(function (e) { + return new(tree.Expression)(tree.map.call(this.value, function (e) { return e.eval(env); })); } else if (this.value.length === 1) { @@ -14,7 +14,7 @@ tree.Expression.prototype = { } }, toCSS: function (env) { - return this.value.map(function (e) { + return tree.map.call(this.value, function (e) { return e.toCSS ? e.toCSS(env) : ''; }).join(' '); } diff --git a/lib/less/tree/javascript.js b/lib/less/tree/javascript.js index 772a31ddd..e24e75055 100644 --- a/lib/less/tree/javascript.js +++ b/lib/less/tree/javascript.js @@ -39,7 +39,7 @@ tree.JavaScript.prototype = { } if (typeof(result) === 'string') { return new(tree.Quoted)('"' + result + '"', result, this.escaped, this.index); - } else if (Array.isArray(result)) { + } else if (tree.isArray(result)) { return new(tree.Anonymous)(result.join(', ')); } else { return new(tree.Anonymous)(result); diff --git a/lib/less/tree/media.js b/lib/less/tree/media.js index 2b7b26e58..a376dc518 100644 --- a/lib/less/tree/media.js +++ b/lib/less/tree/media.js @@ -14,7 +14,7 @@ tree.Media.prototype = { this.ruleset.root = (ctx.length === 0 || ctx[0].multiMedia); return '@media ' + features + (env.compress ? '{' : ' {\n ') + - this.ruleset.toCSS(ctx, env).trim().replace(/\n/g, '\n ') + + tree.trim.call(this.ruleset.toCSS(ctx, env)).replace(/\n/g, '\n ') + (env.compress ? '}': '\n}\n'); }, eval: function (env) { @@ -68,7 +68,7 @@ tree.Media.prototype = { for (i = 0; i < path.length; i++) { value = path[i].features instanceof tree.Value ? path[i].features.value : path[i].features; - path[i] = Array.isArray(value) ? value : [value]; + path[i] = tree.isArray(value) ? value : [value]; } // Trace all permutations to generate the resulting media-query. @@ -78,8 +78,8 @@ tree.Media.prototype = { // a and e // b and c and d // b and c and e - this.features = new(tree.Value)(this.permute(path).map(function (path) { - path = path.map(function (fragment) { + this.features = new(tree.Value)(tree.map.call(this.permute(path), function (path) { + path = tree.map.call(path, function (fragment) { return fragment.toCSS ? fragment : new(tree.Anonymous)(fragment); }); diff --git a/lib/less/tree/mixin.js b/lib/less/tree/mixin.js index b441bf3b2..2579915a5 100644 --- a/lib/less/tree/mixin.js +++ b/lib/less/tree/mixin.js @@ -14,7 +14,7 @@ tree.mixin.Call.prototype = { for (var i = 0; i < env.frames.length; i++) { if ((mixins = env.frames[i].find(this.selector)).length > 0) { - args = this.arguments && this.arguments.map(function (a) { + args = this.arguments && tree.map.call(this.arguments, function (a) { return { name: a.name, value: a.value.eval(env) }; }); for (var m = 0; m < mixins.length; m++) { @@ -33,8 +33,8 @@ tree.mixin.Call.prototype = { } else { throw { type: 'Runtime', message: 'No matching definition was found for `' + - this.selector.toCSS().trim() + '(' + - this.arguments.map(function (a) { + tree.trim.call(this.selector.toCSS()) + '(' + + tree.map.call(this.arguments, function (a) { return a.toCSS(); }).join(', ') + ")`", index: this.index, filename: this.filename }; @@ -42,7 +42,7 @@ tree.mixin.Call.prototype = { } } throw { type: 'Name', - message: this.selector.toCSS().trim() + " is undefined", + message: tree.trim.call(this.selector.toCSS()) + " is undefined", index: this.index, filename: this.filename }; } }; @@ -56,7 +56,7 @@ tree.mixin.Definition = function (name, params, rules, condition, variadic) { this.arity = params.length; this.rules = rules; this._lookups = {}; - this.required = params.reduce(function (count, p) { + this.required = tree.reduce.call(params, function (count, p) { if (!p.name || (p.name && !p.value)) { return count + 1 } else { return count } }, 0); @@ -109,7 +109,7 @@ tree.mixin.Definition.prototype = { frame.rules.unshift(new(tree.Rule)('@arguments', new(tree.Expression)(_arguments).eval(env))); rules = important ? - this.rules.map(function (r) { + tree.map.call(this.rules, function (r) { return new(tree.Rule)(r.name, r.value, '!important', r.index); }) : this.rules.slice(0); diff --git a/lib/less/tree/operation.js b/lib/less/tree/operation.js index 1ce22fb04..f2e289a43 100644 --- a/lib/less/tree/operation.js +++ b/lib/less/tree/operation.js @@ -1,7 +1,7 @@ (function (tree) { tree.Operation = function (op, operands) { - this.op = op.trim(); + this.op = tree.trim.call(op); this.operands = operands; }; tree.Operation.prototype.eval = function (env) { diff --git a/lib/less/tree/rule.js b/lib/less/tree/rule.js index 9e4e54a3a..1a3140280 100644 --- a/lib/less/tree/rule.js +++ b/lib/less/tree/rule.js @@ -3,7 +3,7 @@ tree.Rule = function (name, value, important, index, inline) { this.name = name; this.value = (value instanceof tree.Value) ? value : new(tree.Value)([value]); - this.important = important ? ' ' + important.trim() : ''; + this.important = important ? ' ' + tree.trim.call(important) : ''; this.index = index; this.inline = inline || false; diff --git a/lib/less/tree/ruleset.js b/lib/less/tree/ruleset.js index 3100cc354..1729ed4ff 100644 --- a/lib/less/tree/ruleset.js +++ b/lib/less/tree/ruleset.js @@ -8,7 +8,7 @@ tree.Ruleset = function (selectors, rules, strictImports) { }; tree.Ruleset.prototype = { eval: function (env) { - var selectors = this.selectors && this.selectors.map(function (s) { return s.eval(env) }); + var selectors = this.selectors && tree.map.call(this.selectors, function (s) { return s.eval(env) }); var ruleset = new(tree.Ruleset)(selectors, this.rules.slice(0), this.strictImports); ruleset.root = this.root; @@ -63,7 +63,7 @@ tree.Ruleset.prototype = { variables: function () { if (this._variables) { return this._variables } else { - return this._variables = this.rules.reduce(function (hash, r) { + return this._variables = tree.reduce.call(this.rules, function (hash, r) { if (r instanceof tree.Rule && r.variable === true) { hash[r.name] = r; } @@ -77,7 +77,7 @@ tree.Ruleset.prototype = { rulesets: function () { if (this._rulesets) { return this._rulesets } else { - return this._rulesets = this.rules.filter(function (r) { + return this._rulesets = tree.filter.call(this.rules, function (r) { return (r instanceof tree.Ruleset) || (r instanceof tree.mixin.Definition); }); } @@ -89,7 +89,7 @@ tree.Ruleset.prototype = { if (key in this._lookups) { return this._lookups[key] } - this.rulesets().forEach(function (rule) { + tree.forEach.call(this.rulesets(), function (rule) { if (rule !== self) { for (var j = 0; j < rule.selectors.length; j++) { if (match = selector.match(rule.selectors[j])) { @@ -122,7 +122,7 @@ tree.Ruleset.prototype = { if (! this.root) { if (context.length === 0) { - paths = this.selectors.map(function (s) { return [s] }); + paths = tree.map.call(this.selectors, function (s) { return [s] }); } else { this.joinSelectors(paths, context, this.selectors); } @@ -160,8 +160,8 @@ tree.Ruleset.prototype = { css.push(rules.join(env.compress ? '' : '\n')); } else { if (rules.length > 0) { - selector = paths.map(function (p) { - return p.map(function (s) { + selector = tree.map.call(paths, function (p) { + return tree.map.call(p, function (s) { return s.toCSS(env); }).join('').trim(); }).join(env.compress ? ',' : ',\n'); diff --git a/lib/less/tree/selector.js b/lib/less/tree/selector.js index 65abbb692..fe5a89269 100644 --- a/lib/less/tree/selector.js +++ b/lib/less/tree/selector.js @@ -23,16 +23,16 @@ tree.Selector.prototype.match = function (other) { return true; }; tree.Selector.prototype.eval = function (env) { - return new(tree.Selector)(this.elements.map(function (e) { + return new(tree.Selector)(tree.map.call(this.elements, function (e) { return e.eval(env); })); }; tree.Selector.prototype.toCSS = function (env) { if (this._css) { return this._css } - return this._css = this.elements.map(function (e) { + return this._css = tree.map.call(this.elements, function (e) { if (typeof(e) === 'string') { - return ' ' + e.trim(); + return ' ' + tree.trim.call(e); } else { return e.toCSS(env); } diff --git a/lib/less/tree/value.js b/lib/less/tree/value.js index 3c1eb29a2..81ac8be7c 100644 --- a/lib/less/tree/value.js +++ b/lib/less/tree/value.js @@ -9,13 +9,13 @@ tree.Value.prototype = { if (this.value.length === 1) { return this.value[0].eval(env); } else { - return new(tree.Value)(this.value.map(function (v) { + return new(tree.Value)(tree.map.call(this.value, function (v) { return v.eval(env); })); } }, toCSS: function (env) { - return this.value.map(function (e) { + return tree.map.call(this.value, function (e) { return e.toCSS(env); }).join(env.compress ? ',' : ', '); } From c21553271b4d0f4130851c42bb841ca21de43034 Mon Sep 17 00:00:00 2001 From: James Leigh Date: Mon, 4 Jun 2012 12:19:57 -0400 Subject: [PATCH 2/3] Fix map assignment --- lib/less/tree.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/less/tree.js b/lib/less/tree.js index 955d899a8..91f0aa61c 100644 --- a/lib/less/tree.js +++ b/lib/less/tree.js @@ -12,7 +12,7 @@ tree.forEach = Array.prototype.forEach ? Array.prototype.forEach : function(bloc } } }; -tree.map = Array.prototype.map ? Array.prototype.map : Array.prototype.map = function(fun /*, thisp*/) { +tree.map = Array.prototype.map ? Array.prototype.map : function(fun /*, thisp*/) { var len = this.length >>> 0; var res = new Array(len); var thisp = arguments[1]; From ad2c5a817e93aeae9ea89d29f804fe5832815700 Mon Sep 17 00:00:00 2001 From: James Leigh Date: Thu, 7 Jun 2012 13:46:53 -0400 Subject: [PATCH 3/3] Use conditional operator instead of logical operators in assignments for compatibility with older/buggy JavaScript engines --- lib/less/browser.js | 12 ++++++------ lib/less/index.js | 4 ++-- lib/less/parser.js | 18 +++++++++--------- lib/less/tree.js | 2 +- lib/less/tree/anonymous.js | 2 +- lib/less/tree/dimension.js | 2 +- lib/less/tree/directive.js | 2 +- lib/less/tree/import.js | 8 ++++---- lib/less/tree/mixin.js | 6 +++--- lib/less/tree/quoted.js | 2 +- lib/less/tree/rule.js | 2 +- lib/less/tree/ruleset.js | 4 ++-- 12 files changed, 32 insertions(+), 32 deletions(-) diff --git a/lib/less/browser.js b/lib/less/browser.js index cab913be0..5f49633c9 100644 --- a/lib/less/browser.js +++ b/lib/less/browser.js @@ -7,7 +7,7 @@ var isFileProtocol = (location.protocol === 'file:' || location.protocol === 'chrome-extension:' || location.protocol === 'resource:'); -less.env = less.env || (location.hostname == '127.0.0.1' || +less.env = less.env ? less.env : (location.hostname == '127.0.0.1' || location.hostname == '0.0.0.0' || location.hostname == 'localhost' || location.port.length > 0 || @@ -23,7 +23,7 @@ less.env = less.env || (location.hostname == '127.0.0.1' || less.async = false; // Interval between watch polls -less.poll = less.poll || (isFileProtocol ? 1000 : 1500); +less.poll = less.poll ? less.poll : (isFileProtocol ? 1000 : 1500); // // Watch mode @@ -123,8 +123,8 @@ function loadStyleSheets(callback, reload) { function loadStyleSheet(sheet, callback, reload, remaining) { var url = window.location.href.replace(/[#?].*$/, ''); var href = sheet.href.replace(/\?.*$/, ''); - var css = cache && cache.getItem(href); - var timestamp = cache && cache.getItem(href + ':timestamp'); + var css = cache ? cache.getItem(href) : null; + var timestamp = cache ? cache.getItem(href + ':timestamp') : null; var styles = { css: css, timestamp: timestamp }; // Stylesheets in IE don't always return the full path @@ -192,7 +192,7 @@ function createCSS(styles, sheet, lastModified) { if ((css = document.getElementById(id)) === null) { css = document.createElement('style'); css.type = 'text/css'; - css.media = sheet.media || 'screen'; + css.media = sheet.media ? sheet.media : 'screen'; css.id = id; document.getElementsByTagName('head')[0].appendChild(css); } @@ -285,7 +285,7 @@ function error(e, href) { var id = 'less-error-message:' + extractId(href); var template = '
  • {content}
  • '; var elem = document.createElement('div'), timer, content, error = []; - var filename = e.filename || href; + var filename = e.filename ? sheet.media : href; elem.id = id; elem.className = "less-error-message"; diff --git a/lib/less/index.js b/lib/less/index.js index e7e7caca8..2a768d910 100644 --- a/lib/less/index.js +++ b/lib/less/index.js @@ -8,7 +8,7 @@ var less = { importer: require('./parser').importer, tree: require('./tree'), render: function (input, options, callback) { - options = options || {}; + options = options ? options : {}; if (typeof(options) === 'function') { callback = options, options = {}; @@ -34,7 +34,7 @@ var less = { } }, writeError: function (ctx, options) { - options = options || {}; + options = options ? options : {}; var message = ""; var extract = ctx.extract; diff --git a/lib/less/parser.js b/lib/less/parser.js index 76bbd557d..a23b596a3 100644 --- a/lib/less/parser.js +++ b/lib/less/parser.js @@ -70,11 +70,11 @@ less.Parser = function Parser(env) { var finish = function () {}; var imports = this.imports = { - paths: env && env.paths || [], // Search paths, when importing + paths: env && env.paths ? env.paths : [], // Search paths, when importing queue: [], // Files which haven't been imported yet files: {}, // Holds the imported parse trees contents: {}, // Holds the imported file contents - mime: env && env.mime, // MIME type of .less files + mime: env ? env.mime : null, // MIME type of .less files error: null, // Error in parsing/evaluating an import push: function (path, callback) { var that = this; @@ -178,7 +178,7 @@ less.Parser = function Parser(env) { } function error(msg, type) { - throw { index: i, type: type || 'Syntax', message: msg }; + throw { index: i, type: type ? type : 'Syntax', message: msg }; } // Same as $(), but don't change the state of the parser, @@ -227,12 +227,12 @@ less.Parser = function Parser(env) { col = loc.column, lines = input.split('\n'); - this.type = e.type || 'Syntax'; + this.type = e.type ? e.type : 'Syntax'; this.message = e.message; - this.filename = e.filename || env.filename; + this.filename = e.filename ? e.filename : env.filename; this.index = e.index; this.line = typeof(line) === 'number' ? line + 1 : null; - this.callLine = e.call && (getLocation(e.call, input).line + 1); + this.callLine = e.call ? (getLocation(e.call, input).line + 1) : null; this.callExtract = lines[getLocation(e.call, input).line]; this.stack = e.stack; this.column = col; @@ -243,7 +243,7 @@ less.Parser = function Parser(env) { ]; } - this.env = env = env || {}; + this.env = env = env ? env : {}; // The optimization level dictates the thoroughness of the parser, // the lower the number, the less nodes it will create in the tree. @@ -251,7 +251,7 @@ less.Parser = function Parser(env) { // the individual nodes in the tree. this.optimization = ('optimization' in this.env) ? this.env.optimization : 1; - this.env.filename = this.env.filename || null; + this.env.filename = this.env.filename ? this.env.filename : null; // // The Parser @@ -353,7 +353,7 @@ less.Parser = function Parser(env) { return function (options, variables) { var frames = [], importError; - options = options || {}; + options = options ? options : {}; // // Allows setting variables with a hash, so: // diff --git a/lib/less/tree.js b/lib/less/tree.js index 91f0aa61c..d77fa8bfe 100644 --- a/lib/less/tree.js +++ b/lib/less/tree.js @@ -62,7 +62,7 @@ tree.reduce = Array.prototype.reduce ? Array.prototype.reduce : function(fun /*, }; tree.indexOf = Array.prototype.indexOf ? Array.prototype.indexOf : function (value /*, fromIndex */ ) { var length = this.length; - var i = arguments[1] || 0; + var i = arguments[1] ? arguments[1] : 0; if (!length) return -1; if (i >= length) return -1; diff --git a/lib/less/tree/anonymous.js b/lib/less/tree/anonymous.js index 460c9ec78..851b4ce4b 100644 --- a/lib/less/tree/anonymous.js +++ b/lib/less/tree/anonymous.js @@ -1,7 +1,7 @@ (function (tree) { tree.Anonymous = function (string) { - this.value = string.value || string; + this.value = string.value ? string.value : string; }; tree.Anonymous.prototype = { toCSS: function () { diff --git a/lib/less/tree/dimension.js b/lib/less/tree/dimension.js index 9a6fce3dd..e1ceef7f7 100644 --- a/lib/less/tree/dimension.js +++ b/lib/less/tree/dimension.js @@ -5,7 +5,7 @@ // tree.Dimension = function (value, unit) { this.value = parseFloat(value); - this.unit = unit || null; + this.unit = unit ? unit : null; }; tree.Dimension.prototype = { diff --git a/lib/less/tree/directive.js b/lib/less/tree/directive.js index b6e8911a3..876798e84 100644 --- a/lib/less/tree/directive.js +++ b/lib/less/tree/directive.js @@ -23,7 +23,7 @@ tree.Directive.prototype = { }, eval: function (env) { env.frames.unshift(this); - this.ruleset = this.ruleset && this.ruleset.eval(env); + this.ruleset = this.ruleset ? this.ruleset.eval(env) : null; env.frames.shift(); return this; }, diff --git a/lib/less/tree/import.js b/lib/less/tree/import.js index 7a977def2..ffaef61c7 100644 --- a/lib/less/tree/import.js +++ b/lib/less/tree/import.js @@ -17,13 +17,13 @@ tree.Import = function (path, imports, features, once, index) { this.once = once; this.index = index; this._path = path; - this.features = features && new(tree.Value)(features); + this.features = features ? new(tree.Value)(features) : null; // The '.less' extension is optional if (path instanceof tree.Quoted) { this.path = /\.(le?|c)ss(\?.*)?$/.test(path.value) ? path.value : path.value + '.less'; } else { - this.path = path.value.value || path.value; + this.path = path.value.value ? path.value.value : path.value; } this.css = /css(\?.*)?$/.test(this.path); @@ -33,7 +33,7 @@ tree.Import = function (path, imports, features, once, index) { imports.push(this.path, function (e, root, imported) { if (e) { e.index = index } if (imported && that.once) that.skip = imported; - that.root = root || new(tree.Ruleset)([], []); + that.root = root ? root : new(tree.Ruleset)([], []); }); } }; @@ -58,7 +58,7 @@ tree.Import.prototype = { } }, eval: function (env) { - var ruleset, features = this.features && this.features.eval(env); + var ruleset, features = this.features ? this.features.eval(env) : null; if (this.skip) return []; diff --git a/lib/less/tree/mixin.js b/lib/less/tree/mixin.js index 2579915a5..7867a2a59 100644 --- a/lib/less/tree/mixin.js +++ b/lib/less/tree/mixin.js @@ -14,9 +14,9 @@ tree.mixin.Call.prototype = { for (var i = 0; i < env.frames.length; i++) { if ((mixins = env.frames[i].find(this.selector)).length > 0) { - args = this.arguments && tree.map.call(this.arguments, function (a) { + args = this.arguments ? tree.map.call(this.arguments, function (a) { return { name: a.name, value: a.value.eval(env) }; - }); + }) : null; for (var m = 0; m < mixins.length; m++) { if (mixins[m].match(args, env)) { try { @@ -74,7 +74,7 @@ tree.mixin.Definition.prototype = { var frame = new(tree.Ruleset)(null, []), varargs, arg; for (var i = 0, val, name; i < this.params.length; i++) { - arg = args && args[i] + arg = args ? args[i] : null; if (arg && arg.name) { frame.rules.unshift(new(tree.Rule)(arg.name, arg.value.eval(env))); diff --git a/lib/less/tree/quoted.js b/lib/less/tree/quoted.js index 794bf4cea..fcded8114 100644 --- a/lib/less/tree/quoted.js +++ b/lib/less/tree/quoted.js @@ -2,7 +2,7 @@ tree.Quoted = function (str, content, escaped, i) { this.escaped = escaped; - this.value = content || ''; + this.value = content ? content : ''; this.quote = str.charAt(0); this.index = i; }; diff --git a/lib/less/tree/rule.js b/lib/less/tree/rule.js index 1a3140280..8671097b5 100644 --- a/lib/less/tree/rule.js +++ b/lib/less/tree/rule.js @@ -5,7 +5,7 @@ tree.Rule = function (name, value, important, index, inline) { this.value = (value instanceof tree.Value) ? value : new(tree.Value)([value]); this.important = important ? ' ' + tree.trim.call(important) : ''; this.index = index; - this.inline = inline || false; + this.inline = inline ? inline : false; if (name.charAt(0) === '@') { this.variable = true; diff --git a/lib/less/tree/ruleset.js b/lib/less/tree/ruleset.js index 1729ed4ff..18333dde9 100644 --- a/lib/less/tree/ruleset.js +++ b/lib/less/tree/ruleset.js @@ -8,7 +8,7 @@ tree.Ruleset = function (selectors, rules, strictImports) { }; tree.Ruleset.prototype = { eval: function (env) { - var selectors = this.selectors && tree.map.call(this.selectors, function (s) { return s.eval(env) }); + var selectors = this.selectors ? tree.map.call(this.selectors, function (s) { return s.eval(env) }) : null; var ruleset = new(tree.Ruleset)(selectors, this.rules.slice(0), this.strictImports); ruleset.root = this.root; @@ -83,7 +83,7 @@ tree.Ruleset.prototype = { } }, find: function (selector, self) { - self = self || this; + self = self ? self : this; var rules = [], rule, match, key = selector.toCSS();