Skip to content

Commit

Permalink
Core: Use console.info for deprecations without removals.
Browse files Browse the repository at this point in the history
Also:
1. Group `warnings.md` by this type.
2. Rename `jQuery.migrateWarnings` to `jQuery.migrateMessages`.
3. Rename `jQuery.migrateDeduplicateWarnings` to
   `jQuery.migrateDeduplicateMessages`.
4. Adding "info" versions of some internal APIs.

Fixes jquerygh-472
  • Loading branch information
mgol committed Dec 2, 2024
1 parent fbb3a9d commit cdb01fb
Show file tree
Hide file tree
Showing 24 changed files with 303 additions and 260 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The production build is minified and does not generate console warnings. It will

## Debugging

The development version of the plugin displays warnings in the browser console. Older browsers such as IE9 doesn't support the console interface. No messages will be generated unless you include a debugging library such as [Firebug Lite](https://getfirebug.com/firebuglite) before including the jQuery Migrate plugin. Developers can also inspect the `jQuery.migrateWarnings` array to see what error messages have been generated.
The development version of the plugin displays warnings in the browser console. Older browsers such as IE9 doesn't support the console interface. No messages will be generated unless you include a debugging library such as [Firebug Lite](https://getfirebug.com/firebuglite) before including the jQuery Migrate plugin. Developers can also inspect the `jQuery.migrateMessages` array to see what error messages have been generated.

