[Pkg-javascript-commits] [node-acorn-jsx] 275/484: Do not throw syntax error if strict mode function has same name as one of its parameters.

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:43 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 a246bf83d00f6888268997dbf55533bb33e66bd3
Author: Max Schaefer <max at semmle.com>
Date:   Fri Sep 5 11:18:49 2014 +0100

    Do not throw syntax error if strict mode function has same name as one of its parameters.
---
 acorn.js      |  2 +-
 index.html    | 16 +++++++---------
 test/tests.js |  2 ++
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/acorn.js b/acorn.js
index d7e6ce4..f01d4a4 100644
--- a/acorn.js
+++ b/acorn.js
@@ -2258,7 +2258,7 @@
     if (strict || !isExpression && node.body.body.length && isUseStrict(node.body.body[0])) {
       var nameHash = {};
       if (node.id)
-        checkFunctionParam(node.id, nameHash);
+        checkFunctionParam(node.id, {});
       for (var i = 0; i < node.params.length; i++)
         checkFunctionParam(node.params[i], nameHash);
       if (node.rest)
diff --git a/index.html b/index.html
index bfdc2e1..d0d5e8d 100644
--- a/index.html
+++ b/index.html
@@ -356,16 +356,16 @@ the next one's <code>tokStart</code> will point at the right position.</p>
                         <span class="nx">startLoc</span><span class="p">,</span> <span class="nx">options</span><span class="p">.</span><span class="nx">locations</span> <span class="o">&&</span> <span class="k">new</span> <span class="nx">Position</span><span class="p">);</span>
   <span class="p">}</span>
 
-  <span class="kd">function</span> <span class="nx">skipLineComment</span><span class="p">()</span> <span class="p">{</span>
+  <span class="kd">function</span> <span class="nx">skipLineComment</span><span class="p">(</span><span class="nx">startSkip</span><span class="p">)</span> <span class="p">{</span>
     <span class="kd">var</span> <span class="nx">start</span> <span class="o">=</span> <span class="nx">tokPos</span><span class="p">;</span>
     <span class="kd">var</span> <span class="nx">startLoc</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">onComment</span> <span class="o">&&</span> <span class="nx">options</span><span class="p">.</span><span class="nx">locations</span> <span class="o">&&</span> <span class="k">new</span> <span class="nx">Position</span><span class="p">;</span>
-    <span class="kd">var</span> <span class="nx">ch</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="o">+=</span><span class="mi">2</span><span class="p">);</span>
+    <span class="kd">var</span> <span class="nx">ch</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="o">+=</span><span class="nx">startSkip</span><span class="p">);</span>
     <span class="k">while</span> <span class="p">(</span><span class="nx">tokPos</span> <span class="o"><</span> <span class="nx">inputLen</span> <span class="o">&&</span> <span class="nx">ch</span> <span class="o">!==</span> <span class="mi">10</span> <span class="o">&&</span> <span class="nx">ch</span> <span class="o">!==</span> <span class="mi">13</span> <span class="o">&&</span> <span class="nx">ch</span> <span class="o">!==</span> <span class="mi">8232</sp [...]
       <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span>
       <span class="nx">ch</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</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">onComment</span><span class="p">)</span>
-      <span class="nx">options</span><span class="p">.</span><span class="nx">onComment</span><span class="p">(</span><span class="kc">false</span><span class="p">,</span> <span class="nx">input</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="nx">start</span> <span class="o">+</span> <span class="mi">2</span><span class="p">,</span> <span class="nx">tokPos</span><span class="p">),</span> <span class="nx">start</span><span class="p">,</span> [...]
+      <span class="nx">options</span><span class="p">.</span><span class="nx">onComment</span><span class="p">(</span><span class="kc">false</span><span class="p">,</span> <span class="nx">input</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="nx">start</span> <span class="o">+</span> <span class="nx">startSkip</span><span class="p">,</span> <span class="nx">tokPos</span><span class="p">),</span> <span class="nx">start</span><span class="p"> [...]
                         <span class="nx">startLoc</span><span class="p">,</span> <span class="nx">options</span><span class="p">.</span><span class="nx">locations</span> <span class="o">&&</span> <span class="k">new</span> <span class="nx">Position</span><span class="p">);</span>
   <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-61">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-61">¶</a>               </div>               <p>Called at the start of the parse and after every token. Skips
 whitespace and comments, and.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">skipSpace</span><span class="p">()</span> <span class="p">{</span>
