consider adding more "[no LineTerminator here]" to avoid problem caused by omit the semicolon

Jussi Kalliokoski jussi.kalliokoski at
Fri Jun 22 15:23:22 PDT 2012

I recently made a blog post concerning this issue [1], and my suggestion is
to prefix literals (function, array and friends) with `void`, as it's
almost (if not) designed for this case. So, (function(){}()); becomes void
function(){}(), [1,2,3].forEach(...) becomes void [1,2,3].forEach(...).
This is more resistant to typos as well, even in semicolon-preferring code.

Since Claus shared his work on the subject, I thought I'd also share a
little tool I made [2], called asifier. It's a sort of an education tool
that could be employed by editors, IDEs and such to show where semicolons
will be inserted. It can also replace a semicolonless file with inserted
semicolons so that missing semicolons isn't a problem for projects that
otherwise follow explicit semicolon rules.



On Fri, Jun 22, 2012 at 12:08 PM, 程劭非 <csf178 at> wrote:

> 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 at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list