diff --git a/lib/less/parser.js b/lib/less/parser.js index a87a0e2e..8d39aab6 100644 --- a/lib/less/parser.js +++ b/lib/less/parser.js @@ -575,9 +575,9 @@ less.Parser = function Parser(env) { if (input.charAt(i) !== '/') return; if (input.charAt(i + 1) === '/') { - return new(tree.Comment)($(/^\/\/.*/), true); + return new(tree.Comment)($(/^\/\/.*/), true, i, env.currentFileInfo); } else if (comment = $(/^\/\*(?:[^*]|\*+[^\/*])*\*+\/\n?/)) { - return new(tree.Comment)(comment); + return new(tree.Comment)(comment, false, i, env.currentFileInfo); } }, diff --git a/lib/less/tree/comment.js b/lib/less/tree/comment.js index 2123b4b9..820b7efa 100644 --- a/lib/less/tree/comment.js +++ b/lib/less/tree/comment.js @@ -1,15 +1,16 @@ (function (tree) { -tree.Comment = function (value, silent) { +tree.Comment = function (value, silent, index, currentFileInfo) { this.value = value; this.silent = !!silent; + this.currentFileInfo = currentFileInfo; }; tree.Comment.prototype = { type: "Comment", toCSS: function (env) { - return env.compress ? '' : this.value; + return (env.compress || (this.currentFileInfo && this.currentFileInfo.silent)) ? '' : this.value; }, - eval: function () { return this } + eval: function () { return this; } }; })(require('../tree')); diff --git a/test/css/import-silent.css b/test/css/import-silent.css index 53040b1e..29928611 100644 --- a/test/css/import-silent.css +++ b/test/css/import-silent.css @@ -1,13 +1,9 @@ @media only screen and (max-width: 200px) { width: 480px; } -@media (max-width: 1200px) { - /* a comment */ -} /* - The media statements - 1 is invalid (no selector) and 1 is just a comment - We should band invalid media queries solving the 1st case and not treat comments as rules, - solving the 2nd issue. + The media statement above is invalid (no selector) + We should ban invalid media queries with properties and no selector? */ .visible { color: red; @@ -41,6 +37,10 @@ .b .c { color: green; } +.y { + pulled-in: yes; +} +/* comment pulled in */ .visible { extend: test; } diff --git a/test/less/import-silent.less b/test/less/import-silent.less index 78c37819..f401e07a 100644 --- a/test/less/import-silent.less +++ b/test/less/import-silent.less @@ -2,9 +2,8 @@ @import (silent) url("css-3.less"); @import (silent) url("media.less"); /* - The media statements - 1 is invalid (no selector) and 1 is just a comment - We should band invalid media queries solving the 1st case and not treat comments as rules, - solving the 2nd issue. + The media statement above is invalid (no selector) + We should ban invalid media queries with properties and no selector? */ @import (silent) url("import/import-silent.less"); @@ -12,6 +11,8 @@ .z(); } +.zz(); + .visible:extend(.z all) { extend: test; } \ No newline at end of file diff --git a/test/less/import/import-silent.less b/test/less/import/import-silent.less index 266523b5..9eac45fc 100644 --- a/test/less/import/import-silent.less +++ b/test/less/import/import-silent.less @@ -31,4 +31,13 @@ .hidden { hidden: true; } +} + +/* comment is not output */ + +.zz { + .y { + pulled-in: yes; + } + /* comment pulled in */ } \ No newline at end of file