Skip to content

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

Closed
@cprecioso

Description

@cprecioso

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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Comment EmitThe issue relates to the emission of comments when compilingFix AvailableA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions