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

Add Option to Keep CSS Comments in babel-plugin-emotion. Fixes #1325 #1336

Merged
merged 2 commits into from
Jul 4, 2019

Conversation

Zenwolf
Copy link
Contributor

@Zenwolf Zenwolf commented Apr 30, 2019

[edited to reflect current changes]

What:

Fixes #1325. This PR adds a list of CSS comment values that, when found, keeps the CSS comment instead of removing it when using the babel-plugin-emotion package.

Why:

Some CSS libraries require the use of comments to control library functionality. Stylis plugins can use these libraries to provide support via Stylis that Emotion uses. One example of this is the stylis-rtl plugin and the cssjanus library.

The cssjanus lib requires the use of comments to control the rtl flipping behavior for individual style rules or properties. This is an example of the comment: /* @noflip */.

The babel plugin is very convenient for developers using babel-preset-css-prop for the css react prop by automatically inserting the jsx pragma: /* @jsx jsx */. It would be really helpful if developers using libraries that depend on comments can leverage the plugin instead of having to manually configure every file.

How:

In order to support retaining comments, I added an approved list of CSS comment values. When a standard CSS comment contains the special values, the plugin will keep the comment instead of removing it. All other comments are removed.

Checklist:

  • Documentation
  • Tests -- Updated the comments fixture and snapshot with new test cases.
  • Code complete

Thank you!

@codecov
Copy link

codecov bot commented Apr 30, 2019

Codecov Report

Merging #1336 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted Files Coverage Δ
...ges/babel-plugin-emotion/src/utils/minify-utils.js 97.14% <100%> (+0.47%) ⬆️

@codecov
Copy link

codecov bot commented Apr 30, 2019

Codecov Report

Merging #1336 into master will decrease coverage by 0.24%.
The diff coverage is 64.28%.

Impacted Files Coverage Δ
packages/babel-preset-css-prop/src/index.js 100% <ø> (ø) ⬆️
packages/babel-plugin-emotion/src/utils/minify.js 100% <100%> (ø) ⬆️
...tion/src/utils/transform-expression-with-styles.js 100% <100%> (ø) ⬆️
...ges/babel-plugin-emotion/src/utils/minify-utils.js 84.21% <54.54%> (-12.46%) ⬇️

@netlify
Copy link

netlify bot commented Apr 30, 2019

Preview Docs

Built with commit 5677a2d

https://deploy-preview-1336--emotion.netlify.com

@Zenwolf
Copy link
Contributor Author

Zenwolf commented May 8, 2019

Who can point me in the right direction to add a test for this new babel plugin feature?

@emmatown
Copy link
Member

emmatown commented May 8, 2019

I’m not a fan of adding another option like this. I think the better solution would be to keep all block comments that contain @ and remove everything else.

After that change, you can add a fixture in packages/babel-plugin-emotion/tests/fixtures

@Zenwolf
Copy link
Contributor Author

Zenwolf commented May 10, 2019

I’m not a fan of adding another option like this. I think the better solution would be to keep all block comments that contain @ and remove everything else.

After that change, you can add a fixture in packages/babel-plugin-emotion/tests/fixtures

Thank you for the comments, @mitchellhamilton ! If you are not interested in the general option to keep comments, then this sounds easier to do. I'll update the PR as soon as I get the chance.

…der to support stylis plugins such as those that use cssjanus library, which depend on special css comments.
@Zenwolf Zenwolf force-pushed the add-babel-plugin-css-option branch from 5677a2d to 3d6f522 Compare July 3, 2019 23:15
@changeset-bot
Copy link

changeset-bot bot commented Jul 3, 2019

💥 No Changeset

Latest commit: f1289ae

Merging this PR will not cause any packages to be released. If these changes should not cause updates to packages in this repo, this is fine 🙂

If these changes should be published to npm, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

// @noflip supports RTL via stylis plugin using cssjanus lib. If the comments
// that include this are stripped out, RTL will not work.
'@noflip'
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, let me clarify, I meant any block comment that contains @ anywhere in the comment, they should be kept so /* @whatever */ and etc. should be kept.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, no problem. I can make that change.

Copy link
Member

@emmatown emmatown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!!

@emmatown emmatown merged commit 284f8fa into emotion-js:master Jul 4, 2019
@Zenwolf
Copy link
Contributor Author

Zenwolf commented Aug 19, 2019

Hi @mitchellhamilton , is there any way to know when a new version of Emotion will be released that contains these changes? Or do I need to do something in order to create a release?

@emmatown
Copy link
Member

This change has been included in the past two versions of babel-plugin-emotion

@Zenwolf
Copy link
Contributor Author

Zenwolf commented Aug 20, 2019

@mitchellhamilton Thank you very much! I really appreciate your response.

louisgv pushed a commit to louisgv/emotion that referenced this pull request Sep 6, 2020
…n-js#1325 (emotion-js#1336)

* Add ability to retain CSS comments with specific allowed values in order to support stylis plugins such as those that use cssjanus library, which depend on special css comments.

* Simplify comment-checking.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Comments are stripped out before being passed to Stylis plugins, which breaks the stylis-rtl RTL plugin
2 participants