diff --git a/CHANGELOG.md b/CHANGELOG.md index d384d705c4..0d5988ab85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.12.5 + + * Fix excessive whitespace trimming resulting in innaccurate sourcemap line. + # 1.12.4 * Add `doc` folder for documentation. diff --git a/lib/6to5/generation/buffer.js b/lib/6to5/generation/buffer.js index edd526ea4d..a3f4756653 100644 --- a/lib/6to5/generation/buffer.js +++ b/lib/6to5/generation/buffer.js @@ -76,6 +76,8 @@ Buffer.prototype.newline = function (i, removeLast) { } if (_.isNumber(i)) { + if (this.endsWith(util.repeat(i, "\n"))) return; + var self = this; _.times(i, function () { self.newline(null, removeLast); @@ -86,7 +88,7 @@ Buffer.prototype.newline = function (i, removeLast) { if (removeLast && this.isLast("\n")) this.removeLast("\n"); this.removeLast(" "); - this.buf = this.buf.replace(/\n(\s+)$/, "\n"); + this.buf = this.buf.replace(/\n +$/, "\n"); this._push("\n"); }; diff --git a/lib/6to5/generation/generator.js b/lib/6to5/generation/generator.js index ba146331f4..4a75e27b77 100644 --- a/lib/6to5/generation/generator.js +++ b/lib/6to5/generation/generator.js @@ -115,8 +115,6 @@ CodeGenerator.prototype.print = function (node, parent, opts) { opts = opts || {}; var newline = function (leading) { - var ignoreDuplicates = false; - if (!opts.statement && !n.isUserWhitespacable(node, parent)) { return; } @@ -139,7 +137,7 @@ CodeGenerator.prototype.print = function (node, parent, opts) { lines += needs(node, parent); } - self.newline(lines, ignoreDuplicates); + self.newline(lines); }; if (this[node.type]) { diff --git a/test/fixtures/generation/comments/simple-a-lot-of-line-comment/expected.js b/test/fixtures/generation/comments/simple-a-lot-of-line-comment/expected.js index 47869b2606..9dc22c7c8a 100644 --- a/test/fixtures/generation/comments/simple-a-lot-of-line-comment/expected.js +++ b/test/fixtures/generation/comments/simple-a-lot-of-line-comment/expected.js @@ -20,8 +20,11 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + function test() {} + + // Copyright (C) 2012 Yusuke Suzuki // // Redistribution and use in source and binary forms, with or without diff --git a/test/fixtures/transformation/array-comprehension/arguments/expected.js b/test/fixtures/transformation/array-comprehension/arguments/expected.js index d8457bb0ef..aa3d6cc703 100644 --- a/test/fixtures/transformation/array-comprehension/arguments/expected.js +++ b/test/fixtures/transformation/array-comprehension/arguments/expected.js @@ -2,7 +2,6 @@ function add() { var _arguments = arguments; - return [1, 2, 3].map(function (i) { return i * _arguments[0]; }); diff --git a/test/fixtures/transformation/array-comprehension/multiple-if/expected.js b/test/fixtures/transformation/array-comprehension/multiple-if/expected.js index f0d8c50729..d725285d53 100644 --- a/test/fixtures/transformation/array-comprehension/multiple-if/expected.js +++ b/test/fixtures/transformation/array-comprehension/multiple-if/expected.js @@ -2,13 +2,10 @@ var seattlers = (function () { var _arr = []; - for (var _iterator = countries[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { var customers = _step.value; - for (var _iterator2 = customers[Symbol.iterator](), _step2; !(_step2 = _iterator2.next()).done;) { var c = _step2.value; - if (c.city == "Seattle") { _arr.push({ name: c.name, age: c.age }); } diff --git a/test/fixtures/transformation/array-comprehension/multiple/expected.js b/test/fixtures/transformation/array-comprehension/multiple/expected.js index 2efb3116f2..6f17584afe 100644 --- a/test/fixtures/transformation/array-comprehension/multiple/expected.js +++ b/test/fixtures/transformation/array-comprehension/multiple/expected.js @@ -2,10 +2,8 @@ var arr = (function () { var _arr = []; - for (var _iterator = "abcdefgh".split("")[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { var x = _step.value; - for (var _iterator2 = "12345678".split("")[Symbol.iterator](), _step2; !(_step2 = _iterator2.next()).done;) { var y = _step2.value; _arr.push(x + y); diff --git a/test/fixtures/transformation/array-comprehension/this/expected.js b/test/fixtures/transformation/array-comprehension/this/expected.js index c827d99fb8..4c59ba50dc 100644 --- a/test/fixtures/transformation/array-comprehension/this/expected.js +++ b/test/fixtures/transformation/array-comprehension/this/expected.js @@ -2,7 +2,6 @@ function add() { var _this = this; - return [1, 2, 3].map(function (i) { return i * _this.multiplier; }); diff --git a/test/fixtures/transformation/arrow-functions/arguments/expected.js b/test/fixtures/transformation/arrow-functions/arguments/expected.js index 1d7acb6828..252e99ee1e 100644 --- a/test/fixtures/transformation/arrow-functions/arguments/expected.js +++ b/test/fixtures/transformation/arrow-functions/arguments/expected.js @@ -2,7 +2,6 @@ function one() { var _arguments = arguments; - var inner = function () { return _arguments; }; @@ -12,14 +11,12 @@ one(1, 2); function two() { var _arguments2 = arguments; - var inner = function () { return _arguments2; }; var another = function () { var _arguments3 = arguments; - var inner2 = function () { return _arguments3; }; @@ -31,7 +28,6 @@ two(1, 2); function three() { var _arguments4 = arguments; - var fn = function () { return _arguments4[0] + "bar"; }; @@ -41,7 +37,6 @@ three("foo"); function four() { var _arguments5 = arguments; - var fn = function () { return _arguments5[0].foo + "bar"; }; diff --git a/test/fixtures/transformation/arrow-functions/default-parameters/expected.js b/test/fixtures/transformation/arrow-functions/default-parameters/expected.js index c0b535119d..baba36b081 100644 --- a/test/fixtures/transformation/arrow-functions/default-parameters/expected.js +++ b/test/fixtures/transformation/arrow-functions/default-parameters/expected.js @@ -2,7 +2,6 @@ var some = function (count) { if (count === undefined) count = "30"; - console.log("count", count); }; diff --git a/test/fixtures/transformation/arrow-functions/nested/expected.js b/test/fixtures/transformation/arrow-functions/nested/expected.js index 6ecc735707..022b06abd0 100644 --- a/test/fixtures/transformation/arrow-functions/nested/expected.js +++ b/test/fixtures/transformation/arrow-functions/nested/expected.js @@ -3,7 +3,6 @@ module.exports = { init: function () { var _this = this; - return new Promise(function (resolve, reject) { MongoClient.connect(config.mongodb, function (err, db) { if (err) { diff --git a/test/fixtures/transformation/classes/accessing-super-class/expected.js b/test/fixtures/transformation/classes/accessing-super-class/expected.js index c9c28b5fee..158cc49593 100644 --- a/test/fixtures/transformation/classes/accessing-super-class/expected.js +++ b/test/fixtures/transformation/classes/accessing-super-class/expected.js @@ -2,7 +2,6 @@ var _classProps = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); - if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; diff --git a/test/fixtures/transformation/classes/calling-super-properties/expected.js b/test/fixtures/transformation/classes/calling-super-properties/expected.js index 7bd4cfc56e..9cf6de3d54 100644 --- a/test/fixtures/transformation/classes/calling-super-properties/expected.js +++ b/test/fixtures/transformation/classes/calling-super-properties/expected.js @@ -2,7 +2,6 @@ var _classProps = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); - if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; diff --git a/test/fixtures/transformation/classes/instance-getter-and-setter/expected.js b/test/fixtures/transformation/classes/instance-getter-and-setter/expected.js index 00bdae39a8..0fb4c995d3 100644 --- a/test/fixtures/transformation/classes/instance-getter-and-setter/expected.js +++ b/test/fixtures/transformation/classes/instance-getter-and-setter/expected.js @@ -2,7 +2,6 @@ var _classProps = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); - if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; diff --git a/test/fixtures/transformation/classes/instance-getter/expected.js b/test/fixtures/transformation/classes/instance-getter/expected.js index 39057c75f2..0d50b8e732 100644 --- a/test/fixtures/transformation/classes/instance-getter/expected.js +++ b/test/fixtures/transformation/classes/instance-getter/expected.js @@ -2,7 +2,6 @@ var _classProps = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); - if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; diff --git a/test/fixtures/transformation/classes/instance-method/expected.js b/test/fixtures/transformation/classes/instance-method/expected.js index 0e83d8bd05..6511e20db4 100644 --- a/test/fixtures/transformation/classes/instance-method/expected.js +++ b/test/fixtures/transformation/classes/instance-method/expected.js @@ -2,7 +2,6 @@ var _classProps = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); - if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; diff --git a/test/fixtures/transformation/classes/instance-setter/expected.js b/test/fixtures/transformation/classes/instance-setter/expected.js index 72cacb4828..87f8e40dde 100644 --- a/test/fixtures/transformation/classes/instance-setter/expected.js +++ b/test/fixtures/transformation/classes/instance-setter/expected.js @@ -2,7 +2,6 @@ var _classProps = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); - if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; diff --git a/test/fixtures/transformation/classes/statement/expected.js b/test/fixtures/transformation/classes/statement/expected.js index 5d7f938dee..9186ca15be 100644 --- a/test/fixtures/transformation/classes/statement/expected.js +++ b/test/fixtures/transformation/classes/statement/expected.js @@ -2,7 +2,6 @@ var _classProps = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); - if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; diff --git a/test/fixtures/transformation/classes/static/expected.js b/test/fixtures/transformation/classes/static/expected.js index 26784ce076..a50fd266e8 100644 --- a/test/fixtures/transformation/classes/static/expected.js +++ b/test/fixtures/transformation/classes/static/expected.js @@ -2,7 +2,6 @@ var _classProps = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); - if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; diff --git a/test/fixtures/transformation/default-parameters/multiple/expected.js b/test/fixtures/transformation/default-parameters/multiple/expected.js index 50601e0826..48cb3f0db9 100644 --- a/test/fixtures/transformation/default-parameters/multiple/expected.js +++ b/test/fixtures/transformation/default-parameters/multiple/expected.js @@ -2,14 +2,11 @@ var t = function (t, f) { if (f === undefined) f = 5; - if (t === undefined) t = "foo"; - return t + " bar " + f; }; var a = function (t, f) { if (f === undefined) f = 5; - return t + " bar " + f; }; diff --git a/test/fixtures/transformation/default-parameters/single/expected.js b/test/fixtures/transformation/default-parameters/single/expected.js index 17de701e41..5021d6e0ab 100644 --- a/test/fixtures/transformation/default-parameters/single/expected.js +++ b/test/fixtures/transformation/default-parameters/single/expected.js @@ -2,6 +2,5 @@ var t = function (t) { if (t === undefined) t = "foo"; - return t + " bar"; }; diff --git a/test/fixtures/transformation/destructuring/for-in/expected.js b/test/fixtures/transformation/destructuring/for-in/expected.js index b11f39966e..aeef27f30c 100644 --- a/test/fixtures/transformation/destructuring/for-in/expected.js +++ b/test/fixtures/transformation/destructuring/for-in/expected.js @@ -3,6 +3,5 @@ for (var _ref in obj) { var name = _ref[0]; var value = _ref[1]; - print("Name: " + name + ", Value: " + value); } diff --git a/test/fixtures/transformation/destructuring/parameters/expected.js b/test/fixtures/transformation/destructuring/parameters/expected.js index 6031784993..df43c193f7 100644 --- a/test/fixtures/transformation/destructuring/parameters/expected.js +++ b/test/fixtures/transformation/destructuring/parameters/expected.js @@ -10,7 +10,6 @@ function somethingAdvanced(_ref) { function unpackObject(_ref2) { var title = _ref2.title; var author = _ref2.author; - return title + " " + author; } @@ -23,7 +22,6 @@ var unpackArray = function (_ref3, _ref4) { var x = _ref4[0]; var y = _ref4[1]; var z = _ref4[2]; - return a + b + c; }; diff --git a/test/fixtures/transformation/react/display-name-assignment-expression/expected.js b/test/fixtures/transformation/react/display-name-assignment-expression/expected.js index 6d4c263e16..86a1009408 100644 --- a/test/fixtures/transformation/react/display-name-assignment-expression/expected.js +++ b/test/fixtures/transformation/react/display-name-assignment-expression/expected.js @@ -1,7 +1,6 @@ var Component; Component = React.createClass({ displayName: "Component", - render: function () { return null; } diff --git a/test/fixtures/transformation/react/display-name-object-declaration/expected.js b/test/fixtures/transformation/react/display-name-object-declaration/expected.js index ab809e9330..5203f7a7c5 100644 --- a/test/fixtures/transformation/react/display-name-object-declaration/expected.js +++ b/test/fixtures/transformation/react/display-name-object-declaration/expected.js @@ -1,7 +1,6 @@ exports = { Component: React.createClass({ displayName: "Component", - render: function () { return null; } diff --git a/test/fixtures/transformation/react/display-name-property-assignment/expected.js b/test/fixtures/transformation/react/display-name-property-assignment/expected.js index a4e1c4a382..2aacec1437 100644 --- a/test/fixtures/transformation/react/display-name-property-assignment/expected.js +++ b/test/fixtures/transformation/react/display-name-property-assignment/expected.js @@ -1,6 +1,5 @@ exports.Component = React.createClass({ displayName: "Component", - render: function () { return null; } diff --git a/test/fixtures/transformation/react/display-name-variable-declaration/expected.js b/test/fixtures/transformation/react/display-name-variable-declaration/expected.js index 15d409759a..d52d1f31d6 100644 --- a/test/fixtures/transformation/react/display-name-variable-declaration/expected.js +++ b/test/fixtures/transformation/react/display-name-variable-declaration/expected.js @@ -1,6 +1,5 @@ var Component = React.createClass({ displayName: "Component", - render: function () { return null; } diff --git a/test/fixtures/transformation/source-maps/class/expected.js b/test/fixtures/transformation/source-maps/class/expected.js index 413cba0fb1..7a04a39640 100644 --- a/test/fixtures/transformation/source-maps/class/expected.js +++ b/test/fixtures/transformation/source-maps/class/expected.js @@ -2,7 +2,6 @@ var _classProps = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); - if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; diff --git a/test/fixtures/transformation/source-maps/class/source-mappings.json b/test/fixtures/transformation/source-maps/class/source-mappings.json index 0bb3b62b7f..8b95905776 100644 --- a/test/fixtures/transformation/source-maps/class/source-mappings.json +++ b/test/fixtures/transformation/source-maps/class/source-mappings.json @@ -4,7 +4,7 @@ "column": 10 }, "generated": { - "line": 15, + "line": 14, "column": 15 } }]