All warnings generated by this plugin start with the string "JQMIGRATE". A list of the warnings you may see are in [warnings.md](https://github.com/jquery/jquery-migrate/blob/main/warnings.md).

Expand All @@ -57,17 +57,17 @@ All warnings generated by this plugin start with the string "JQMIGRATE". A list

This plugin adds some properties to the `jQuery` object that can be used to programmatically control and examine its behavior:

`jQuery.migrateWarnings`: This property is an array of string warning messages that have been generated by the code on the page, in the order they were generated. Messages appear in the array only once, even if the condition has occurred multiple times, unless `jQuery.migrateReset()` is called.
`jQuery.migrateMessages`: This property is an array of string warning messages that have been generated by the code on the page, in the order they were generated. Messages appear in the array only once, even if the condition has occurred multiple times, unless `jQuery.migrateReset()` is called.

`jQuery.migrateMute`: Set this property to `true` to prevent console warnings from being generated in the development version. The `jQuery.migrateWarnings` array is still maintained when this property is set, which allows programmatic inspection without console output.
`jQuery.migrateMute`: Set this property to `true` to prevent console warnings from being generated in the development version. The `jQuery.migrateMessages` array is still maintained when this property is set, which allows programmatic inspection without console output.

`jQuery.migrateTrace`: Set this property to `false` if you want warnings but do not want stack traces to appear on the console.

`jQuery.migrateReset()`: This method clears the `jQuery.migrateWarnings` array and "forgets" the list of messages that have been seen already.
`jQuery.migrateReset()`: This method clears the `jQuery.migrateMessages` array and "forgets" the list of messages that have been seen already.

`jQuery.migrateVersion`: This string property indicates the version of Migrate in use.

`jQuery.migrateDeduplicateWarnings`: By default, Migrate only gives a specific warning once. If you set this property to `false` it will give a warning for every occurrence each time it happens. Note that this can generate a lot of output, for example when a warning occurs in a loop.
`jQuery.migrateDeduplicateMessages`: By default, Migrate only gives a specific warning once. If you set this property to `false` it will give a warning for every occurrence each time it happens. Note that this can generate a lot of output, for example when a warning occurs in a loop.

`jQuery.migrateDisablePatches`: Disables patches by their codes. You can find a code for each patch in square brackets in [warnings.md](https://github.com/jquery/jquery-migrate/blob/main/warnings.md). A limited number of warnings doesn't have codes defined and cannot be disabled. These are mostly setup issues like using an incorrect version of jQuery or loading Migrate multiple times.

Expand Down
8 changes: 4 additions & 4 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ export default [
QUnit: false,
sinon: false,
url: false,
expectWarning: false,
expectNoWarning: false,
expectMessage: false,
expectNoMessage: false,
compareVersions: false,
jQueryVersionSince: false,
startIframeTest: false,
Expand Down Expand Up @@ -132,8 +132,8 @@ export default [
url: true,
compareVersions: true,
jQueryVersionSince: false,
expectWarning: true,
expectNoWarning: true,
expectMessage: true,
expectNoMessage: true,
startIframeTest: true,
TestManager: true
}
Expand Down
2 changes: 1 addition & 1 deletion src/jquery/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,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 and removed" );
migrateWarn( "jsonp-promotion", "JSON-to-JSONP auto-promotion is removed" );

// Get callback name, remembering preexisting value associated with it
callbackName = s.jsonpCallback = typeof s.jsonpCallback === "function" ?
Expand Down
2 changes: 1 addition & 1 deletion src/jquery/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ migratePatchFunc( jQuery.fn, "toggleClass", function( state ) {
return oldToggleClass.apply( this, arguments );
}

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

// Toggle entire class name of each element
return this.each( function() {
Expand Down
32 changes: 16 additions & 16 deletions src/jquery/core.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { migrateWarnProp, migratePatchAndWarnFunc } from "../main.js";
import { migrateWarnProp, migratePatchAndWarnFunc, migratePatchAndInfoFunc } from "../main.js";
import "../disablePatches.js";

var arr = [],
Expand All @@ -14,28 +14,28 @@ var arr = [],
migratePatchAndWarnFunc( jQuery, "parseJSON", function() {
return JSON.parse.apply( null, arguments );
}, "parseJSON",
"jQuery.parseJSON is deprecated and removed; use JSON.parse" );
"jQuery.parseJSON is removed; use JSON.parse" );

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

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

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

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

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

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

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

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

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

// Bind a function to a context, optionally partially applying any
// arguments.
// jQuery.proxy is deprecated to promote standards (specifically Function#bind)
// However, it is not slated for removal any time soon
migratePatchAndWarnFunc( jQuery, "proxy", jQuery.proxy,
migratePatchAndInfoFunc( jQuery, "proxy", jQuery.proxy,
"proxy", "jQuery.proxy() is deprecated" );

migrateWarnProp( jQuery.fn, "push", push, "push",
"jQuery.fn.push() is deprecated and removed; use .add or convert to an array" );
"jQuery.fn.push() is removed; use .add() or convert to an array" );
migrateWarnProp( jQuery.fn, "sort", sort, "sort",
"jQuery.fn.sort() is deprecated and removed; convert to an array before sorting" );
"jQuery.fn.sort() is removed; convert to an array before sorting" );
migrateWarnProp( jQuery.fn, "splice", splice, "splice",
"jQuery.fn.splice() is deprecated and removed; use .slice or .not with .eq" );
"jQuery.fn.splice() is removed; use .slice() or .not() with .eq()" );
6 changes: 3 additions & 3 deletions src/jquery/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var origFnCss, internalCssNumber,
if ( typeof Proxy !== "undefined" ) {
jQuery.cssProps = new Proxy( jQuery.cssProps || {}, {
set: function() {
migrateWarn( "cssProps", "jQuery.cssProps is deprecated and removed" );
migrateWarn( "cssProps", "jQuery.cssProps is removed" );
return Reflect.set.apply( this, arguments );
}
} );
Expand Down Expand Up @@ -123,8 +123,8 @@ migratePatchFunc( jQuery.fn, "css", function( name, value ) {
// internal check.
if ( !isAutoPx( camelName ) && !internalCssNumber[ camelName ] ) {
migrateWarn( "css-number",
"Auto-appending 'px' to number-typed values is deprecated and removed " +
"for jQuery.fn.css( \"" + name + "\", value )" );
"Auto-appending 'px' to number-typed values " +
"for jQuery.fn.css( \"" + name + "\", value ) is removed" );
}
}

Expand Down
12 changes: 5 additions & 7 deletions src/jquery/deferred.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
migratePatchFunc,
migratePatchAndWarnFunc,
migratePatchAndInfoFunc,
migrateWarn
} from "../main.js";

Expand All @@ -14,9 +14,9 @@ migratePatchFunc( jQuery, "Deferred", function( func ) {
var deferred = oldDeferred(),
promise = deferred.promise();

migratePatchAndWarnFunc( deferred, "pipe", deferred.pipe, "deferred-pipe",
migratePatchAndInfoFunc( deferred, "pipe", deferred.pipe, "deferred-pipe",
"deferred.pipe() is deprecated" );
migratePatchAndWarnFunc( promise, "pipe", promise.pipe, "deferred-pipe",
migratePatchAndInfoFunc( promise, "pipe", promise.pipe, "deferred-pipe",
"deferred.pipe() is deprecated" );

if ( func ) {
Expand All @@ -40,8 +40,7 @@ Object.defineProperty( jQuery.Deferred, "getStackHook", {
get: function() {
if ( jQuery.migrateIsPatchEnabled( "deferred-getStackHook" ) ) {
migrateWarn( "deferred-getStackHook",
"jQuery.Deferred.getStackHook is deprecated and removed; " +
"use jQuery.Deferred.getErrorHook" );
"jQuery.Deferred.getStackHook is removed; use jQuery.Deferred.getErrorHook" );
return jQuery.Deferred.getErrorHook;
} else {
return unpatchedGetStackHookValue;
Expand All @@ -50,8 +49,7 @@ Object.defineProperty( jQuery.Deferred, "getStackHook", {
set: function( newValue ) {
if ( jQuery.migrateIsPatchEnabled( "deferred-getStackHook" ) ) {
migrateWarn( "deferred-getStackHook",
"jQuery.Deferred.getStackHook is deprecated and removed; " +
"use jQuery.Deferred.getErrorHook" );
"jQuery.Deferred.getStackHook is removed; use jQuery.Deferred.getErrorHook" );
jQuery.Deferred.getErrorHook = newValue;
} else {
unpatchedGetStackHookValue = newValue;
Expand Down
2 changes: 1 addition & 1 deletion src/jquery/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "../disablePatches.js";
if ( jQuery.fx ) {

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

// Don't warn if document is hidden, jQuery uses setTimeout (gh-292)
Object.defineProperty( jQuery.fx, "interval", {
Expand Down
14 changes: 7 additions & 7 deletions src/jquery/event.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
migrateWarn,
migratePatchAndWarnFunc,
migratePatchAndInfoFunc,
migratePatchFunc
} from "../main.js";
import "../disablePatches.js";
Expand All @@ -26,18 +26,18 @@ jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " +
function( _i, name ) {

// Handle event binding
migratePatchAndWarnFunc( jQuery.fn, name, jQuery.fn[ name ], "shorthand-deprecated-v3",
migratePatchAndInfoFunc( jQuery.fn, name, jQuery.fn[ name ], "shorthand-deprecated-v3",
"jQuery.fn." + name + "() event shorthand is deprecated" );
} );

migratePatchAndWarnFunc( jQuery.fn, "bind", jQuery.fn.bind,
migratePatchAndInfoFunc( jQuery.fn, "bind", jQuery.fn.bind,
"pre-on-methods", "jQuery.fn.bind() is deprecated" );
migratePatchAndWarnFunc( jQuery.fn, "unbind", jQuery.fn.unbind,
migratePatchAndInfoFunc( jQuery.fn, "unbind", jQuery.fn.unbind,
"pre-on-methods", "jQuery.fn.unbind() is deprecated" );
migratePatchAndWarnFunc( jQuery.fn, "delegate", jQuery.fn.delegate,
migratePatchAndInfoFunc( jQuery.fn, "delegate", jQuery.fn.delegate,
"pre-on-methods", "jQuery.fn.delegate() is deprecated" );
migratePatchAndWarnFunc( jQuery.fn, "undelegate", jQuery.fn.undelegate,
migratePatchAndInfoFunc( jQuery.fn, "undelegate", jQuery.fn.undelegate,
"pre-on-methods", "jQuery.fn.undelegate() is deprecated" );

migratePatchAndWarnFunc( jQuery.fn, "hover", jQuery.fn.hover,
migratePatchAndInfoFunc( jQuery.fn, "hover", jQuery.fn.hover,
"hover", "jQuery.fn.hover() is deprecated" );
10 changes: 5 additions & 5 deletions src/jquery/selector.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { migratePatchFunc, migrateWarnProp, migrateWarn } from "../main.js";
import { migratePatchFunc, migrateInfoProp, migrateInfo } from "../main.js";

// Now jQuery.expr.pseudos is the standard incantation
migrateWarnProp( jQuery.expr, "filters", jQuery.expr.pseudos, "expr-pre-pseudos",
migrateInfoProp( jQuery.expr, "filters", jQuery.expr.pseudos, "expr-pre-pseudos",
"jQuery.expr.filters is deprecated; use jQuery.expr.pseudos" );
migrateWarnProp( jQuery.expr, ":", jQuery.expr.pseudos, "expr-pre-pseudos",
migrateInfoProp( jQuery.expr, ":", jQuery.expr.pseudos, "expr-pre-pseudos",
"jQuery.expr[':'] is deprecated; use jQuery.expr.pseudos" );

function markFunction( fn ) {
Expand Down Expand Up @@ -33,7 +33,7 @@ migratePatchFunc( jQuery.expr.filter, "PSEUDO", function( pseudo, argument ) {

// But maintain support for old signatures
if ( fn.length > 1 ) {
migrateWarn( "legacy-custom-pseudos",
migrateInfo( "legacy-custom-pseudos",
"Pseudos with multiple arguments are deprecated; " +
"use jQuery.expr.createPseudo()" );
args = [ pseudo, pseudo, "", argument ];
Expand All @@ -60,7 +60,7 @@ if ( typeof Proxy !== "undefined" ) {
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",
migrateInfo( "legacy-custom-pseudos",
"Pseudos with multiple arguments are deprecated; " +
"use jQuery.expr.createPseudo()" );
}
Expand Down
Loading

0 comments on commit cdb01fb

Please sign in to comment.