Skip to content

Commit 2877dd6

Browse files
author
Caitlin Potter
committed
Fixes jashkenas#3132 - Improve rendering of block-comments
1 parent 18c4858 commit 2877dd6

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

lib/coffee-script/nodes.js

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,8 @@ exports.Comment = class Comment extends Base
556556
makeReturn: THIS
557557

558558
compileNode: (o, level) ->
559-
code = "/*#{multident @comment, @tab}#{if '\n' in @comment then "\n#{@tab}" else ''}*/"
559+
comment = @comment.replace /^(\s*)#/gm, "$1 *"
560+
code = "/*#{multident comment, @tab}#{if '\n' in comment then "\n#{@tab}" else ''} */"
560561
code = o.indent + code if (level or o.level) is LEVEL_TOP
561562
[@makeCode("\n"), @makeCode(code)]
562563

test/comments.coffee

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,24 @@ test "#2916: block comment before implicit call with implicit object", ->
211211
### ###
212212
fn
213213
a: yes
214+
215+
test "#3132: format block comments prettily", ->
216+
cmp = CoffeeScript.compile
217+
eq cmp("###\n# Multi-line\n# block\n# comment\n###", bare: on),
218+
"\n/*\n * Multi-line\n * block\n * comment\n */\n\n"
219+
eq cmp("###\nNot indented\n###\n", bare: on),
220+
"\n/*\nNot indented\n */\n\n"
221+
eq cmp("fn = () ->\n ###\n # Indented\nMultiline\n ###\n 1", bare: on),
222+
"""
223+
var fn;
224+
225+
fn = function() {
226+
227+
/*
228+
* Indented
229+
Multiline
230+
*/
231+
return 1;
232+
};
233+
234+
"""

0 commit comments

Comments
 (0)