Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> If you insert the semicolons yourself and don't depend on the auto insertions, you don't have to worry about the edge cases where the lack of a semicolon would introduce a bug.

I think this is not correct. It will still insert a semicolon where you don't want one. It's not like there's a compiler flag to turn insertion off.



That's not how it works, semicolons are only automatically inserted if they were omitted.

Use semicolons, lint the code, ????, profit


I just tried to get the linter (JShint) to break some valid code, but it didn't. So you can actually rely on the linter to insert the semicolons for you. It would be interesting to find out if there are any cases where the linter will insert the semicolon in the wrong place.


The browser somehow detects that the missing semicolon wasn't omitted and doesn't add it???


No. If it's missing it's inserted obviously. That's why you shouldn't omit it.

Here are the rules for parsing if you're interested

When the program contains a token that is not allowed by the formal grammar, then a semicolon is inserted if (a) there is a line break at that point, or (b) the unexpected token was a closing brace.

When the end of a file is reached, if the program cannot be parsed otherwise, then a semicolon is inserted.

When a "restricted production" is encountered and contains a line terminator in a place where the grammar contains the annotation "[no LineTerminator here]", then a semicolon is inserted.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: