consider adding more "[no LineTerminator here]" to avoidproblemcaused by omit the semicolon

Claus Reinke claus.reinke at talk21.com
Fri Jun 22 08:14:59 PDT 2012


> My own favourite approach would link ASI to layout/indentation,
> and introduce warnings instead of breaking code:
> 
> 1 if ASI kicks in, but indentation suggests statement continuation,
>    issue a warning
> 2 if ASI does not kick in, but indentation suggests new statement,
>    issue a warning

I did once try to implement this, by instrumenting esprima to
keep track of indents and ASI and other side-conditions, but 
got somewhat distracted/disillusioned by the number of
special cases that kept popping up. Nevertheless, that sketch
is now available as a gist:

https://gist.github.com/2973296

Perhaps it inspires someone to do it right?-)
Claus

// ----------------- output
$ node basil.js sample.js
ASI at line 5(2) before indented line 6(8)
multiline VariableDeclaration 12(2), not indented: line 13(2)
multiline VariableDeclaration 21(2), not indented: line 22(2)
ASI at line 23(2) before indented line 24(11)
multiline IfStatement 33(2), not indented: line 34(2)
ASI at line 37(2) before indented line 38(4)
multiline ExpressionStatement 40(2), not indented: line 42(2)
multiline WhileStatement 44(2), not indented: line 45(2)-line 47(2)

// ----------------- sample.js
$ cat sample.js

// examples

function restricted_production() {
  return  //;
        "hi"; // warn here
  return  //;
  "hi";   // don't warn here
}

function newline_no_asi() {
  var x = ["hi"] //;
  [1];  // warn here
  var y = ["hi"] //;
    [1];  // don't warn here
}

function newline_error_asi(alp,ha) {
  var a1 = "hi"+
           "ho"; // don't warn here
  var a2 = "hi"+
  "ho";          // warn here
  var b1 = "hi"  //;
           "ho"; // warn here
  var b2 = "hi"  //;
  "ho";          // don't warn here
}

function continued_statements() {
  if (condition) {
  } else {  // don't warn here
  }         // don't warn here
  if (condition) f
  ()        // warn here
  if (condition) f
    ()      // don't warn here
  if (condition) return
    ""      // warn here
  if (condition) return
  ""        // don't warn here
            // don't warn here (comment/empty multiline) FIXME
  while (condition) {
  }         // don't warn here
  while (condition) f
  ()        // warn here

  function f() {
  }         // don't warn here
} 


More information about the es-discuss mailing list