8000 Core: Prepare for Migrate 4.0.0 by mgol · Pull Request #555 · jquery/jquery-migrate · GitHub
[go: up one dir, main page]

Skip to content

Core: Prepare for Migrate 4.0.0 #555

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

Merged
merged 6 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Core: Remove patches for breaking changes in jQuery 3.0.0 or older
The `self-closed-tags` patch remains, despite being a breaking change in jQuery
3.5.0, not 4.0.0. There are a few reasons for that:
1. It's an exception that a breaking change arrived in a non-major version bump.
   Some people may be upgrading from jQuery 3.4.0 or older and it's good to
   make it work for them.
2. The patch is disabled by default, so the concern of people on newer jQuery
   3.x upgrading to jQuery 4.x with Migrate 4.x getting patches restoring
   behavior from an version older than the pre-upgrade one does not exist.
3. This was a pretty big break, it may help people update if we still support
   it.
  • Loading branch information
mgol committed Feb 2, 2025
commit fdc12398bf6f9a6142fb2ba55af9d5abae0f703e
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"title": "jQuery Migrate",
"description": "Migrate older jQuery code to jQuery 3.0+",
"main": "dist/jquery-migrate.js",
"version": "3.5.3-pre",
"version": "4.0.0-pre",
"type": "module",
"homepage": "https://github.com/jquery/jquery-migrate",
"author": {
Expand Down
23 changes: 3 additions & 20 deletions src/jquery/ajax.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
import { migrateWarn, migratePatchAndWarnFunc, migratePatchFunc } from "../main.js";
import { migrateWarn } from "../main.js";

// Support jQuery slim which excludes the ajax module
if ( jQuery.ajax ) {

var oldAjax = jQuery.ajax,
oldCallbacks = [],
var oldCallbacks = [],
guid = "migrate-" + Date.now(),
origJsonpCallback = jQuery.ajaxSettings.jsonpCallback,
rjsonp = /(=)\?(?=&|$)|\?\?/,
rquery = /\?/;

migratePatchFunc( jQuery, "ajax", function() {
var jQXHR = oldAjax.apply( this, arguments );

// Be sure we got a jQXHR (e.g., not sync)
if ( jQXHR.promise ) {
migratePatchAndWarnFunc( jQXHR, "success", jQXHR.done, "jqXHR-methods",
"jQXHR.success is deprecated and removed" );
migratePatchAndWarnFunc( jQXHR, "error", jQXHR.fail, "jqXHR-methods",
"jQXHR.error is deprecated and removed" );
migratePatchAndWarnFunc( jQXHR, "complete", jQXHR.always, "jqXHR-methods",
"jQXHR.complete is deprecated and removed" );
}

return jQXHR;
}, "jqXHR-methods" );

jQuery.ajaxSetup( {
jsonpCallback: function() {

Expand Down Expand Up @@ -64,7 +47,7 @@ jQuery.ajaxPrefilter( "+json", function( s, originalSettings, jqXHR ) {

// Handle iff the expected data type is "jsonp" or we have a parameter to set
if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
migrateWarn( "jsonp-promotion", "JSON-to-JSONP auto-promotion is deprecated" );
migrateWarn( "jsonp-promotion", "JSON-to-JSONP auto-promotion is deprecated and removed" );

// Get callback name, remembering preexisting value associated with it
callbackName = s.jsonpCallback = typeof s.jsonpCallback === "function" ?
Expand Down
34 changes: 2 additions & 32 deletions src/jquery/attributes.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { migratePatchFunc, migrateWarn } from "../main.js";

var oldRemoveAttr = jQuery.fn.removeAttr,
oldJQueryAttr = jQuery.attr,
var oldJQueryAttr = jQuery.attr,
oldToggleClass = jQuery.fn.toggleClass,
booleans = "checked|selected|async|autofocus|autoplay|controls|defer|" +
"disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",
rbooleans = new RegExp( "^(?:" + booleans + ")$", "i" ),
rmatchNonSpace = /\S+/g,

// Some formerly boolean attributes gained new values with special meaning.
// Skip the old boolean attr logic for those values.
Expand Down Expand Up @@ -92,34 +90,6 @@ migratePatchFunc( jQuery, "attr", function( elem, name, value ) {
return oldJQueryAttr.apply( this, arguments );
}, "attr-false" );

migratePatchFunc( jQuery.fn, "removeAttr", function( name ) {
var self = this,
patchNeeded = false;

jQuery.each( name.match( rmatchNonSpace ), function( _i, attr ) {
if ( rbooleans.test( attr ) ) {

// Only warn if at least a single node had the property set to
// something else than `false`. Otherwise, this Migrate patch
// doesn't influence the behavior and there's no need to set or warn.
self.each( function() {
if ( jQuery( this ).prop( attr ) !== false ) {
patchNeeded = true;
return false;
}
} );
}

if ( patchNeeded ) {
migrateWarn( "removeAttr-bool",
"jQuery.fn.removeAttr no longer sets boolean properties: " + attr );
self.prop( attr, false );
}
} );

return oldRemoveAttr.apply( this, arguments );
}, "removeAttr-bool" );

migratePatchFunc( jQuery.fn, "toggleClass", function( state ) {

// Only deprecating no-args or single boolean arg
Expand All @@ -128,7 +98,7 @@ migratePatchFunc( jQuery.fn, "toggleClass", function( state ) {
return oldToggleClass.apply( this, arguments );
}

migrateWarn( "toggleClass-bool", "jQuery.fn.toggleClass( boolean ) is deprecated" );
migrateWarn( "toggleClass-bool", "jQuery.fn.toggleClass( boolean ) is deprecated and removed" );

// Toggle entire class name of each element
return this.each( function() {
Expand Down
24 changes: 9 additions & 15 deletions src/jquery/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,31 @@ var arr = [],
// to avoid O(N^2) behavior when the engine would try matching "\s+$" at each space position.
rtrim = /^[\s\uFEFF\xA0]+|([^\s\uFEFF\xA0])[\s\uFEFF\xA0]+$/g;

// The number of elements contained in the matched element set
migratePatchAndWarnFunc( jQuery.fn, "size", function() {
return this.length;
}, "size",
"jQuery.fn.size() is deprecated and removed; use the .length property" );

migratePatchAndWarnFunc( jQuery, "parseJSON", function() {
return JSON.parse.apply( null, arguments );
}, "parseJSON",
"jQuery.parseJSON is deprecated; use JSON.parse" );
"jQuery.parseJSON is deprecated and removed; use JSON.parse" );

migratePatchAndWarnFunc( jQuery, "holdReady", jQuery.holdReady,
"holdReady", "jQuery.holdReady is deprecated" );

migratePatchAndWarnFunc( jQuery, "unique", jQuery.uniqueSort,
"unique", "jQuery.unique is deprecated; use jQuery.uniqueSort" );
"unique", "jQuery.unique() is deprecated and removed; use jQuery.uniqueSort()" );

migratePatchAndWarnFunc( jQuery, "trim", function( text ) {
return text == null ?
"" :
( text + "" ).replace( rtrim, "$1" );
}, "trim",
"jQuery.trim is deprecated; use String.prototype.trim" );
"jQuery.trim() is deprecated and removed; use String.prototype.trim" );

migratePatchAndWarnFunc( jQuery, "nodeName", function( elem, name ) {
return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
}, "nodeName",
"jQuery.nodeName is deprecated" );
"jQuery.nodeName() is deprecated and removed" );

migratePatchAndWarnFunc( jQuery, "isArray", Array.isArray, "isArray",
"jQuery.isArray is deprecated; use Array.isArray"
"jQuery.isArray() is deprecated and removed; use Array.isArray()"
);

migratePatchAndWarnFunc( jQuery, "isNumeric",
Expand All @@ -59,7 +53,7 @@ migratePatchAndWarnFunc( jQuery, "isNumeric",
// subtraction forces infinities to NaN
!isNaN( obj - parseFloat( obj ) );
}, "isNumeric",
"jQuery.isNumeric() is deprecated"
"jQuery.isNumeric() is deprecated and removed"
);

// Populate the class2type map
Expand All @@ -78,18 +72,18 @@ migratePatchAndWarnFunc( jQuery, "type", function( obj ) {
class2type[ Object.prototype.toString.call( obj ) ] || "object" :
typeof obj;
}, "type",
"jQuery.type is deprecated" );
"jQuery.type() is deprecated abd removed" );

migratePatchAndWarnFunc( jQuery, "isFunction", function( obj ) {
return typeof obj === "function";
}, "isFunction",
"jQuery.isFunction() is deprecated" );
"jQuery.isFunction() is deprecated and removed" );

migratePatchAndWarnFunc( jQuery, "isWindow",
function( obj ) {
return obj != null && obj === obj.window;
}, "isWindow",
"jQuery.isWindow() is deprecated"
"jQuery.isWindow() is deprecated and removed"
);

// Bind a function to a context, optionally partially applying any
Expand Down
49 changes: 3 additions & 46 deletions src/jquery/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { migrateWarn, migratePatchFunc } from "../main.js";
import { camelCase } from "../utils.js";

var origFnCss, internalCssNumber,
internalSwapCall = false,
ralphaStart = /^[a-z]/,

// The regex visualized:
Expand All @@ -28,52 +27,10 @@ var origFnCss, internalCssNumber,
// \ Max / \ Height /
rautoPx = /^(?:Border(?:Top|Right|Bottom|Left)?(?:Width|)|(?:Margin|Padding)?(?:Top|Right|Bottom|Left)?|(?:Min|Max)?(?:Width|Height))$/;

// If this version of jQuery has .swap(), don't false-alarm on internal uses
if ( jQuery.swap ) {
jQuery.each( [ "height", "width", "reliableMarginRight" ], function( _, name ) {
var oldHook = jQuery.cssHooks[ name ] && jQuery.cssHooks[ name ].get;

if ( oldHook ) {
jQuery.cssHooks[ name ].get = function() {
var ret;

internalSwapCall = true;
ret = oldHook.apply( this, arguments );
internalSwapCall = false;
return ret;
};
}
} );
}

migratePatchFunc( jQuery, "swap", function( elem, options, callback, args ) {
var ret, name,
old = {};

if ( !internalSwapCall ) {
migrateWarn( "swap", "jQuery.swap() is undocumented and deprecated" );
}

// Remember the old values, and insert the new ones
for ( name in options ) {
old[ name ] = elem.style[ name ];
elem.style[ name ] = options[ name ];
}

ret = callback.apply( elem, args || [] );

// Revert the old values
for ( name in options ) {
elem.style[ name ] = old[ name ];
}

return ret;
}, "swap" );

if ( typeof Proxy !== "undefined" ) {
jQuery.cssProps = new Proxy( jQuery.cssProps || {}, {
set: function() {
migrateWarn( "cssProps", "jQuery.cssProps is deprecated" );
migrateWarn( "cssProps", "jQuery.cssProps is deprecated and removed" );
return Reflect.set.apply( this, arguments );
}
} );
Expand Down Expand Up @@ -166,8 +123,8 @@ migratePatchFunc( jQuery.fn, "css", function( name, value ) {
// internal check.
if ( !isAutoPx( camelName ) && !internalCssNumber[ camelName ] ) {
migrateWarn( "css-number",
"Number-typed values are deprecated for jQuery.fn.css( \"" +
name + "\", value )" );
"Auto-appending 'px' to number-typed values is deprecated and removed " +
"for jQuery.fn.css( \"" + name + "\", value )" );
}
}

Expand Down
44 changes: 0 additions & 44 deletions src/jquery/data.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/jquery/deferred.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Object.defineProperty( jQuery.Deferred, "getStackHook", {
get: function() {
if ( jQuery.migrateIsPatchEnabled( "deferred-getStackHook" ) ) {
migrateWarn( "deferred-getStackHook",
"jQuery.Deferred.getStackHook is deprecated; " +
"jQuery.Deferred.getStackHook is deprecated and removed; " +
"use jQuery.Deferred.getErrorHook" );
return jQuery.Deferred.getErrorHook;
} else {
Expand All @@ -89,7 +89,7 @@ Object.defineProperty( jQuery.Deferred, "getStackHook", {
set: function( newValue ) {
if ( jQuery.migrateIsPatchEnabled( "deferred-getStackHook" ) ) {
migrateWarn( "deferred-getStackHook",
"jQuery.Deferred.getStackHook is deprecated; " +
"jQuery.Deferred.getStackHook is deprecated and removed; " +
"use jQuery.Deferred.getErrorHook" );
jQuery.Deferred.getErrorHook = newValue;
} else {
Expand Down
25 changes: 3 additions & 22 deletions src/jquery/effects.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,11 @@
import { migratePatchFunc, migrateWarn } from "../main.js";
import { migrateWarn } from "../main.js";
import "../disablePatches.js";

// Support jQuery slim which excludes the effects module
if ( jQuery.fx ) {

var intervalValue, intervalMsg,
oldTweenRun = jQuery.Tween.prototype.run,
linearEasing = function( pct ) {
return pct;
};

migratePatchFunc( jQuery.Tween.prototype, "run", function( ) {
if ( jQuery.easing[ this.easing ].length > 1 ) {
migrateWarn(
"easing-one-arg",
"'jQuery.easing." + this.easing.toString() + "' should use only one argument"
);

jQuery.easing[ this.easing ] = linearEasing;
}

oldTweenRun.apply( this, arguments );
}, "easing-one-arg" );

intervalValue = jQuery.fx.interval;
intervalMsg = "jQuery.fx.interval is deprecated";
var intervalValue = jQuery.fx.interval,
intervalMsg = "jQuery.fx.interval is deprecated and removed";

// Don't warn if document is hidden, jQuery uses setTimeout (gh-292)
Object.defineProperty( jQuery.fx, "interval", {
Expand Down
Loading
0