Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

semicolon required? #63

Closed
bounceme opened this issue Jun 2, 2017 · 11 comments
Closed

semicolon required? #63

bounceme opened this issue Jun 2, 2017 · 11 comments

Comments

@bounceme
Copy link

bounceme commented Jun 2, 2017

https://gist.github.com/jeffmo/054df782c05639da2adb#gistcomment-2112307

just reposting the comment above, if this repo is preferred for discussion

@littledan
Copy link
Member

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.

@bounceme
Copy link
Author

bounceme commented Jun 2, 2017

So there isn't any ambiguity with in/instanceof being used as property/method names?

@bakkot
Copy link
Contributor

bakkot commented Jun 2, 2017

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.

@bounceme
Copy link
Author

bounceme commented Jun 2, 2017


class AB  {
a=1
in(i){}
}

babel breaks with that ^^

@bakkot
Copy link
Contributor

bakkot commented Jun 2, 2017

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.

@bounceme
Copy link
Author

bounceme commented Jun 2, 2017

well *|in|instanceof are operators, so they are just traps waiting to be fallen into

@bakkot
Copy link
Contributor

bakkot commented Jun 2, 2017

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.

@bounceme
Copy link
Author

bounceme commented Jun 2, 2017

I would say allowing the use of reserved words in situations that are basically indistinguishable from Identifier, and allowing asi in the same construct should be a major concern

@ljharb
Copy link
Member

ljharb commented Jun 2, 2017

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.

@littledan
Copy link
Member

Thanks for explaining how ASI applies here, @bakkot. This issue seems resolved to me--you can use these names as public fields.

@littledan
Copy link
Member

Closing as semicolons are not required.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants