[Pkg-javascript-commits] [node-acorn-jsx] 111/484: Properly back up line state when re-reading a token on strict mode

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:12 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 54e78b7035bbb54862df3fd83f4778380e33c68d
Author: Marijn Haverbeke <marijnh at gmail.com>
Date:   Mon Mar 25 15:10:55 2013 +0100

    Properly back up line state when re-reading a token on strict mode
    
    Issue #38
---
 acorn.js      |  4 +++
 index.html    |  6 ++++-
 test/tests.js | 80 +++++++++++++++++++++++++++++------------------------------
 3 files changed, 49 insertions(+), 41 deletions(-)

diff --git a/acorn.js b/acorn.js
index fbd3c92..0500d20 100644
--- a/acorn.js
+++ b/acorn.js
@@ -945,6 +945,10 @@
   function setStrict(strct) {
     strict = strct;
     tokPos = lastEnd;
+    while (tokPos < tokLineStart) {
+      tokLineStart = input.lastIndexOf("\n", tokLineStart - 2) + 1;
+      --tokCurLine;
+    }
     skipSpace();
     readToken();
   }
diff --git a/index.html b/index.html
index 257958c..76826c3 100644
--- a/index.html
+++ b/index.html
@@ -590,7 +590,7 @@ will return <code>null</code> unless the integer has exactly <code>len</code> di
           <span class="k">case</span> <span class="mi">85</span><span class="o">:</span> <span class="nx">out</span> <span class="o">+=</span> <span class="nb">String</span><span class="p">.</span><span class="nx">fromCharCode</span><span class="p">(</span><span class="nx">readHexChar</span><span class="p">(</span><span class="mi">8</span><span class="p">));</span> <span class="k">break</span><span class="p">;</span> <span class="c1">// 'U'</span>
           <span class="k">case</span> <span class="mi">116</span><span class="o">:</span> <span class="nx">out</span> <span class="o">+=</span> <span class="s2">"\t"</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span> <span class="c1">// 't' -> '\t'</span>
           <span class="k">case</span> <span class="mi">98</span><span class="o">:</span> <span class="nx">out</span> <span class="o">+=</span> <span class="s2">"\b"</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span> <span class="c1">// 'b' -> '\b'</span>
-          <span class="k">case</span> <span class="mi">118</span><span class="o">:</span> <span class="nx">out</span> <span class="o">+=</span> <span class="s2">"\v"</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span> <span class="c1">// 'v' -> '\u000b'</span>
+          <span class="k">case</span> <span class="mi">118</span><span class="o">:</span> <span class="nx">out</span> <span class="o">+=</span> <span class="s2">"\u000b"</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span> <span class="c1">// 'v' -> '\u000b'</span>
           <span class="k">case</span> <span class="mi">102</span><span class="o">:</span> <span class="nx">out</span> <span class="o">+=</span> <span class="s2">"\f"</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span> <span class="c1">// 'f' -> '\f'</span>
           <span class="k">case</span> <span class="mi">48</span><span class="o">:</span> <span class="nx">out</span> <span class="o">+=</span> <span class="s2">"\0"</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span> <span class="c1">// 0 -> '\0'</span>
           <span class="k">case</span> <span class="mi">13</span><span class="o">:</span> <span class="k">if</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="p">)</span> <span class="o">===</span> <span class="mi">10</span><span class="p">)</span> <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span> <span class="c1">// '\r\n [...]
@@ -678,6 +678,10 @@ precedence levels that JavaScript defines.</p>             </td>             <td
 tests ("use strict"; 010; -- should fail).</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">setStrict</span><span class="p">(</span><span class="nx">strct</span><span class="p">)</span> <span class="p">{</span>
     <span class="nx">strict</span> <span class="o">=</span> <span class="nx">strct</span><span class="p">;</span>
     <span class="nx">tokPos</span> <span class="o">=</span> <span class="nx">lastEnd</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">tokLineStart</span><span class="p">)</span> <span class="p">{</span>
