[Pkg-javascript-commits] [node-acorn-jsx] 106/484: Add walk.findNodeBefore

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:11 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 0b10aa225629c27e070497e84b81ad1fe253bd0f
Author: Marijn Haverbeke <marijnh at gmail.com>
Date:   Thu Feb 28 19:27:29 2013 +0100

    Add walk.findNodeBefore
---
 index.html   |  3 ++-
 util/walk.js | 18 +++++++++++++++++-
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/index.html b/index.html
index fe54262..e005f75 100644
--- a/index.html
+++ b/index.html
@@ -464,7 +464,8 @@ of the type given by its first argument.</p>             </td>             <td c
   <span class="p">}</span>
 
   <span class="kd">function</span> <span class="nx">readToken</span><span class="p">(</span><span class="nx">forceRegexp</span><span class="p">)</span> <span class="p">{</span>
-    <span class="nx">tokStart</span> <span class="o">=</span> <span class="nx">tokPos</span><span class="p">;</span>
+    <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">forceRegexp</span><span class="p">)</span> <span class="nx">tokStart</span> <span class="o">=</span> <span class="nx">tokPos</span><span class="p">;</span>
+    <span class="k">else</span> <span class="nx">tokPos</span> <span class="o">=</span> <span class="nx">tokStart</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">options</span><span class="p">.</span><span class="nx">locations</span><span class="p">)</span> <span class="nx">tokStartLoc</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">line_loc_t</span><span class="p">;</span>
     <span class="k">if</span> <span class="p">(</span><span class="nx">forceRegexp</span><span class="p">)</span> <span class="k">return</span> <span class="nx">readRegexp</span><span class="p">();</span>
     <span class="k">if</span> <span class="p">(</span><span class="nx">tokPos</span> <span class="o">>=</span> <span class="nx">inputLen</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_eof</span><span class="p">);</span>
diff --git a/util/walk.js b/util/walk.js
index d6f2074..afed78c 100644
--- a/util/walk.js
+++ b/util/walk.js
@@ -103,7 +103,7 @@
       var c = function(node, st, override) {
         if (node.end < pos) return;
         var type = override || node.type;
-        if (node.start >= pos && test(node, type)) throw new Found(node, st);
+        if (node.start >= pos && test(type, node)) throw new Found(node, st);
         base[type](node, st, c);
       };
       c(node, state);
@@ -113,6 +113,22 @@
     }
   };
 
+  // Find the outermost matching node before a given position.
+  exports.findNodeBefore = function(node, pos, test, base, state) {
+    test = makeTest(test);
+    if (!base) base = exports.base;
+    var max;
+    var c = function(node, st, override) {
+      if (node.start > pos) return;
+      var type = override || node.type;
+      if (node.end <= pos && (!max || max.node.end < node.end) && test(type, node))
+        max = new Found(node, st);
+      base[type](node, st, c);
+    };
+    c(node, state);
+    return max;
+  };
+
   // Used to create a custom walker. Will fill in all missing node
   // type properties with the defaults.
   exports.make = function(funcs, base) {

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