Hi, everyone,

During some recent discussion in Chinese JS community, I've noticed
several case which JS behave out of user's expect if omitting the
semicolon.

See the following code:
--------------------------------------------
var a = this.a  //!!!! here no semicolon will be auto inserted
[1,2,3].forEach(function(){
    // do something
})
--------------------------------------------
(function(){
     //do something
})()  //!!!! here no semicolon will be auto inserted
(function(){
     //do something else
})()
--------------------------------------------

I was thinking that if we could change some grammar rules to make it
behave as most user's expect. Just adding several [no LineTerminator
here] will do so:
--------------------------------------------
CallExpression :
    MemberExpression [no LineTerminator here] Arguments
    CallExpression [no LineTerminator here] Arguments
    CallExpression [no LineTerminator here] [ Expression ]
    CallExpression . IdentifierName
--------------------------------------------

Though some of you might consider omitting the semicolon as a bad
style, but its used by several group and company (including zepto.js
and npmjs).  I think this change will benefit them a lot with very
small side effect.


/Shaofei
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to