Skip to content

TSC strips certain comments in object literal #13939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
grovesNL opened this issue Feb 7, 2017 · 2 comments
Closed

TSC strips certain comments in object literal #13939

grovesNL opened this issue Feb 7, 2017 · 2 comments
Assignees
Labels
Bug A bug in TypeScript Domain: Comment Emit The issue relates to the emission of comments when compiling Duplicate An existing issue was already created

Comments

@grovesNL
Copy link

grovesNL commented Feb 7, 2017

TypeScript Version: 2.1.5

When using comments in an object literal, TSC appears to strip any comments following commas. For example (TypeScript Playground):

const a = {
    b: 1, // Invisible comment
    c: 1 // Visible comment
};

Expected behavior (compiled JavaScript):

var a = {
    b: 1, // Invisible comment
    c: 1 // Visible comment
};

Actual behavior (compiled JavaScript):

var a = {
    b: 1,
    c: 1 // Visible comment
};

This issue has been ported from #13602 (comment).

@grovesNL grovesNL changed the title TSC strips comments following commas in object literal TSC strips certain comments in object literal Feb 7, 2017
@yuit
Copy link
Contributor

yuit commented Apr 12, 2017

Similar issue is reported by @mxtopher

Hello!

We are seeing the same errors on arrays that span more than one line:

Typescript source

/* comment1 */
[1 /* comment2 */ ,2, /* comment3 */ 3, /* comment4 */
4,5];
function hue (a, /* comment5 */
b, c) {
}

Compiled Javascript:

/* comment1 */
[1 /* comment2 */, 2, /* comment3 */ 3,
4, 5];
function hue(a, /* comment5 */ b, c) {
}

(comment4 is being stripped)
It only happens when it's the last thing in a line.

Thank you for investigating.

The reason of this issue is that "," is not stored in our tree and at the moment there is no way to retrieve the comment after it. These comments /* comment4 */ and // Invisible comment are not considered leading comment of the next node as leading comment use new line to indicate that anything that following should be consumed as comments.

@mhegazy mhegazy added the Bug A bug in TypeScript label Apr 13, 2017
@mhegazy mhegazy added this to the Future milestone Apr 13, 2017
@mhegazy mhegazy added the Domain: Comment Emit The issue relates to the emission of comments when compiling label Sep 1, 2017
@weswigham
Copy link
Member

Duplicates #10385

@weswigham weswigham added the Duplicate An existing issue was already created label Dec 12, 2017
@mhegazy mhegazy removed this from the Future milestone Apr 26, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Domain: Comment Emit The issue relates to the emission of comments when compiling Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants