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

Comments not preserved when semicolon exists #9505

Closed
fi3ework opened this issue Aug 27, 2024 · 1 comment · Fixed by #9509
Closed

Comments not preserved when semicolon exists #9505

fi3ework opened this issue Aug 27, 2024 · 1 comment · Fixed by #9509
Assignees
Labels
Milestone

Comments

@fi3ework
Copy link

Describe the bug

If a leading semicolon appears before a comment, the comment will still be stripped, even if the ⁠format.comments setting is set to ⁠"all".

Input code

;// a.ts
const a = 1

;// b.ts
const b = 2

Config

{
  "minify": false,
  "jsc": {
    "parser": {
      "syntax": "typescript"
    },
    "target": "es2022",
    "minify": {
      "mangle": false,
      "format": {
        "comments": "all"
      }
    }
  }
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.7.18&code=H4sIAAAAAAAAA7PW11dI1Csp5krOzysuUUhUsFUw5OKyBoomIUSTgKJGAMr7TWcqAAAA&config=H4sIAAAAAAAAA02NsQ7DIAxEd74Cec5QMfZvLGQiKiAIeyiK%2BPeaNImyWL53Z99urIUcSwwd3jZgYlom%2BrBXveuqomJjardWwr0IfpWA9ErsW6wChzmW%2F41gW0lmgti9nIOT3133r4xlTfRsP3DYWkZ5BJX5LWcqwvMtpgSnM8w1hxk%2FKrltzdIAAAA%3D

SWC Info output

No response

Expected behavior

All comments are reserved as format.comments is already set to "all"

Expected:

// a.ts
const a = 1;
// b.ts
const b = 2;

Actual behavior

The first comment is striped, and the second comment's position is offset.

const a = 1; // b.ts
const b = 2;

Version

1.7.18

Additional context

The leading semicolon before comments is used by webpack when generating concatenated modules debug comments. The comment will lose if it can't be preserved.

@fi3ework fi3ework added the C-bug label Aug 27, 2024
@magic-akari magic-akari self-assigned this Aug 28, 2024
@kdy1 kdy1 added this to the Planned milestone Aug 28, 2024
kdy1 pushed a commit that referenced this issue Aug 28, 2024
@kdy1 kdy1 modified the milestones: Planned, v1.7.21 Aug 28, 2024
@swc-bot
Copy link
Collaborator

swc-bot commented Sep 28, 2024

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Sep 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

4 participants