2 ms·
> you don’t expect the browser to run malformed JavaScript Refer to https://tc39.es/ecma262/2024/multipage/ecmascript-language-lexical-grammar.html#sec-automat
by wizzwizz4 2y ago
> you don’t expect the browser to run malformed JavaScript
Refer to https://tc39.es/ecma262/2024/multipage/ecmascript-language-lexical-grammar.html#sec-automatic-semicolon-insertion https://tc39.es/ecma262/2024/multipage/ecmascript-language-l... (extract below)
---
In contrast, the source
{ 1
2 } 3
is also not a valid ECMAScript sentence, but is transformed by automatic semicolon insertion into the following:
{ 1
;2 ;} 3;
which is a valid ECMAScript sentence.
- notpushkin 2y agoThat's a weird wording, huh. I would interpret it not as yeah this is invalid code but we fix it for you, but rather this code would be invalid if not for this weird exception we carve out for it. I would love to say “let's abolish ASI too”, but (1) some folks genuinely use it assuming that it's a syntax feature and not a compat thing, and (2) it's a compat thing, meaning it's not getting removed without a very valid reason. A shame, though. But JS parsing is still undeniably way more strict than HTML, no?
- wizzwizz4 2y agoHow about Appendix B? https://tc39.es/ecma262/2024/multipage/additional-ecmascript-features-for-web-browsers.html https://tc39.es/ecma262/2024/multipage/additional-ecmascript... > These features are not considered part of the core ECMAScript language. Programmers should not use or assume the existence of these features and behaviours when writing new ECMAScript code. ECMAScript implementations are discouraged from implementing these features unless the implementation is part of a web browser or is required to run the same legacy ECMAScript code that web browsers encounter. Some of these are legacy APIs, but some of them are just plain syntax errors.