From 896929378ec3f28f7b366c4b5f61b9eab3b7fcf4 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Wed, 12 Nov 2014 12:17:26 +1100 Subject: [PATCH] add util.trimRight method - fixes #147 --- lib/6to5/generation/buffer.js | 4 ++-- lib/6to5/util.js | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/6to5/generation/buffer.js b/lib/6to5/generation/buffer.js index bbee2de4a7..edd526ea4d 100644 --- a/lib/6to5/generation/buffer.js +++ b/lib/6to5/generation/buffer.js @@ -11,7 +11,7 @@ function Buffer(position, format) { } Buffer.prototype.get = function () { - return this.buf.trimRight(); + return util.trimRight(this.buf); }; Buffer.prototype.getIndent = function () { @@ -116,7 +116,7 @@ Buffer.prototype.endsWith = function (str) { Buffer.prototype.isLast = function (cha, trimRight) { var buf = this.buf; - if (trimRight) buf = buf.trimRight(); + if (trimRight) buf = util.trimRight(buf); var chars = [].concat(cha); return _.contains(chars, _.last(buf)); diff --git a/lib/6to5/util.js b/lib/6to5/util.js index 499ef4d234..3a2ae95e33 100644 --- a/lib/6to5/util.js +++ b/lib/6to5/util.js @@ -25,6 +25,10 @@ exports.resolve = function (loc) { } }; +exports.trimRight = function (str) { + return str.replace(/[\n\s]+$/g, ""); +}; + exports.list = function (val) { return val ? val.split(",") : []; };