google / closure-linter

Automatically exported from code.google.com/p/closure-linter
Apache License 2.0
109 stars 37 forks source link

Bad missing semi-colon error when line ends with var keyword. #10

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
From initial report as part of issue 8:

$> cat with_var.js
var
  a = 2,
  b = 3;

console.log(a, b);

$> node with_var.js 
2 3

$> fixjsstyle with_var.js
Fixed 1 errors in with_var.js

$ cat with_var.js 
var;
  a = 2,
  b = 3;

console.log(a, b);

$> node with_var.js

with_var.js:1
var;
   ^
SyntaxError: Unexpected token ;
    at Module._compile (node.js:457:37)
    at Module._loadScriptSync (node.js:468:10)
    at Module.loadSync (node.js:338:12)
    at Object.runMain (node.js:521:24)
    at node.js:751:10

Original issue reported on code.google.com by a...@google.com on 16 Sep 2010 at 1:51

GoogleCodeExporter commented 9 years ago
This is still in 2.2.6 :(

Original comment by filip.noetzel on 12 Nov 2010 at 8:25

GoogleCodeExporter commented 9 years ago
Attached is a simplified version of the above testcase + fix.

Basically, _StatementCouldEndInContext[1] should not return True if the current 
token is "var".

[1] 
http://code.google.com/p/closure-linter/source/browse/trunk/closure_linter/ecmam
etadatapass.py#472

Original comment by filip.noetzel on 20 Feb 2011 at 9:49

Attachments:

GoogleCodeExporter commented 9 years ago
Yep. I looked into fixing this quite a while ago. It's fairly straight forward 
to not have the missing semi-colon error. The problem is that this then leads 
to a much more difficult to fix error in indentation checking. I'd prefer for a 
fix that just makes the case work completely rather than trading one error for 
another. The right way to do indentation checking and missing semi-colon 
detection is probably to have a real grammar and parser, though it might be 
easier at this point to just improve GJsLint home-grown efforts to be good 
enough. Hopefully someone will be willing to take on the larger indentation / 
missing semi-colon work and fix all the issues, of which this is only one of 
several.

Original comment by a...@google.com on 20 Feb 2011 at 11:40

GoogleCodeExporter commented 9 years ago

Original comment by vagra...@google.com on 5 Aug 2013 at 9:49