[Pkg-javascript-commits] [node-acorn-jsx] 186/484: Check duplicate argument names for rest params

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:24 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 7f0f07e1f9c227d61147f2962f3418149b55e66a
Author: Marijn Haverbeke <marijnh at gmail.com>
Date:   Wed May 28 23:24:10 2014 +0200

    Check duplicate argument names for rest params
    
    Issue #79
---
 acorn.js   | 13 +++++++++++--
 index.html | 19 +++++++++++++------
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/acorn.js b/acorn.js
index 9201398..ad2f609 100644
--- a/acorn.js
+++ b/acorn.js
@@ -1741,8 +1741,17 @@
     // are not repeated, and it does not try to bind the words `eval`
     // or `arguments`.
     if (strict || node.body.body.length && isUseStrict(node.body.body[0])) {
-      for (var i = node.id ? -1 : 0; i < node.params.length; ++i) {
-        var id = i < 0 ? node.id : node.params[i];
+      // Negative indices are used to reuse loop body for node.rest and node.id
+      for (var i = -2, id; i < node.params.length; ++i) {
+        if (i >= 0) {
+          id = node.params[i];
+        } else if (i == -2) {
+          if (node.rest) id = node.rest;
+          else continue;
+        } else {
+          if (node.id) id = node.id;
+          else continue;
+        }
         if (isStrictReservedWord(id.name) || isStrictBadIdWord(id.name))
           raise(id.start, "Defining '" + id.name + "' in strict mode");
         if (i >= 0) for (var j = 0; j < i; ++j) if (id.name === node.params[j].name)
diff --git a/index.html b/index.html
index f336e3c..1f74c47 100644
--- a/index.html
+++ b/index.html
@@ -473,7 +473,7 @@ number, or float.</p>             </td>             <td class="code">
 often referred to. <code>finishOp</code> simply skips the amount of
 characters it is given as second argument, and returns a token
 of the type given by its first argument.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="k">case</span> <span class="mi">47</span><span class="o">:</span> <span class="c1">// '/'</span>
-      <span class="k">return</span> <span class="nx">readToken_slash</span><span class="p">(</span><span class="nx">code</span><span class="p">);</span>
+      <span class="k">return</span> <span class="nx">readToken_slash</span><span class="p">();</span>
 
     <span class="k">case</span> <span class="mi">37</span><span class="o">:</span> <span class="k">case</span> <span class="mi">42</span><span class="o">:</span> <span class="c1">// '%*'</span>
       <span class="k">return</span> <span class="nx">readToken_mult_modulo</span><span class="p">();</span>
@@ -1308,9 +1308,16 @@ flag (restore them to their old value afterwards).</p>             </td>
     <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">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></pre></div>             </td>           </tr>                               <tr id="section-123">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-123">¶</a>               </div>       [...]
 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="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 class="nx">length</span> <span class="o">&&</span> <span class="nx">isUseStrict</span><spa [...]
-      <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="nx">node</span><span class="p">.</span><span class="nx">id</span> <span class="o">?</span> <span class="o">-</span><span class="mi">1</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">node</span><span class="p">.</span><span class="nx">para [...]
-        <span class="kd">var</span> <span class="nx">id</span> <span class="o">=</span> <span class="nx">i</span> <span class="o"><</span> <span class="mi">0</span> <span class="o">?</span> <span class="nx">node</span><span class="p">.</span><span class="nx">id</span> <span class="o">:</span> <span class="nx">node</span><span class="p">.</span><span class="nx">params</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
+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="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 class="nx">length</span> <span class="o">&&</span> <span class="nx">isUseStrict</span><spa [...]
+        <span class="k">if</span> <span class="p">(</span><span class="nx">i</span> <span class="o">>=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+          <span class="nx">id</span> <span class="o">=</span> <span class="nx">node</span><span class="p">.</span><span class="nx">params</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
+        <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">i</span> <span class="o">==</span> <span class="o">-</span><span class="mi">2</span><span class="p">)</span> <span class="p">{</span>
+          <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">id</span> <span class="o">=</span> <span class="nx">node</span><span class="p">.</span><span class="nx">rest</span><span class="p">;</span>
+          <span class="k">else</span> <span class="k">continue</span><span class="p">;</span>
+        <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+          <span class="k">if</span> <span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">id</span><span class="p">)</span> <span class="nx">id</span> <span class="o">=</span> <span class="nx">node</span><span class="p">.</span><span class="nx">id</span><span class="p">;</span>
+          <span class="k">else</span> <span class="k">continue</span><span class="p">;</span>
+        <span class="p">}</span>
         <span class="k">if</span> <span class="p">(</span><span class="nx">isStrictReservedWord</span><span class="p">(</span><span class="nx">id</span><span class="p">.</span><span class="nx">name</span><span class="p">)</span> <span class="o">||</span> <span class="nx">isStrictBadIdWord</span><span class="p">(</span><span class="nx">id</span><span class="p">.</span><span class="nx">name</span><span class="p">))</span>
           <span class="nx">raise</span><span class="p">(</span><span class="nx">id</span><span class="p">.</span><span class="nx">start</span><span class="p">,</span> <span class="s2">"Defining '"</span> <span class="o">+</span> <span class="nx">id</span><span class="p">.</span><span class="nx">name</span> <span class="o">+</span> <span class="s2">"' in strict mode"</span><span class="p">);</span>
         <span class="k">if</span> <span class="p">(</span><span class="nx">i</span> <span class="o">>=</span> <span class="mi">0</span><span class="p">)</span> <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">j</span> <span class="o"><</span> <span class="nx">i</span><span class="p">;</span> <span class="o">++</span><span class="nx">j</ [...]
@@ -1319,7 +1326,7 @@ or <code>arguments</code>.</p>             </td>             <td class="code">
     <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-124">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-124">¶</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-125">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-125">¶</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
@@ -1335,7 +1342,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-125">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-125">¶</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-126">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-126">¶</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>

-- 
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