[Pkg-javascript-commits] [node-acorn-jsx] 230/484: Added test for BindingPattern inside ArrayComprehension

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:35 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-acorn-jsx.

commit f2dfeff9777e1fc26dd615af885210ada4a4d0da
Author: Ingvar Stepanyan <me at rreverser.com>
Date:   Fri Jul 25 18:59:19 2014 +0300

    Added test for BindingPattern inside ArrayComprehension
    
    (fails in esprima - https://code.google.com/p/esprima/issues/detail?id=570).
---
 index.html            |  65 ++++++++++------
 test/tests-harmony.js | 203 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 245 insertions(+), 23 deletions(-)

diff --git a/index.html b/index.html
index ff59372..88ea6a3 100644
--- a/index.html
+++ b/index.html
@@ -849,8 +849,10 @@ to.</p>             </td>             <td class="code">               <div class
         <span class="k">break</span><span class="p">;</span>
 
       <span class="k">case</span> <span class="s2">"ArrayPattern"</span><span class="o">:</span>
-        <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">expr</span><span class="p">.</span><span class="nx">elements</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span>
-          <span class="nx">checkLVal</span><span class="p">(</span><span class="nx">expr</span><span class="p">.</span><span class="nx">elements</span><span class="p">[</span><span class="nx">i</span><span class="p">],</span> <span class="nx">isBinding</span><span class="p">);</span>
+        <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">expr</span><span class="p">.</span><span class="nx">elements</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class= [...]
+          <span class="kd">var</span> <span class="nx">elem</span> <span class="o">=</span> <span class="nx">expr</span><span class="p">.</span><span class="nx">elements</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
+          <span class="k">if</span> <span class="p">(</span><span class="nx">elem</span><span class="p">)</span> <span class="nx">checkLVal</span><span class="p">(</span><span class="nx">elem</span><span class="p">,</span> <span class="nx">isBinding</span><span class="p">);</span>
+        <span class="p">}</span>
         <span class="k">break</span><span class="p">;</span>
 
       <span class="k">case</span> <span class="s2">"SpreadElement"</span><span class="o">:</span>
@@ -1319,10 +1321,9 @@ or <code>{}</code>.</p>             </td>             <td class="code">
       <span class="k">if</span> <span class="p">(</span><span class="nx">tokType</span> <span class="o">!==</span> <span class="nx">_parenR</span><span class="p">)</span> <span class="p">{</span>
         <span class="nx">val</span> <span class="o">=</span> <span class="nx">parseExpression</span><span class="p">();</span>
       <span class="p">}</span>
-      <span class="nx">expect</span><span class="p">(</span><span class="nx">_parenR</span><span class="p">);</span>
-      <span class="k">if</span> <span class="p">(</span><span class="nx">metParenL</span> <span class="o">===</span> <span class="nx">oldParenL</span> <span class="o">&&</span> <span class="nx">eat</span><span class="p">(</span><span class="nx">_arrow</span><span class="p">))</span> <span class="p">{</span>
+      <span class="nx">expect</span><span class="p">(</span><span class="nx">_parenR</span><span class="p">);</span></pre></div>             </td>           </tr>                               <tr id="section-119">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-119">¶</a>               </div>               <p>if '=>' follows '(...)', convert contents to arguments</p>             </td>             <td class="code">  [...]
         <span class="nx">val</span> <span class="o">=</span> <span class="nx">parseArrowExpression</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="o">!</span><span class="nx">val</span> <span class="o">?</span> <span class="p">[]</span> <span class="o">:</span> <span class="nx">val</span><span class="p">.</span><span class="nx">type</span> <span class="o">===</span> <span class="s2">"SequenceExpression"</span> <span class="o">?</s [...]
-      <span class="p">}</span> <span class="k">else</span> <span class="p">{</span></pre></div>             </td>           </tr>                               <tr id="section-119">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-119">¶</a>               </div>               <p>disallow '()' before everything but error</p>             </td>             <td class="code">               <div class="highlight"><pre>     [...]
+      <span class="p">}</span> <span class="k">else</span> <span class="p">{</span></pre></div>             </td>           </tr>                               <tr id="section-120">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-120">¶</a>               </div>               <p>forbid '()' before everything but '=>'</p>             </td>             <td class="code">               <div class="highlight"><pre>        [...]
       <span class="p">}</span>
       <span class="nx">val</span><span class="p">.</span><span class="nx">start</span> <span class="o">=</span> <span class="nx">tokStart1</span><span class="p">;</span>
       <span class="nx">val</span><span class="p">.</span><span class="nx">end</span> <span class="o">=</span> <span class="nx">lastEnd</span><span class="p">;</span>
