[Pkg-javascript-commits] [node-acorn-jsx] 88/484: Add walk.findNodeAt utility

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:09 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 e95c4cce50cfcb63813eb0ef1923cdf1ed827ea2
Author: Marijn Haverbeke <marijnh at gmail.com>
Date:   Mon Jan 28 13:00:08 2013 +0100

    Add walk.findNodeAt utility
---
 acorn_loose.js |  1 -
 index.html     |  2 +-
 util/walk.js   | 25 +++++++++++++++++++++++++
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/acorn_loose.js b/acorn_loose.js
index 771b205..f781bfa 100644
--- a/acorn_loose.js
+++ b/acorn_loose.js
@@ -65,7 +65,6 @@
 
         // Try to skip some text, based on the error message, and then continue
         var msg = e.message, pos = e.raisedAt, replace = true;
-        console.log(msg);
         if (/unterminated/i.test(msg)) {
           pos = lineEnd(e.pos);
           if (/string/.test(msg)) {
diff --git a/index.html b/index.html
index d2a46e1..0a3e945 100644
--- a/index.html
+++ b/index.html
@@ -312,7 +312,7 @@ the next one's <code>tokStart</code> will point at the right position.</p>
       <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="o">-</span> <span class="mi">1</span><span class="p">),</span> <s [...]
+      <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">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="nx">curLineLoc</span><span class="p">());</span>
   <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-54">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-54">¶</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>
diff --git a/util/walk.js b/util/walk.js
index c47132f..28659e4 100644
--- a/util/walk.js
+++ b/util/walk.js
@@ -41,6 +41,31 @@
     c(node, state);
   };
 
+  function Found(node, state) { this.node = node; this.state = state; }
+
+  // Find a node with a given start, end, and type (all are optional,
+  // null can be used as wildcard). Returns a {node, state} object, or
+  // undefined when it doesn't find a matching node.
+  exports.findNodeAt = function(node, start, end, targetType, base, state) {
+    try {
+      if (!base) base = exports;
+      var c = function(node, st, override) {
+        var type = override || node.type;
+        if ((start == null || node.start <= start) &&
+            (end == null || node.end >= end))
+          base[type](node, st, c);
+        if ((targetType == null || type == targetType) &&
+            (start == null || node.start == start) &&
+            (end == null || node.end == end))
+          throw new Found(node, st);
+      };
+      c(node, state);
+    } catch (e) {
+      if (e instanceof Found) return e;
+      throw e;
+    }
+  };
+
   // 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