Skip to content
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

preserve_annotations changes position of /* #__PURE__ */ comments in function calls #1528

Open
justin-schroeder opened this issue May 7, 2024 · 1 comment
Labels

Comments

@justin-schroeder
Copy link

Bug report

When using inline arrow functions as function call arguments and those functions utilize the /* #__PURE__ */ annotation, the annotation is moved to an invalid location (downstream this results in rollup warnings and suboptimal tree shaking).

Version (complete output of terser -V or specific git commit)

v5.31

Complete CLI command or minify() options used

{
  format: {
    preserve_annotations: true
  }
}

terser input

export function x(a,b) {}

const nestedStatement = () => /* #__PURE__ */ x(() => 'foo', /* #__PURE__ */ x('a', 'b'));

export const foobar = nestedStatement()

terser output or error

export function x(o,t){}export const foobar=/* #__PURE__ */x((()=>"foo"/* #__PURE__ */),x("a","b"));

Expected result

export function x(o,t){}export const foobar=/* #__PURE__ */x((()=>"foo"), /* #__PURE__ */ x("a","b"));
@fabiosantoscode
Copy link
Collaborator

I'm pretty sure these comments are being attached to the wrong node at the input 🤔

Maybe this isn't the best approach. Maybe annotations should be reconstructed as opposed to preserved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants