diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index ab775ba9fc6..88d9d20c4c0 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4280,9 +4280,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // TODO (yuisu) : we should not have special cases to condition emitting comments // but have one place to fix check for these conditions. - if (node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature && - node.parent && node.parent.kind !== SyntaxKind.PropertyAssignment && - node.parent.kind !== SyntaxKind.CallExpression) { + if (node.kind !== SyntaxKind.MethodDeclaration && + node.kind !== SyntaxKind.MethodSignature && + node.parent && + node.parent.kind !== SyntaxKind.PropertyAssignment && + node.parent.kind !== SyntaxKind.CallExpression && + node.parent.kind !== SyntaxKind.ArrayLiteralExpression) { // 1. Methods will emit the comments as part of emitting method declaration // 2. If the function is a property of object literal, emitting leading-comments diff --git a/tests/baselines/reference/arrayLiteralComments.js b/tests/baselines/reference/arrayLiteralComments.js new file mode 100644 index 00000000000..4f13df1c828 --- /dev/null +++ b/tests/baselines/reference/arrayLiteralComments.js @@ -0,0 +1,31 @@ +//// [arrayLiteralComments.ts] +var testArrayWithFunc = [ + // Function comment + function() { + let x = 1; + }, + // String comment + '1', + // Numeric comment + 2, + // Object comment + { a: 1 }, + // Array comment + [1, 2, 3] +] + +//// [arrayLiteralComments.js] +var testArrayWithFunc = [ + // Function comment + function () { + var x = 1; + }, + // String comment + '1', + // Numeric comment + 2, + // Object comment + { a: 1 }, + // Array comment + [1, 2, 3] +]; diff --git a/tests/baselines/reference/arrayLiteralComments.symbols b/tests/baselines/reference/arrayLiteralComments.symbols new file mode 100644 index 00000000000..c1c173d741f --- /dev/null +++ b/tests/baselines/reference/arrayLiteralComments.symbols @@ -0,0 +1,21 @@ +=== tests/cases/compiler/arrayLiteralComments.ts === +var testArrayWithFunc = [ +>testArrayWithFunc : Symbol(testArrayWithFunc, Decl(arrayLiteralComments.ts, 0, 3)) + + // Function comment + function() { + let x = 1; +>x : Symbol(x, Decl(arrayLiteralComments.ts, 3, 11)) + + }, + // String comment + '1', + // Numeric comment + 2, + // Object comment + { a: 1 }, +>a : Symbol(a, Decl(arrayLiteralComments.ts, 10, 5)) + + // Array comment + [1, 2, 3] +] diff --git a/tests/baselines/reference/arrayLiteralComments.types b/tests/baselines/reference/arrayLiteralComments.types new file mode 100644 index 00000000000..a8c32b48e41 --- /dev/null +++ b/tests/baselines/reference/arrayLiteralComments.types @@ -0,0 +1,36 @@ +=== tests/cases/compiler/arrayLiteralComments.ts === +var testArrayWithFunc = [ +>testArrayWithFunc : ((() => void) | string | number | { a: number; } | number[])[] +>[ // Function comment function() { let x = 1; }, // String comment '1', // Numeric comment 2, // Object comment { a: 1 }, // Array comment [1, 2, 3]] : ((() => void) | string | number | { a: number; } | number[])[] + + // Function comment + function() { +>function() { let x = 1; } : () => void + + let x = 1; +>x : number +>1 : number + + }, + // String comment + '1', +>'1' : string + + // Numeric comment + 2, +>2 : number + + // Object comment + { a: 1 }, +>{ a: 1 } : { a: number; } +>a : number +>1 : number + + // Array comment + [1, 2, 3] +>[1, 2, 3] : number[] +>1 : number +>2 : number +>3 : number + +] diff --git a/tests/cases/compiler/arrayLiteralComments.ts b/tests/cases/compiler/arrayLiteralComments.ts new file mode 100644 index 00000000000..131cecc1d95 --- /dev/null +++ b/tests/cases/compiler/arrayLiteralComments.ts @@ -0,0 +1,14 @@ +var testArrayWithFunc = [ + // Function comment + function() { + let x = 1; + }, + // String comment + '1', + // Numeric comment + 2, + // Object comment + { a: 1 }, + // Array comment + [1, 2, 3] +] \ No newline at end of file