Skip to content

Instantly share code, notes, and snippets.

#lang racket
(require json
rackunit)
(define path-to-shell "/Users/clements/jsshell-mac/js")
(define path-to-target-file "/tmp/foo")
;; convert a JS string to a list of varrefs
(define (str->varrefs str)
var fs = require("fs");
var uglify = require("uglify-js"),
jsp = uglify.parser,
pro = uglify.uglify;
var code = fs.readFileSync(process.argv[2], "utf8");
var ast = jsp.parse(code);
var varList = new Array();
const literals = ["null", "true", "false", "this"];
<html>
<head>
<script type="text/javascript">
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
Components.utils.import("resource://gre/modules/reflect.jsm");
var varrefs = []; //holds our varref list
//try and open source file and parse it
/***
* @dependency jslint.js
*/
/**
* Uses JSLINT parse tree to find variable references.
* A variable reference is labeled as an identifier, and has no children,
* (identifiers such as 'var' would have children).
* @param source (or string (array string))
* @return (array string)
@jbclements
jbclements / steigerwald.js
Created April 11, 2012 16:55
Steigerwald
impress_src = read("test.js");
program = Reflect.parse(impress_src);
print(node_varrefs(program));
// Accepts any number of Node objects or arrays of node objects defined by the Parser API
// Returns an array of all varrefs declared in those nodes
function node_varrefs() {
// Step through the array of nodes
var args = Array.prototype.slice.call(arguments);
var SAMPLE_FILE = 'sample2.js';
var jsCode = read(SAMPLE_FILE);
var jsAST = Reflect.parse(jsCode);
JSON.parse(JSON.stringify(jsAST), function(key, value) {
if (key == "name") {
print (value);
}
});
from slimit.parser import Parser
from slimit.visitors import nodevisitor
from slimit import ast
from sets import Set
# create parser instance
parser = Parser()
# parse the javascript code
#tree = parser.parse('for(var i=0; i<10; i++) {var x=5+i;}')
function getIdentifiersFromFile(filename) { return getIdentifiers(read(filename)); }
function getVarsFromFile(filename) { return getVars(read(filename)); }
/**
* Returns a list of all the identifiers in the source passed in. This will
* include property names, labels, and several other things (not just
* variables). These names we be deduplicated. However, it's much cleaner (and
* a bit faster) than the getVars function. This function operates by handing
* in a callback for identifiers to the parser. This callback is called for all
* Identifiers which the parser encounters and keeps track of all the names of
var fs = require("fs");
var jsp = require("uglify-js").parser;
var pro = require("uglify-js").uglify;
fs.readFile(process.argv[2], "utf8", function(err, data) {
if (err) throw err;
var ast = jsp.parse(data);
var w = pro.ast_walker(), walk = w.walk;
var vars = {};
var fs = require("fs");
var uglify = require("uglify-js"),
jsp = uglify.parser,
pro = uglify.uglify;
var code = fs.readFileSync(process.argv[2], "utf8");
var ast = jsp.parse(code);
var varList = new Array();
const literals = ["null", "true", "false", "this"];