Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing Error "Unrecognised input" for color operations with color names #2124 #2775

Merged
merged 4 commits into from
Jan 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions lib/less/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,26 @@ var Parser = function Parser(context, imports, fileInfo) {
}
},

namedColor: function () {
parserInput.save();
var autoCommentAbsorb = parserInput.autoCommentAbsorb;
parserInput.autoCommentAbsorb = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Investigating #2802. Indeed that's mysterious. W/o autoCommentAbsorb = false;
this property: yes /* comment */; causes infinite parser loop (why?),
but otherwise property: red /* comment */; is obviously expected to fail.
No ideas how to fix this so far.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I found another workaround on top of that. Now just polishing a performance for the fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added parserInput.autoCommentAbsorb = false because the comments were either doubled or swallowed without it (I do not remember which one).

var k = parserInput.$re(/^[_A-Za-z-][_A-Za-z0-9-]*/);
parserInput.autoCommentAbsorb = autoCommentAbsorb;
if (!k) {
parserInput.forget();
return ;
}
var result = tree.Color.fromKeyword(k);
if (!result) {
parserInput.restore();
} else {
parserInput.forget();
return result;
}

},

//
// A function call
//
Expand Down Expand Up @@ -491,6 +511,8 @@ var Parser = function Parser(context, imports, fileInfo) {
}
return new(tree.Color)(rgb[1], undefined, '#' + colorCandidateString);
}

return this.namedColor();
},

//
Expand Down Expand Up @@ -1692,8 +1714,8 @@ var Parser = function Parser(context, imports, fileInfo) {
}

var o = this.sub() || entities.dimension() ||
entities.color() || entities.variable() ||
entities.call();
entities.variable() ||
entities.call() || entities.color();

if (negate) {
o.parensInOp = true;
Expand Down
12 changes: 12 additions & 0 deletions test/css/no-strict-math/no-sm-operations.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.named-colors-in-expressions {
color-0: 0 -red;
color-1: #000101;
color-2: #ff0000;
color-3: #ff0000;
}
.named-colors-in-expressions-bar-red {
x: y;
}
.named-colors-in-expressions-barred {
a: a;
}
1 change: 1 addition & 0 deletions test/css/operations.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#operations {
color: #111111;
color-2: #f8f800;
height: 9px;
width: 3em;
substraction: 0;
Expand Down
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ lessTester.runTestSet({plugin: 'test/plugins/postprocess/'}, "postProcessorPlugi
lessTester.runTestSet({plugin: 'test/plugins/preprocess/'}, "preProcessorPlugin/");
lessTester.runTestSet({plugin: 'test/plugins/visitor/'}, "visitorPlugin/");
lessTester.runTestSet({plugin: 'test/plugins/filemanager/'}, "filemanagerPlugin/");
lessTester.runTestSet({}, "no-strict-math/");
lessTester.testSyncronous({syncImport: true}, "import");
lessTester.testSyncronous({syncImport: true}, "css");
lessTester.testNoOptions();
Expand Down
7 changes: 6 additions & 1 deletion test/less-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,12 @@ module.exports = function() {
fail("ERROR: " + (err && err.message));
if (isVerbose) {
process.stdout.write("\n");
process.stdout.write(err.stack + "\n");
if (err.stack) {
process.stdout.write(err.stack + "\n");
} else {
//this sometimes happen - show the whole error object
console.log(err);
}
}
release();
return;
Expand Down
10 changes: 10 additions & 0 deletions test/less/no-strict-math/no-sm-operations.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.named-colors-in-expressions {
color-0: 0 -red;
color-1: 1 - red;
color-2: red * 2;
color-3: 2 * red;
@3: -red;
&-bar@{3} {x: y}
@color: red;
&-bar@{color} {a: a}
}
1 change: 1 addition & 0 deletions test/less/operations.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#operations {
color: (#110000 + #000011 + #001100); // #111111
color-2: (yellow - #070707);
height: (10px / 2px + 6px - 1px * 2); // 9px
width: (2 * 4 - 5em); // 3em
.spacing {
Expand Down