Last active
August 29, 2015 14:09
-
-
Save nulayuhz/a0c5c172ed34876622ff to your computer and use it in GitHub Desktop.
Automatic Semicolons Insertion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://github.com/getify/You-Dont-Know-JS/blob/master/types%20&%20grammar/ch5.md#automatic-semicolons | |
"It's important to note that ASI will only take effect in the presence of a new-line (aka line-break). | |
Semicolons are not inserted in the middle of a line. | |
Basically, if the JS parser parses a line where a parser error would occur (a missing expected ;), | |
and it can reasonably insert one, it does so. What's reasonable for insertion? | |
Only if there's nothing but whitespace and/or comments between the end of some statement and that | |
line's new-line/line break." | |
"...In my view, the only way a parser error occurs is if it's given an incorrect/errored program to parse. | |
So, while ASI is strictly correcting parser errors, the only way it can get such errors to correct is | |
if there were first program authoring errors -- omitting semicolons where the grammar rules require them. | |
So, to state it more bluntly, when I hear someone claim that they want to omit "optional semicolons", | |
my brain translates that claim to "I want to write the most parser-broken program I can that can still work." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/getify/You-Dont-Know-JS/blob/master/types%20&%20grammar/ch5.md#automatic-semicolons