Skip to content

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

@JSerFeng

Description

@JSerFeng

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions