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

[preserveAllComments] Pure annotations are placed in the wrong position #7735

Open
JSerFeng opened this issue Aug 1, 2023 · 1 comment
Open
Labels
Milestone

Comments

@JSerFeng
Copy link
Contributor

JSerFeng commented Aug 1, 2023

Describe the bug

SWC injects pure annotation right before the async polyfill call, however if async arrow function is been assigned, the PURE annotation appear in the wrong position.

Why does this matter

Because if Pure appears before the import statements, when this code is processed by webpack, if this module's dependencies are all concatenated, then the import statements are gone, and the code will be like this

/*#__PURE__*/ 
setSomeEffect()

As you can see the PURE annotation points that setSomeEffect call is pure which is not, and removes this call expression after minimization.

Input code

setSomeEffect()

// 123
const a = async () => {
};

function rightPlace() {
    // 123
    async () => {
    };
}

Config

{
  "jsc": {
    "externalHelpers": true,
    "parser": {
      "tsx": true,
      "syntax": "typescript",
    },
    "preserveAllComments": true,
    "target": "es5"
  },
}

Playground link

https://play.swc.rs/?version=1.3.71&code=H4sIAAAAAAAAAytOLQnOz011TUtLTS7R0OTi0tdXMDQy5krOzysuUUhUsFVILK7MS1bQ0FSwtVOo5qq15uJKK81LLsnMz1MoykzPKAnISUxOBUpXcykAAVQ7iImqESQC1FwLAKBlQRFxAAAA&config=H4sIAAAAAAAAA12NwQqDQAxE737FkrNXL95KL%2F2NRQaxrNslGUUR%2F72xUqG9JW8mL1sVgjytkzZsPvqChdAc0wOpQM0D6oT6DEtUg15lJ7Tlp%2BLI1sx4UOFaYJ0OhXKm%2B9ejcM%2BMW0r31zgi8%2B8Ro%2Fbg4YA1Un0u9zcWcwxJrQAAAA%3D%3D

Expected behavior

Pure annotation should appear inside the assignment expr, like the one inside rightPlace function body

Actual behavior

Pure annotation appears at the top of the module

Version

1.3.71

Additional context

No response

@JSerFeng JSerFeng added the C-bug label Aug 1, 2023
@kdy1 kdy1 added this to the Planned milestone Aug 1, 2023
@kdy1 kdy1 assigned kdy1 and unassigned kdy1 Aug 1, 2023
@kdy1 kdy1 changed the title Pure annotations are placed in the wrong position [preserveAllComments] Pure annotations are placed in the wrong position Aug 7, 2023
@danieltroger
Copy link

danieltroger commented Aug 23, 2023

For me (using SWC as part of parcel) pure comments are not respected at all right now. Not sure if it's this issue or parcel-bundler/parcel#9111?

EDIT: Some actually are but some are "eaten up" even when building with --no-optimize and checking the output, weird. I found a good workaround though in the meantime - wrote a custom babel transformer that changes (0, FUNCTION)(...) back to FUNCTION(...) because my functions don't care about this anyways and now my output bundle is 50KB smaller

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

No branches or pull requests

3 participants