swc icon indicating copy to clipboard operation
swc copied to clipboard

`/*#__PURE__*/` comment in the wrong place

Open walkerburgin opened this issue 8 months ago • 0 comments

Describe the bug

We're upgrading to a new version of rollup (by way of vite) and started seeing a bunch of errors that look like this:

(!) src/index.js (2:36): A comment

"/*#__PURE__*/"

in "src/index.js" contains an annotation that Rollup cannot interpret due to the position of the comment. The comment will be removed to avoid issues.

We're using SWC for transpilation from TypeScript to JavaScript, and I think what's happening is that the new version of rollup is better at detecting incorrect SWC output than the previous version.

Input code

const createFragment = (key: { name: string }): JSX.Element => (
    <>Key Name: {key.name ?? "None"}</>
);

Config

{
  "sourceMaps": true,
  "module": {
    "type": "es6",
    "strictMode": true,
    "noInterop": false
  },
  "jsc": {
    "externalHelpers": false,
    "target": "es2017",
    "parser": {
      "syntax": "typescript",
      "tsx": true,
      "decorators": true,
      "dynamicImport": true
    },
    "transform": {
      "legacyDecorator": true,
      "decoratorMetadata": false,
      "react": {
        "throwIfNamespace": false,
        "useBuiltins": false,
        "pragma": "React.createElement",
        "pragmaFrag": "React.Fragment",
        "importSource": "react",
        "runtime": "automatic"
      }
    },
    "keepClassNames": true,
    "paths": {},
    "baseUrl": "../.."
  }
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.6.5&code=H4sIAAAAAAAAA0vOzysuUUguSk0sSXUrSkzPTc0rUbBV0MhOrbRSqFbIS8xNtVIoLinKzEtXqNW0UvAKjtBzzUmFKLNT0OBSAAIbO%2B%2FUSgU%2FsNpqoE49kDYFe3sFJb%2F8vFSlWht9Oy5NawDqpaNrawAAAA%3D%3D&config=H4sIAAAAAAAAA3VSy07DMBC89yuqnKvwOIDEkZfooRxAfMDibIvBL%2B1uRKMq%2F443TdqkwMXSzoxnxivvZvN5wbEmgytIXNzMhWpcKOpjVTvMyC5PeZYm6VQgXxWLPcRC1sgqVji6mPEQl0GQYsrwGhxjhtvO9JPN0RG3WRTAPaFLSDyIexMB2qDsEy%2FPL66H0ATESAcXrdEEga0qtSMbskl6tfrwdtIuQxWaSCCR%2BBfTBPDWLH2KJD3Zce3QiiDwOpIfF3C4AdPcD67%2Fxq1QoAKB6UuzghCMjBw16IPi93L9DB45gcHTO1lSM97W1okN%2FAebCDZeo4oXdS9NDhF8cOgxHNdzED7m8yjW6VRnu6W8dp9FlfvSIwHVQazvOKglehBrip5uJ1v8Qkx3Dpi7500%2FTwL5UGg3iN%2BB8Y2c2pblWVmqZTtrZz81fnyAvAIAAA%3D%3D

SWC Info output

Operating System:
    Platform: darwin
    Arch: arm64
    Machine Type: arm64
    Version: Darwin Kernel Version 23.5.0: Wed May  1 20:13:18 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6030
    CPU: (12 cores)
        Models: Apple M3 Pro

Binaries:
    Node: 20.5.1
    npm: 9.8.0
    Yarn: ⚠️  We've switched to PNPM; Yarn is no longer available.

Relevant Packages:
    @swc/core: 1.6.5
    @swc/helpers: N/A
    @swc/types: N/A
    typescript: 5.4.5

SWC Config:
    output: N/A
    .swcrc path: N/A

Next.js info:
    output: N/A

Expected behavior

Correct placement (or omission?) of the /*#__PURE__*/ comment

Actual behavior

The /*#__PURE__*/ comment is emitted in a bad location

Version

@swc/[email protected]

Additional context

Related issues:

  • https://github.com/swc-project/swc/issues/8419
  • https://github.com/swc-project/swc/issues/8199

walkerburgin avatar Jun 27 '24 21:06 walkerburgin