@@ -1337,7 +1338,25 @@ or <code>{}</code>.</p>             </td>             <td class="code">
 
     <span class="k">case</span> <span class="nx">_bracketL</span><span class="o">:</span>
       <span class="kd">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">();</span>
-      <span class="nx">next</span><span class="p">();</span>
+      <span class="nx">next</span><span class="p">();</span></pre></div>             </td>           </tr>                               <tr id="section-121">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-121">¶</a>               </div>               <p>check whether this is array comprehension or regular array</p>             </td>             <td class="code">               <div class="highlight"><pre>      <spa [...]
+        <span class="nx">node</span><span class="p">.</span><span class="nx">blocks</span> <span class="o">=</span> <span class="p">[];</span>
+        <span class="k">while</span> <span class="p">(</span><span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_for</span><span class="p">)</span> <span class="p">{</span>
+          <span class="kd">var</span> <span class="nx">block</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">();</span>
+          <span class="nx">next</span><span class="p">();</span>
+          <span class="nx">expect</span><span class="p">(</span><span class="nx">_parenL</span><span class="p">);</span>
+          <span class="nx">block</span><span class="p">.</span><span class="nx">left</span> <span class="o">=</span> <span class="nx">toAssignable</span><span class="p">(</span><span class="nx">parseExprAtom</span><span class="p">());</span>
+          <span class="nx">checkLVal</span><span class="p">(</span><span class="nx">block</span><span class="p">.</span><span class="nx">left</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span>
+          <span class="nx">expect</span><span class="p">(</span><span class="nx">_of</span><span class="p">);</span></pre></div>             </td>           </tr>                               <tr id="section-122">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-122">¶</a>               </div>               <p><code>of</code> property is here for compatibility with Esprima's AST
+which also supports deprecated [for (... in ...) expr]</p>             </td>             <td class="code">               <div class="highlight"><pre>          <span class="nx">block</span><span class="p">.</span><span class="nx">of</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+          <span class="nx">block</span><span class="p">.</span><span class="nx">right</span> <span class="o">=</span> <span class="nx">parseExpression</span><span class="p">();</span>
+          <span class="nx">expect</span><span class="p">(</span><span class="nx">_parenR</span><span class="p">);</span>
+          <span class="nx">node</span><span class="p">.</span><span class="nx">blocks</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">finishNode</span><span class="p">(</span><span class="nx">block</span><span class="p">,</span> <span class="s2">"ComprehensionBlock"</span><span class="p">));</span>
+        <span class="p">}</span>
+        <span class="nx">node</span><span class="p">.</span><span class="nx">filter</span> <span class="o">=</span> <span class="nx">eat</span><span class="p">(</span><span class="nx">_if</span><span class="p">)</span> <span class="o">?</span> <span class="nx">parseParenExpression</span><span class="p">()</span> <span class="o">:</span> <span class="kc">null</span><span class="p">;</span>
+        <span class="nx">node</span><span class="p">.</span><span class="nx">body</span> <span class="o">=</span> <span class="nx">parseExpression</span><span class="p">();</span>
+        <span class="nx">expect</span><span class="p">(</span><span class="nx">_bracketR</span><span class="p">);</span>
+        <span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"ComprehensionExpression"</span><span class="p">);</span>
+      <span class="p">}</span>
       <span class="nx">node</span><span class="p">.</span><span class="nx">elements</span> <span class="o">=</span> <span class="nx">parseExprList</span><span class="p">(</span><span class="nx">_bracketR</span><span class="p">,</span> <span class="kc">true</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span>
       <span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"ArrayExpression"</span><span class="p">);</span>
 
@@ -1361,7 +1380,7 @@ or <code>{}</code>.</p>             </td>             <td class="code">
     <span class="k">default</span><span class="o">:</span>
       <span class="nx">unexpected</span><span class="p">();</span>
     <span class="p">}</span>
