Skip to content

Commit

Permalink
Editorial: Delete now-redundant para + add example
Browse files Browse the repository at this point in the history
In the section about early errors of ObjectLiterals,
delete the paragraph about the non-application of some rules in some cases.

But add a related example to the previous section.
  • Loading branch information
jmdyck committed Nov 22, 2023
1 parent 4b80bcf commit 9dc5ad6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -18402,6 +18402,16 @@ <h2>Syntax</h2>
</emu-note>
<emu-note>
<p>In certain contexts, |ObjectLiteral| is used as a cover grammar for a more restricted secondary grammar. The |CoverInitializedName| production is necessary to fully cover these secondary grammars. However, use of this production results in an early Syntax Error in normal contexts where an actual |ObjectLiteral| is expected.</p>
<p>For example, consider:</p>
<pre><code class="javascript">
let o = {f = 1};
</code></pre>
<p>`{f = 1}` is parsed as an |ObjectLiteral| with a |CoverInitializedName|, which results in a Syntax Error via one of the early error rules in the next section.</p>
<p>In contrast, consider:</p>
<pre><code class="javascript">
({f = 1} = {f: 2});
</code></pre>
<p>Here, `{f = 1}` is again initially parsed as an |ObjectLiteral| with a |CoverInitializedName|, but since it's the |LeftHandSideExpression| of an |AssignmentExpression|, it must cover an |AssignmentPattern|, so the |ObjectLiteral| and |CoverInitializedName| are not subject to early error rules. Instead, `{f = 1}` is reparsed as an |ObjectAssignmentPattern| with an |AssignmentProperty|, and there is no Syntax Error.</p>
</emu-note>

<emu-clause id="sec-object-initializer-static-semantics-early-errors" oldids="sec-__proto__-property-names-in-object-initializers">
Expand All @@ -18415,7 +18425,6 @@ <h1>Static Semantics: Early Errors</h1>
It is a Syntax Error if PrivateBoundIdentifiers of |MethodDefinition| is not empty.
</li>
</ul>
<p>In addition to describing an actual object initializer the |ObjectLiteral| productions are also used as a cover grammar for |ObjectAssignmentPattern| and may be recognized as part of a |CoverParenthesizedExpressionAndArrowParameterList|. When |ObjectLiteral| appears in a context where |ObjectAssignmentPattern| is required the following Early Error rules are <b>not</b> applied. In addition, they are not applied when initially parsing a |CoverParenthesizedExpressionAndArrowParameterList| or |CoverCallExpressionAndAsyncArrowHead|.</p>
<emu-grammar>PropertyDefinition : CoverInitializedName</emu-grammar>
<ul>
<li>
Expand Down

0 comments on commit 9dc5ad6

Please sign in to comment.