diff --git a/lib/rewriters/coffeescript.js b/lib/rewriters/coffeescript.js index 4315ef9..c1618a4 100644 --- a/lib/rewriters/coffeescript.js +++ b/lib/rewriters/coffeescript.js @@ -25,11 +25,23 @@ const chunksCoffee = input => { for (const comment of comments (CoffeeScript.nodes (input))) { const [start, end] = comment.locationData.range; chunks.literals.set (offset, input.slice (offset, start)); - chunks.comments.set (start, { - indent: ' '.repeat (comment.locationData.first_column), - number: comment.locationData.first_line + 1, - text: comment.content, - }); + offset = start + (comment.here ? '###' : '#').length; + const indent = ' '.repeat (comment.locationData.first_column); + let from = 0; + let number = comment.locationData.first_line + 1; + while (true) { + const to = comment.content.indexOf ('\n', from); + if (to < 0) { + const text = comment.content.slice (from); + chunks.comments.set (offset + from, {indent, number, text}); + break; + } else { + const text = comment.content.slice (from, to); + chunks.comments.set (offset + from, {indent, number, text}); + from = to + '\n'.length; + number += 1; + } + } offset = end; } chunks.literals.set (offset, input.slice (offset)); diff --git a/test/shared/index.coffee b/test/shared/index.coffee index c8b328e..d23189f 100644 --- a/test/shared/index.coffee +++ b/test/shared/index.coffee @@ -104,20 +104,20 @@ do -> # ..... .5 # 1234.5 - 23: 'TODO: multiline comment' - # - # > 3 ** 3 - 2 ** 2 - # 23 - # - - 24: 'TODO: multiline comment with wrapped input' - # - # > (["foo", "bar", "baz"] - # . .slice(0, -1) - # . .join(" ") - # . .toUpperCase()) - # "FOO BAR" - # + 23: 'multiline comment' + ### + > 3 ** 3 - 2 ** 2 + 23 + ### + + 24: 'multiline comment with wrapped input' + ### + > (["foo", "bar", "baz"] + . .slice(0, -1) + . .join(" ") + . .toUpperCase()) + "FOO BAR" + ###