Skip to content

Commit 64a2892

Browse files
nltncsrtimmywil
authored andcommitted
Core: make camelCase function available only for internal usage
Close gh-3604 Fixes gh-3384
1 parent 3c0f2cf commit 64a2892

9 files changed

Lines changed: 66 additions & 58 deletions

File tree

src/core.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,7 @@ var
3737

3838
// Support: Android <=4.0 only
3939
// Make sure we trim BOM and NBSP
40-
rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
41-
42-
// Matches dashed string for camelizing
43-
rmsPrefix = /^-ms-/,
44-
rdashAlpha = /-([a-z])/g,
45-
46-
// Used by jQuery.camelCase as callback to replace()
47-
fcamelCase = function( all, letter ) {
48-
return letter.toUpperCase();
49-
};
40+
rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
5041

5142
jQuery.fn = jQuery.prototype = {
5243

@@ -284,13 +275,6 @@ jQuery.extend( {
284275
DOMEval( code );
285276
},
286277

287-
// Convert dashed to camelCase; used by the css and data modules
288-
// Support: IE <=9 - 11, Edge 12 - 15
289-
// Microsoft forgot to hump their vendor prefix (#9572)
290-
camelCase: function( string ) {
291-
return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
292-
},
293-
294278
each: function( obj, callback ) {
295279
var length, i = 0;
296280

src/core/camelCase.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
define( [], function() {
2+
3+
"use strict";
4+
5+
// Matches dashed string for camelizing
6+
var rmsPrefix = /^-ms-/,
7+
rdashAlpha = /-([a-z])/g;
8+
9+
// Used by camelCase as callback to replace()
10+
function fcamelCase( all, letter ) {
11+
return letter.toUpperCase();
12+
}
13+
14+
// Convert dashed to camelCase; used by the css and data modules
15+
// Support: IE <=9 - 11, Edge 12 - 15
16+
// Microsoft forgot to hump their vendor prefix (#9572)
17+
function camelCase( string ) {
18+
return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
19+
}
20+
21+
return camelCase;
22+
23+
} );

src/css.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ define( [
22
"./core",
33
"./var/pnum",
44
"./core/access",
5+
"./core/camelCase",
56
"./var/document",
67
"./var/rcssNum",
78
"./css/var/rnumnonpx",
@@ -16,7 +17,7 @@ define( [
1617
"./core/init",
1718
"./core/ready",
1819
"./selector" // contains
19-
], function( jQuery, pnum, access, document, rcssNum, rnumnonpx, cssExpand,
20+
], function( jQuery, pnum, access, camelCase, document, rcssNum, rnumnonpx, cssExpand,
2021
getStyles, swap, curCSS, adjustCSS, addGetHookIf, support ) {
2122

2223
"use strict";
@@ -245,7 +246,7 @@ jQuery.extend( {
245246

246247
// Make sure that we're working with the right name
247248
var ret, type, hooks,
248-
origName = jQuery.camelCase( name ),
249+
origName = camelCase( name ),
249250
isCustomProp = rcustomProp.test( name ),
250251
style = elem.style;
251252

@@ -313,7 +314,7 @@ jQuery.extend( {
313314

314315
css: function( elem, name, extra, styles ) {
315316
var val, num, hooks,
316-
origName = jQuery.camelCase( name ),
317+
origName = camelCase( name ),
317318
isCustomProp = rcustomProp.test( name );
318319

319320
// Make sure that we're working with the right name. We don't

src/data.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
define( [
22
"./core",
33
"./core/access",
4+
"./core/camelCase",
45
"./data/var/dataPriv",
56
"./data/var/dataUser"
6-
], function( jQuery, access, dataPriv, dataUser ) {
7+
], function( jQuery, access, camelCase, dataPriv, dataUser ) {
78

89
"use strict";
910

@@ -112,7 +113,7 @@ jQuery.fn.extend( {
112113
if ( attrs[ i ] ) {
113114
name = attrs[ i ].name;
114115
if ( name.indexOf( "data-" ) === 0 ) {
115-
name = jQuery.camelCase( name.slice( 5 ) );
116+
name = camelCase( name.slice( 5 ) );
116117
dataAttr( elem, name, data[ name ] );
117118
}
118119
}

src/data/Data.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
define( [
22
"../core",
3+
"../core/camelCase",
34
"../var/rnothtmlwhite",
45
"./var/acceptData"
5-
], function( jQuery, rnothtmlwhite, acceptData ) {
6+
], function( jQuery, camelCase, rnothtmlwhite, acceptData ) {
67

78
"use strict";
89

@@ -54,14 +55,14 @@ Data.prototype = {
5455
// Handle: [ owner, key, value ] args
5556
// Always use camelCase key (gh-2257)
5657
if ( typeof data === "string" ) {
57-
cache[ jQuery.camelCase( data ) ] = value;
58+
cache[ camelCase( data ) ] = value;
5859

5960
// Handle: [ owner, { properties } ] args
6061
} else {
6162

6263
// Copy the properties one-by-one to the cache object
6364
for ( prop in data ) {
64-
cache[ jQuery.camelCase( prop ) ] = data[ prop ];
65+
cache[ camelCase( prop ) ] = data[ prop ];
6566
}
6667
}
6768
return cache;
@@ -71,7 +72,7 @@ Data.prototype = {
7172
this.cache( owner ) :
7273

7374
// Always use camelCase key (gh-2257)
74-
owner[ this.expando ] && owner[ this.expando ][ jQuery.camelCase( key ) ];
75+
owner[ this.expando ] && owner[ this.expando ][ camelCase( key ) ];
7576
},
7677
access: function( owner, key, value ) {
7778

@@ -119,9 +120,9 @@ Data.prototype = {
119120

120121
// If key is an array of keys...
121122
// We always set camelCase keys, so remove that.
122-
key = key.map( jQuery.camelCase );
123+
key = key.map( camelCase );
123124
} else {
124-
key = jQuery.camelCase( key );
125+
key = camelCase( key );
125126

126127
// If a key with the spaces exists, use it.
127128
// Otherwise, create an array by matching non-whitespace

src/effects.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
define( [
22
"./core",
3+
"./core/camelCase",
34
"./var/document",
45
"./var/rcssNum",
56
"./var/rnothtmlwhite",
@@ -17,8 +18,8 @@ define( [
1718
"./manipulation",
1819
"./css",
1920
"./effects/Tween"
20-
], function( jQuery, document, rcssNum, rnothtmlwhite, cssExpand, isHiddenWithinTree, swap,
21-
adjustCSS, dataPriv, showHide ) {
21+
], function( jQuery, camelCase, document, rcssNum, rnothtmlwhite, cssExpand, isHiddenWithinTree,
22+
swap, adjustCSS, dataPriv, showHide ) {
2223

2324
"use strict";
2425

@@ -259,7 +260,7 @@ function propFilter( props, specialEasing ) {
259260

260261
// camelCase, specialEasing and expand cssHook pass
261262
for ( index in props ) {
262-
name = jQuery.camelCase( index );
263+
name = camelCase( index );
263264
easing = specialEasing[ name ];
264265
value = props[ index ];
265266
if ( Array.isArray( value ) ) {

test/unit/core.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,25 +1683,6 @@ QUnit.test( "jQuery.parseXML", function( assert ) {
16831683
}
16841684
} );
16851685

1686-
QUnit.test( "jQuery.camelCase()", function( assert ) {
1687-
1688-
var tests = {
1689-
"foo-bar": "fooBar",
1690-
"foo-bar-baz": "fooBarBaz",
1691-
"girl-u-want": "girlUWant",
1692-
"the-4th-dimension": "the-4thDimension",
1693-
"-o-tannenbaum": "OTannenbaum",
1694-
"-moz-illa": "MozIlla",
1695-
"-ms-take": "msTake"
1696-
};
1697-
1698-
assert.expect( 7 );
1699-
1700-
jQuery.each( tests, function( key, val ) {
1701-
assert.equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val );
1702-
} );
1703-
} );
1704-
17051686
testIframe(
17061687
"Conditional compilation compatibility (#13274)",
17071688
"core/cc_on.html",

test/unit/data.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ QUnit.test( ".data should not miss attr() set data-* with hyphenated property na
602602
} );
603603

604604
QUnit.test( ".data always sets data with the camelCased key (gh-2257)", function( assert ) {
605-
assert.expect( 18 );
605+
assert.expect( 9 );
606606

607607
var div = jQuery( "<div>" ).appendTo( "#qunit-fixture" ),
608608
datas = {
@@ -625,7 +625,6 @@ QUnit.test( ".data always sets data with the camelCased key (gh-2257)", function
625625
div.data( key, val );
626626
var allData = div.data();
627627
assert.equal( allData[ key ], undefined, ".data does not store with hyphenated keys" );
628-
assert.equal( allData[ jQuery.camelCase( key ) ], val, ".data stores the camelCased key" );
629628
} );
630629
} );
631630

@@ -639,7 +638,7 @@ QUnit.test( ".data should not strip more than one hyphen when camelCasing (gh-20
639638
assert.equal( allData[ "nested--Triple" ], "triple", "Key with triple hyphens is correctly camelCased" );
640639
} );
641640

642-
QUnit.test( ".data supports interoperable hyphenated/camelCase get/set of properties with arbitrary non-null|NaN|undefined values", function( assert ) {
641+
QUnit.test( ".data supports interoperable hyphenated get/set of properties with arbitrary non-null|NaN|undefined values", function( assert ) {
643642

644643
var div = jQuery( "<div/>", { id: "hyphened" } ).appendTo( "#qunit-fixture" ),
645644
datas = {
@@ -661,17 +660,16 @@ QUnit.test( ".data supports interoperable hyphenated/camelCase get/set of proper
661660
"2-num-start": true
662661
};
663662

664-
assert.expect( 24 );
663+
assert.expect( 12 );
665664

666665
jQuery.each( datas, function( key, val ) {
667666
div.data( key, val );
668667

669668
assert.deepEqual( div.data( key ), val, "get: " + key );
670-
assert.deepEqual( div.data( jQuery.camelCase( key ) ), val, "get: " + jQuery.camelCase( key ) );
671669
} );
672670
} );
673671

674-
QUnit.test( ".data supports interoperable removal of hyphenated/camelCase properties", function( assert ) {
672+
QUnit.test( ".data supports interoperable removal of hyphenated properties", function( assert ) {
675673
var div = jQuery( "<div/>", { id: "hyphened" } ).appendTo( "#qunit-fixture" ),
676674
datas = {
677675
"non-empty": "a string",
@@ -689,13 +687,12 @@ QUnit.test( ".data supports interoperable removal of hyphenated/camelCase proper
689687
"some-json": "{ \"foo\": \"bar\" }"
690688
};
691689

692-
assert.expect( 27 );
690+
assert.expect( 18 );
693691

694692
jQuery.each( datas, function( key, val ) {
695693
div.data( key, val );
696694

697695
assert.deepEqual( div.data( key ), val, "get: " + key );
698-
assert.deepEqual( div.data( jQuery.camelCase( key ) ), val, "get: " + jQuery.camelCase( key ) );
699696

700697
div.removeData( key );
701698

test/unit/deprecated.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,22 @@ QUnit.test( "jQuery.isWindow", function( assert ) {
183183
assert.ok( !jQuery.isWindow( /window/ ), "regexp" );
184184
assert.ok( !jQuery.isWindow( function() {} ), "function" );
185185
} );
186+
187+
QUnit.test( "jQuery.camelCase()", function( assert ) {
188+
189+
var tests = {
190+
"foo-bar": "fooBar",
191+
"foo-bar-baz": "fooBarBaz",
192+
"girl-u-want": "girlUWant",
193+
"the-4th-dimension": "the-4thDimension",
194+
"-o-tannenbaum": "OTannenbaum",
195+
"-moz-illa": "MozIlla",
196+
"-ms-take": "msTake"
197+
};
198+
199+
assert.expect( 7 );
200+
201+
jQuery.each( tests, function( key, val ) {
202+
assert.equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val );
203+
} );
204+
} );

0 commit comments

Comments
 (0)