[Pkg-javascript-commits] [node-lexical-scope] 25/83: factored out ast walking to astw

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 15 09:45:47 UTC 2017


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

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

commit 53f0159c2d58a74bb36609f01ff3582a57fa9c14
Author: James Halliday <mail at substack.net>
Date:   Sat Mar 2 02:36:39 2013 -0800

    factored out ast walking to astw
---
 index.js     | 29 ++++-------------------------
 package.json |  4 ++--
 2 files changed, 6 insertions(+), 27 deletions(-)

diff --git a/index.js b/index.js
index 6987a49..0e9fadf 100644
--- a/index.js
+++ b/index.js
@@ -1,4 +1,4 @@
-var esprima = require('esprima');
+var astw = require('astw');
 
 module.exports = function (src) {
     var locals = {};
@@ -6,9 +6,9 @@ module.exports = function (src) {
     var exported = {};
     
     src = String(src).replace(/^#![^\n]*\n/, '');
-    var ast = esprima.parse(src);
+    var walk = astw(src);
     
-    walk(ast, undefined, function (node) {
+    walk(function (node) {
         if (node.type === 'VariableDeclaration') {
             // take off the leading `var `
             var id = getScope(node);
@@ -23,7 +23,7 @@ module.exports = function (src) {
         }
     });
     
-    walk(ast, undefined, function (node) {
+    walk(function (node) {
         if (node.type === 'Identifier'
         && lookup(node) === undefined) {
             if (node.parent.type === 'MemberExpression'
@@ -155,24 +155,3 @@ function indexOf (xs, x) {
     }
     return -1;
 }
-
-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);
-}
diff --git a/package.json b/package.json
index c0b2f23..37d84af 100644
--- a/package.json
+++ b/package.json
@@ -1,10 +1,10 @@
 {
     "name": "lexical-scope",
-    "version": "0.0.5",
+    "version": "0.0.6",
     "description": "detect global and local lexical identifiers from javascript source code",
     "main": "index.js",
     "dependencies": {
-        "esprima": "1.0.2"
+        "astw": "~0.0.0"
     },
     "devDependencies": {
         "tap": "~0.4.0",

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



More information about the Pkg-javascript-commits mailing list