diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d3e46f0827d..7adac106e8c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1347,6 +1347,8 @@ namespace ts { else { writeToken(SyntaxKind.OpenBraceToken, node.pos, /*contextNode*/ node); emitBlockStatements(node); + // We have to call emitLeadingComments explicitly here because otherwise leading comments of the close brace token will not be emitted + emitLeadingComments(node.statements.end, /*isEmittedNode*/true); writeToken(SyntaxKind.CloseBraceToken, node.statements.end, /*contextNode*/ node); } } diff --git a/tests/baselines/reference/amdImportAsPrimaryExpression.js b/tests/baselines/reference/amdImportAsPrimaryExpression.js index 3c2e9c041fa..25f390c0b32 100644 --- a/tests/baselines/reference/amdImportAsPrimaryExpression.js +++ b/tests/baselines/reference/amdImportAsPrimaryExpression.js @@ -26,5 +26,6 @@ define(["require", "exports"], function (require, exports) { define(["require", "exports", "./foo_0"], function (require, exports, foo) { "use strict"; if (foo.E1.A === 0) { + // Should cause runtime import - interesting optimization possibility, as gets inlined to 0. } }); diff --git a/tests/baselines/reference/argsInScope.js b/tests/baselines/reference/argsInScope.js index 90906426d24..27405a47d87 100644 --- a/tests/baselines/reference/argsInScope.js +++ b/tests/baselines/reference/argsInScope.js @@ -17,6 +17,7 @@ var C = (function () { } C.prototype.P = function (ii, j, k) { for (var i = 0; i < arguments.length; i++) { + // WScript.Echo("param: " + arguments[i]); } }; return C; diff --git a/tests/baselines/reference/commentLeadingCloseBrace.js b/tests/baselines/reference/commentLeadingCloseBrace.js new file mode 100644 index 00000000000..9fc696219e1 --- /dev/null +++ b/tests/baselines/reference/commentLeadingCloseBrace.js @@ -0,0 +1,24 @@ +//// [commentLeadingCloseBrace.ts] +declare function commentedParameters(...args): any; + +function ifelse() { + if (commentedParameters(1, 2)) { + /*comment1*/ + commentedParameters(3, 4); + /*comment2*/ + } else { + commentedParameters(5, 6); + } +} + +//// [commentLeadingCloseBrace.js] +function ifelse() { + if (commentedParameters(1, 2)) { + /*comment1*/ + commentedParameters(3, 4); + /*comment2*/ + } + else { + commentedParameters(5, 6); + } +} diff --git a/tests/baselines/reference/commentLeadingCloseBrace.symbols b/tests/baselines/reference/commentLeadingCloseBrace.symbols new file mode 100644 index 00000000000..72dcfb1e047 --- /dev/null +++ b/tests/baselines/reference/commentLeadingCloseBrace.symbols @@ -0,0 +1,21 @@ +=== tests/cases/compiler/commentLeadingCloseBrace.ts === +declare function commentedParameters(...args): any; +>commentedParameters : Symbol(commentedParameters, Decl(commentLeadingCloseBrace.ts, 0, 0)) +>args : Symbol(args, Decl(commentLeadingCloseBrace.ts, 0, 37)) + +function ifelse() { +>ifelse : Symbol(ifelse, Decl(commentLeadingCloseBrace.ts, 0, 51)) + + if (commentedParameters(1, 2)) { +>commentedParameters : Symbol(commentedParameters, Decl(commentLeadingCloseBrace.ts, 0, 0)) + + /*comment1*/ + commentedParameters(3, 4); +>commentedParameters : Symbol(commentedParameters, Decl(commentLeadingCloseBrace.ts, 0, 0)) + + /*comment2*/ + } else { + commentedParameters(5, 6); +>commentedParameters : Symbol(commentedParameters, Decl(commentLeadingCloseBrace.ts, 0, 0)) + } +} diff --git a/tests/baselines/reference/commentLeadingCloseBrace.types b/tests/baselines/reference/commentLeadingCloseBrace.types new file mode 100644 index 00000000000..444320737a6 --- /dev/null +++ b/tests/baselines/reference/commentLeadingCloseBrace.types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/commentLeadingCloseBrace.ts === +declare function commentedParameters(...args): any; +>commentedParameters : (...args: any[]) => any +>args : any[] + +function ifelse() { +>ifelse : () => void + + if (commentedParameters(1, 2)) { +>commentedParameters(1, 2) : any +>commentedParameters : (...args: any[]) => any +>1 : 1 +>2 : 2 + + /*comment1*/ + commentedParameters(3, 4); +>commentedParameters(3, 4) : any +>commentedParameters : (...args: any[]) => any +>3 : 3 +>4 : 4 + + /*comment2*/ + } else { + commentedParameters(5, 6); +>commentedParameters(5, 6) : any +>commentedParameters : (...args: any[]) => any +>5 : 5 +>6 : 6 + } +} diff --git a/tests/baselines/reference/commonJSImportAsPrimaryExpression.js b/tests/baselines/reference/commonJSImportAsPrimaryExpression.js index b8cf42ea762..1eb7b5ff214 100644 --- a/tests/baselines/reference/commonJSImportAsPrimaryExpression.js +++ b/tests/baselines/reference/commonJSImportAsPrimaryExpression.js @@ -27,4 +27,5 @@ exports.C1 = C1; "use strict"; var foo = require("./foo_0"); if (foo.C1.s1) { +// Should cause runtime import } diff --git a/tests/baselines/reference/duplicateLocalVariable1.js b/tests/baselines/reference/duplicateLocalVariable1.js index 734b01eaed7..432830d85b6 100644 --- a/tests/baselines/reference/duplicateLocalVariable1.js +++ b/tests/baselines/reference/duplicateLocalVariable1.js @@ -391,6 +391,7 @@ var TestRunner = (function () { } } if (testResult === false) { + //console.log(e.message); } } if ((testcase.errorMessageRegEx !== undefined) && !exception) { diff --git a/tests/baselines/reference/jsFileCompilationLetBeingRenamed.js b/tests/baselines/reference/jsFileCompilationLetBeingRenamed.js index c9e16f35981..bb2aa10dc95 100644 --- a/tests/baselines/reference/jsFileCompilationLetBeingRenamed.js +++ b/tests/baselines/reference/jsFileCompilationLetBeingRenamed.js @@ -9,5 +9,6 @@ function foo(a) { //// [out.js] function foo(a) { for (var a_1 = 0; a_1 < 10; a_1++) { + // do something } } diff --git a/tests/baselines/reference/narrowExceptionVariableInCatchClause.js b/tests/baselines/reference/narrowExceptionVariableInCatchClause.js index 5808ed76826..18344df5994 100644 --- a/tests/baselines/reference/narrowExceptionVariableInCatchClause.js +++ b/tests/baselines/reference/narrowExceptionVariableInCatchClause.js @@ -27,6 +27,7 @@ function tryCatch() { //// [narrowExceptionVariableInCatchClause.js] function tryCatch() { try { + // do stuff... } catch (err) { if (isFooError(err)) { diff --git a/tests/baselines/reference/noCatchBlock.js b/tests/baselines/reference/noCatchBlock.js index 7b0404c3cad..158ac1257f3 100644 --- a/tests/baselines/reference/noCatchBlock.js +++ b/tests/baselines/reference/noCatchBlock.js @@ -8,7 +8,9 @@ try { //// [noCatchBlock.js] try { +// ... } finally { +// N.B. No 'catch' block } //# sourceMappingURL=noCatchBlock.js.map \ No newline at end of file diff --git a/tests/baselines/reference/noCatchBlock.js.map b/tests/baselines/reference/noCatchBlock.js.map index 149a2167f46..ddac2894e0b 100644 --- a/tests/baselines/reference/noCatchBlock.js.map +++ b/tests/baselines/reference/noCatchBlock.js.map @@ -1,2 +1,2 @@ //// [noCatchBlock.js.map] -{"version":3,"file":"noCatchBlock.js","sourceRoot":"","sources":["noCatchBlock.ts"],"names":[],"mappings":"AACA,IAAI,CAAC;AAEL,CAAC;QAAS,CAAC;AAEX,CAAC"} \ No newline at end of file +{"version":3,"file":"noCatchBlock.js","sourceRoot":"","sources":["noCatchBlock.ts"],"names":[],"mappings":"AACA,IAAI,CAAC;AACJ,MAAM;AACP,CAAC;QAAS,CAAC;AACV,wBAAwB;AACzB,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/noCatchBlock.sourcemap.txt b/tests/baselines/reference/noCatchBlock.sourcemap.txt index 18cb0d5a479..a75c119ca9f 100644 --- a/tests/baselines/reference/noCatchBlock.sourcemap.txt +++ b/tests/baselines/reference/noCatchBlock.sourcemap.txt @@ -12,6 +12,7 @@ sourceFile:noCatchBlock.ts 1 > 2 >^^^^ 3 > ^ +4 > ^^-> 1 > > 2 >try @@ -20,34 +21,51 @@ sourceFile:noCatchBlock.ts 2 >Emitted(1, 5) Source(2, 5) + SourceIndex(0) 3 >Emitted(1, 6) Source(2, 6) + SourceIndex(0) --- +>>>// ... +1-> +2 >^^^^^^ +1-> + > +2 >// ... +1->Emitted(2, 1) Source(3, 2) + SourceIndex(0) +2 >Emitted(2, 7) Source(3, 8) + SourceIndex(0) +--- >>>} 1 > 2 >^ 3 > ^^^^^^^^^-> 1 > - > // ... > 2 >} -1 >Emitted(2, 1) Source(4, 1) + SourceIndex(0) -2 >Emitted(2, 2) Source(4, 2) + SourceIndex(0) +1 >Emitted(3, 1) Source(4, 1) + SourceIndex(0) +2 >Emitted(3, 2) Source(4, 2) + SourceIndex(0) --- >>>finally { 1->^^^^^^^^ 2 > ^ +3 > ^^^^^^^^^^^^^^^^-> 1-> finally 2 > { -1->Emitted(3, 9) Source(4, 11) + SourceIndex(0) -2 >Emitted(3, 10) Source(4, 12) + SourceIndex(0) +1->Emitted(4, 9) Source(4, 11) + SourceIndex(0) +2 >Emitted(4, 10) Source(4, 12) + SourceIndex(0) +--- +>>>// N.B. No 'catch' block +1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^ +1-> + > +2 >// N.B. No 'catch' block +1->Emitted(5, 1) Source(5, 2) + SourceIndex(0) +2 >Emitted(5, 25) Source(5, 26) + SourceIndex(0) --- >>>} 1 > 2 >^ 3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > - > // N.B. No 'catch' block > 2 >} -1 >Emitted(4, 1) Source(6, 1) + SourceIndex(0) -2 >Emitted(4, 2) Source(6, 2) + SourceIndex(0) +1 >Emitted(6, 1) Source(6, 1) + SourceIndex(0) +2 >Emitted(6, 2) Source(6, 2) + SourceIndex(0) --- >>>//# sourceMappingURL=noCatchBlock.js.map \ No newline at end of file diff --git a/tests/baselines/reference/objectRestForOf.js b/tests/baselines/reference/objectRestForOf.js index f8a88fe2868..5f0399b2df2 100644 --- a/tests/baselines/reference/objectRestForOf.js +++ b/tests/baselines/reference/objectRestForOf.js @@ -37,4 +37,5 @@ for (let _b of array) { } for (const norest of array.map(a => (Object.assign({}, a, { x: 'a string' })))) { [norest.x, norest.y]; +// x is now a string. who knows why. } diff --git a/tests/baselines/reference/parserRealSource14.js b/tests/baselines/reference/parserRealSource14.js index 907efc6f26a..4e4e23e81c3 100644 --- a/tests/baselines/reference/parserRealSource14.js +++ b/tests/baselines/reference/parserRealSource14.js @@ -1011,6 +1011,7 @@ var TypeScript; ctx.path.push(cur); } else { + //logger.log("TODO: Ignoring node because minChar, limChar not better than previous node in stack"); } } // The AST walker skips comments, but we might be in one, so check the pre/post comments for this node manually diff --git a/tests/baselines/reference/recursiveReturns.js b/tests/baselines/reference/recursiveReturns.js index 18c9ed4dd7c..56762a9ad2d 100644 --- a/tests/baselines/reference/recursiveReturns.js +++ b/tests/baselines/reference/recursiveReturns.js @@ -23,6 +23,7 @@ function R1() { function R2() { R2(); } function R3(n) { if (n == 0) { + //return; } else { R3(n--); diff --git a/tests/baselines/reference/sourceMap-SkippedNode.js b/tests/baselines/reference/sourceMap-SkippedNode.js index 656b5a244e9..daac27cf49f 100644 --- a/tests/baselines/reference/sourceMap-SkippedNode.js +++ b/tests/baselines/reference/sourceMap-SkippedNode.js @@ -7,7 +7,9 @@ try { //// [sourceMap-SkippedNode.js] try { +// ... } finally { +// N.B. No 'catch' block } //# sourceMappingURL=sourceMap-SkippedNode.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMap-SkippedNode.js.map b/tests/baselines/reference/sourceMap-SkippedNode.js.map index 77340424640..b86b3905a73 100644 --- a/tests/baselines/reference/sourceMap-SkippedNode.js.map +++ b/tests/baselines/reference/sourceMap-SkippedNode.js.map @@ -1,2 +1,2 @@ //// [sourceMap-SkippedNode.js.map] -{"version":3,"file":"sourceMap-SkippedNode.js","sourceRoot":"","sources":["sourceMap-SkippedNode.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC;AAEL,CAAC;QAAS,CAAC;AAEX,CAAC"} \ No newline at end of file +{"version":3,"file":"sourceMap-SkippedNode.js","sourceRoot":"","sources":["sourceMap-SkippedNode.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC;AACL,MAAM;AACN,CAAC;QAAS,CAAC;AACX,wBAAwB;AACxB,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMap-SkippedNode.sourcemap.txt b/tests/baselines/reference/sourceMap-SkippedNode.sourcemap.txt index f68320a531f..b48a5f09f4a 100644 --- a/tests/baselines/reference/sourceMap-SkippedNode.sourcemap.txt +++ b/tests/baselines/reference/sourceMap-SkippedNode.sourcemap.txt @@ -12,6 +12,7 @@ sourceFile:sourceMap-SkippedNode.ts 1 > 2 >^^^^ 3 > ^ +4 > ^^-> 1 > 2 >try 3 > { @@ -19,34 +20,51 @@ sourceFile:sourceMap-SkippedNode.ts 2 >Emitted(1, 5) Source(1, 5) + SourceIndex(0) 3 >Emitted(1, 6) Source(1, 6) + SourceIndex(0) --- +>>>// ... +1-> +2 >^^^^^^ +1-> + > +2 >// ... +1->Emitted(2, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(2, 7) Source(2, 7) + SourceIndex(0) +--- >>>} 1 > 2 >^ 3 > ^^^^^^^^^-> 1 > - >// ... > 2 >} -1 >Emitted(2, 1) Source(3, 1) + SourceIndex(0) -2 >Emitted(2, 2) Source(3, 2) + SourceIndex(0) +1 >Emitted(3, 1) Source(3, 1) + SourceIndex(0) +2 >Emitted(3, 2) Source(3, 2) + SourceIndex(0) --- >>>finally { 1->^^^^^^^^ 2 > ^ +3 > ^^^^^^^^^^^^^^^^-> 1-> finally 2 > { -1->Emitted(3, 9) Source(3, 11) + SourceIndex(0) -2 >Emitted(3, 10) Source(3, 12) + SourceIndex(0) +1->Emitted(4, 9) Source(3, 11) + SourceIndex(0) +2 >Emitted(4, 10) Source(3, 12) + SourceIndex(0) +--- +>>>// N.B. No 'catch' block +1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^ +1-> + > +2 >// N.B. No 'catch' block +1->Emitted(5, 1) Source(4, 1) + SourceIndex(0) +2 >Emitted(5, 25) Source(4, 25) + SourceIndex(0) --- >>>} 1 > 2 >^ 3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > - >// N.B. No 'catch' block > 2 >} -1 >Emitted(4, 1) Source(5, 1) + SourceIndex(0) -2 >Emitted(4, 2) Source(5, 2) + SourceIndex(0) +1 >Emitted(6, 1) Source(5, 1) + SourceIndex(0) +2 >Emitted(6, 2) Source(5, 2) + SourceIndex(0) --- >>>//# sourceMappingURL=sourceMap-SkippedNode.js.map \ No newline at end of file diff --git a/tests/cases/compiler/commentLeadingCloseBrace.ts b/tests/cases/compiler/commentLeadingCloseBrace.ts new file mode 100644 index 00000000000..bdf7a604a9b --- /dev/null +++ b/tests/cases/compiler/commentLeadingCloseBrace.ts @@ -0,0 +1,11 @@ +declare function commentedParameters(...args): any; + +function ifelse() { + if (commentedParameters(1, 2)) { + /*comment1*/ + commentedParameters(3, 4); + /*comment2*/ + } else { + commentedParameters(5, 6); + } +} \ No newline at end of file