Re-insert semi-colons
Opened this issue ยท 3 comments
Prettier has a option to toggle semicolons, which should nearly always be set to "have semi colons".
The now defunct "Standard JS" lint style espoused not having them for conciseness but unfortunately they aren't truly optional. The way most engines figure out if a semi colon is needed is by throwing an exception, seeing if a semi colon put in the exception location fixes it, then carrying on.
As you might imagine this can lead to slower compiles and some truly devilish bugs.
What kind of bugs are you imagining? I've built JS apps without semicolons for over two years and literally never had an issue.
Also
The way most engines figure out if a semi colon is needed is by throwing an exception, seeing if a semi colon put in the exception location fixes it, then carrying on.
Source? As a lapsed compiler geek this sounds unlikely, but maybe I'm underestimating the complexity of JS ๐
Also, semicolons get inserted during minification so this shouldn't matter anyway.
I got that insight from Douglas Crockford during a talk of his.
One example of an ambiguous case can be seen here.
That was an interesting talk ๐ Luckily ambiguous syntax can be avoided with an eslint rule: https://eslint.org/docs/rules/semi#options โ and prettier will respect using semicolons in those (extremely rare) situations too. So it's completely safe to not use semicolons ๐ yay, tooling!