[Pkg-javascript-commits] [node-astw] 01/30: ripped fast walker out of lexical-scope

Bastien Roucariès rouca at moszumanska.debian.org
Tue Sep 26 12:55:03 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-astw.

commit 2406bba5666008c222800702cd20c9f7c50a6ea4
Author: James Halliday <mail at substack.net>
Date:   Sat Mar 2 02:01:05 2013 -0800

    ripped fast walker out of lexical-scope
---
 index.js | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/index.js b/index.js
new file mode 100644
index 0000000..1d9b91d
--- /dev/null
+++ b/index.js
@@ -0,0 +1,29 @@
+var parse = require('esprima').parse;
+
+module.exports = function (src) {
+    var ast = typeof src === 'string' ? parse(src) : src;
+    return function (cb) {
+        return walk(ast, undefined, cb);
+    };
+};
+
+function walk (node, parent, cb) {
+    objectKeys(node).forEach(function (key) {
+        if (key === 'parent') return;
+        
+        var child = node[key];
+        if (isArray(child)) {
+            child.forEach(function (c) {
+                if (c && typeof c.type === 'string') {
+                    c.parent = node;
+                    walk(c, node, cb);
+                }
+            });
+        }
+        else if (child && typeof child.type === 'string') {
+            child.parent = node;
+            walk(child, node, cb);
+        }
+    });
+    cb(node);
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-astw.git



More information about the Pkg-javascript-commits mailing list