diff --git a/lib/less/index.js b/lib/less/index.js index c83153c5..f764f66e 100644 --- a/lib/less/index.js +++ b/lib/less/index.js @@ -21,14 +21,14 @@ less.render = function (input, options, callback) { } catch (err) { callback(err); return; } callback(null, css); - }); + }, options); } else { return new PromiseConstructor(function (resolve, reject) { parser.parse(input, function (e, root) { if (e) { return reject(e); } try { resolve(root.toCSS(options)); } catch (err) { reject( err); } - }); + }, options); }); } }; diff --git a/lib/less/parser/parser.js b/lib/less/parser/parser.js index 8691ec5e..dfc6acee 100644 --- a/lib/less/parser/parser.js +++ b/lib/less/parser/parser.js @@ -1173,6 +1173,7 @@ var Parser = function Parser(env) { value = this.detachedRuleset(); } + parserInput.commentStore.length = 0; if (!value) { // a name returned by this.ruleProperty() is always an array of the form: // [string-1, ..., string-n, ""] or [string-1, ..., string-n, "+"] @@ -1433,6 +1434,8 @@ var Parser = function Parser(env) { break; } + parserInput.commentStore.length = 0; + if (hasIdentifier) { value = this.entity(); if (!value) { diff --git a/lib/less/tree/rule.js b/lib/less/tree/rule.js index ec09dcf5..521a2f08 100644 --- a/lib/less/tree/rule.js +++ b/lib/less/tree/rule.js @@ -2,7 +2,7 @@ var Node = require("./node.js"), Value = require("./value.js"), Keyword = require("./keyword.js"); -var Rule = function (name, value, important, merge, index, currentFileInfo, inline) { +var Rule = function (name, value, important, merge, index, currentFileInfo, inline, variable) { this.name = name; this.value = (value instanceof Node) ? value : new(Value)([value]); //value instanceof tree.Value || value instanceof tree.Ruleset ?? this.important = important ? ' ' + important.trim() : ''; @@ -10,7 +10,8 @@ var Rule = function (name, value, important, merge, index, currentFileInfo, inli this.index = index; this.currentFileInfo = currentFileInfo; this.inline = inline || false; - this.variable = name.charAt && (name.charAt(0) === '@'); + this.variable = (variable !== undefined) ? variable + : (name.charAt && (name.charAt(0) === '@')); }; function evalName(env, name) { @@ -37,13 +38,14 @@ Rule.prototype.genCSS = function (env, output) { output.add(this.important + ((this.inline || (env.lastRule && env.compress)) ? "" : ";"), this.currentFileInfo, this.index); }; Rule.prototype.eval = function (env) { - var strictMathBypass = false, name = this.name, evaldValue; + var strictMathBypass = false, name = this.name, evaldValue, variable = this.variable; if (typeof name !== "string") { // expand 'primitive' name directly to get // things faster (~10% for benchmark.less): name = (name.length === 1) && (name[0] instanceof Keyword) ? name[0].value : evalName(env, name); + variable = false; // never treat expanded interpolation as new variable name } if (name === "font" && !env.strictMath) { strictMathBypass = true; @@ -61,7 +63,8 @@ Rule.prototype.eval = function (env) { evaldValue, this.important, this.merge, - this.index, this.currentFileInfo, this.inline); + this.index, this.currentFileInfo, this.inline, + variable); } catch(e) { if (typeof e.index !== 'number') { diff --git a/test/css/comments.css b/test/css/comments.css index a18ab808..31e23f7f 100644 --- a/test/css/comments.css +++ b/test/css/comments.css @@ -58,6 +58,12 @@ .sr-only-focusable { clip: auto; } +@-webkit-keyframes hover { + /* and Chrome */ + 0% { + color: red; + } +} #last { color: blue; } diff --git a/test/css/property-name-interp.css b/test/css/property-name-interp.css index 2082b819..315815e3 100644 --- a/test/css/property-name-interp.css +++ b/test/css/property-name-interp.css @@ -1,5 +1,6 @@ pi-test { border: 0; + @not-variable: @not-variable; ufo-width: 50%; *-z-border: 1px dashed blue; -www-border-top: 2px; diff --git a/test/less/comments.less b/test/less/comments.less index 2ecf0da6..3cb6d162 100644 --- a/test/less/comments.less +++ b/test/less/comments.less @@ -62,7 +62,7 @@ */ .selector /* .with */, .lots, /* of */ .comments { - color: grey, /* blue */ orange; + color/* survive */ /* me too */: grey, /* blue */ orange; -webkit-border-radius: 2px /* webkit only */; -moz-border-radius: (2px * 4) /* moz only with operation */; } @@ -84,6 +84,12 @@ clip: auto; } +@-webkit-keyframes /* Safari */ hover /* and Chrome */ { + 0% { + color: red; + } +} + #last { color: blue } // diff --git a/test/less/property-name-interp.less b/test/less/property-name-interp.less index a4e5b5c7..ad1dd419 100644 --- a/test/less/property-name-interp.less +++ b/test/less/property-name-interp.less @@ -7,7 +7,10 @@ pi-test { @d-d4: radius; @-: -; + @var: ~'@not-variable'; + @{a}: 0; + @{var}: @var; @{prefix}width: 50%; *-z-@{a} :1px dashed blue; -www-@{a}-@{bb}: 2px; diff --git a/test/modify-vars.js b/test/modify-vars.js new file mode 100644 index 00000000..c4c6c5b4 --- /dev/null +++ b/test/modify-vars.js @@ -0,0 +1,17 @@ +var less = require('../lib/less'), + fs = require('fs') + +var input = fs.readFileSync("./test/less/modifyVars/extended.less", 'utf8') +var expectedCss = fs.readFileSync('./test/css/modifyVars/extended.css', 'utf8') +var options = { + modifyVars: JSON.parse(fs.readFileSync("./test/less/modifyVars/extended.json", 'utf8')) +} + +less.render(input, options, function (err, css) { + if (err) console.log(err); + if (css === expectedCss) { + console.log("PASS") + } else { + console.log("FAIL") + } +}) \ No newline at end of file