-  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-120">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-120">¶</a>               </div>               <p>New's precedence is slightly tricky. It must allow its argument
+  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-123">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-123">¶</a>               </div>               <p>New's precedence is slightly tricky. It must allow its argument
 to be a <code>[]</code> or dot subscript expression, but not a call — at
 least, not without wrapping it in parentheses. Thus, it uses the</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">parseNew</span><span class="p">()</span> <span class="p">{</span>
     <span class="kd">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">();</span>
@@ -1370,12 +1389,12 @@ least, not without wrapping it in parentheses. Thus, it uses the</p>
     <span class="k">if</span> <span class="p">(</span><span class="nx">eat</span><span class="p">(</span><span class="nx">_parenL</span><span class="p">))</span> <span class="nx">node</span><span class="p">.</span><span class="nx">arguments</span> <span class="o">=</span> <span class="nx">parseExprList</span><span class="p">(</span><span class="nx">_parenR</span><span class="p">,</span> <span class="kc">false</span><span class="p">);</span>
     <span class="k">else</span> <span class="nx">node</span><span class="p">.</span><span class="nx">arguments</span> <span class="o">=</span> <span class="nx">empty</span><span class="p">;</span>
     <span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"NewExpression"</span><span class="p">);</span>
-  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-121">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-121">¶</a>               </div>               <p>Parse spread element '...expr'</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">parseSpread</span><s [...]
+  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-124">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-124">¶</a>               </div>               <p>Parse spread element '...expr'</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">parseSpread</span><s [...]
     <span class="kd">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">();</span>
     <span class="nx">next</span><span class="p">();</span>
     <span class="nx">node</span><span class="p">.</span><span class="nx">argument</span> <span class="o">=</span> <span class="nx">parseExpression</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span>
     <span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"SpreadElement"</span><span class="p">);</span>
-  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-122">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-122">¶</a>               </div>               <p>Parse an object literal.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">parseObj</span><span class [...]
+  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-125">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-125">¶</a>               </div>               <p>Parse an object literal.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">parseObj</span><span class [...]
     <span class="kd">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">(),</span> <span class="nx">first</span> <span class="o">=</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">sawGetSet</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
     <span class="nx">node</span><span class="p">.</span><span class="nx">properties</span> <span class="o">=</span> <span class="p">[];</span>
     <span class="nx">next</span><span class="p">();</span>
@@ -1416,7 +1435,7 @@ least, not without wrapping it in parentheses. Thus, it uses the</p>
       <span class="nx">addProperty</span><span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">properties</span><span class="p">,</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">prop</span><span class="p">,</span> <span class="s2">"Property"</span><span class="p">),</span> <span class="nx">sawGetSet</span><span class="p">,</span> <span class="s2">"init"</span><span class="p">);</span>
     <span class="p">}</span>
     <span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"ObjectExpression"</span><span class="p">);</span>
-  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-123">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-123">¶</a>               </div>               <p>Add property to list with keeping in mind and checking that
+  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-126">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-126">¶</a>               </div>               <p>Add property to list with keeping in mind and checking that
 object/class getters and setters are not allowed to clash —
 either with each other or with an init property — and in
 strict mode, init properties are also not allowed to be repeated.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">addProperty</span><span class="p">(</span><span class="nx">props</span><span class="p">,</span> <span class="nx">current</span><span class="p">,</span> <span class="nx">sawGetSet</span><span class="p">,</span> <span class="nx">defaultKind</span><span class="p">)</span> <span clas [...]
@@ -1447,7 +1466,7 @@ strict mode, init properties are also not allowed to be repeated.</p>
       <span class="p">}</span>
     <span class="p">}</span>
     <span class="nx">prop</span><span class="p">.</span><span class="nx">key</span> <span class="o">=</span> <span class="p">(</span><span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_num</span> <span class="o">||</span> <span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_string</span><span class="p">)</span> <span class="o">?</span> <span class="nx">parseExprAtom</span><span class="p">()</span> <span class="o">:</span> <span class="nx"> [...]
-  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-124">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-124">¶</a>               </div>               <p>Initialize empty function node.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">initFunction</span> [...]
+  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-127">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-127">¶</a>               </div>               <p>Initialize empty function node.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">initFunction</span> [...]
     <span class="nx">node</span><span class="p">.</span><span class="nx">id</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
     <span class="nx">node</span><span class="p">.</span><span class="nx">params</span> <span class="o">=</span> <span class="p">[];</span>
     <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">ecmaVersion</span> <span class="o">>=</span> <span class="mi">6</span><span class="p">)</span> <span class="p">{</span>
