Attributes: Shave off a couple of bytes

The `attrHooks` entries for boolean attributes are only defined for jQuery 4+;
jQuery 3.x used a separate mechanism - assigning them to
`jQuery.expr.attrHandle`. That object used to be maintained by Sizzle, since
jQuery 3.7.0 it's kept in the selector module. Because of that, the `isXMLDoc`
check used to be require in this hook.

Now that standard `attrHooks` are used, the `isXMLDoc` check already happens
inside of `jQuery.attr` and there's no need to repeat it in the test. Note that
this repetition is even incorrect - while Sizzle's `jQuery.find.attr` used to
treat an `undefined` output of the hooks from `jQuery.expr.attrHandle` as a way
to opt out of the hook, jQuery's `attrHooks` use `null` to opt out of a getter
hook.

Apart from the size, this patch also avoids unnecessary extra checks.

Closes gh-5398
This commit is contained in:
Michał Gołębiowski-Owczarek 2024-01-31 01:47:11 +01:00 committed by GitHub
parent 805cdb43fd
commit b40a4807b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -108,16 +108,9 @@ jQuery.each( (
).split( " " ), function( _i, name ) { ).split( " " ), function( _i, name ) {
jQuery.attrHooks[ name ] = { jQuery.attrHooks[ name ] = {
get: function( elem ) { get: function( elem ) {
var ret, return elem.getAttribute( name ) != null ?
isXML = jQuery.isXMLDoc( elem ), name.toLowerCase() :
lowercaseName = name.toLowerCase();
if ( !isXML ) {
ret = elem.getAttribute( name ) != null ?
lowercaseName :
null; null;
}
return ret;
}, },
set: function( elem, value, name ) { set: function( elem, value, name ) {