Skip to content

Commit 1b7491d

Browse files
author
Caitlin Potter
committed
Fixes jashkenas#3132 - Improve rendering of block-comments
1 parent 96e807c commit 1b7491d

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed

lib/coffee-script/nodes.js

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

+2-1
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

+63
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,66 @@ test "#2916: block comment before implicit call with implicit object", ->
211211
### ###
212212
fn
213213
a: yes
214+
215+
test "#3132: Format multi-line block comment nicely", ->
216+
input = """
217+
###
218+
# Multi-line
219+
# block
220+
# comment
221+
###"""
222+
223+
result = """
224+
225+
/*
226+
* Multi-line
227+
* block
228+
* comment
229+
*/
230+
231+
232+
"""
233+
eq CoffeeScript.compile(input, bare: on), result
234+
235+
test "#3132: Format simple block comment nicely", ->
236+
input = """
237+
###
238+
No
239+
Preceding hash
240+
###"""
241+
242+
result = """
243+
244+
/*
245+
No
246+
Preceding hash
247+
*/
248+
249+
250+
"""
251+
252+
eq CoffeeScript.compile(input, bare: on), result
253+
254+
test "#3132: Format indented block-comment nicely", ->
255+
input = """
256+
fn = () ->
257+
###
258+
# Indented
259+
Multiline
260+
###
261+
1"""
262+
263+
result = """
264+
var fn;
265+
266+
fn = function() {
267+
268+
/*
269+
* Indented
270+
Multiline
271+
*/
272+
return 1;
273+
};
274+
275+
"""
276+
eq CoffeeScript.compile(input, bare: on), result

0 commit comments

Comments
 (0)