@@ -1455,7 +1474,7 @@ strict mode, init properties are also not allowed to be repeated.</p>
       <span class="nx">node</span><span class="p">.</span><span class="nx">rest</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
       <span class="nx">node</span><span class="p">.</span><span class="nx">generator</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
     <span class="p">}</span>
-  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-125">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-125">¶</a>               </div>               <p>Parse a function declaration or literal (depending on the
+  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-128">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-128">¶</a>               </div>               <p>Parse a function declaration or literal (depending on the
 <code>isStatement</code> parameter).</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">parseFunction</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">isStatement</span><span class="p">,</span> <span class="nx">allowExpressionBody</span><span class="p">)</span> <span class="p">{</span>
     <span class="nx">initFunction</span><span class="p">(</span><span class="nx">node</span><span class="p">);</span>
     <span class="k">if</span> <span class="p">(</span><span class="nx">isStatement</span> <span class="o">||</span> <span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_name</span><span class="p">)</span> <span class="p">{</span>
@@ -1464,7 +1483,7 @@ strict mode, init properties are also not allowed to be repeated.</p>
     <span class="nx">parseFunctionParams</span><span class="p">(</span><span class="nx">node</span><span class="p">);</span>
     <span class="nx">parseFunctionBody</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">allowExpressionBody</span><span class="p">);</span>
     <span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">isStatement</span> <span class="o">?</span> <span class="s2">"FunctionDeclaration"</span> <span class="o">:</span> <span class="s2">"FunctionExpression"</span><span class="p">);</span>
-  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-126">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-126">¶</a>               </div>               <p>Parse arrow function expression with given parameters.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class=" [...]
+  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-129">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-129">¶</a>               </div>               <p>Parse arrow function expression with given parameters.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class=" [...]
     <span class="nx">initFunction</span><span class="p">(</span><span class="nx">node</span><span class="p">);</span>
 
     <span class="kd">var</span> <span class="nx">defaults</span> <span class="o">=</span> <span class="nx">node</span><span class="p">.</span><span class="nx">defaults</span><span class="p">,</span> <span class="nx">hasDefaults</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
@@ -1492,7 +1511,7 @@ strict mode, init properties are also not allowed to be repeated.</p>
 
     <span class="nx">parseFunctionBody</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span>
     <span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"ArrowFunctionExpression"</span><span class="p">);</span>
-  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-127">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-127">¶</a>               </div>               <p>Parse function parameters.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">parseFunctionParams</spa [...]
+  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-130">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-130">¶</a>               </div>               <p>Parse function parameters.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">parseFunctionParams</spa [...]
     <span class="kd">var</span> <span class="nx">defaults</span> <span class="o">=</span> <span class="p">[],</span> <span class="nx">hasDefaults</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
     
     <span class="nx">expect</span><span class="p">(</span><span class="nx">_parenL</span><span class="p">);</span>
@@ -1519,19 +1538,19 @@ strict mode, init properties are also not allowed to be repeated.</p>
     <span class="p">}</span>
 
     <span class="k">if</span> <span class="p">(</span><span class="nx">hasDefaults</span><span class="p">)</span> <span class="nx">node</span><span class="p">.</span><span class="nx">defaults</span> <span class="o">=</span> <span class="nx">defaults</span><span class="p">;</span>
