tc39 / ecma262

Status, process, and documents for ECMA-262
https://tc39.es/ecma262/
Other
15.06k stars 1.29k forks source link

Section 11.10.1 description too line oriented (rather than statement)? #2234

Open jmm opened 3 years ago

jmm commented 3 years ago

Regarding this description:

As a consequence of the rules above, at the end of a line ending an expression, a semicolon is required if the following line begins with any of the following:

It seems like it would be more accurate and clear to describe it in terms of statements like in section 11.9. Something like:

As a consequence of the rules above, a semicolon is required between a statement that ends with an expression and a statement that begins with any of the following:

The current version seems as if it could imply a difference between cases like these:

// A.1
// I personally find this way ugly in otherwise non-semicolon-terminated code.
const a1 = "a1";
[1]

// A.2
const a2 = "a2"
;[1]

// A.3
const a3 = "a3"
;
[1]

// or

// B.1
const b1 = "b1"
[1]

// B.2
const b2 = "b2"

[1]

Considering that the layout of lines actually is relevant in some cases, I think it would be good for clarity to describe this in terms of statements.

bakkot commented 3 years ago

Absent an intervening line terminator, "a semicolon is required between a statement that ends with an expression and a statement [...]" is true regardless of the second statement, not just the given list. It really does need to talk about lines.

We could probably rephrase it in a way which makes it clear that the semicolon just has to be between the two, though, not necessarily at the end of the first line. And we should probably change "the following line" to "the following line of code" or something.

jmm commented 3 years ago

@bakkot thanks for reading and giving feedback.

You're right, but this section is in the context of cases where automatic semicolon insertion might happen, and as you noted there's no expectation that it would happen in the scenario without any intervening LineTerminators. So I don't think it's the responsibility of this section to exhaustively detail when it won't happen. But to be more specific, it could be phrased something like:

As a consequence of the rules above, a semicolon is required between StatementListItems when a StatementListItem that ends with an expression is followed by zero or more LineTerminators followed by a StatementListItem that begins with any of the following:

Or:

As a consequence of the rules above, a semicolon is required between a StatementListItem that ends with an expression and a StatementListItem that begins with any of the following, even when one or more LineTerminators appear between StatementListItems:

Or:

In some cases, a semicolon would be automatically inserted when a StatementListItem that ends with an expression is followed by one or more LineTerminators and a StatementListItem. However, as a consequence of the rules above, an explicit semicolon is required between StatementListItems when the second StatementListItem begins with any of the following:

Then the list items all reference "the two lines together". Maybe it would be simpler there to just say "the lines together".