Skip to content

Commit 0a6a377

Browse files
committed
Core: Patch & warn against jQuery.now & jQuery.camelCase
These APIs have been deprecated in jQuery 3.3. Fixes gh-594 Fixes gh-595
1 parent bfce100 commit 0a6a377

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

src/jquery/core.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ var arr = [],
77
splice = arr.splice,
88
class2type = {},
99

10+
// Matches dashed string for camelizing
11+
rmsPrefix = /^-ms-/,
12+
rdashAlpha = /-([a-z])/g,
13+
1014
// Require that the "whitespace run" starts from a non-whitespace
1115
// to avoid O(N^2) behavior when the engine would try matching "\s+$" at each space position.
1216
rtrim = /^[\s\uFEFF\xA0]+|([^\s\uFEFF\xA0])[\s\uFEFF\xA0]+$/g;
@@ -85,6 +89,26 @@ migratePatchAndWarnFunc( jQuery, "isWindow",
8589
"jQuery.isWindow() is removed"
8690
);
8791

92+
migratePatchAndWarnFunc( jQuery, "now", Date.now, "now",
93+
"jQuery.now() is removed; use Date.now()"
94+
);
95+
96+
// Used by camelCase as callback to replace()
97+
function fcamelCase( _all, letter ) {
98+
return letter.toUpperCase();
99+
}
100+
101+
migratePatchAndWarnFunc( jQuery, "camelCase",
102+
function( string ) {
103+
104+
// Convert dashed to camelCase; used by the css and data modules
105+
// Support: IE <=9 - 11, Edge 12 - 15
106+
// Microsoft forgot to hump their vendor prefix (trac-9572)
107+
return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
108+
}, "camelCase",
109+
"jQuery.camelCase() is removed"
110+
);
111+
88112
// Bind a function to a context, optionally partially applying any
89113
// arguments.
90114
// jQuery.proxy is deprecated to promote standards (specifically Function#bind)

test/unit/jquery/core.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,35 @@ QUnit.test( "jQuery.isWindow", function( assert ) {
191191
} );
192192
} );
193193

194+
QUnit.test( "jQuery.now", function( assert ) {
195+
assert.expect( 2 );
196+
197+
expectMessage( assert, "now", 1, function() {
198+
assert.ok( typeof jQuery.now() === "number", "jQuery.now is a function" );
199+
} );
200+
} );
201+
202+
QUnit.test( "jQuery.camelCase()", function( assert ) {
203+
204+
var tests = {
205+
"foo-bar": "fooBar",
206+
"foo-bar-baz": "fooBarBaz",
207+
"girl-u-want": "girlUWant",
208+
"the-4th-dimension": "the-4thDimension",
209+
"-o-tannenbaum": "OTannenbaum",
210+
"-moz-illa": "MozIlla",
211+
"-ms-take": "msTake"
212+
};
213+
214+
assert.expect( 8 );
215+
216+
expectMessage( assert, "now", 7, function() {
217+
jQuery.each( tests, function( key, val ) {
218+
assert.equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val );
219+
} );
220+
} );
221+
} );
222+
194223
QUnit.test( "jQuery.unique", function( assert ) {
195224
assert.expect( 2 );
196225

warnings.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ This is _not_ a warning, but a console log message the plugin shows when it firs
138138

139139
**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 )`.
140140

141+
### \[now\] JQMIGRATE: jQuery.now() is removed; use Date.now
142+
143+
**Cause:** The `jQuery.now()` method was a simple alias for `Date.now()`, which is now supported in all browsers supported by jQuery 4.0.
144+
145+
**Solution:** Replace any calls to `jQuery.now()` with `Date.now()`.
146+
147+
### \[camelCase\] JQMIGRATE: jQuery.camelCase() is removed
148+
149+
**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.
150+
151+
**Solution:** If you need this functionality, you can implement it yourself.
152+
141153
### \[css-number\] JQMIGRATE: Auto-appending 'px' to number-typed values for jQuery.fn.css( _(property name)_, value ) is removed
142154

143155
**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"`.

0 commit comments

Comments
 (0)