Selector: Properly deprecate jQuery.expr[ ":" ]/jQuery.expr.filters

Those APIs have formally been deprecated since `3.0.0`, but they never made its
way into the deprecated module.

`jQuery.expr[ ":" ]` has been removed when Sizzle got inlined into Core in
gh-4395; this change restores it.

Closes gh-5580
Ref gh-5570
Ref gh-4395
This commit is contained in:
Michał Gołębiowski-Owczarek 2024-11-04 23:59:30 +01:00 committed by GitHub
parent 07c9f02bd6
commit 329661fd53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 9 deletions

View File

@ -43,4 +43,6 @@ jQuery.holdReady = function( hold ) {
} }
}; };
jQuery.expr[ ":" ] = jQuery.expr.filters = jQuery.expr.pseudos;
export { jQuery, jQuery as $ }; export { jQuery, jQuery as $ };

View File

@ -846,7 +846,7 @@ for ( i in { submit: true, reset: true } ) {
// Easy API for creating new setFilters // Easy API for creating new setFilters
function setFilters() {} function setFilters() {}
setFilters.prototype = jQuery.expr.filters = jQuery.expr.pseudos; setFilters.prototype = jQuery.expr.pseudos;
jQuery.expr.setFilters = new setFilters(); jQuery.expr.setFilters = new setFilters();
function addCombinator( matcher, combinator, base ) { function addCombinator( matcher, combinator, base ) {

View File

@ -205,4 +205,17 @@ QUnit.test( "jQuery.proxy", function( assert ) {
cb.call( thisObject, "arg3" ); cb.call( thisObject, "arg3" );
} ); } );
if ( includesModule( "selector" ) ) {
QUnit[ QUnit.jQuerySelectors ? "test" : "skip" ](
"jQuery.expr[ \":\" ], jQuery.expr.filters",
function( assert ) {
assert.expect( 2 );
assert.strictEqual( jQuery.expr[ ":" ], jQuery.expr.pseudos,
"jQuery.expr[ \":\" ] is an alias of jQuery.expr.pseudos" );
assert.strictEqual( jQuery.expr.filters, jQuery.expr.pseudos,
"jQuery.expr.filters is an alias of jQuery.expr.pseudos" );
} );
}
} }

View File

@ -2167,10 +2167,10 @@ QUnit[ QUnit.jQuerySelectors ? "test" : "skip" ]( "custom pseudos", function( as
assert.expect( 6 ); assert.expect( 6 );
try { try {
jQuery.expr.filters.foundation = jQuery.expr.filters.root; jQuery.expr.pseudos.foundation = jQuery.expr.pseudos.root;
assert.deepEqual( jQuery.find( ":foundation" ), [ document.documentElement ], "Copy element filter with new name" ); assert.deepEqual( jQuery.find( ":foundation" ), [ document.documentElement ], "Copy element filter with new name" );
} finally { } finally {
delete jQuery.expr.filters.foundation; delete jQuery.expr.pseudos.foundation;
} }
try { try {
@ -2181,25 +2181,25 @@ QUnit[ QUnit.jQuerySelectors ? "test" : "skip" ]( "custom pseudos", function( as
} }
try { try {
jQuery.expr.filters.aristotlean = jQuery.expr.createPseudo( function() { jQuery.expr.pseudos.aristotlean = jQuery.expr.createPseudo( function() {
return function( elem ) { return function( elem ) {
return !!elem.id; return !!elem.id;
}; };
} ); } );
assert.t( "Custom element filter", "#foo :aristotlean", [ "sndp", "en", "yahoo", "sap", "anchor2", "timmy" ] ); assert.t( "Custom element filter", "#foo :aristotlean", [ "sndp", "en", "yahoo", "sap", "anchor2", "timmy" ] );
} finally { } finally {
delete jQuery.expr.filters.aristotlean; delete jQuery.expr.pseudos.aristotlean;
} }
try { try {
jQuery.expr.filters.endswith = jQuery.expr.createPseudo( function( text ) { jQuery.expr.pseudos.endswith = jQuery.expr.createPseudo( function( text ) {
return function( elem ) { return function( elem ) {
return jQuery.text( elem ).slice( -text.length ) === text; return jQuery.text( elem ).slice( -text.length ) === text;
}; };
} ); } );
assert.t( "Custom element filter with argument", "a:endswith(ogle)", [ "google" ] ); assert.t( "Custom element filter with argument", "a:endswith(ogle)", [ "google" ] );
} finally { } finally {
delete jQuery.expr.filters.endswith; delete jQuery.expr.pseudos.endswith;
} }
try { try {
@ -2213,7 +2213,7 @@ QUnit[ QUnit.jQuerySelectors ? "test" : "skip" ]( "custom pseudos", function( as
} ); } );
assert.t( "Custom set filter", "#qunit-fixture p:second", [ "ap" ] ); assert.t( "Custom set filter", "#qunit-fixture p:second", [ "ap" ] );
} finally { } finally {
delete jQuery.expr.filters.second; delete jQuery.expr.setFilters.second;
} }
try { try {
@ -2233,7 +2233,7 @@ QUnit[ QUnit.jQuerySelectors ? "test" : "skip" ]( "custom pseudos", function( as
} ); } );
assert.t( "Custom set filter with argument", "#qunit-fixture p:slice(1:3)", [ "ap", "sndp" ] ); assert.t( "Custom set filter with argument", "#qunit-fixture p:slice(1:3)", [ "ap", "sndp" ] );
} finally { } finally {
delete jQuery.expr.filters.slice; delete jQuery.expr.setFilters.slice;
} }
} ); } );