W3C home > Mailing lists > Public > www-style@w3.org > August 2012

Re: Comment syntax

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Mon, 27 Aug 2012 16:17:20 -0700
Message-ID: <CAAWBYDBBZ37esTyzvG8jP7xkqWsORc=9qsp8wE8eX1bE=MJK=w@mail.gmail.com>
To: Greg Houston <gregory.houston@gmail.com>
Cc: "Kang-Hao (Kenny) Lu" <kanghaol@oupeng.com>, "Zachary “Gamer_Z.” Yaro" <zmyaro@gmail.com>, Liam R E Quin <liam@w3.org>, WWW Style <www-style@w3.org>, "Jens O. Meiert" <jens@meiert.com>
On Mon, Aug 27, 2012 at 4:07 PM, Greg Houston <gregory.houston@gmail.com> wrote:
> On Mon, Aug 27, 2012 at 5:27 PM, Tab Atkins Jr. <jackalmage@gmail.com> wrote:
>> This is the big thing I'm afraid of, and would like a compat study
>> done for before I could support this.
>>
>> Right now, you can naively minify just by replacing all runs of
>> whitespace with a single space.  (The only exception is if you use a \
>> at the end of a line to create a multi-line string, but this is rare
>> enough that I wouldn't be surprised if there were plenty of naive
>> minifiers that didn't take this into account.)  If you use // comments
>> on your source document, the minified document today will act
>> identically (the next property will be ignored as invalid).  If we
>> switched behavior, it would instead remove the entire rest of the
>> stylesheet.
>>
>> This is, unfortunately, a problem with *existing* stylesheets, so we
>> can't just rely on the "well, don't do that" defense.  I'd like a
>> reasonable assurance that adding this wouldn't cause a significant
>> number of sites to suddenly break due to this. ^_^
>>
>> ~TJ
>>
>
> In all these years of working with CSS I'm pretty sure I've never seen
> // in a stylesheet. I think such a study would find that the chances
> of // being used in a stylesheet AND the stylesheet being minified
> will be incredibly few if not none.

I've used // comments in stylesheets to comment out properties before.
 It actually shows up quite a bit, which is why a lot of the CSS
preprocessors support it natively (translating it into a /* */ comment
in the generated source).

> Regarding causing trouble for developers, I think most developers
> check their work; particularly those that minify their code. If it
> looks good unminified and then suddenly does not once minified, it is
> a short troubleshooting path to find that once minified a bunch of
> rules were cut off right after a single line comment. Okay, I can't
> use single line comments with this minifier until it is updated.

The problem I'm scared of is stylesheets that *work* today, but have
been minified in such a way that they'll break if we make // a "real"
comment.

For example, the following stylesheet works fine today:

foo {
  background: white;
  //background: linear-gradient(white, silver);
  color: red;
}

The second declaration is "commented out", because the CSS parser
barfs upon seeing the / and recovers by throwing away everything until
the next ";" character.

When minified, it works exactly the same way:

foo { background: white; //background: linear-gradient(white, silver);
color: red; }

However, if we change // from being invalid syntax to being a
line-terminated comment, this minified stylesheet suddenly changes
meaning, and the 'color' declaration is thrown out (along with the
entire rest of the stylesheet, if anything follows it).

This is why I'd like to see compat data for this.  There is *nothing
wrong* with naively minifying it like this today, so there may be
significant amounts of stylesheets which would break if we changed the
meaning of //.

We could avoid this hazard by instead making // just a "blessed" way
to comment out properties, but it already does that job just fine, so
there doesn't seem to be any value in actually recognizing it in the
parser.

~TJ
Received on Monday, 27 August 2012 23:18:08 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:20:58 GMT