-  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-128">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-128">¶</a>               </div>               <p>Parse function body and check parameters.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">parseFunc [...]
+  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-131">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-131">¶</a>               </div>               <p>Parse function body and check parameters.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">parseFunc [...]
     <span class="kd">var</span> <span class="nx">isExpression</span> <span class="o">=</span> <span class="nx">allowExpression</span> <span class="o">&&</span> <span class="nx">tokType</span> <span class="o">!==</span> <span class="nx">_braceL</span><span class="p">;</span>
     
     <span class="k">if</span> <span class="p">(</span><span class="nx">isExpression</span><span class="p">)</span> <span class="p">{</span>
       <span class="nx">node</span><span class="p">.</span><span class="nx">body</span> <span class="o">=</span> <span class="nx">parseExpression</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span>
       <span class="nx">node</span><span class="p">.</span><span class="nx">expression</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
-    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span></pre></div>             </td>           </tr>                               <tr id="section-129">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-129">¶</a>               </div>               <p>Start a new scope with regard to labels and the <code>inFunction</code>
+    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span></pre></div>             </td>           </tr>                               <tr id="section-132">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-132">¶</a>               </div>               <p>Start a new scope with regard to labels and the <code>inFunction</code>
 flag (restore them to their old value afterwards).</p>             </td>             <td class="code">               <div class="highlight"><pre>      <span class="kd">var</span> <span class="nx">oldInFunc</span> <span class="o">=</span> <span class="nx">inFunction</span><span class="p">,</span> <span class="nx">oldLabels</span> <span class="o">=</span> <span class="nx">labels</span><span class="p">;</span>
       <span class="nx">inFunction</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span> <span class="nx">labels</span> <span class="o">=</span> <span class="p">[];</span>
       <span class="nx">node</span><span class="p">.</span><span class="nx">body</span> <span class="o">=</span> <span class="nx">parseBlock</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span>
       <span class="nx">node</span><span class="p">.</span><span class="nx">expression</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
       <span class="nx">inFunction</span> <span class="o">=</span> <span class="nx">oldInFunc</span><span class="p">;</span> <span class="nx">labels</span> <span class="o">=</span> <span class="nx">oldLabels</span><span class="p">;</span>
-    <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-130">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-130">¶</a>               </div>               <p>If this is a strict mode function, verify that argument names
+    <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-133">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-133">¶</a>               </div>               <p>If this is a strict mode function, verify that argument names
 are not repeated, and it does not try to bind the words <code>eval</code>
 or <code>arguments</code>.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="k">if</span> <span class="p">(</span><span class="nx">strict</span> <span class="o">||</span> <span class="o">!</span><span class="nx">isExpression</span> <span class="o">&&</span> <span class="nx">node</span><span class="p">.</span><span class="nx">body</span><span class="p">.</span><span class="nx">body</span><span class="p">.</span><span cla [...]
       <span class="kd">var</span> <span class="nx">nameHash</span> <span class="o">=</span> <span class="p">{};</span>
@@ -1542,7 +1561,7 @@ or <code>arguments</code>.</p>             </td>             <td class="code">
       <span class="k">if</span> <span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">rest</span><span class="p">)</span>
         <span class="nx">checkFunctionParam</span><span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">rest</span><span class="p">,</span> <span class="nx">nameHash</span><span class="p">);</span>
     <span class="p">}</span>
-  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-131">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-131">¶</a>               </div>               <p>Verify that argument names are not repeated, and it does not
+  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-134">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-134">¶</a>               </div>               <p>Verify that argument names are not repeated, and it does not
 try to bind the words <code>eval</code> or <code>arguments</code>.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">checkFunctionParam</span><span class="p">(</span><span class="nx">param</span><span class="p">,</span> <span class="nx">nameHash</span><span class="p">)</span> <span class="p">{</span>
     <span class="k">switch</span> <span class="p">(</span><span class="nx">param</span><span class="p">.</span><span class="nx">type</span><span class="p">)</span> <span class="p">{</span>
       <span class="k">case</span> <span class="s2">"Identifier"</span><span class="o">:</span>
@@ -1563,7 +1582,7 @@ try to bind the words <code>eval</code> or <code>arguments</code>.</p>
           <span class="nx">checkFunctionParam</span><span class="p">(</span><span class="nx">param</span><span class="p">.</span><span class="nx">elements</span><span class="p">[</span><span class="nx">i</span><span class="p">],</span> <span class="nx">nameHash</span><span class="p">);</span>
         <span class="k">break</span><span class="p">;</span>
     <span class="p">}</span>
-  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-132">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-132">¶</a>               </div>               <p>Parse a class declaration or literal (depending on the
+  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-135">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-135">¶</a>               </div>               <p>Parse a class declaration or literal (depending on the
 <code>isStatement</code> parameter).</p>             </td>             <td class="code">               <div class="highlight"><pre>  
   <span class="kd">function</span> <span class="nx">parseClass</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">isStatement</span><span class="p">)</span> <span class="p">{</span>
     <span class="nx">next</span><span class="p">();</span>
@@ -1589,7 +1608,7 @@ try to bind the words <code>eval</code> or <code>arguments</code>.</p>
     <span class="p">}</span>
     <span class="nx">node</span><span class="p">.</span><span class="nx">body</span> <span class="o">=</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">classBody</span><span class="p">,</span> <span class="s2">"ClassBody"</span><span class="p">);</span>
     <span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">isStatement</span> <span class="o">?</span> <span class="s2">"ClassDeclaration"</span> <span class="o">:</span> <span class="s2">"ClassExpression"</span><span class="p">);</span>
-  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-133">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-133">¶</a>               </div>               <p>Parses a comma-separated list of expressions, and returns them as
+  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-136">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-136">¶</a>               </div>               <p>Parses a comma-separated list of expressions, and returns them as
 an array. <code>close</code> is the token type that ends the list, and
 <code>allowEmpty</code> can be turned on to allow subsequent commas with
 nothing in between them to be parsed as <code>null</code> (which is needed
@@ -1605,7 +1624,7 @@ for array literals).</p>             </td>             <td class="code">
       <span class="k">else</span> <span class="nx">elts</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">parseExpression</span><span class="p">(</span><span class="kc">true</span><span class="p">));</span>
     <span class="p">}</span>
     <span class="k">return</span> <span class="nx">elts</span><span class="p">;</span>
