[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:
Yui
2017-05-23 10:24:46 -07:00
committed by Mohamed Hegazy
parent 7adfa8d854
commit e4aa515191
17 changed files with 362 additions and 16 deletions

View File

@@ -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]);