From 2e0cd0f3491c010704a47f14aaca67e9d685208d Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 7 Dec 2014 02:06:41 -0800 Subject: [PATCH 1/2] Add tests for newlines before comments --- .../2-space-multi-comment-with-space/actual.js | 10 ++++++++++ .../2-space-multi-comment-with-space/expected.js | 10 ++++++++++ .../comments/comment-only-with-space/actual.js | 7 +++++++ .../comments/comment-only-with-space/expected.js | 7 +++++++ 4 files changed, 34 insertions(+) create mode 100644 test/fixtures/generation/comments/2-space-multi-comment-with-space/actual.js create mode 100644 test/fixtures/generation/comments/2-space-multi-comment-with-space/expected.js create mode 100644 test/fixtures/generation/comments/comment-only-with-space/actual.js create mode 100644 test/fixtures/generation/comments/comment-only-with-space/expected.js diff --git a/test/fixtures/generation/comments/2-space-multi-comment-with-space/actual.js b/test/fixtures/generation/comments/2-space-multi-comment-with-space/actual.js new file mode 100644 index 0000000000..aa61a9c8fe --- /dev/null +++ b/test/fixtures/generation/comments/2-space-multi-comment-with-space/actual.js @@ -0,0 +1,10 @@ +function test() { + + + /* + * this is comment + */ + + + var i = 20; +} diff --git a/test/fixtures/generation/comments/2-space-multi-comment-with-space/expected.js b/test/fixtures/generation/comments/2-space-multi-comment-with-space/expected.js new file mode 100644 index 0000000000..aa61a9c8fe --- /dev/null +++ b/test/fixtures/generation/comments/2-space-multi-comment-with-space/expected.js @@ -0,0 +1,10 @@ +function test() { + + + /* + * this is comment + */ + + + var i = 20; +} diff --git a/test/fixtures/generation/comments/comment-only-with-space/actual.js b/test/fixtures/generation/comments/comment-only-with-space/actual.js new file mode 100644 index 0000000000..befcf38bfa --- /dev/null +++ b/test/fixtures/generation/comments/comment-only-with-space/actual.js @@ -0,0 +1,7 @@ + +// from #23 + +/**/ + +/* +*/ diff --git a/test/fixtures/generation/comments/comment-only-with-space/expected.js b/test/fixtures/generation/comments/comment-only-with-space/expected.js new file mode 100644 index 0000000000..befcf38bfa --- /dev/null +++ b/test/fixtures/generation/comments/comment-only-with-space/expected.js @@ -0,0 +1,7 @@ + +// from #23 + +/**/ + +/* +*/ From f592f95a68f5923f1acacbc8ef43fa09ae29c71e Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 7 Dec 2014 02:06:54 -0800 Subject: [PATCH 2/2] Subtract one if line already ends with "{\n" --- lib/6to5/generation/buffer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/6to5/generation/buffer.js b/lib/6to5/generation/buffer.js index a3f4756653..ae6e174400 100644 --- a/lib/6to5/generation/buffer.js +++ b/lib/6to5/generation/buffer.js @@ -68,7 +68,6 @@ Buffer.prototype.removeLast = function (cha) { Buffer.prototype.newline = function (i, removeLast) { if (!this.buf) return; if (this.format.compact) return; - if (this.endsWith("{\n")) return; if (_.isBoolean(i)) { removeLast = i; @@ -76,6 +75,7 @@ Buffer.prototype.newline = function (i, removeLast) { } if (_.isNumber(i)) { + if (this.endsWith("{\n")) i--; if (this.endsWith(util.repeat(i, "\n"))) return; var self = this;