Brendan Eich (2016-01-02T22:28:04.000Z)
Thanks, Claude.

It may be tempting to assume the standard specified something dumb, or due
to "legacy" mysteries. Not so. HTML5 fully specifies <script>, which I
created in 1995 at Netscape. I had no time for the src= attribute, and even
if I had (I implemented that in 1996 for Netscape 3), but basis case was
code directly in the HTML page, as I noted on twitter:
https://twitter.com/BrendanEich/status/683344089308200960.

kdex, think about how < is interpreted within an inline <script> -- it is
not escaped via < nor can or should it be. Likewise, HTML comments don't
work as such in script content. The script element's content model, which I
borrowed from SGML in a hurry in late spring '95, is called CDATA. For ease
of use, I chose not to require the <![CDATA[ and ]]> marked section
delimiters from SGML (this was controversial back then! SGML and later XML
people actually were angry with me over this design decision).

Netscape's HTML parser of the time (Netscape 1 and 1.1, predating JS in
Netscape 2; same as in Mosaic) already supported <!--  and --> as HTML
comment delimiters, without fully parsing SGML comments in all their glory
(see http://www.flightlab.com/~joe/sgml/comments.html).

Thus, to help early JS adopters hide inline script content from old
(non-JS-supporting) browsers, my "two-way comment-hiding hack" was born in
Netscape 2. I did require something like this:

//-->

as the last line of the script content, not wanting to make --> yet another
comment-till-end-of-line special case. However, IE implemented support for
just --> (no // in front to hide the otherwise-invalid JS syntax) at some
point while cloning JS prior to ECMA-262 Edition 1. The Ecma TC39 group
only got around to specifying all of this in ES6 Annex B.

Often enough, things are the way they are for good reasons. See
"Chesterton's Fence".

/be

On Sat, Jan 2, 2016 at 1:41 PM Claude Pache <claude.pache at gmail.com> wrote:

> Historically, the HTML comments were used as a hack to hide the code from
> browsers that didn't understood the `<script>` element. It is not meant to
> commenting JavaScript code. For example,
>
> ```js
> <script>
> <!--
> foo = bar;
> baz();
> -->
> </script>
> ```
>
> browsers that didn't support `<script>` treat its content as an HTML
> comment, and browsers that do support it ignore the `<!--` and `-->` lines,
> but certainly not the lines inbetween.
>
> —Claude
>
>
>
>
> > Le 2 janv. 2016 à 21:56, kdex <kdex at kdex.de> a écrit :
> >
> > ES2015's annex section B.1.3 (*HTML-like Comments*) currently defines
> `Comment`
> > in a way that makes
> >
> > ```js
> > <!-- This whole line
> > ```
> >
> > a comment, and likewise for
> >
> > ```js
> > undefined --> everything after the first occurrence of "-->" in this
> line.
> > ```
> >
> > However, the tokens `<!--` and `-->` are inherently used as *block*
> comments
> > in HTML, whereas EcmaScript doesn't allow them to span over multiple
> lines. As
> > a consequence,
> >
> > ```js
> > <!-- This looks is a comment in HTML, so
> > shouldn't it behave like a comment in JS, too? -->
> > ```
> >
> > would result in a syntax error.
> >
> > Is this a deliberate choice? Are there reasons for or against matching
> HTML's
> > behavior in ES2016?
> >
> > Personally, I don't use these tokens anyway, but this seems like an
> obvious
> > inconsistency to me.
> > _______________________________________________
> > es-discuss mailing list
> > es-discuss at mozilla.org
> > https://mail.mozilla.org/listinfo/es-discuss
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160102/82600b2e/attachment-0001.html>
mathias at qiwi.be (2016-01-03T11:06:39.694Z)
Thanks, Claude.

It may be tempting to assume the standard specified something dumb, or due
to "legacy" mysteries. Not so. HTML5 fully specifies <script>, which I created
in 1995 at Netscape. I had no time for the src= attribute, and even if I
had (I implemented that in 1996 for Netscape 3), but basis case was
code directly in the HTML page, as I noted on Twitter:
https://twitter.com/BrendanEich/status/683344089308200960.

kdex, think about how `<` is interpreted within an inline `<script>` -- it is
not escaped via `<` nor can or should it be. Likewise, HTML comments don't
work as such in script content. The script element's content model, which I
borrowed from SGML in a hurry in late spring '95, is called CDATA. For ease
of use, I chose not to require the `<![CDATA[` and `]]>` marked section
delimiters from SGML (this was controversial back then! SGML and later XML
people actually were angry with me over this design decision).

Netscape's HTML parser of the time (Netscape 1 and 1.1, predating JS in
Netscape 2; same as in Mosaic) already supported `<!--` and `-->` as HTML
comment delimiters, without fully parsing SGML comments in all their glory
(see http://www.flightlab.com/~joe/sgml/comments.html).

Thus, to help early JS adopters hide inline script content from old
(non-JS-supporting) browsers, my "two-way comment-hiding hack" was born in
Netscape 2. I did require something like this:

```
//-->
```

as the last line of the script content, not wanting to make `-->` yet another
comment-till-end-of-line special case. However, IE implemented support for
just `-->` (no `//` in front to hide the otherwise-invalid JS syntax) at some
point while cloning JS prior to ECMA-262 Edition 1. The Ecma TC39 group
only got around to specifying all of this in ES6 Annex B.

Often enough, things are the way they are for good reasons. See
"Chesterton's Fence".