From f5436bfed9b1bd01ec35a074d8369d4a330e85ec Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Thu, 11 Jan 2018 08:59:57 -0600 Subject: [PATCH] Editorial: Add Interesting Cases of Automatic Semicolon Insertion (#1062) Co-authored-by: Bradley Farias Co-authored-by: Daniel Ehrenberg Co-authored-by: Mathias Bynens --- spec.html | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/spec.html b/spec.html index a7eac67b82..c4b47bee53 100644 --- a/spec.html +++ b/spec.html @@ -12054,6 +12054,7 @@

Rules of Automatic Semicolon Insertion

Examples of Automatic Semicolon Insertion

+ This section is non-normative.

The source

{ 1 2 } 3

is not a valid sentence in the ECMAScript grammar, even with the automatic semicolon insertion rules. In contrast, the source

@@ -12115,6 +12116,44 @@

Examples of Automatic Semicolon Insertion

In the circumstance that an assignment statement must begin with a left parenthesis, it is a good idea for the programmer to provide an explicit semicolon at the end of the preceding statement rather than to rely on automatic semicolon insertion.

+ +

Interesting Cases of Automatic Semicolon Insertion

+ This section is non-normative. +

ECMAScript programs can be written in a style with very few semicolons by relying on automatic semicolon insertion. As described above, semicolons are not inserted at every newline, and automatic semicolon insertion can depend on multiple tokens across line terminators.

+ +

As new syntactic features are added to ECMAScript, additional grammar productions could be added that cause lines relying on automatic semicolon insertion preceding them to change grammar productions when parsed.

+ +

The interesting cases of automatic semicolon insertion are places where a semicolon may or may not be inserted depending on preceding source text according to the rules above. These places are considered interesting if changes outside of an existing source text grammar production could change the grammar production of the existing source text depending on automatic semicolon insertion. The rest of this section describes a number of interesting cases of automatic semicolon insertion in this version of ECMAScript.

+ +

Interesting Cases of Automatic Semicolon Insertion in Statement Lists

+

In a |StatementList|, many |StatementListItem|s end in semicolons, which may be omitted using automatic semicolon insertion. 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: +

    +
  • An opening parenthesis ((). Without a semicolon, the two lines together are treated as a |CallExpression|.
  • +
  • An opening square bracket ([). Without a semicolon, the two lines together are treated as property access, rather than an |ArrayLiteral| or |ArrayAssignmentPattern|.
  • +
  • A template literal (`). Without a semicolon, the two lines together are interpreted as a tagged Template (), with the previous expression as the |MemberExpression|.
  • +
  • Unary + or -. Without a semicolon, the two lines together are interpreted as a usage of the corresponding binary operator.
  • +
  • A RegExp literal. Without a semicolon, the two lines together may be parsed instead as the `/` |MultiplicativeOperator|, for example if the RegExp has flags.
  • +
+
+
+ +

Cases of Automatic Semicolon Insertion and “[no |LineTerminator| here]”

+ This section is non-normative. +

ECMAScript contains grammar productions which include “[no |LineTerminator| here]”. These productions are sometimes a means to have optional operands in the grammar. Introducing a |LineTerminator| in these locations would change the grammar production of a source text by using the grammar production without the optional operand.

+ +

The rest of this section describes a number of productions using “[no |LineTerminator| here]” in this version of ECMAScript.

+ +

List of Grammar Productions with Optional Operands and “[no |LineTerminator| here]”

+
    +
  • |UpdateExpression|.
  • +
  • |ContinueStatement|.
  • +
  • |BreakStatement|.
  • +
  • |ReturnStatement|.
  • +
  • |YieldExpression|.
  • +
  • Async Function Definitions () with relation to Function Definitions ()
  • +
+
+