Skip to content

Commit 5ddd859

Browse files
committed
Bring together all the prose about ObjectLiteral being a cover for ObjectAssignmentPattern.
1 parent d2f6cd1 commit 5ddd859

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

spec.html

+13-12
Original file line numberDiff line numberDiff line change
@@ -18401,17 +18401,7 @@ <h2>Syntax</h2>
1840118401
<p>|MethodDefinition| is defined in <emu-xref href="#sec-method-definitions"></emu-xref>.</p>
1840218402
</emu-note>
1840318403
<emu-note>
18404-
<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>
18405-
<p>For example, consider:</p>
18406-
<pre><code class="javascript">
18407-
let o = {f = 1};
18408-
</code></pre>
18409-
<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>
18410-
<p>In contrast, consider:</p>
18411-
<pre><code class="javascript">
18412-
({f = 1} = {f: 2});
18413-
</code></pre>
18414-
<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>
18404+
<p>See the next section for the significance of |CoverInitializedName|.</p>
1841518405
</emu-note>
1841618406

1841718407
<emu-clause id="sec-object-initializer-static-semantics-early-errors" oldids="sec-__proto__-property-names-in-object-initializers">
@@ -18445,7 +18435,18 @@ <h1>Static Semantics: Early Errors</h1>
1844518435
</li>
1844618436
</ul>
1844718437
<emu-note>
18448-
<p>This production exists so that |ObjectLiteral| can serve as a cover grammar for |ObjectAssignmentPattern|. It cannot occur in an actual object initializer.</p>
18438+
<p>Elsewhere in this specification, there are early error rules that, under certain circumstances, require that a |LeftHandSideExpression| must cover an |AssignmentPattern|. Consequently, |ObjectLiteral| serves as a cover grammar for |ObjectAssignmentPattern|. The |CoverInitializedName| production is necessary to fully cover |AssignmentProperty|, but is not valid within an actual object initializer.</p>
18439+
<p>Specifically, in a context where an actual |ObjectLiteral| is expected, the above early error rule prevents the use of |CoverInitializedName|. But in cases where |ObjectLiteral| is used as a cover grammar, the semantics of "must cover" state that the Parse Nodes within the |ObjectLiteral| are not subject to early error rules, and so |CoverInitializedName| is allowed.</p>
18440+
<p>For example, consider:</p>
18441+
<pre><code class="javascript">
18442+
let o = {f = 1};
18443+
</code></pre>
18444+
<p>`{f = 1}` is parsed as an |ObjectLiteral| with a |CoverInitializedName|, which results in a Syntax Error via this early error rule.</p>
18445+
<p>In contrast, consider:</p>
18446+
<pre><code class="javascript">
18447+
({f = 1} = {f: 2});
18448+
</code></pre>
18449+
<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>
1844918450
</emu-note>
1845018451
</emu-clause>
1845118452

0 commit comments

Comments
 (0)