Skip to content

Bug: comment in array literal is moved into multi-line string #5325

@sa-0001

Description

@sa-0001

Bug

when compiled, a comment which is inside an array literal is moved into a multi-line string preceding the array literal.

Input Code

minimal example which exhibits the incorrect behavior:

result = db_select sql_transform("""
	select *
	from users
	where id = ?
"""), [
	# a comment here
	user_id
]

results in the following:

var result;

result = db_select(sql_transform(`select *
from users
// a comment here
where id = ?`), [user_id]);

can also be seen at this link: Coffeescript Online REPL

example which does work correctly: Coffeescript Online REPL

Expected Behavior

the comment should be within the array literal, or directly preceding it, or even not output at all if it's ambiguous where it should go. it should definitely not be moved inside a string literal. it seems to work correctly when the array literal has two comments, because then the array literal remains multi-line, whereas with a single comment, it's changed to a single-line array literal, and the comment is moved a line above it.

Current Behavior

the comment is moved inside a string.

Environment

  • CoffeeScript version: 2.5.1
  • Node.js version: not relevant (issue also seen in online REPL)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions