Kozea/tinycss2

Correctly serialize the <an+b> type

gherkz opened this issue · 3 comments

I'm not 100% sure what the extra empty comments are for in the serializer (something about BAD_PAIRS it seems, whatever they are):

write('/**/')

These seem to get added in the following sample:

tinycss2.serialize(tinycss2.parse_stylesheet('div:nth-child(2n+1){}'))

Which results in

div:nth-child(2n/**/+1){}

This is clearly not the desired output. It would be nice if this feature was disabled by default. It could probably even be removed altogether - I can't imagine anyone is relying on these empty comments for anything.

liZe commented

Hi!

This extra empty comment is actually required by the specification, when we find two tokens that shouldn’t be next to each other (that’s what bad pairs are). So, we won’t remove these extra comments added by the serializer 😉.

But.

I don’t know why 2n+1 is a bad pair. Maybe the "problem" is here, I have to check that more deeply.

liZe commented

I don’t know why 2n+1 is a bad pair. Maybe the "problem" is here, I have to check that more deeply.

That’s because the an+b syntax used to be described with a dedicated tokenizer. But an <an+b> type is now available, tinycss2 should use its dedicated serialization.