Skip to content

Do not remove PURE comment after typed declaration #32060

Closed
@LongTengDao

Description

@LongTengDao

TypeScript Version: 3.4.0-dev.201xxxxx

Search Terms:

Code

const a :Type = /*#__PURE__*/ function () {}();

Expected behavior:

const a = /*#__PURE__*/ function () {}();

Actual behavior:

const a = function () {}();

Playground Link:

Related Issues:

Activity

AnyhowStep

AnyhowStep commented on Jun 24, 2019

@AnyhowStep
Contributor

Why not make it a JSDoc?

/**
 * __PURE__
 */
const a : Type = function () {}();

Output:

/**
 * __PURE__
 */
var a = function () { }();
AlCalzone

AlCalzone commented on Jun 24, 2019

@AlCalzone
Contributor

This is #13721 I think

LongTengDao

LongTengDao commented on Jun 24, 2019

@LongTengDao
ContributorAuthor

@AnyhowStep Thanks for reply. I didn't know that. But only /*#__PURE__*/ is widely used in downstream tools, like rollup (pack tool) or uglify/terser (minify tool).

BTW: I wonder why the comment removed, it's just same line with types syntax, not same part of an expression, even not same side of assignment equal mark...

added this to the Backlog milestone on Jun 26, 2019
ashi009

ashi009 commented on Sep 17, 2019

@ashi009

@AlCalzone

This is #13721 I think

#13721 is mainly for classes, which is fixed in #16631. This is actually #7770.

@LongTengDao

A workaround is to add parentheses around the pure expression, which will preserve the comment until this is fixed.

const a : Type = (/*#__PURE__*/ function () {}());
// var a = ( /*#__PURE__*/function () { }());
LongTengDao

LongTengDao commented on Sep 17, 2019

@LongTengDao
ContributorAuthor

@ashi009 Oh, that works, thank you!

Anyway, I wrote my personal ts transpiler (@ ltd/j-ts) ;)

LongTengDao

LongTengDao commented on Dec 25, 2023

@LongTengDao
ContributorAuthor

seems fixed in 5.3

jakebailey

jakebailey commented on Jan 4, 2024

@jakebailey
Member

Yes, this was fixed by #47407 (and #47158 was a dupe of this one).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ashi009@jakebailey@AnyhowStep@RyanCavanaugh@AlCalzone

        Issue actions

          Do not remove PURE comment after typed declaration · Issue #32060 · microsoft/TypeScript