swc icon indicating copy to clipboard operation
swc copied to clipboard

preserveAllComments does not place comment close to original position

Open smcenlly opened this issue 3 years ago • 0 comments

Describe the bug

I understand that preserveAllComments follow a heuristic but it seems quite wrong in this case and leads to some weird behavior in our application that relies on comments to be close to the AST node that they were placed against. We were hoping you might be able to do something about this for us.

Input code

export function a() {
    globalThis //?
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true,
      "decorators": false,
      "dynamicImport": true
    },
    "transform": {
      "react": {
          "runtime": "automatic"
      }
    },
    "target": "es2018",
    "preserveAllComments": true
  },
  "sourceMaps": true
}

Playground link

https://play.swc.rs/?version=1.2.185&code=H4sIAAAAAAAAA0utKMgvKlFIK81LLsnMz1NI1NBUqOZSAIL0nPykxJyQjMxiBX19e65aAI2m0qAqAAAA&config=H4sIAAAAAAAAAz2OMQ7CMAxF7%2BK5AzChboiJgUNYxkVBdRzZDqKqencSEGxfT8%2F%2Fe4WHE4wrFDRn68mXHPiCEWIp7GSpBAwQ3lBY5QFuTGoYag7jhLN3tGSURBcpavH1tnZjmH1Sk15rjBSfUHMk4TaANVQwEsHWbbQ7NwPYD7v9sW0W4%2FbTk0%2FzfFYRzuH%2FbtdqxFcsP%2FQGyaRUqsoAAAA%3D

Expected behavior

export function a() {
    globalThis; //?
}


//# sourceMappingURL=file.js.map

Actual behavior

export function a() {
    globalThis;
} //?


//# sourceMappingURL=file.js.map

Version

@swc/[email protected], @swc/[email protected]

Additional context

No response

smcenlly avatar May 17 '22 00:05 smcenlly