mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
[Master] Fix 15179 missing comment in switch case clause (#16033)
* Fix emit comments after switch case clause * Update baselines * Add new tests and baselines
This commit is contained in:
@@ -2021,6 +2021,22 @@ namespace ts {
|
||||
rangeStartPositionsAreOnSameLine(parentNode, statements[0], currentSourceFile)
|
||||
);
|
||||
|
||||
// e.g:
|
||||
// case 0: // Zero
|
||||
// case 1: // One
|
||||
// case 2: // two
|
||||
// return "hi";
|
||||
// If there is no statements, emitNodeWithComments of the parentNode which is caseClause will take care of trailing comment.
|
||||
// So in example above, comment "// Zero" and "// One" will be emit in emitTrailingComments in emitNodeWithComments.
|
||||
// However, for "case 2", because parentNode which is caseClause has an "end" property to be end of the statements (in this case return statement)
|
||||
// comment "// two" will not be emitted in emitNodeWithComments.
|
||||
// Therefore, we have to do the check here to emit such comment.
|
||||
if (statements.length > 0) {
|
||||
// We use emitTrailingCommentsOfPosition instead of emitLeadingCommentsOfPosition because leading comments is defined as comments before the node after newline character separating it from previous line
|
||||
// Note: we can't use parentNode.end as such position includes statements.
|
||||
emitTrailingCommentsOfPosition(statements.pos);
|
||||
}
|
||||
|
||||
if (emitAsSingleStatement) {
|
||||
write(" ");
|
||||
emit(statements[0]);
|
||||
|
||||
Reference in New Issue
Block a user