add whitespace option and move util.errorWithNode to File

This commit is contained in:
Sebastian McKenzie
2014-11-03 11:09:58 +11:00
parent bf61c1e85d
commit 85f0f6fb14
2 changed files with 25 additions and 24 deletions

View File

@@ -4,6 +4,7 @@ var SHEBANG_REGEX = /^\#\!.*/;
var transform = require("./transform");
var generate = require("./generator");
var acorn = require("acorn-6to5");
var util = require("./util");
var b = require("./builders");
var _ = require("lodash");
@@ -21,11 +22,12 @@ File.normaliseOptions = function (opts) {
opts = opts || {};
_.defaults(opts, {
blacklist: [],
whitelist: [],
sourceMap: false,
filename: "unknown",
modules: "common"
whitespace: true,
blacklist: [],
whitelist: [],
sourceMap: false,
filename: "unknown",
modules: "common"
});
_.defaults(opts, {
@@ -78,10 +80,25 @@ File.prototype.addDeclaration = function (name) {
return uid;
};
File.prototype.errorWithNode = function (node, msg) {
var loc
if (node.loc) {
loc = node.loc.start;
} else {
loc = acorn.getLineInfo(this.code, node.start);
}
var err = new SyntaxError("Line " + loc.line + ": " + msg);
err.lineNumber = loc.line;
err.column = loc.column;
return err;
};
File.prototype.parse = function (code) {
var self = this;
this.code = code;
this.code = code;
code = this.parseShebang(code);
return util.parse(this.opts, code, function (tree) {