Postcss: "Unknown word" error when commenting with "//"

Created on 2 Jan 2018  Â·  7Comments  Â·  Source: postcss/postcss

You can reproduce the issue using autoprefixer's live demo:
https://autoprefixer.github.io/

After the closing "}", (with or without newline) add a comment, using "//".

The same error occurs when a comment is entered after the last css rule inside the brackets.

Most helpful comment

Wonder if there's a postcss plugin to allow for such comments.

As @ai said, you'll need to use a non-standard syntax parser (like postcss-scss) if you want to use a construct that isn't part of the CSS language.

All 7 comments

@ZeeCoder can you show exactly code input?

Yeah, these all cause the same error to appear:

// some comment without actual css
.a-class {
color: inherit;
}
// this will cause an error too
.ert {} // won't work

On 2 Jan 2018 17:53, "Andrey Sitnik" notifications@github.com wrote:

@ZeeCoder https://github.com/zeecoder can you show exactly code input?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/postcss/postcss/issues/1102#issuecomment-354830188,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ADglEhzM5vE6slEmhvF5ELYHKDf7MRufks5tGm02gaJpZM4RQyWv
.

@ZeeCoder // is not a comment in CSS language. CSS allows only /**/ comments ;).

Use postcss-scss if you want to use // comments.

Maybe we should use better error for this cases, but I am not sure.

I was so sure postcss allowed for such comments! it works for the most part too, only on these edge cases it fails.

it works for the most part too,

You might be thinking of next construct comments.

Incidentally, if you want to disallow this quirky feature of the CSS language, you can do so with the no-invalid-double-slash-comment stylelint rule.

I think I just tried using it and since it worked fine, assumed it was part of postcss.
I probably littered my postcss files with such comments all over the place without realising it could fail to compile.

Wonder if there's a postcss plugin to allow for such comments. 🤔

Wonder if there's a postcss plugin to allow for such comments.

As @ai said, you'll need to use a non-standard syntax parser (like postcss-scss) if you want to use a construct that isn't part of the CSS language.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ai picture ai  Â·  5Comments

jbg picture jbg  Â·  14Comments

StephenEsser picture StephenEsser  Â·  9Comments

azat-io picture azat-io  Â·  3Comments

ben-eb picture ben-eb  Â·  11Comments