|
1 | | -/// <reference path="checker.ts" /> |
| 1 | +/// <reference path="checker.ts" /> |
2 | 2 | /// <reference path="transformer.ts" /> |
3 | 3 | /// <reference path="declarationEmitter.ts" /> |
4 | 4 | /// <reference path="sourcemap.ts" /> |
@@ -211,6 +211,7 @@ namespace ts { |
211 | 211 | emitNodeWithComments, |
212 | 212 | emitBodyWithDetachedComments, |
213 | 213 | emitTrailingCommentsOfPosition, |
| 214 | + emitLeadingCommentsOfPosition, |
214 | 215 | } = comments; |
215 | 216 |
|
216 | 217 | let currentSourceFile: SourceFile; |
@@ -1346,6 +1347,10 @@ namespace ts { |
1346 | 1347 | else { |
1347 | 1348 | writeToken(SyntaxKind.OpenBraceToken, node.pos, /*contextNode*/ node); |
1348 | 1349 | emitBlockStatements(node); |
| 1350 | + // We have to call emitLeadingComments explicitly here because otherwise leading comments of the close brace token will not be emitted |
| 1351 | + increaseIndent(); |
| 1352 | + emitLeadingCommentsOfPosition(node.statements.end); |
| 1353 | + decreaseIndent(); |
1349 | 1354 | writeToken(SyntaxKind.CloseBraceToken, node.statements.end, /*contextNode*/ node); |
1350 | 1355 | } |
1351 | 1356 | } |
@@ -2228,6 +2233,15 @@ namespace ts { |
2228 | 2233 |
|
2229 | 2234 | // Write the delimiter if this is not the first node. |
2230 | 2235 | if (previousSibling) { |
| 2236 | + // i.e |
| 2237 | + // function commentedParameters( |
| 2238 | + // /* Parameter a */ |
| 2239 | + // a |
| 2240 | + // /* End of parameter a */ -> this comment isn't considered to be trailing comment of parameter "a" due to newline |
| 2241 | + // , |
| 2242 | + if (delimiter && previousSibling.end !== parentNode.end) { |
| 2243 | + emitLeadingCommentsOfPosition(previousSibling.end); |
| 2244 | + } |
2231 | 2245 | write(delimiter); |
2232 | 2246 |
|
2233 | 2247 | // Write either a line terminator or whitespace to separate the elements. |
@@ -2274,6 +2288,17 @@ namespace ts { |
2274 | 2288 | write(","); |
2275 | 2289 | } |
2276 | 2290 |
|
| 2291 | + |
| 2292 | + // Emit any trailing comment of the last element in the list |
| 2293 | + // i.e |
| 2294 | + // var array = [... |
| 2295 | + // 2 |
| 2296 | + // /* end of element 2 */ |
| 2297 | + // ]; |
| 2298 | + if (previousSibling && delimiter && previousSibling.end !== parentNode.end) { |
| 2299 | + emitLeadingCommentsOfPosition(previousSibling.end); |
| 2300 | + } |
| 2301 | + |
2277 | 2302 | // Decrease the indent, if requested. |
2278 | 2303 | if (format & ListFormat.Indented) { |
2279 | 2304 | decreaseIndent(); |
|
0 commit comments