From 56ac964e54aca82f10879db0332012bb729f5df3 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Fri, 7 Nov 2014 13:51:31 +1100 Subject: [PATCH] remove newline assurance and add optional Error constructor to File::errorWithNode --- lib/6to5/file.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/6to5/file.js b/lib/6to5/file.js index 0da0505506..7aae813d31 100644 --- a/lib/6to5/file.js +++ b/lib/6to5/file.js @@ -81,16 +81,11 @@ File.prototype.addDeclaration = function (name) { return uid; }; -File.prototype.errorWithNode = function (node, msg) { - var loc; +File.prototype.errorWithNode = function (node, msg, Error) { + Error = Error || SyntaxError; - if (node.loc) { - loc = node.loc.start; - } else { - loc = acorn.getLineInfo(this.code, node.start); - } - - var err = new SyntaxError("Line " + loc.line + ": " + msg); + var loc = node.loc.start; + var err = new Error("Line " + loc.line + ": " + msg); err.loc = loc; return err; }; @@ -98,9 +93,8 @@ File.prototype.errorWithNode = function (node, msg) { File.prototype.parse = function (code) { var self = this; - code = code.trimRight() + "\n"; - this.code = code; + code = this.parseShebang(code); return util.parse(this.opts, code, function (tree) {