1+ import { jQueryVersionSince } from "../compareVersions.js" ;
12import { migratePatchFunc , migrateWarnProp , migrateWarn } from "../main.js" ;
23
34// Now jQuery.expr.pseudos is the standard incantation
@@ -11,59 +12,66 @@ function markFunction( fn ) {
1112 return fn ;
1213}
1314
14- migratePatchFunc ( jQuery . expr . filter , "PSEUDO" , function ( pseudo , argument ) {
15+ // jQuery older than 3.7.0 used Sizzle which has its own private expando
16+ // variable that we cannot access. This makes thi patch impossible in those
17+ // jQuery versions.
18+ if ( jQueryVersionSince ( "3.7.0" ) ) {
19+ migratePatchFunc ( jQuery . expr . filter , "PSEUDO" , function ( pseudo , argument ) {
1520
16- // pseudo-class names are case-insensitive
17- // https://www.w3.org/TR/selectors/#pseudo-classes
18- // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters
19- // Remember that setFilters inherits from pseudos
20- var args ,
21- fn = jQuery . expr . pseudos [ pseudo ] ||
22- jQuery . expr . setFilters [ pseudo . toLowerCase ( ) ] ||
23- jQuery . error ( "Syntax error, unrecognized expression: unsupported pseudo: " + pseudo ) ;
21+ // pseudo-class names are case-insensitive
22+ // https://www.w3.org/TR/selectors/#pseudo-classes
23+ // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters
24+ // Remember that setFilters inherits from pseudos
25+ var args ,
26+ fn = jQuery . expr . pseudos [ pseudo ] ||
27+ jQuery . expr . setFilters [ pseudo . toLowerCase ( ) ] ||
28+ jQuery . error (
29+ "Syntax error, unrecognized expression: unsupported pseudo: " +
30+ pseudo ) ;
2431
25- // The user may use createPseudo to indicate that
26- // arguments are needed to create the filter function
27- // just as jQuery does
28- if ( fn [ jQuery . expando ] ) {
29- return fn ( argument ) ;
30- }
32+ // The user may use createPseudo to indicate that
33+ // arguments are needed to create the filter function
34+ // just as jQuery does
35+ if ( fn [ jQuery . expando ] ) {
36+ return fn ( argument ) ;
37+ }
3138
32- // But maintain support for old signatures
33- if ( fn . length > 1 ) {
34- migrateWarn ( "legacy-custom-pseudos" ,
35- "Pseudos with multiple arguments are deprecated; " +
36- "use jQuery.expr.createPseudo()" ) ;
37- args = [ pseudo , pseudo , "" , argument ] ;
38- return jQuery . expr . setFilters . hasOwnProperty ( pseudo . toLowerCase ( ) ) ?
39- markFunction ( function ( seed , matches ) {
40- var idx ,
41- matched = fn ( seed , argument ) ,
42- i = matched . length ;
43- while ( i -- ) {
44- idx = Array . prototype . indexOf . call ( seed , matched [ i ] ) ;
45- seed [ idx ] = ! ( matches [ idx ] = matched [ i ] ) ;
46- }
47- } ) :
48- function ( elem ) {
49- return fn ( elem , 0 , args ) ;
50- } ;
51- }
39+ // But maintain support for old signatures
40+ if ( fn . length > 1 ) {
41+ migrateWarn ( "legacy-custom-pseudos" ,
42+ "Pseudos with multiple arguments are deprecated; " +
43+ "use jQuery.expr.createPseudo()" ) ;
44+ args = [ pseudo , pseudo , "" , argument ] ;
45+ return jQuery . expr . setFilters . hasOwnProperty ( pseudo . toLowerCase ( ) ) ?
46+ markFunction ( function ( seed , matches ) {
47+ var idx ,
48+ matched = fn ( seed , argument ) ,
49+ i = matched . length ;
50+ while ( i -- ) {
51+ idx = Array . prototype . indexOf . call ( seed , matched [ i ] ) ;
52+ seed [ idx ] = ! ( matches [ idx ] = matched [ i ] ) ;
53+ }
54+ } ) :
55+ function ( elem ) {
56+ return fn ( elem , 0 , args ) ;
57+ } ;
58+ }
5259
53- return fn ;
54- } , "legacy-custom-pseudos" ) ;
60+ return fn ;
61+ } , "legacy-custom-pseudos" ) ;
5562
56- if ( typeof Proxy !== "undefined" ) {
57- jQuery . each ( [ "pseudos" , "setFilters" ] , function ( _ , api ) {
58- jQuery . expr [ api ] = new Proxy ( jQuery . expr [ api ] , {
59- set : function ( _target , _prop , fn ) {
60- if ( typeof fn === "function" && ! fn [ jQuery . expando ] && fn . length > 1 ) {
61- migrateWarn ( "legacy-custom-pseudos" ,
62- "Pseudos with multiple arguments are deprecated; " +
63- "use jQuery.expr.createPseudo()" ) ;
63+ if ( typeof Proxy !== "undefined" ) {
64+ jQuery . each ( [ "pseudos" , "setFilters" ] , function ( _ , api ) {
65+ jQuery . expr [ api ] = new Proxy ( jQuery . expr [ api ] , {
66+ set : function ( _target , _prop , fn ) {
67+ if ( typeof fn === "function" && ! fn [ jQuery . expando ] && fn . length > 1 ) {
68+ migrateWarn ( "legacy-custom-pseudos" ,
69+ "Pseudos with multiple arguments are deprecated; " +
70+ "use jQuery.expr.createPseudo()" ) ;
71+ }
72+ return Reflect . set . apply ( this , arguments ) ;
6473 }
65- return Reflect . set . apply ( this , arguments ) ;
66- }
74+ } ) ;
6775 } ) ;
68- } ) ;
76+ }
6977}
0 commit comments