From eef0344cb27dd823ecbc73d0eb1cf2b1e8092ddb Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 7 Dec 2014 11:30:50 +1100 Subject: [PATCH] fix comments-only rendering --- lib/6to5/generation/generator.js | 10 ++++++++-- .../generation/comments/comment-only/expected.js | 2 -- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/6to5/generation/generator.js b/lib/6to5/generation/generator.js index 6c0274a7b8..842e397899 100644 --- a/lib/6to5/generation/generator.js +++ b/lib/6to5/generation/generator.js @@ -75,7 +75,7 @@ CodeGenerator.prototype.generate = function () { _.each(ast.comments, function (comment) { if (!comment._displayed) comments.push(comment); }); - if (comments.length) this._printComments(comments); + this._printComments(comments); return { map: this.map.get(), @@ -265,7 +265,13 @@ CodeGenerator.prototype._printComments = function (comments) { var self = this; _.each(comments, function (comment) { - comment._displayed = true; + // find the original comment in the ast and set it as displayed + _.each(self.ast.comments, function (origComment) { + if (origComment.start === comment.start) { + origComment._displayed = true; + return false; + } + }); // 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/expected.js index b30266f9e6..acfb1b9a7b 100644 --- a/test/fixtures/generation/comments/comment-only/expected.js +++ b/test/fixtures/generation/comments/comment-only/expected.js @@ -1,5 +1,3 @@ -"use strict"; - // from #23 /**/ /*