Skip to content

Commit

Permalink
Editorial: Add Automatic Semicolon Insertion hazard clause
Browse files Browse the repository at this point in the history
  • Loading branch information
littledan authored and bfarias-godaddy committed Jan 11, 2018
1 parent 7e94e28 commit 936398d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -10998,6 +10998,7 @@ <h1>Rules of Automatic Semicolon Insertion</h1>
<!-- es6num="11.9.2" -->
<emu-clause id="sec-examples-of-automatic-semicolon-insertion">
<h1>Examples of Automatic Semicolon Insertion</h1>
<em>This section is non-normative.</em>
<p>The source</p>
<pre><code class="javascript">{ 1 2 } 3</code></pre>
<p>is not a valid sentence in the ECMAScript grammar, even with the automatic semicolon insertion rules. In contrast, the source</p>
Expand Down Expand Up @@ -11059,6 +11060,26 @@ <h1>Examples of Automatic Semicolon Insertion</h1>
<p>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.</p>
</emu-clause>
</emu-clause>
<emu-clause id="sec-hazards-of-automatic-semicolon-insertion">
<h1>Hazards of Automatic Semicolon Insertion</h1>
<em>This section is non-normative.</em>
<p>ECMAScript programs can be written in a style with very few semicolons, based on a heavy dependence on automatic semicolon insertion. However, as described above, semicolons are not inserted at every newline, and some of these cases which do not have an automatically inserted semicolon can be counter-intuitive or confusing.</p>

<p>As new syntactic features are added to ECMAScript, additional cases requiring explicit semicolons emerge over time. As such, consistently explicit semicolon use is recommended.</p>

<p>The term "automatic semicolon insertion hazard" refers, informally, to a place where a developer may expect a semicolon to be inserted, but according to the rules described above, it is not. The rest of this section describes a number of automatic semicolon insertion hazards in this version of ECMAScript.</p>
<emu-clause id="sec-asi-hazards-in-statement-lists">
<h1>Automatic Semicolon Insertion Hazards in Statement Lists</h1>
<p>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 will be required if the following line begins with any of the following:
<ul>
<li><strong>An opening parenthesis (<code>(</code>)</strong>. Without a semicolon, the two lines together will be treated as a function call.</li>
<li><strong>An opening square bracket (<code>[</code>)</strong>. Without a semicolon, the two lines together will be treated as property access, rather than an array literal.</li>
<li><strong>A template string (<code>`</code>)</strong>. Without a semicolon, the two lines together will be interpreted as tagged template literal, with the previous expression as the function tag.</li>
<li><strong>Unary <code>+</code> or <code>-</code></strong>. Without a semicolon, the two lines together will be interpreted as a usage of the corresponding binary operator.</li>
<li><strong>A RegExp literal</strong>. Without a semicolon, the two lines together may be parsed instead as a division, for example if the RegExp has flags.</li>
</ul>
</emu-clause>
</emu-clause>
</emu-clause>

<!-- es6num="12" -->
Expand Down

0 comments on commit 936398d

Please sign in to comment.