mummybot / postcss-strip-inline-comments

Remove inline comments from postcss-scss parser
MIT License
31 stars 3 forks source link

Fails on comment and closing brace on the same line #5

Closed akost closed 7 years ago

akost commented 8 years ago

The plugin does not work if there is 'inline' comment and the closing brace on the same line.

The plugin fails on this code example:

a { color:red; //comment }

I got an error:

(node:58626) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): CssSyntaxError: <css input>:1:16: Unknown word

> 1 | a { color:red; //comment }
    |                ^

Example code:

var postcss = require('postcss');
var syntax  = require('postcss-scss');
var stripInlineComments = require('postcss-strip-inline-comments');

var badCss = 'a { color:red; //comment }';

postcss([stripInlineComments]).process(badCss, { parser: syntax }).then(function (result) {
    console.log(result.css) 
});
imseanpan commented 8 years ago

The same as me .

mummybot commented 7 years ago

Sorry for my long delay in answering this guys - I was on an epic holiday through East Africa :)

The problem with the CSS example is that you have effectively commented out the closing curly bracket. To explain further the following javascript won't run because of the same issue:

function() { alert("hello world"); // Error due to function closing brace commented out }

By commenting out the closing brace you are making a syntax error in JS. It is not possible (or desirable) to grok the comments for possible code.