-
Notifications
You must be signed in to change notification settings - Fork 470
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
Core: Fix the selector module, make CI green #552
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { jQueryVersionSince } from "../compareVersions.js"; | ||
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. Does this import mean we don't need it as a global in the eslint config? 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. Imports are in source, globals are in tests; the ESLint global is for tests. Tests are loaded as regular scripts. 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. ...which annoys me a lot, as WebStorm keeps inserting the imports the first time I add usage in a test file and I have to remove it. 😅 When we no longer support IE, we can consider loading test files as modules and remove all the globals (plus, this would allow us to only keep one version of these utils; now they're duplicated). |
||
import { migratePatchFunc, migrateWarnProp, migrateWarn } from "../main.js"; | ||
|
||
// Now jQuery.expr.pseudos is the standard incantation | ||
|
@@ -11,59 +12,66 @@ function markFunction( fn ) { | |
return fn; | ||
} | ||
|
||
migratePatchFunc( jQuery.expr.filter, "PSEUDO", function( pseudo, argument ) { | ||
// jQuery older than 3.7.0 used Sizzle which has its own private expando | ||
// variable that we cannot access. This makes thi patch impossible in those | ||
// jQuery versions. | ||
if ( jQueryVersionSince( "3.7.0" ) ) { | ||
migratePatchFunc( jQuery.expr.filter, "PSEUDO", function( pseudo, argument ) { | ||
|
||
// pseudo-class names are case-insensitive | ||
// https://www.w3.org/TR/selectors/#pseudo-classes | ||
// Prioritize by case sensitivity in case custom pseudos are added with uppercase letters | ||
// Remember that setFilters inherits from pseudos | ||
var args, | ||
fn = jQuery.expr.pseudos[ pseudo ] || | ||
jQuery.expr.setFilters[ pseudo.toLowerCase() ] || | ||
jQuery.error( "Syntax error, unrecognized expression: unsupported pseudo: " + pseudo ); | ||
// pseudo-class names are case-insensitive | ||
// https://www.w3.org/TR/selectors/#pseudo-classes | ||
// Prioritize by case sensitivity in case custom pseudos are added with uppercase letters | ||
// Remember that setFilters inherits from pseudos | ||
var args, | ||
fn = jQuery.expr.pseudos[ pseudo ] || | ||
jQuery.expr.setFilters[ pseudo.toLowerCase() ] || | ||
jQuery.error( | ||
"Syntax error, unrecognized expression: unsupported pseudo: " + | ||
pseudo ); | ||
|
||
// The user may use createPseudo to indicate that | ||
// arguments are needed to create the filter function | ||
// just as jQuery does | ||
if ( fn[ jQuery.expando ] ) { | ||
return fn( argument ); | ||
} | ||
// The user may use createPseudo to indicate that | ||
// arguments are needed to create the filter function | ||
// just as jQuery does | ||
if ( fn[ jQuery.expando ] ) { | ||
return fn( argument ); | ||
} | ||
|
||
// But maintain support for old signatures | ||
if ( fn.length > 1 ) { | ||
migrateWarn( "legacy-custom-pseudos", | ||
"Pseudos with multiple arguments are deprecated; " + | ||
"use jQuery.expr.createPseudo()" ); | ||
args = [ pseudo, pseudo, "", argument ]; | ||
return jQuery.expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ? | ||
markFunction( function( seed, matches ) { | ||
var idx, | ||
matched = fn( seed, argument ), | ||
i = matched.length; | ||
while ( i-- ) { | ||
idx = Array.prototype.indexOf.call( seed, matched[ i ] ); | ||
seed[ idx ] = !( matches[ idx ] = matched[ i ] ); | ||
} | ||
} ) : | ||
function( elem ) { | ||
return fn( elem, 0, args ); | ||
}; | ||
} | ||
// But maintain support for old signatures | ||
if ( fn.length > 1 ) { | ||
migrateWarn( "legacy-custom-pseudos", | ||
"Pseudos with multiple arguments are deprecated; " + | ||
"use jQuery.expr.createPseudo()" ); | ||
args = [ pseudo, pseudo, "", argument ]; | ||
return jQuery.expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ? | ||
markFunction( function( seed, matches ) { | ||
var idx, | ||
matched = fn( seed, argument ), | ||
i = matched.length; | ||
while ( i-- ) { | ||
idx = Array.prototype.indexOf.call( seed, matched[ i ] ); | ||
seed[ idx ] = !( matches[ idx ] = matched[ i ] ); | ||
} | ||
} ) : | ||
function( elem ) { | ||
return fn( elem, 0, args ); | ||
}; | ||
} | ||
|
||
return fn; | ||
}, "legacy-custom-pseudos" ); | ||
return fn; | ||
}, "legacy-custom-pseudos" ); | ||
|
||
if ( typeof Proxy !== "undefined" ) { | ||
jQuery.each( [ "pseudos", "setFilters" ], function( _, api ) { | ||
jQuery.expr[ api ] = new Proxy( jQuery.expr[ api ], { | ||
set: function( _target, _prop, fn ) { | ||
if ( typeof fn === "function" && !fn[ jQuery.expando ] && fn.length > 1 ) { | ||
migrateWarn( "legacy-custom-pseudos", | ||
"Pseudos with multiple arguments are deprecated; " + | ||
"use jQuery.expr.createPseudo()" ); | ||
if ( typeof Proxy !== "undefined" ) { | ||
jQuery.each( [ "pseudos", "setFilters" ], function( _, api ) { | ||
jQuery.expr[ api ] = new Proxy( jQuery.expr[ api ], { | ||
set: function( _target, _prop, fn ) { | ||
if ( typeof fn === "function" && !fn[ jQuery.expando ] && fn.length > 1 ) { | ||
migrateWarn( "legacy-custom-pseudos", | ||
"Pseudos with multiple arguments are deprecated; " + | ||
"use jQuery.expr.createPseudo()" ); | ||
} | ||
return Reflect.set.apply( this, arguments ); | ||
} | ||
return Reflect.set.apply( this, arguments ); | ||
} | ||
} ); | ||
} ); | ||
} ); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,11 +189,20 @@ QUnit.test( "custom pseudos", function( assert ) { | |
} ); | ||
} ); | ||
|
||
QUnit.test( "backwards-compatible custom pseudos", function( assert ) { | ||
QUnit[ | ||
jQueryVersionSince( "3.7.0" ) ? "test" : "skip" | ||
]( "backwards-compatible custom pseudos", function( assert ) { | ||
assert.expect( 7 ); | ||
|
||
var expectWarningWithProxy = typeof Proxy !== "undefined" ? | ||
expectWarning : | ||
function( _assert, _title, fn ) { | ||
fn(); | ||
assert.ok( true, "No Proxy => warnings not expected" ); | ||
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 is added so that the number of assertions is identical in both versions. |
||
}; | ||
|
||
try { | ||
expectWarning( assert, "Custom element filter with argument - setter", function() { | ||
expectWarningWithProxy( assert, "Custom element filter with argument - setter", function() { | ||
jQuery.expr.pseudos.icontains = function( elem, i, match ) { | ||
return jQuery | ||
.text( elem ) | ||
|
@@ -214,7 +223,7 @@ QUnit.test( "backwards-compatible custom pseudos", function( assert ) { | |
} | ||
|
||
try { | ||
expectWarning( assert, "Custom setFilter pseudo - setter", function() { | ||
expectWarningWithProxy( assert, "Custom setFilter pseudo - setter", function() { | ||
jQuery.expr.setFilters.podium = function( elements, argument ) { | ||
var count = argument == null || argument === "" ? 3 : +argument; | ||
return elements.slice( 0, count ); | ||
|
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.
I almost said something in the previous PR, but forgot the main branch still supports IE9.