This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
* @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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;}') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]; |