-
Notifications
You must be signed in to change notification settings - Fork 25
semicolon required? #63
Comments
No, semicolons are not required; they follow normal ASI rules and may come automatically. The grammar contains semicolons, just as it does at the end of normal statements which are also subject to ASI. |
So there isn't any ambiguity with |
I don't think so. What ambiguity would there be? My implementations of parsers for this feature didn't run into any. Unless you mean class A {
foo = prop
in
obj
} ? That's not actually ambiguous in the grammar; it's the same as class A {
foo = prop in obj;
} There are a few of these weird edge cases when you omit semicolons; the more significant ones are to do with computed properties and generators. But, well, weird edge cases when you omit semicolons are nothing new to JS. |
babel breaks with that ^^ |
That's because it's not valid syntax. ASI can only be performed if the next token cannot occur as part of any valid production; in that case it can. Babel will also refuse class A {
foo = bar
*baz(){}
} for the same reason. This is an inevitable downside of relying on ASI. |
well |
I don't see this as any more of a hazard than a = b
({c} = d) parsing as a call expression. Again, this is an inevitable downside of relying on ASI. Tooling can help. |
I would say allowing the use of reserved words in situations that are basically indistinguishable from |
The concern is relying on asi- if you don't do it, you don't have to worry about things like this. If you do, use a linter that can check it for you. |
Thanks for explaining how ASI applies here, @bakkot. This issue seems resolved to me--you can use these names as public fields. |
Closing as semicolons are not required. |
https://gist.github.com/jeffmo/054df782c05639da2adb#gistcomment-2112307
just reposting the comment above, if this repo is preferred for discussion
The text was updated successfully, but these errors were encountered: