Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omitting semicolons is not future-proof #581

Closed
bakkot opened this issue Aug 3, 2016 · 5 comments

Comments

@bakkot
Copy link

commented Aug 3, 2016

Consider for example the public fields proposal.

Under it, this is valid code:

class A {
  get;
  set;
}

and this is a syntax error:

class A {
  get
  set
}

You could add a rule which says that class fields must always start or end with a semicolon (or some other, even more special-case-y rule), but it's more overhead to remember.

I don't mean to rehash the great semicolon debate; I just wanted to point out that this style is only going to become harder and harder to follow as the language evolves.

(Incidentally, Babel's parsing of class properties is fairly broken, so don't rely on it as an oracle here.)

class A {
  x
  y
}

is legal; it's just 'get', 'set', 'static', and similar names which have this issue. ASI will not put a semicolon in the second snippet above because in class bodies an identifier such as 'set' is in fact a legal token to follow 'get' without an intervening semicolon.

@dcousens dcousens added the question label Aug 3, 2016

@timoxley

This comment has been minimized.

Copy link
Contributor

commented Aug 3, 2016

I think you're throwing the baby out with the bath water. Cases like get/set/static would fall in the realm of "necessary' semicolons, like those in for loops, and appears easy to identify. Perhaps we need to add a few more semicolons in, no drama. Standard isn't so zealous about "no semicolons" that it's going to disallow/break valid JavaScript constructs just because they require semicolons. Standard simply enforces no unnecessary semicolons. Adding new rules to handle new syntax is an inevitability. I don't see any problem here.

@yoshuawuyts

This comment has been minimized.

Copy link
Contributor

commented Aug 3, 2016

@bakkot thanks for the feedback. You raise an interesting point, but like Tim said we'll add new rules when new syntax is introduced.

Closing because there's not really anything to be done here now

@yoshuawuyts yoshuawuyts closed this Aug 3, 2016

@bakkot

This comment has been minimized.

Copy link
Author

commented Aug 3, 2016

For posterity, this is related to #372.

@jamesplease

This comment has been minimized.

Copy link

commented Jan 11, 2018

Cross-referencing tc39/ecma262#1062 , which seems related.

tl;dr, TC39 discourages the practice of relying on ASI.

@bcomnes

This comment has been minimized.

Copy link
Member

commented Jan 11, 2018

@jmeas I responded tc39/ecma262#1062 (comment)

I think they could improve their neutrality and suggested a re-wording on the issue to more accurately and fairly represent the issue.

@lock lock bot locked as resolved and limited conversation to collaborators May 25, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
6 participants
You can’t perform that action at this time.