Skip to content

Commit bfd4b3a

Browse files
authored
Core: Fix the selector module, make CI green
Changes: 1. Support legacy pseudos only in jQuery 3.7.0+. 2. Downgrade sinon to a version working with IE 9+. 3. Skip cross-domain ajax tests in IE 9. 4. Skip tests requiring `jQuery.Deferred.getErrorHook` in <3.7. 5. Don't require warnings for backwards-compatible pseudos if Proxy unsupported. Closes jquerygh-552
1 parent 77e2245 commit bfd4b3a

File tree

6 files changed

+153
-96
lines changed

6 files changed

+153
-96
lines changed

package-lock.json

Lines changed: 74 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"qunit": "2.21.0",
5858
"rollup": "4.22.4",
5959
"selenium-webdriver": "4.21.0",
60-
"sinon": "9.2.4",
60+
"sinon": "7.5.0",
6161
"uglify-js": "3.9.4",
6262
"yargs": "17.7.2"
6363
},

src/jquery/selector.js

Lines changed: 56 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { jQueryVersionSince } from "../compareVersions.js";
12
import { 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
}

test/unit/jquery/ajax.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ QUnit.test( "jQuery.ajax() deprecations on jqXHR", function( assert ) {
3030
function runTests( options ) {
3131
var forceEnablePatch = ( options || {} ).forceEnablePatch || false;
3232

33-
QUnit.test( "jQuery.ajax() JSON-to-JSONP auto-promotion" + label + (
33+
// Support: IE <10 only
34+
// IE 9 doesn't support CORS, skip cross-domain tests there.
35+
QUnit[
36+
document.documentMode < 10 && crossDomain ? "skip" : "test"
37+
]( "jQuery.ajax() JSON-to-JSONP auto-promotion" + label + (
3438
forceEnablePatch ? ", patch force-enabled" : ""
3539
), function( assert ) {
3640

test/unit/jquery/deferred.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ QUnit.test( "jQuery.Deferred.getStackHook - setter", function( assert ) {
123123
} );
124124
} );
125125

126-
QUnit.test( "jQuery.Deferred.getStackHook - disabled patch, getter", function( assert ) {
126+
// jQuery.Deferred.getErrorHook was introduced in jQuery 3.7.0 and this test
127+
// depends on it.
128+
QUnit[
129+
jQueryVersionSince( "3.7.0" ) ? "test" : "skip"
130+
]( "jQuery.Deferred.getStackHook - disabled patch, getter", function( assert ) {
127131
assert.expect( 5 );
128132

129133
var exceptionHookSpy,

test/unit/jquery/selector.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,20 @@ QUnit.test( "custom pseudos", function( assert ) {
189189
} );
190190
} );
191191

192-
QUnit.test( "backwards-compatible custom pseudos", function( assert ) {
192+
QUnit[
193+
jQueryVersionSince( "3.7.0" ) ? "test" : "skip"
194+
]( "backwards-compatible custom pseudos", function( assert ) {
193195
assert.expect( 7 );
194196

197+
var expectWarningWithProxy = typeof Proxy !== "undefined" ?
198+
expectWarning :
199+
function( _assert, _title, fn ) {
200+
fn();
201+
assert.ok( true, "No Proxy => warnings not expected" );
202+
};
203+
195204
try {
196-
expectWarning( assert, "Custom element filter with argument - setter", function() {
205+
expectWarningWithProxy( assert, "Custom element filter with argument - setter", function() {
197206
jQuery.expr.pseudos.icontains = function( elem, i, match ) {
198207
return jQuery
199208
.text( elem )
@@ -214,7 +223,7 @@ QUnit.test( "backwards-compatible custom pseudos", function( assert ) {
214223
}
215224

216225
try {
217-
expectWarning( assert, "Custom setFilter pseudo - setter", function() {
226+
expectWarningWithProxy( assert, "Custom setFilter pseudo - setter", function() {
218227
jQuery.expr.setFilters.podium = function( elements, argument ) {
219228
var count = argument == null || argument === "" ? 3 : +argument;
220229
return elements.slice( 0, count );

0 commit comments

Comments
 (0)