Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix broken parens on return statements with leading comments
  • Loading branch information
micschro authored Apr 10, 2018
1 parent f0488e1 commit 26be28d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions escodegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -1738,10 +1738,19 @@

ReturnStatement: function (stmt, flags) {
if (stmt.argument) {
return [join(
'return',
this.generateExpression(stmt.argument, Precedence.Sequence, E_TTT)
), this.semicolon(flags)];
var shouldParenthesize = stmt.argument.leadingComments && stmt.argument.leadingComments.length > 0;
var result = [];
if (shouldParenthesize) {
var that = this;
result.push('(', newline)
withIndent(function () {
result.push(addIndent(that.generateExpression(stmt.argument, Precedence.Sequence, E_TTT)), newline)
});
result.push(addIndent(')'))
} else {
result.push(this.generateExpression(stmt.argument, Precedence.Sequence, E_TTT));
}
return [join('return', result), this.semicolon(flags)];
}
return ['return' + this.semicolon(flags)];
},
Expand Down

0 comments on commit 26be28d

Please sign in to comment.