Skip to content

Call expression's leading comments are removed when assigned to a explicitly typed variable #40943

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
cprecioso opened this issue Oct 5, 2020 · 0 comments · Fixed by #48015
Closed
Assignees
Labels
Bug A bug in TypeScript Domain: Comment Emit The issue relates to the emission of comments when compiling Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@cprecioso
Copy link

The leading comment of a call expression should be kept when removeComments: false. And indeed, it is kept in the majority of cases, except when it is in an assignment statement that also has an explicit type annotation.

My use case for this is to keep /** @__PURE__ */ annotations in some assignments that are side-effect free, so terser and uglify can remove them if unused.

There are some similar issues here already but they are closed and I suspect this is an edge case that was not accounted for.

TypeScript Version: 4.1.0-dev.20201005

Search Terms: comments, pure, annotation, uglify

Code

const var1 = /* comment1 */ foo(bar);
const var2: any = /* comment2 */ foo(bar);

Expected behavior:

const var1 = /* comment1 */ foo(bar);
const var2 = /* comment2 */ foo(bar);

Actual behavior:

const var1 = /* comment1 */ foo(bar);
const var2 = foo(bar);

Playground Link: https://www.typescriptlang.org/play?ts=4.1.0-dev.20201005#code/MYewdgzgLgBAbgQwE4EYYF4YHoBUNQC2BApmFGjljAGYggAUARsgJQDcAUKJLIkgEwAuGAjABPDNjyESZfjEo06TVpyA

Related Issues: #17606 #16727

@andrewbranch andrewbranch added Bug A bug in TypeScript Domain: Comment Emit The issue relates to the emission of comments when compiling labels Oct 6, 2020
@andrewbranch andrewbranch added this to the TypeScript 4.2.0 milestone Oct 6, 2020
@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label Mar 4, 2021
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Comment Emit The issue relates to the emission of comments when compiling Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants