mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-14 19:16:17 -06:00
Emit leading comment before brace token
This commit is contained in:
parent
7fd404dbbc
commit
80eae169ee
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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.
|
||||
}
|
||||
});
|
||||
|
||||
@ -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;
|
||||
|
||||
24
tests/baselines/reference/commentLeadingCloseBrace.js
Normal file
24
tests/baselines/reference/commentLeadingCloseBrace.js
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
21
tests/baselines/reference/commentLeadingCloseBrace.symbols
Normal file
21
tests/baselines/reference/commentLeadingCloseBrace.symbols
Normal file
@ -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))
|
||||
}
|
||||
}
|
||||
30
tests/baselines/reference/commentLeadingCloseBrace.types
Normal file
30
tests/baselines/reference/commentLeadingCloseBrace.types
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
@ -27,4 +27,5 @@ exports.C1 = C1;
|
||||
"use strict";
|
||||
var foo = require("./foo_0");
|
||||
if (foo.C1.s1) {
|
||||
// Should cause runtime import
|
||||
}
|
||||
|
||||
@ -391,6 +391,7 @@ var TestRunner = (function () {
|
||||
}
|
||||
}
|
||||
if (testResult === false) {
|
||||
//console.log(e.message);
|
||||
}
|
||||
}
|
||||
if ((testcase.errorMessageRegEx !== undefined) && !exception) {
|
||||
|
||||
@ -9,5 +9,6 @@ function foo(a) {
|
||||
//// [out.js]
|
||||
function foo(a) {
|
||||
for (var a_1 = 0; a_1 < 10; a_1++) {
|
||||
// do something
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,6 +27,7 @@ function tryCatch() {
|
||||
//// [narrowExceptionVariableInCatchClause.js]
|
||||
function tryCatch() {
|
||||
try {
|
||||
// do stuff...
|
||||
}
|
||||
catch (err) {
|
||||
if (isFooError(err)) {
|
||||
|
||||
@ -8,7 +8,9 @@ try {
|
||||
|
||||
//// [noCatchBlock.js]
|
||||
try {
|
||||
// ...
|
||||
}
|
||||
finally {
|
||||
// N.B. No 'catch' block
|
||||
}
|
||||
//# sourceMappingURL=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"}
|
||||
{"version":3,"file":"noCatchBlock.js","sourceRoot":"","sources":["noCatchBlock.ts"],"names":[],"mappings":"AACA,IAAI,CAAC;AACJ,MAAM;AACP,CAAC;QAAS,CAAC;AACV,wBAAwB;AACzB,CAAC"}
|
||||
@ -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
|
||||
@ -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.
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -23,6 +23,7 @@ function R1() {
|
||||
function R2() { R2(); }
|
||||
function R3(n) {
|
||||
if (n == 0) {
|
||||
//return;
|
||||
}
|
||||
else {
|
||||
R3(n--);
|
||||
|
||||
@ -7,7 +7,9 @@ try {
|
||||
|
||||
//// [sourceMap-SkippedNode.js]
|
||||
try {
|
||||
// ...
|
||||
}
|
||||
finally {
|
||||
// N.B. No 'catch' block
|
||||
}
|
||||
//# sourceMappingURL=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"}
|
||||
{"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"}
|
||||
@ -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
|
||||
11
tests/cases/compiler/commentLeadingCloseBrace.ts
Normal file
11
tests/cases/compiler/commentLeadingCloseBrace.ts
Normal file
@ -0,0 +1,11 @@
|
||||
declare function commentedParameters(...args): any;
|
||||
|
||||
function ifelse() {
|
||||
if (commentedParameters(1, 2)) {
|
||||
/*comment1*/
|
||||
commentedParameters(3, 4);
|
||||
/*comment2*/
|
||||
} else {
|
||||
commentedParameters(5, 6);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user