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

Avoid prefixing :export for css modules #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ function increaseSpecifityOfRule(rule, opts) {
) {
return selector + opts.stackableRoot.repeat(opts.repeat);
}

// Avoid prefix for :exports since :export block defines the symbols
// that are going to be exported to the consumer
Comment on lines +24 to +25
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
// Avoid prefix for :exports since :export block defines the symbols
// that are going to be exported to the consumer
// Avoid prefix for `:export` blocks because they define the symbols
// that are going to be exported to the consumer,
// https://github.com/css-modules/icss#export

if (selector.indexOf(":export") !== -1) {
return selector;
}
Copy link
Owner

Choose a reason for hiding this comment

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

Seems fine to me. But let's add a test for this case so we don't regress on this in the future.

Copy link
Author

Choose a reason for hiding this comment

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

Done, test added


// Otherwise just make it a descendant (this is what will happen most of the time)
// `:not(#\\9):not(#\\9):not(#\\9) .foo`
Expand Down
15 changes: 15 additions & 0 deletions test/fixtures/scss/export-option.expected.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
:not(#\9):not(#\9):not(#\9) [id="foo"] {
background: #f00 !important;
}

:not(#\9):not(#\9):not(#\9) [id^="bar"] {
background: #0f0 !important;
}

:not(#\9):not(#\9):not(#\9) .foo {
background: #f00;
}

:export {
listColor: red;
}
15 changes: 15 additions & 0 deletions test/fixtures/scss/export-option.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[id="foo"] {
background: #f00;
}

[id^="bar"] {
background: #0f0;
}

Comment on lines +1 to +8
Copy link
Owner

Choose a reason for hiding this comment

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

I think we can assert the same functionality with just the .foo and :export rules or maybe just :export by itself

Suggested change
[id="foo"] {
background: #f00;
}
[id^="bar"] {
background: #0f0;
}

.foo {
background: #f00;
}

:export {
listColor: red;
}
4 changes: 4 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,8 @@ describe('postcss-increase-specificity', function() {
it('should not change the descendant rules of @keyframes', function() {
return testPlugin('./test/fixtures/keyframes.css', './test/fixtures/keyframes.expected.css');
});

it('should ignore :export option used in scss files', function() {
return testPlugin('./test/fixtures/scss/export-option.scss', './test/fixtures/scss/export-option.expected.scss');
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think we need to use the scss extension here. CSS modules seem like they also applies to .css

});
});