-
Notifications
You must be signed in to change notification settings - Fork 16
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
Feat/add comment exclusions #20
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -55,14 +55,33 @@ module.exports = postcss.plugin('postcss-increase-specificity', function(options | |||||||||
var opts = objectAssign({}, defaults, options); | ||||||||||
|
||||||||||
return function(css) { | ||||||||||
css.walkRules(function(rule) { | ||||||||||
// Avoid adding additional selectors (stackableRoot) to descendant rules of @keyframe {} | ||||||||||
// i.e. `from`, `to`, or `{number}%` | ||||||||||
var isInsideKeyframes = rule.parent.type === 'atrule' && rule.parent.name === 'keyframes'; | ||||||||||
let isExcluded = false; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
css.walk(function(node) { | ||||||||||
|
||||||||||
if(!isInsideKeyframes) { | ||||||||||
increaseSpecifityOfRule(rule, opts); | ||||||||||
if (node.type === 'comment') { | ||||||||||
|
||||||||||
const commentStart = 'no important-start'; | ||||||||||
const commentEnd = 'no important-end'; | ||||||||||
Comment on lines
+63
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have to
Suggested change
|
||||||||||
|
||||||||||
if(node.text === commentStart) { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have to worry about comparing whitespace here? Perhaps we need to |
||||||||||
isExcluded = true; | ||||||||||
} | ||||||||||
|
||||||||||
if(node.text === commentEnd) { | ||||||||||
isExcluded = false; | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
if (node.type === 'rule' && !isExcluded) { | ||||||||||
const rule = node; | ||||||||||
// Avoid adding additional selectors (stackableRoot) to descendant rules of @keyframe {} | ||||||||||
// i.e. `from`, `to`, or `{number}%` | ||||||||||
var isInsideKeyframes = rule.parent.type === 'atrule' && rule.parent.name === 'keyframes'; | ||||||||||
|
||||||||||
if (!isInsideKeyframes) { | ||||||||||
increaseSpecifityOfRule(rule, opts); | ||||||||||
} | ||||||||||
} | ||||||||||
}); | ||||||||||
}) | ||||||||||
}; | ||||||||||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.foo { | ||
background: #f00; | ||
} | ||
|
||
/* no important-start */ | ||
.boo { | ||
background: green; | ||
} | ||
|
||
/* no important-end */ | ||
.coo { | ||
background:goldenrod; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
:not(#\9):not(#\9):not(#\9) .foo { | ||
background: #f00; | ||
} | ||
|
||
/* no important-start */ | ||
.boo { | ||
background: green; | ||
} | ||
/* no important-end */ | ||
|
||
:not(#\9):not(#\9):not(#\9) .coo { | ||
background:goldenrod; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,10 @@ describe('postcss-increase-specificity', function() { | |
return testPlugin('./test/fixtures/classes.css', './test/fixtures/classes.expected.css'); | ||
}); | ||
|
||
it('should handle exclusion commments', function () { | ||
return testPlugin('./test/fixtures/comments-to-exclude.css', './test/fixtures/comments-to-exclude.expected.css'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}); | ||
|
||
it('should work with multiple classes `.foo, .bar`', function() { | ||
return testPlugin('./test/fixtures/multiple-classes.css', './test/fixtures/multiple-classes.expected.css'); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay @mihaisavezi 🙇
This looks like a great v1 we can merge of this feature 👍
My comments are mainly framing everything in terms of
disable
/enable
instead ofexclude