From 0a6a377d87a30ca2a3c5ea008154f82853eac31a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Go=C5=82e=CC=A8biowski-Owczarek?= Date: Fri, 12 Sep 2025 16:07:07 +0200 Subject: [PATCH 1/2] Core: Patch & warn against jQuery.now & jQuery.camelCase These APIs have been deprecated in jQuery 3.3. Fixes gh-594 Fixes gh-595 --- src/jquery/core.js | 24 ++++++++++++++++++++++++ test/unit/jquery/core.js | 29 +++++++++++++++++++++++++++++ warnings.md | 12 ++++++++++++ 3 files changed, 65 insertions(+) diff --git a/src/jquery/core.js b/src/jquery/core.js index d11403b7..774d8951 100644 --- a/src/jquery/core.js +++ b/src/jquery/core.js @@ -7,6 +7,10 @@ var arr = [], splice = arr.splice, class2type = {}, + // Matches dashed string for camelizing + rmsPrefix = /^-ms-/, + rdashAlpha = /-([a-z])/g, + // 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. rtrim = /^[\s\uFEFF\xA0]+|([^\s\uFEFF\xA0])[\s\uFEFF\xA0]+$/g; @@ -85,6 +89,26 @@ migratePatchAndWarnFunc( jQuery, "isWindow", "jQuery.isWindow() is removed" ); +migratePatchAndWarnFunc( jQuery, "now", Date.now, "now", + "jQuery.now() is removed; use Date.now()" +); + +// Used by camelCase as callback to replace() +function fcamelCase( _all, letter ) { + return letter.toUpperCase(); +} + +migratePatchAndWarnFunc( jQuery, "camelCase", + function( string ) { + + // Convert dashed to camelCase; used by the css and data modules + // Support: IE <=9 - 11, Edge 12 - 15 + // Microsoft forgot to hump their vendor prefix (trac-9572) + return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase ); + }, "camelCase", + "jQuery.camelCase() is removed" +); + // Bind a function to a context, optionally partially applying any // arguments. // jQuery.proxy is deprecated to promote standards (specifically Function#bind) diff --git a/test/unit/jquery/core.js b/test/unit/jquery/core.js index 2ab857eb..a03e4deb 100644 --- a/test/unit/jquery/core.js +++ b/test/unit/jquery/core.js @@ -191,6 +191,35 @@ QUnit.test( "jQuery.isWindow", function( assert ) { } ); } ); +QUnit.test( "jQuery.now", function( assert ) { + assert.expect( 2 ); + + expectMessage( assert, "now", 1, function() { + assert.ok( typeof jQuery.now() === "number", "jQuery.now is a function" ); + } ); +} ); + +QUnit.test( "jQuery.camelCase()", function( assert ) { + + var tests = { + "foo-bar": "fooBar", + "foo-bar-baz": "fooBarBaz", + "girl-u-want": "girlUWant", + "the-4th-dimension": "the-4thDimension", + "-o-tannenbaum": "OTannenbaum", + "-moz-illa": "MozIlla", + "-ms-take": "msTake" + }; + + assert.expect( 8 ); + + expectMessage( assert, "now", 7, function() { + jQuery.each( tests, function( key, val ) { + assert.equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val ); + } ); + } ); +} ); + QUnit.test( "jQuery.unique", function( assert ) { assert.expect( 2 ); diff --git a/warnings.md b/warnings.md index aa76cd24..a1209568 100644 --- a/warnings.md +++ b/warnings.md @@ -138,6 +138,18 @@ This is _not_ a warning, but a console log message the plugin shows when it firs **Solution:** Replace any calls to `jQuery.trim( text )` with `text.trim()` if you know `text` is a string; otherwise, you can replace it with `String.prototype.trim.call( text == null ? "" : text )`. +### \[now\] JQMIGRATE: jQuery.now() is removed; use Date.now + +**Cause:** The `jQuery.now()` method was a simple alias for `Date.now()`, which is now supported in all browsers supported by jQuery 4.0. + +**Solution:** Replace any calls to `jQuery.now()` with `Date.now()`. + +### \[camelCase\] JQMIGRATE: jQuery.camelCase() is removed + +**Cause:** The `jQuery.camelCase()` method was a utility to convert dashed strings like `"background-color"` into camel-cased strings like `"backgroundColor"`. This method was never documented and is removed as of jQuery 4.0. + +**Solution:** If you need this functionality, you can implement it yourself. + ### \[css-number\] JQMIGRATE: Auto-appending 'px' to number-typed values for jQuery.fn.css( _(property name)_, value ) is removed **Cause:** In past versions, when a number-typed value was passed to `.css()` jQuery converted it to a string and added `"px"` to the end. As the CSS standard has evolved, an increasingly large set of CSS properties now accept values that are unitless numbers, where this behavior is incorrect. It has become impractical to manage these exceptions in the `jQuery.cssNumber` object. In addition, some CSS properties like `line-height` can accept both a bare number `2` or a pixel value `2px`. jQuery cannot know the correct way to interpret `$.css("line-height", 2)` and currently treats it as `"2px"`. From f77b5dafbdbc1e3326165b1cdfca9f75ccd0e28b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Go=C5=82=C4=99biowski-Owczarek?= Date: Sat, 13 Sep 2025 00:11:07 +0200 Subject: [PATCH 2/2] Update warnings.md --- warnings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/warnings.md b/warnings.md index a1209568..f788ce23 100644 --- a/warnings.md +++ b/warnings.md @@ -148,7 +148,7 @@ This is _not_ a warning, but a console log message the plugin shows when it firs **Cause:** The `jQuery.camelCase()` method was a utility to convert dashed strings like `"background-color"` into camel-cased strings like `"backgroundColor"`. This method was never documented and is removed as of jQuery 4.0. -**Solution:** If you need this functionality, you can implement it yourself. +**Solution:** Use a custom utility. ### \[css-number\] JQMIGRATE: Auto-appending 'px' to number-typed values for jQuery.fn.css( _(property name)_, value ) is removed