From 6c9b87500dd44852c23bd60ab9becb1916f7431a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Go=C5=82e=CC=A8biowski-Owczarek?= Date: Wed, 6 Nov 2024 09:51:51 +0100 Subject: [PATCH] Core: Don't reimplement deprecated but not removed APIs This will save space and avoid potential divergence from Core. To minimize risk, this only handles APIs still present in jQuery 4.x. --- src/jquery/core.js | 35 +++-------------------------------- src/jquery/event.js | 33 ++++++++++++--------------------- 2 files changed, 15 insertions(+), 53 deletions(-) diff --git a/src/jquery/core.js b/src/jquery/core.js index c1f8b311..26d47a0f 100644 --- a/src/jquery/core.js +++ b/src/jquery/core.js @@ -2,9 +2,7 @@ import { jQueryVersionSince } from "../compareVersions.js"; import { migratePatchAndWarnFunc } from "../main.js"; import "../disablePatches.js"; -var arr = [], - slice = arr.slice, - class2type = {}, +var class2type = {}, // Require that the "whitespace run" starts from a non-whitespace // to avoid O(N^2) behavior when the engine would try matching "\s+$" at each space position. @@ -116,34 +114,7 @@ if ( jQueryVersionSince( "3.3.0" ) ) { // arguments. // jQuery.proxy is deprecated to promote standards (specifically Function#bind) // However, it is not slated for removal any time soon - migratePatchAndWarnFunc( jQuery, "proxy", - function( fn, context ) { - var tmp, args, proxy; - - if ( typeof context === "string" ) { - tmp = fn[ context ]; - context = fn; - fn = tmp; - } - - // Quick check to determine if target is callable, in the spec - // this throws a TypeError, but we will just return undefined. - if ( !isFunction( fn ) ) { - return undefined; - } - - // Simulated bind - args = slice.call( arguments, 2 ); - proxy = function() { - return fn.apply( context || this, args.concat( slice.call( arguments ) ) ); - }; - - // Set the guid of unique handler to the same of original handler, so it can be removed - proxy.guid = fn.guid = fn.guid || jQuery.guid++; - - return proxy; - }, "proxy", - "jQuery.proxy() is deprecated" - ); + migratePatchAndWarnFunc( jQuery, "proxy", jQuery.proxy, + "proxy", "DEPRECATED: jQuery.proxy()" ); } diff --git a/src/jquery/event.js b/src/jquery/event.js index 5a5ea9a1..e7a6c4b8 100644 --- a/src/jquery/event.js +++ b/src/jquery/event.js @@ -96,13 +96,9 @@ jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " + function( _i, name ) { // Handle event binding - migratePatchAndWarnFunc( jQuery.fn, name, function( data, fn ) { - return arguments.length > 0 ? - this.on( name, null, data, fn ) : - this.trigger( name ); - }, - "shorthand-deprecated-v3", - "jQuery.fn." + name + "() event shorthand is deprecated" ); + migratePatchAndWarnFunc( jQuery.fn, name, jQuery.fn[ name ], "shorthand-deprecated-v3", + "DEPRECATED: jQuery.fn." + name + "() event shorthand" ); + } ); // Trigger "ready" event only once, on document ready @@ -118,20 +114,15 @@ jQuery.event.special.ready = { } }; -migratePatchAndWarnFunc( jQuery.fn, "bind", function( types, data, fn ) { - return this.on( types, null, data, fn ); -}, "pre-on-methods", "jQuery.fn.bind() is deprecated" ); -migratePatchAndWarnFunc( jQuery.fn, "unbind", function( types, fn ) { - return this.off( types, null, fn ); -}, "pre-on-methods", "jQuery.fn.unbind() is deprecated" ); -migratePatchAndWarnFunc( jQuery.fn, "delegate", function( selector, types, data, fn ) { - return this.on( types, selector, data, fn ); -}, "pre-on-methods", "jQuery.fn.delegate() is deprecated" ); -migratePatchAndWarnFunc( jQuery.fn, "undelegate", function( selector, types, fn ) { - return arguments.length === 1 ? - this.off( selector, "**" ) : - this.off( types, selector || "**", fn ); -}, "pre-on-methods", "jQuery.fn.undelegate() is deprecated" ); +migratePatchAndWarnFunc( jQuery.fn, "bind", jQuery.fn.bind, + "pre-on-methods", "jQuery.fn.bind() is deprecated" ); +migratePatchAndWarnFunc( jQuery.fn, "unbind", jQuery.fn.unbind, + "pre-on-methods", "jQuery.fn.unbind() is deprecated" ); +migratePatchAndWarnFunc( jQuery.fn, "delegate", jQuery.fn.delegate, + "pre-on-methods", "jQuery.fn.delegate() is deprecated" ); +migratePatchAndWarnFunc( jQuery.fn, "undelegate", jQuery.fn.undelegate, + "pre-on-methods", "jQuery.fn.undelegate() is deprecated" ); + migratePatchAndWarnFunc( jQuery.fn, "hover", function( fnOver, fnOut ) { return this.on( "mouseenter", fnOver ).on( "mouseleave", fnOut || fnOver ); }, "pre-on-methods", "jQuery.fn.hover() is deprecated" );