+      <span class="nx">tokLineStart</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">lastIndexOf</span><span class="p">(</span><span class="s2">"\n"</span><span class="p">,</span> <span class="nx">tokLineStart</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
+      <span class="o">--</span><span class="nx">tokCurLine</span><span class="p">;</span>
+    <span class="p">}</span>
     <span class="nx">skipSpace</span><span class="p">();</span>
     <span class="nx">readToken</span><span class="p">();</span>
   <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-79">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-79">¶</a>               </div>               <p>Start an AST node, attaching a start offset.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">node_t</ [...]
diff --git a/test/tests.js b/test/tests.js
index b4c0005..4bc8754 100644
--- a/test/tests.js
+++ b/test/tests.js
@@ -25798,33 +25798,33 @@ test("foo: if (true) break foo;", {
   ]
 });
 
-test("(function () { 'use strict'; '\0'; }())", {
+test("(function () {\n 'use strict';\n '\0';\n}())", {
   type: "Program",
   start: 0,
-  end: 38,
+  end: 40,
   loc: {
     start: {
       line: 1,
       column: 0
     },
     end: {
-      line: 1,
-      column: 38
+      line: 4,
+      column: 4
     }
   },
   body: [
     {
       type: "ExpressionStatement",
       start: 0,
-      end: 38,
+      end: 40,
       loc: {
         start: {
           line: 1,
           column: 0
         },
         end: {
-          line: 1,
-          column: 38
+          line: 4,
+          column: 4
         }
       },
       expression: {
@@ -25836,22 +25836,22 @@ test("(function () { 'use strict'; '\0'; }())", {
             column: 0
           },
           end: {
-            line: 1,
-            column: 38
+            line: 4,
+            column: 4
           }
         },
         callee: {
           type: "FunctionExpression",
           start: 1,
-          end: 35,
+          end: 37,
           loc: {
             start: {
               line: 1,
               column: 1
             },
             end: {
-              line: 1,
-              column: 35
+              line: 4,
+              column: 1
             }
           },
           id: null,
@@ -25859,44 +25859,44 @@ test("(function () { 'use strict'; '\0'; }())", {
           body: {
             type: "BlockStatement",
             start: 13,
-            end: 35,
+            end: 37,
             loc: {
               start: {
                 line: 1,
                 column: 13
               },
               end: {
-                line: 1,
-                column: 35
+                line: 4,
+                column: 1
               }
             },
             body: [
               {
                 type: "ExpressionStatement",
-                start: 15,
-                end: 28,
+                start: 16,
+                end: 29,
                 loc: {
                   start: {
-                    line: 1,
-                    column: 15
+                    line: 2,
+                    column: 1
                   },
                   end: {
-                    line: 1,
-                    column: 28
+                    line: 2,
+                    column: 14
                   }
                 },
                 expression: {
                   type: "Literal",
-                  start: 15,
-                  end: 27,
+                  start: 16,
+                  end: 28,
                   loc: {
                     start: {
-                      line: 1,
-                      column: 15
+                      line: 2,
+                      column: 1
                     },
                     end: {
-                      line: 1,
-                      column: 27
+                      line: 2,
+                      column: 13
                     }
                   },
                   value: "use strict"
@@ -25904,30 +25904,30 @@ test("(function () { 'use strict'; '\0'; }())", {
               },
               {
                 type: "ExpressionStatement",
-                start: 29,
-                end: 33,
+                start: 31,
+                end: 35,
                 loc: {
                   start: {
-                    line: 1,
-                    column: 29
+                    line: 3,
+                    column: 1
                   },
                   end: {
-                    line: 1,
-                    column: 33
+                    line: 3,
+                    column: 5
                   }
                 },
                 expression: {
                   type: "Literal",
-                  start: 29,
-                  end: 32,
+                  start: 31,
+                  end: 34,
                   loc: {
                     start: {
-                      line: 1,
-                      column: 29
+                      line: 3,
+                      column: 1
                     },
                     end: {
-                      line: 1,
-                      column: 32
+                      line: 3,
+                      column: 4
                     }
                   },
                   value: "\u0000"
@@ -25937,7 +25937,7 @@ test("(function () { 'use strict'; '\0'; }())", {
           }
         },
         arguments: [],
-        end: 38
+        end: 40
       }
     }
   ]

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