Merge acorn 0.12.1 and acorn-babel (formerly "embed acorn" in the original git history).
This commit is contained in:
54
bin/acorn
54
bin/acorn
@@ -1,54 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
var acorn = require("../acorn.js");
|
||||
|
||||
var infile, parsed, tokens, options = {}, silent = false, compact = false, tokenize = false;
|
||||
|
||||
function help(status) {
|
||||
var print = (status == 0) ? console.log : console.error;
|
||||
print("usage: " + path.basename(process.argv[1]) + " [--ecma3|--ecma5|--ecma6] [--strictSemicolons]");
|
||||
print(" [--tokenize] [--locations] [--compact] [--silent] [--help] [--] infile");
|
||||
process.exit(status);
|
||||
}
|
||||
|
||||
for (var i = 2; i < process.argv.length; ++i) {
|
||||
var arg = process.argv[i];
|
||||
if (arg[0] != "-" && !infile) infile = arg;
|
||||
else if (arg == "--" && !infile && i + 2 == process.argv.length) infile = process.argv[++i];
|
||||
else if (arg == "--ecma3") options.ecmaVersion = 3;
|
||||
else if (arg == "--ecma5") options.ecmaVersion = 5;
|
||||
else if (arg == "--ecma6") options.ecmaVersion = 6;
|
||||
else if (arg == "--ecma7") options.ecmaVersion = 7;
|
||||
else if (arg == "--strictSemicolons") options.strictSemicolons = true;
|
||||
else if (arg == "--locations") options.locations = true;
|
||||
else if (arg == "--silent") silent = true;
|
||||
else if (arg == "--compact") compact = true;
|
||||
else if (arg == "--help") help(0);
|
||||
else if (arg == "--tokenize") tokenize = true;
|
||||
else help(1);
|
||||
}
|
||||
|
||||
try {
|
||||
var code = fs.readFileSync(infile, "utf8");
|
||||
|
||||
if (!tokenize)
|
||||
parsed = acorn.parse(code, options);
|
||||
else {
|
||||
var get = acorn.tokenize(code, options);
|
||||
tokens = [];
|
||||
while (true) {
|
||||
var token = get();
|
||||
tokens.push(token);
|
||||
if (token.type.type == "eof")
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
console.log(e.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (!silent)
|
||||
console.log(JSON.stringify(tokenize ? tokens : parsed, null, compact ? null : 2));
|
||||
@@ -1,6 +0,0 @@
|
||||
# Combine existing list of authors with everyone known in git, sort, add header.
|
||||
tail --lines=+3 AUTHORS > AUTHORS.tmp
|
||||
git log --format='%aN' | grep -v abraidwood >> AUTHORS.tmp
|
||||
echo -e "List of Acorn contributors. Updated before every release.\n" > AUTHORS
|
||||
sort -u AUTHORS.tmp >> AUTHORS
|
||||
rm -f AUTHORS.tmp
|
||||
@@ -1,45 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var fs = require("fs");
|
||||
|
||||
var acornSrc = fs.readFileSync(require.resolve("../acorn"), "utf8");
|
||||
var acorn = require("../acorn"), walk = require("../util/walk");
|
||||
|
||||
var ast = acorn.parse(acornSrc);
|
||||
var touchups = [], uses = [];
|
||||
|
||||
walk.simple(ast, {
|
||||
FunctionDeclaration: function(node) {
|
||||
if (node.id.name == "makePredicate")
|
||||
touchups.push({text: "// Removed to create an eval-free library", from: node.start, to: node.end});
|
||||
},
|
||||
VariableDeclaration: function(node) {
|
||||
node.declarations.forEach(function(decl) {
|
||||
if (decl.init && decl.init.type == "CallExpression" &&
|
||||
decl.init.callee.name == "makePredicate")
|
||||
uses.push(decl);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var results = Object.create(null);
|
||||
var functions = new Function("predicates", acornSrc.replace(
|
||||
/\}\);\s*$/, uses.map(function(decl) {
|
||||
return "predicates[" + JSON.stringify(decl.id.name) + "] = " + decl.id.name + ";";
|
||||
}).join("") + "});"))(results);
|
||||
|
||||
uses.forEach(function(decl) {
|
||||
touchups.push({text: results[decl.id.name].toString(),
|
||||
from: decl.init.start, to: decl.init.end});
|
||||
});
|
||||
|
||||
var result = "", pos = 0;
|
||||
touchups.sort(function(a, b) { return a.from - b.from; });
|
||||
touchups.forEach(function(touchup) {
|
||||
result += acornSrc.slice(pos, touchup.from);
|
||||
result += touchup.text;
|
||||
pos = touchup.to;
|
||||
});
|
||||
result += acornSrc.slice(pos);
|
||||
|
||||
process.stdout.write(result);
|
||||
Reference in New Issue
Block a user