-  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-134">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-134">¶</a>               </div>               <p>Parse the next token as an identifier. If <code>liberal</code> is true (used
+  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-137">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-137">¶</a>               </div>               <p>Parse the next token as an identifier. If <code>liberal</code> is true (used
 when parsing properties), it will also convert keywords into
 identifiers.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">parseIdent</span><span class="p">(</span><span class="nx">liberal</span><span class="p">)</span> <span class="p">{</span>
     <span class="kd">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">();</span>
@@ -1626,7 +1645,7 @@ identifiers.</p>             </td>             <td class="code">               <
     <span class="nx">tokRegexpAllowed</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
     <span class="nx">next</span><span class="p">();</span>
     <span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"Identifier"</span><span class="p">);</span>
-  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-135">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-135">¶</a>               </div>               <p>Convert existing expression atom to assignable pattern
+  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-138">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-138">¶</a>               </div>               <p>Convert existing expression atom to assignable pattern
 if possible.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">toAssignable</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">allowSpread</span><span class="p">)</span> <span class="p">{</span>
     <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">ecmaVersion</span> <span class="o">>=</span> <span class="mi">6</span> <span class="o">&&</span> <span class="nx">node</span><span class="p">)</span> <span class="p">{</span>
       <span class="k">switch</span> <span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">type</span><span class="p">)</span> <span class="p">{</span>
@@ -1662,7 +1681,7 @@ if possible.</p>             </td>             <td class="code">               <
       <span class="p">}</span>
     <span class="p">}</span>
     <span class="k">return</span> <span class="nx">node</span><span class="p">;</span>
-  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-136">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-136">¶</a>               </div>               <p>Checks if node can be assignable spread argument.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">c [...]
+  <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-139">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-139">¶</a>               </div>               <p>Checks if node can be assignable spread argument.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">c [...]
     <span class="k">if</span> <span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">type</span> <span class="o">!==</span> <span class="s2">"Identifier"</span> <span class="o">&&</span> <span class="nx">node</span><span class="p">.</span><span class="nx">type</span> <span class="o">!==</span> <span class="s2">"ArrayPattern"</span><span class="p">)</span>
       <span class="nx">unexpected</span><span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">start</span><span class="p">);</span>
   <span class="p">}</span>
diff --git a/test/tests-harmony.js b/test/tests-harmony.js
index a0833d1..f69ae66 100644
--- a/test/tests-harmony.js
+++ b/test/tests-harmony.js
@@ -3700,6 +3700,209 @@ test("[for (x of array) for (y of array2) if (x === test) x]", {
   locations: true
 });
 
