Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix false negatives for where, is, nth-child and nth-last-child in se…
…lector-max-* (except selector-max-type) (#4842) * updates keywordSets * replaces functionality of isLogicalCombination with isContextFunctionalPseudoClass note: possible logic error in selector-max-type, will investigate further * adds a check for nonstandard syntax type selectors to selector-max-type * Apply suggestions from code review minor documentation fixes! Co-authored-by: Richard Hallows <jeddy3@users.noreply.github.com> Co-authored-by: Richard Hallows <jeddy3@users.noreply.github.com>
- Loading branch information
Showing
12 changed files
with
101 additions
and
85 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
48 changes: 48 additions & 0 deletions
48
lib/utils/__tests__/isContextFunctionalPseudoClass.test.js
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,48 @@ | ||
'use strict'; | ||
|
||
const isContextFunctionalPseudoClass = require('../isContextFunctionalPseudoClass'); | ||
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('isContextFunctionalPseudoClass', () => { | ||
it('handles non-context-functional pseudo-classes, like hover', () => { | ||
selector('a:hover {}', (selector) => { | ||
expect(isContextFunctionalPseudoClass(selector)).toBe(false); | ||
}); | ||
}); | ||
|
||
it('handles logical combinations, ', () => { | ||
selector('a:has(.foo) {}', (selector) => { | ||
expect(isContextFunctionalPseudoClass(selector)).toBe(true); | ||
}); | ||
selector('a:is(.foo) {}', (selector) => { | ||
expect(isContextFunctionalPseudoClass(selector)).toBe(true); | ||
}); | ||
selector('a:matches(.foo) {}', (selector) => { | ||
expect(isContextFunctionalPseudoClass(selector)).toBe(true); | ||
}); | ||
selector('a:not(.foo) {}', (selector) => { | ||
expect(isContextFunctionalPseudoClass(selector)).toBe(true); | ||
}); | ||
selector('a:where(.foo) {}', (selector) => { | ||
expect(isContextFunctionalPseudoClass(selector)).toBe(true); | ||
}); | ||
}); | ||
|
||
it('handles tree structural/NPlusBOfSNotationPseudoClasses classes', () => { | ||
selector('a:nth-child(n+7) {}', (selector) => { | ||
expect(isContextFunctionalPseudoClass(selector)).toBe(true); | ||
}); | ||
selector('a:nth-last-child(n+7) {}', (selector) => { | ||
expect(isContextFunctionalPseudoClass(selector)).toBe(true); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
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,23 @@ | ||
'use strict'; | ||
|
||
const keywordSets = require('../reference/keywordSets'); | ||
|
||
/** | ||
* Check whether a node is a context-functional pseudo-class (i.e. either a logical combination | ||
* or a 'aNPlusBOfSNotationPseudoClasses' / tree-structural pseudo-class) | ||
* | ||
* @param {import('postcss-selector-parser').Pseudo} node postcss-selector-parser node (of type pseudo) | ||
* @return {boolean} If `true`, the node is a context-functional pseudo-class | ||
*/ | ||
module.exports = function isContextFunctionalPseudoClass(node) { | ||
if (node.type === 'pseudo') { | ||
const normalisedParentName = node.value.toLowerCase().replace(/:+/, ''); | ||
|
||
return ( | ||
keywordSets.logicalCombinationsPseudoClasses.has(normalisedParentName) || | ||
keywordSets.aNPlusBOfSNotationPseudoClasses.has(normalisedParentName) | ||
); | ||
} | ||
|
||
return false; | ||
}; |
This file was deleted.
Oops, something went wrong.
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