@@ -396,7 +396,7 @@ whitespace and comments, and.</p>             </td>             <td class="code"
         <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">42</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// '*'</span>
           <span class="nx">skipBlockComment</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">next</span> <span class="o">===</span> <span class="mi">47</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// '/'</span>
-          <span class="nx">skipLineComment</span><span class="p">();</span>
+          <span class="nx">skipLineComment</span><span class="p">(</span><span class="mi">2</span><span class="p">);</span>
         <span class="p">}</span> <span class="k">else</span> <span class="k">break</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">ch</span> <span class="o">===</span> <span class="mi">160</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// '\xa0'</span>
         <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span>
@@ -457,8 +457,7 @@ into it.</p>
     <span class="kd">var</span> <span class="nx">next</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
     <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="nx">code</span><span class="p">)</span> <span class="p">{</span>
       <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">==</span> <span class="mi">45</span> <span class="o">&&</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span> <span class="o">+</span> <span class="mi">2</span><span class="p">)</span> <span class="o">==</span> <span class="mi">62</span> <span class="o">&&</span>
-          <span class="nx">newline</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">input</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="nx">lastEnd</span><span class="p">,</span> <span class="nx">tokPos</span><span class="p">)))</span> <span class="p">{</span></pre></div>             </td>           </tr>                               <tr id="section-64">             <td class="docs">      [...]
-        <span class="nx">skipLineComment</span><span class="p">();</span>
+          <span class="nx">newline</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">input</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="nx">lastEnd</span><span class="p">,</span> <span class="nx">tokPos</span><span class="p">)))</span> <span class="p">{</span></pre></div>             </td>           </tr>                               <tr id="section-64">             <td class="docs">      [...]
         <span class="nx">skipSpace</span><span class="p">();</span>
         <span class="k">return</span> <span class="nx">readToken</span><span class="p">();</span>
       <span class="p">}</span>
@@ -477,8 +476,7 @@ into it.</p>
       <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_bitShift</span><span class="p">,</span> <span class="nx">size</span><span class="p">);</span>
     <span class="p">}</span>
     <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">==</span> <span class="mi">33</span> <span class="o">&&</span> <span class="nx">code</span> <span class="o">==</span> <span class="mi">60</span> <span class="o">&&</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span> <span class="o">+</span> <span class="mi">2</span><span class="p [...]
-        <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span> <span class="o">+</span> <span class="mi">3</span><span class="p">)</span> <span class="o">==</span> <span class="mi">45</span><span class="p">)</span> <span class="p">{</span></pre></div>             </td>           </tr>                               <tr id="section-65">             <td class="docs">               <div class="pilwrap">    [...]
-      <span class="nx">skipLineComment</span><span class="p">();</span>
+        <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span> <span class="o">+</span> <span class="mi">3</span><span class="p">)</span> <span class="o">==</span> <span class="mi">45</span><span class="p">)</span> <span class="p">{</span></pre></div>             </td>           </tr>                               <tr id="section-65">             <td class="docs">               <div class="pilwrap">    [...]
       <span class="nx">skipSpace</span><span class="p">();</span>
       <span class="k">return</span> <span class="nx">readToken</span><span class="p">();</span>
     <span class="p">}</span>
@@ -1750,7 +1748,7 @@ 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>
       <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">checkFunctionParam</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">nameHash</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">id</span><span class="p">,</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">node</span><span class="p">.</span><span class="nx">params</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">checkFunctionParam</span><span class="p">(</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="nx">nameHash</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>
diff --git a/test/tests.js b/test/tests.js
index 211d4a1..b51695a 100644
--- a/test/tests.js
+++ b/test/tests.js
@@ -28785,3 +28785,5 @@ test("<!--\n;", {
     }
   });
 })();
+
+test("function f(f) { 'use strict'; }", {});

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