Skip to content

Instantly share code, notes, and snippets.

@jbclements
Created April 11, 2012 18:06
Show Gist options
  • Save jbclements/2361027 to your computer and use it in GitHub Desktop.
Save jbclements/2361027 to your computer and use it in GitHub Desktop.
Augustine
<html>
<head>
<script src='jslint.js'></script>
<script>
function findVariables() {
var text = document.getElementById('inputJS').value;
var output = "";
var res = JSLINT(text, {'bitwise': true, 'browser': true,
'cap': true, 'continue': true,
'debug': true, 'devel': true,
'eqeq': true, 'evil': true,
'forin': true, 'fragment': true,
'newcap': true, 'nomen': true,
'on': true, 'plusplus': true,
'regexp': true, 'sloppy': true,
'stupid': true, 'undef': true,
'unparam': true, 'vars': true,
'white': true, 'windows': true});
if (res)
{
output = JSON.stringify(JSLINT.tree, [
'label', 'id', 'string', 'number', 'arity', 'name', 'first',
'second', 'third', 'block', 'else', 'quote', 'flag', 'type'
], 4);
var identifiers = {};
var invokeCount = 0;
var uniqueCount = 0;
output.replace(/\{\s+"id":\s+"\(identifier\)",\s+"string":\s+"([^"]+)"\s+\}/g, function(match, contents, offset, s) {
invokeCount++;
//if (identifiers.hasOwnProperty(contents)) {
if (Object.prototype.hasOwnProperty.call(identifiers, contents)) {
uniqueCount++;
}
//console.log("contents: " + contents);
identifiers[contents] = true;
});
output = "Number of unique identifiers: " + uniqueCount + "<br />";
output += "Number of invocations: " + invokeCount + "<br />";
output += "<br />Identifiers:<br />";
output += "<ul>";
var id;
for (id in identifiers) {
output += "<li>" + id + "</li>";
}
output += "</ul>";
}
else
{
output = "Error Parsing JS<br />" + JSLINT.report(true);
}
document.getElementById('result').innerHTML = output;
}
</script>
</head>
<body>
<textarea id='inputJS' rows=20 cols=80>
</textarea>
<br />
<input type='button' value='Find Variables' onClick='findVariables();'/>
<hr />
<div id='result'>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment