From ef1566c8980e7d09c2657f2ce1bf394f58e5f0e1 Mon Sep 17 00:00:00 2001 From: Rasmus Back Date: Mon, 10 Mar 2014 17:04:05 +0200 Subject: [PATCH 1/4] Pass options object to parser.parse in less.render. --- lib/less/index.js | 4 ++-- test/modify-vars.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 test/modify-vars.js diff --git a/lib/less/index.js b/lib/less/index.js index 348a5d8f..3be8672d 100644 --- a/lib/less/index.js +++ b/lib/less/index.js @@ -27,7 +27,7 @@ var less = { } catch (err) { callback(err); return; } callback(null, css); - }); + }, options); } else { ee = new (require('events').EventEmitter)(); @@ -36,7 +36,7 @@ var less = { if (e) { return ee.emit('error', e); } try { ee.emit('success', root.toCSS(options)); } catch (err) { ee.emit('error', err); } - }); + }, options); }); return ee; } 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 From d086d64e12f3999c23e9c7c3a0f414688127c7de Mon Sep 17 00:00:00 2001 From: jurcovicovam Date: Wed, 27 Aug 2014 17:50:33 +0200 Subject: [PATCH 2/4] Eat up comments instead of calling them parse error: * in @keyframe declaration #2059, * after rule name before semicolon #826. The comments are eaten instead of being printed into output, but it is better then crashing on them. --- lib/less/parser.js | 16 ++++++++++++++++ test/css/comments.css | 5 +++++ test/less/comments.less | 8 +++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/less/parser.js b/lib/less/parser.js index 6bfa5f29..7e0e55d2 100644 --- a/lib/less/parser.js +++ b/lib/less/parser.js @@ -1578,6 +1578,7 @@ less.Parser = function Parser(env) { value = this.detachedRuleset(); } + this.comments(); if (!value) { // prefer to try to parse first if its a variable or we are compressing // but always fallback on the other one @@ -1822,6 +1823,8 @@ less.Parser = function Parser(env) { break; } + this.comments(); + if (hasIdentifier) { value = this.entity(); if (!value) { @@ -1839,6 +1842,8 @@ less.Parser = function Parser(env) { } } + this.comments(); + if (hasBlock) { rules = this.blockRuleset(); } @@ -2053,9 +2058,20 @@ less.Parser = function Parser(env) { return name.push(a[1]); } } + function cutOutBlockComments() { + //match block comments + var a = /^\s*\/\*(?:[^*]|\*+[^\/*])*\*+\//.exec(c); + if (a) { + length += a[0].length; + c = c.slice(a[0].length); + return true; + } + return false; + } match(/^(\*?)/); while (match(/^((?:[\w-]+)|(?:@\{[\w-]+\}))/)); // ! + while (cutOutBlockComments()); if ((name.length > 1) && match(/^\s*((?:\+_|\+)?)\s*:/)) { // at last, we have the complete match now. move forward, // convert name particles to tree objects and return: diff --git a/test/css/comments.css b/test/css/comments.css index 58b78ea1..d3c57b4d 100644 --- a/test/css/comments.css +++ b/test/css/comments.css @@ -58,6 +58,11 @@ .sr-only-focusable { clip: auto; } +@-webkit-keyframes hover { + 0% { + color: red; + } +} #last { color: #0000ff; } diff --git a/test/less/comments.less b/test/less/comments.less index 3e5578b6..468877cb 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 } // From 9c7854708bafa2bddc36f37bf49d7a256ecf7d57 Mon Sep 17 00:00:00 2001 From: jurcovicovam Date: Wed, 27 Aug 2014 22:36:23 +0200 Subject: [PATCH 3/4] tt --- test/less/comments.less | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/less/comments.less b/test/less/comments.less index 468877cb..bfdce248 100644 --- a/test/less/comments.less +++ b/test/less/comments.less @@ -62,7 +62,7 @@ */ .selector /* .with */, .lots, /* of */ .comments { - color/* survive *//* me too */: 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 */; } From 36383dc89b2eecd06349fefc005dd33cb8b1e629 Mon Sep 17 00:00:00 2001 From: seven-phases-max Date: Tue, 2 Sep 2014 00:02:49 +0400 Subject: [PATCH 4/4] Fix property interpolation for `@*` values --- lib/less/tree/rule.js | 11 +++++++---- test/css/property-name-interp.css | 1 + test/less/property-name-interp.less | 5 ++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/less/tree/rule.js b/lib/less/tree/rule.js index 4e1ccde6..8e62c407 100644 --- a/lib/less/tree/rule.js +++ b/lib/less/tree/rule.js @@ -1,6 +1,6 @@ (function (tree) { -tree.Rule = function (name, value, important, merge, index, currentFileInfo, inline) { +tree.Rule = function (name, value, important, merge, index, currentFileInfo, inline, variable) { this.name = name; this.value = (value instanceof tree.Value || value instanceof tree.Ruleset) ? value : new(tree.Value)([value]); this.important = important ? ' ' + important.trim() : ''; @@ -8,7 +8,8 @@ tree.Rule = function (name, value, important, merge, index, currentFileInfo, inl this.index = index; this.currentFileInfo = currentFileInfo; this.inline = inline || false; - this.variable = name.charAt && (name.charAt(0) === '@'); + this.variable = (variable !== undefined) ? variable + : (name.charAt && (name.charAt(0) === '@')); }; tree.Rule.prototype = { @@ -30,13 +31,14 @@ tree.Rule.prototype = { }, toCSS: tree.toCSS, eval: function (env) { - var strictMathBypass = false, name = this.name, evaldValue; + var strictMathBypass = false, name = this.name, variable = this.variable, evaldValue; if (typeof name !== "string") { // expand 'primitive' name directly to get // things faster (~10% for benchmark.less): name = (name.length === 1) && (name[0] instanceof tree.Keyword) ? name[0].value : evalName(env, name); + variable = false; // never treat expanded interpolation as new variable name } if (name === "font" && !env.strictMath) { strictMathBypass = true; @@ -54,7 +56,8 @@ tree.Rule.prototype = { 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/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/property-name-interp.less b/test/less/property-name-interp.less index 9886e65f..46e33791 100644 --- a/test/less/property-name-interp.less +++ b/test/less/property-name-interp.less @@ -6,8 +6,11 @@ pi-test { @c_c: left; @d-d4: radius; @-: -; - + + @var: ~'@not-variable'; + @{a}: 0; + @{var}: @var; @{prefix}width: 50%; *-z-@{a} :1px dashed blue; -www-@{a}-@{bb}: 2px;