+test("[for ([,x] of array) for ({[start.x]: x, [start.y]: y} of array2) x]", {
+  type: "Program",
+  body: [{
+    type: "ExpressionStatement",
+    expression: {
+      type: "ComprehensionExpression",
+      filter: null,
+      blocks: [
+        {
+          type: "ComprehensionBlock",
+          left: {
+            type: "ArrayPattern",
+            elements: [
+              null,
+              {
+                type: "Identifier",
+                name: "x",
+                range: [8, 9],
+                loc: {
+                  start: {line: 1, column: 8},
+                  end: {line: 1, column: 9}
+                }
+              }
+            ],
+            range: [6, 10],
+            loc: {
+              start: {line: 1, column: 6},
+              end: {line: 1, column: 10}
+            }
+          },
+          right: {
+            type: "Identifier",
+            name: "array",
+            range: [14, 19],
+            loc: {
+              start: {line: 1, column: 14},
+              end: {line: 1, column: 19}
+            }
+          },
+          range: [1, 20],
+          loc: {
+            start: {line: 1, column: 1},
+            end: {line: 1, column: 20}
+          },
+          of: true
+        },
+        {
+          type: "ComprehensionBlock",
+          left: {
+            type: "ObjectPattern",
+            properties: [
+              {
+                type: "Property",
+                key: {
+                  type: "MemberExpression",
+                  computed: false,
+                  object: {
+                    type: "Identifier",
+                    name: "start",
+                    range: [28, 33],
+                    loc: {
+                      start: {line: 1, column: 28},
+                      end: {line: 1, column: 33}
+                    }
+                  },
+                  property: {
+                    type: "Identifier",
+                    name: "x",
+                    range: [34, 35],
+                    loc: {
+                      start: {line: 1, column: 34},
+                      end: {line: 1, column: 35}
+                    }
+                  },
+                  range: [28, 35],
+                  loc: {
+                    start: {line: 1, column: 28},
+                    end: {line: 1, column: 35}
+                  }
+                },
+                value: {
+                  type: "Identifier",
+                  name: "x",
+                  range: [38, 39],
+                  loc: {
+                    start: {line: 1, column: 38},
+                    end: {line: 1, column: 39}
+                  }
+                },
+                kind: "init",
+                method: false,
+                shorthand: false,
+                computed: true,
+                range: [27, 39],
+                loc: {
+                  start: {line: 1, column: 27},
+                  end: {line: 1, column: 39}
+                }
+              },
+              {
+                type: "Property",
+                key: {
+                  type: "MemberExpression",
+                  computed: false,
+                  object: {
+                    type: "Identifier",
+                    name: "start",
+                    range: [42, 47],
+                    loc: {
+                      start: {line: 1, column: 42},
+                      end: {line: 1, column: 47}
+                    }
+                  },
+                  property: {
+                    type: "Identifier",
+                    name: "y",
+                    range: [48, 49],
+                    loc: {
+                      start: {line: 1, column: 48},
+                      end: {line: 1, column: 49}
+                    }
+                  },
+                  range: [42, 49],
+                  loc: {
+                    start: {line: 1, column: 42},
+                    end: {line: 1, column: 49}
+                  }
+                },
+                value: {
+                  type: "Identifier",
+                  name: "y",
+                  range: [52, 53],
+                  loc: {
+                    start: {line: 1, column: 52},
+                    end: {line: 1, column: 53}
+                  }
+                },
+                kind: "init",
+                method: false,
+                shorthand: false,
+                computed: true,
+                range: [41, 53],
+                loc: {
+                  start: {line: 1, column: 41},
+                  end: {line: 1, column: 53}
+                }
+              }
+            ],
+            range: [26, 54],
+            loc: {
+              start: {line: 1, column: 26},
+              end: {line: 1, column: 54}
+            }
+          },
+          right: {
+            type: "Identifier",
+            name: "array2",
+            range: [58, 64],
+            loc: {
+              start: {line: 1, column: 58},
+              end: {line: 1, column: 64}
+            }
+          },
+          range: [21, 65],
+          loc: {
+            start: {line: 1, column: 21},
+            end: {line: 1, column: 65}
+          },
+          of: true
+        }
+      ],
+      body: {
+        type: "Identifier",
+        name: "x",
+        range: [66, 67],
+        loc: {
+          start: {line: 1, column: 66},
+          end: {line: 1, column: 67}
+        }
+      },
+      range: [0, 68],
+      loc: {
+        start: {line: 1, column: 0},
+        end: {line: 1, column: 68}
+      }
+    },
+    range: [0, 68],
+    loc: {
+      start: {line: 1, column: 0},
+      end: {line: 1, column: 68}
+    }
+  }],
+  range: [0, 68],
+  loc: {
+    start: {line: 1, column: 0},
+    end: {line: 1, column: 68}
+  }
+}, {
+  ecmaVersion: 6,
+  ranges: true,
+  locations: true
+});
+
 // Harmony: Object Literal Property Value Shorthand
 
 test("x = { y, z }", {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-acorn-jsx.git



More information about the Pkg-javascript-commits mailing list