Newlines in blockcomments

# liorean (18 years ago)

Hello!

According to ES3, a blockcomment which contains at least one newline parses like a LineTerminator, and isn't just thrown away. That means /**/ and /\n/ will behave different with to all the constructs that have [no LineTerminator here] limitations.

I doubt this is expected behaviour for developers - developers don't expect the contents of comments to change the meaning of the code surrounding it. Further, neither SpiderMonkey, JavaScriptCore nor JScript seem to obey this part of the ES3 spec. Opera's engines are to my knowledge the only browser hosted ones that do.

Wouldn't it be better to simply treat all blockcomments alike?

(Opera bug 280849, Mozilla bug 397104)

(function(){
    return/*
    */{};
}());

This code returns undefined in linear_b and in futhark, per ES3. This code returns the object in SpiderMonkey, JScript and JavaScriptCore, which I think is the behaviour that the vast majority of developers would expect.

I haven't done any extensive studies of this in the other places where [no LineTerminator here] can be found in the syntactic grammar. However, I note that the behaviour is not consistent between PostFixExpression and ReturnStatement in a few engines.

var
    a=0;
a ++;
a /**/ ++;
a/*
*/ ++;

SpiderMonkey and Futhark: SyntaxError JScript, JavaScriptCore: 2