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

Specify which types of comments should be removed #10272

Open
Markshall opened this issue Jul 26, 2019 · 3 comments

Comments

@Markshall
Copy link

commented Jul 26, 2019

Describe the bug

I'm setting

{
  "comments": false
}

...in my babel.config.js which obviously, as expected, removes all comments.

What I want to do is keep 'loud' comments, i.e. comments that start with /*! rather than just /* or //.
I know Sass/Scss allows this functionality but I've done some digging around and it looks as though Babel doesn't support it.

To Reproduce

Minimal code to reproduce the bug

/*!
here is my loud comment
here is some more stuff to comment
*/

//here is a single-line comment

/*
here is a multi-line comment
*/

Actual Output

Expected Output

/*!
here is my loud comment
here is some more stuff to comment
*/

Configuration

module.exports = {
  "presets": [
    [
      "minify",
      {
        "keepFnName": false
      }
    ]
  ],
  "plugins": [
    ["@babel/plugin-transform-arrow-functions"],
    ["@babel/plugin-transform-destructuring"],
    ["@babel/plugin-transform-template-literals"]
  ],
  "comments": false
};

Possible solution

I'd suggest being able to specify which types of comments shouldn't be stripped out. If no value is passed, then all comments should be removed.

For example, all comments would be removed here:

{
  "comments": []
}

All comments except for loud comments will be removed:

{
  "comments": ['loud']
}

Only single-line comments will be removed:

{
  "comments": ['loud', 'multi-line']
}
@babel-bot

This comment has been minimized.

Copy link
Collaborator

commented Jul 26, 2019

Hey @Markshall! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

@JLHwung

This comment has been minimized.

Copy link
Contributor

commented Jul 29, 2019

I would suggest you define your own shouldPrintComment handler. E.g.

{
  shouldPrintComment(val) {
    return val.startsWith("!") // keep loud comments
  }
}

Note that in this case your babel config should be written as JavaScript instead of JSON.

@Markshall

This comment has been minimized.

Copy link
Author

commented Jul 30, 2019

I would suggest you define your own shouldPrintComment handler. E.g.

{
  shouldPrintComment(val) {
    return val.startsWith("!") // keep loud comments
  }
}

Note that in this case your babel config should be written as JavaScript instead of JSON.

Will take a look into that now, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.