[TASK] Allow whitepace parsing to be stopped at EOL#1505
Conversation
The whitespace parsing includes extraction of comments to be associated with the content. There are cases where the comment is after the content, but should be associated with the preceding rather than the following. This will help achieve that.
|
I don't quite understand this yet: Why should consuming whitespace stop at a linefeed, i.e., what makes the linefeed whitespace character special? |
It's so we would be able to correctly attribute comments to the relevant declarations as 'before' and 'after' (or 'leading' and 'trailing'), e.g. /* This is a comment about the font size. */
font-size: 14px;
color: green; /* This is a trailing comment about the colour. It has nothing to do with the width. */
/* This is a comment about the width. */
width: 50%;So after parsing a property declaration, we can consume whitespace and any trailing comments up to the next line feed. Then we parse the next property declaration, consuming possibly more whitespace and any leading comments. |
I'm not entirely happy with this approach. We should (or could) be able to have line number information for comments. Comments should not "belong" to CSS elements, though - they could be within a declaration, after a declaration, before a declaration, or between declarations. Particularly, I'd like to avoid introducing of end-of-line comments belong to the declaration before it. This will avoid a can of complexity worms for us, and I currently don't see a usecase for that. And in general, I'd strongly prefer we drop the concept of comments belonging to a declaration (maybe, just maybe with the exception of a comment that is within a declaration - but even that can get hairy when a declaration is represented as more than one object). Would you be okay with dropping this concept, @JakeQZ ? |
That's fine by me. It was just an idea I had for solving issues like #663 and #1445, on the basis that currently each declaration owns comments that come before it, but trailing comments become associated with the next declaration, or dropped if there are no more declarations. So we could instead have
The current design has all the various entities implement the
I suspect something like color: /* My favourite colour */ purple;currently gets rendered as /* My favourite colour */
color: purple;because the placement of the comment is not recorded. |
The whitespace parsing includes extraction of comments to be associated with the content.
There are cases where the comment is after the content, but should be associated with the preceding rather than the following. This will help achieve that.