mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-20 13:45:34 -05:00
fix(35779): emit comments after trailing comma (#37887)
This commit is contained in:
@@ -4165,20 +4165,26 @@ namespace ts {
|
||||
}
|
||||
|
||||
// Write a trailing comma, if requested.
|
||||
const hasTrailingComma = (format & ListFormat.AllowTrailingComma) && children!.hasTrailingComma;
|
||||
if (format & ListFormat.CommaDelimited && hasTrailingComma) {
|
||||
writePunctuation(",");
|
||||
const emitFlags = previousSibling ? getEmitFlags(previousSibling) : 0;
|
||||
const skipTrailingComments = commentsDisabled || !!(emitFlags & EmitFlags.NoTrailingComments);
|
||||
const hasTrailingComma = children?.hasTrailingComma && (format & ListFormat.AllowTrailingComma) && (format & ListFormat.CommaDelimited);
|
||||
if (hasTrailingComma) {
|
||||
if (previousSibling && !skipTrailingComments) {
|
||||
emitTokenWithComment(SyntaxKind.CommaToken, previousSibling.end, writePunctuation, previousSibling);
|
||||
}
|
||||
else {
|
||||
writePunctuation(",");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Emit any trailing comment of the last element in the list
|
||||
// i.e
|
||||
// var array = [...
|
||||
// 2
|
||||
// /* end of element 2 */
|
||||
// ];
|
||||
if (previousSibling && format & ListFormat.DelimitersMask && previousSibling.end !== parentNode.end && !(getEmitFlags(previousSibling) & EmitFlags.NoTrailingComments)) {
|
||||
emitLeadingCommentsOfPosition(previousSibling.end);
|
||||
if (previousSibling && parentNode.end !== previousSibling.end && (format & ListFormat.DelimitersMask) && !skipTrailingComments) {
|
||||
emitLeadingCommentsOfPosition(hasTrailingComma && children?.end ? children.end : previousSibling.end);
|
||||
}
|
||||
|
||||
// Decrease the indent, if requested.
|
||||
|
||||
Reference in New Issue
Block a user