-
Notifications
You must be signed in to change notification settings - Fork 948
Selector: Use Sizzle :has
if CSS.supports(selector(...))
non-compliant
#486
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -356,6 +356,27 @@ function Sizzle( selector, context, results, seed ) { | |
} | ||
|
||
try { | ||
|
||
// `qSA` may not throw for unrecognized parts using forgiving parsing: | ||
// https://drafts.csswg.org/selectors/#forgiving-selector | ||
// like the `:has()` pseudo-class: | ||
// https://drafts.csswg.org/selectors/#relational | ||
// `CSS.supports` is still expected to return `false` then: | ||
// https://drafts.csswg.org/css-conditional-4/#typedef-supports-selector-fn | ||
// https://drafts.csswg.org/css-conditional-4/#dfn-support-selector | ||
if ( support.cssSupportsSelector && | ||
|
||
// eslint-disable-next-line no-undef | ||
!CSS.supports( "selector(" + newSelector + ")" ) ) { | ||
|
||
// Support: IE 11+ | ||
// Throw to get to the same code path as an error directly in qSA. | ||
// Note: once we only support browser supporting | ||
// `CSS.supports('selector(...)')`, we can most likely drop | ||
// the `try-catch`. IE doesn't implement the API. | ||
throw new Error(); | ||
} | ||
|
||
push.apply( results, | ||
newContext.querySelectorAll( newSelector ) | ||
); | ||
|
@@ -651,6 +672,31 @@ setDocument = Sizzle.setDocument = function( node ) { | |
!el.querySelectorAll( ":scope fieldset div" ).length; | ||
} ); | ||
|
||
// Support: Chrome 105+, Firefox 104+, Safari 15.4+ | ||
// Make sure forgiving mode is not used in `CSS.supports( "selector(...)" )`. | ||
// | ||
// `:is()` uses a forgiving selector list as an argument and is widely | ||
// implemented, so it's a good one to test against. | ||
support.cssSupportsSelector = assert( function() { | ||
/* eslint-disable no-undef */ | ||
|
||
return CSS.supports( "selector(*)" ) && | ||
|
||
// Support: Firefox 78-81 only | ||
// In old Firefox, `:is()` didn't use forgiving parsing. In that case, | ||
// fail this test as there's no selector to test against that. | ||
// `CSS.supports` uses unforgiving parsing | ||
document.querySelectorAll( ":is(:jqfake)" ) && | ||
|
||
// `*` is needed as Safari & newer Chrome implemented something in between | ||
// for `:has()` - it throws in `qSA` if it only contains an unsupported | ||
// argument but multiple ones, one of which is supported, are fine. | ||
// We want to play safe in case `:is()` gets the same treatment. | ||
!CSS.supports( "selector(:is(*,:jqfake))" ); | ||
|
||
/* eslint-enable */ | ||
} ); | ||
|
||
/* Attributes | ||
---------------------------------------------------------------------- */ | ||
|
||
|
@@ -917,6 +963,18 @@ setDocument = Sizzle.setDocument = function( node ) { | |
} ); | ||
} | ||
|
||
if ( !support.cssSupportsSelector ) { | ||
|
||
// Support: Chrome 105+, Safari 15.4+ | ||
// `:has()` uses a forgiving selector list as an argument so our regular | ||
// `try-catch` mechanism fails to catch `:has()` with arguments not supported | ||
// natively like `:has(:contains("Foo"))`. Where supported & spec-compliant, | ||
// we now use `CSS.supports("selector(SELECTOR_TO_BE_TESTED)")` but outside | ||
// that, let's mark `:has` as buggy to always use jQuery traversal for | ||
// `:has()`. | ||
rbuggyQSA.push( ":has" ); | ||
} | ||
|
||
rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join( "|" ) ); | ||
rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join( "|" ) ); | ||
|
||
|
@@ -1719,7 +1777,7 @@ Expr = Sizzle.selectors = { | |
return elem.nodeName.toLowerCase() === "input" && | ||
elem.type === "text" && | ||
|
||
// Support: IE<8 | ||
// Support: IE <10 only | ||
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. This change is not related but I found it while working on jquery/jquery#5113 and discovering removal of this workaround breaks the relevant test in IE 9. |
||
// New HTML5 attribute values (e.g., "search") appear with elem.type === "text" | ||
( ( attr = elem.getAttribute( "type" ) ) == null || | ||
attr.toLowerCase() === "text" ); | ||
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Plus, I should mention IE & Edge as ones not supporting the API at all.