[Pkg-javascript-commits] [node-detective] 25/119: Replaced burrito with raw Uglify-JS to dramatically increase performance.
Bastien Roucariès
rouca at moszumanska.debian.org
Wed Sep 6 09:44:31 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-detective.
commit 3efb2efedb86df78fcde9f176fee208822e31822
Author: Alexander Shtuchkin <ashtuchkin at gmail.com>
Date: Fri Mar 2 13:19:19 2012 +0400
Replaced burrito with raw Uglify-JS to dramatically increase performance.
---
index.js | 32 +++++++++++++++++++++++++++-----
package.json | 4 ++--
2 files changed, 29 insertions(+), 7 deletions(-)
diff --git a/index.js b/index.js
index 0dfb5e1..6e76e2e 100644
--- a/index.js
+++ b/index.js
@@ -1,4 +1,26 @@
-var burrito = require('burrito');
+var uglify = require('uglify-js');
+
+
+var traverse = function (node, cb) {
+ // Call cb on all good AST nodes.
+ if (Array.isArray(node) && node[0] && typeof node[0] === 'object' && node[0].name)
+ cb({name: node[0].name, value: node.slice(1)});
+
+ // Traverse down the tree on arrays and objects.
+ if (Array.isArray(node) || Object.prototype.toString.call(node) === "[object Object]")
+ for (var key in node)
+ traverse(node[key], cb);
+};
+
+var process = function (src, cb) {
+ var ast = uglify.parser.parse(src.toString(), false, true);
+ traverse(ast, cb);
+};
+
+var deparse = function (ast) {
+ return uglify.uglify.gen_code(ast);
+};
+
var exports = module.exports = function (src, opts) {
return exports.find(src, opts).strings;
@@ -12,7 +34,7 @@ exports.find = function (src, opts) {
if (src.toString().indexOf(word) == -1) return modules;
- burrito(src, function (node) {
+ process(src, function (node) {
var isRequire = node.name === 'call'
&& node.value[0][0] === 'name'
&& node.value[0][1] === word
@@ -24,7 +46,7 @@ exports.find = function (src, opts) {
modules.strings.push(expr[1]);
}
else {
- modules.expressions.push(burrito.deparse(expr));
+ modules.expressions.push(deparse(expr));
}
}
@@ -40,7 +62,7 @@ exports.find = function (src, opts) {
modules.strings.push(expr[1]);
}
else {
- modules.expressions.push(burrito.deparse(expr));
+ modules.expressions.push(deparse(expr));
}
}
@@ -56,7 +78,7 @@ exports.find = function (src, opts) {
modules.strings.push(expr[1]);
}
else {
- modules.expressions.push(burrito.deparse(expr));
+ modules.expressions.push(deparse(expr));
}
}
});
diff --git a/package.json b/package.json
index 12bb33f..ee98ade 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name" : "detective",
"description" : "Find all calls to require() no matter how crazily nested using a proper walk of the AST",
- "version" : "0.0.4",
+ "version" : "0.0.5",
"repository" : {
"type" : "git",
"url" : "git://github.com/substack/node-detective.git"
@@ -22,7 +22,7 @@
"test" : "expresso"
},
"dependencies" : {
- "burrito" : "0.2.x"
+ "uglify-js" : "1.x"
},
"devDependencies" : {
"expresso" : "=0.7.x"
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-detective.git
More information about the Pkg-javascript-commits
mailing list