From 88a85c0ca8e44575dea7c6a74b89d7553dec70bc Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 7 Dec 2014 11:19:17 +1100 Subject: [PATCH] fix files only containg comments not being output - fixes #259 --- CHANGELOG.md | 4 ++++ lib/6to5/generation/generator.js | 8 ++++++++ .../{.comment-only/expected.js => comment-only/actual.js} | 0 .../{.comment-only/actual.js => comment-only/expected.js} | 4 ++-- 4 files changed, 14 insertions(+), 2 deletions(-) rename test/fixtures/generation/comments/{.comment-only/expected.js => comment-only/actual.js} (100%) rename test/fixtures/generation/comments/{.comment-only/actual.js => comment-only/expected.js} (63%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93935fa179..76a09da17b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.14.18 + + * Fix files only containg comments not being output. + # 1.14.17 * Add default initializer to let variables within loop bodies. diff --git a/lib/6to5/generation/generator.js b/lib/6to5/generation/generator.js index 18fa9b00a3..6c0274a7b8 100644 --- a/lib/6to5/generation/generator.js +++ b/lib/6to5/generation/generator.js @@ -71,6 +71,12 @@ CodeGenerator.prototype.generate = function () { this.print(ast); + var comments = []; + _.each(ast.comments, function (comment) { + if (!comment._displayed) comments.push(comment); + }); + if (comments.length) this._printComments(comments); + return { map: this.map.get(), code: this.buffer.get() @@ -259,6 +265,8 @@ CodeGenerator.prototype._printComments = function (comments) { var self = this; _.each(comments, function (comment) { + comment._displayed = true; + // whitespace before self.newline(self.whitespace.getNewlinesBefore(comment)); diff --git a/test/fixtures/generation/comments/.comment-only/expected.js b/test/fixtures/generation/comments/comment-only/actual.js similarity index 100% rename from test/fixtures/generation/comments/.comment-only/expected.js rename to test/fixtures/generation/comments/comment-only/actual.js diff --git a/test/fixtures/generation/comments/.comment-only/actual.js b/test/fixtures/generation/comments/comment-only/expected.js similarity index 63% rename from test/fixtures/generation/comments/.comment-only/actual.js rename to test/fixtures/generation/comments/comment-only/expected.js index 2cc6cab81c..b30266f9e6 100644 --- a/test/fixtures/generation/comments/.comment-only/actual.js +++ b/test/fixtures/generation/comments/comment-only/expected.js @@ -1,6 +1,6 @@ +"use strict"; + // from #23 /**/ /* */ - -test