Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for all logical combinations (:matches, :has) in selector…
…-* (#4179)
- Loading branch information
1 parent
7a0c036
commit b658f41
Showing
14 changed files
with
198 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"use strict"; | ||
|
||
const isLogicalCombination = require("../isLogicalCombination"); | ||
const parseSelector = require("postcss-selector-parser"); | ||
const postcss = require("postcss"); | ||
|
||
function selector(css, cb) { | ||
postcss.parse(css).walkRules(rule => { | ||
parseSelector(selectorAST => { | ||
selectorAST.walkPseudos(cb); | ||
}).processSync(rule.selector); | ||
}); | ||
} | ||
|
||
describe("isLogicalCombination", () => { | ||
it("hover pseudo class is NOT logical combination", () => { | ||
selector("a:hover {}", selector => { | ||
expect(isLogicalCombination(selector)).toBe(false); | ||
}); | ||
}); | ||
|
||
it("not pseudo class is logical combination", () => { | ||
selector("a:not(.foo) {}", selector => { | ||
expect(isLogicalCombination(selector)).toBe(true); | ||
}); | ||
}); | ||
|
||
it("has pseudo class is logical combination", () => { | ||
selector("a:has(.foo) {}", selector => { | ||
expect(isLogicalCombination(selector)).toBe(true); | ||
}); | ||
}); | ||
|
||
it("matches pseudo class is logical combination", () => { | ||
selector("a:matches(.foo) {}", selector => { | ||
expect(isLogicalCombination(selector)).toBe(true); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* @flow */ | ||
"use strict"; | ||
|
||
/** | ||
* Check whether a node is logical combination (`:not`, `:has`, `:matches`) | ||
* | ||
* @param {Node} postcss-selector-parser node (of type pseudo) | ||
* @return {boolean} If `true`, the combination is logical | ||
*/ | ||
module.exports = function isLogicalCombination( | ||
node /*: Object*/ | ||
) /*: boolean*/ { | ||
if (node.type === "pseudo") { | ||
switch (node.value) { | ||
case ":not": | ||
case ":has": | ||
case ":matches": | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
return false; | ||
}; |