From 58f0c00bed695f934bb205c6115e5fe99dd5c27b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20Go=C5=82=C4=99biowski-Owczarek?= Date: Mon, 29 Apr 2019 22:04:52 +0200 Subject: [PATCH] Core: Remove deprecated jQuery APIs Fixes gh-4056 Closes gh-4364 --- src/css.js | 4 - src/css/finalPropName.js | 9 +- src/deprecated.js | 24 --- test/unit/css.js | 27 --- test/unit/data.js | 11 +- test/unit/deprecated.js | 436 --------------------------------------- 6 files changed, 14 insertions(+), 497 deletions(-) diff --git a/src/css.js b/src/css.js index f9277bf6c..c92fc684a 100644 --- a/src/css.js +++ b/src/css.js @@ -199,10 +199,6 @@ jQuery.extend( { } }, - // Add in properties whose names you wish to fix before - // setting or getting the value - cssProps: {}, - // Get and set the style property on a DOM Node style: function( elem, name, value, extra ) { diff --git a/src/css/finalPropName.js b/src/css/finalPropName.js index 352d18a27..c290eb2b4 100644 --- a/src/css/finalPropName.js +++ b/src/css/finalPropName.js @@ -1,7 +1,6 @@ define( [ - "../var/document", - "../core" -], function( document, jQuery ) { + "../var/document" +], function( document ) { "use strict"; @@ -24,9 +23,9 @@ function vendorPropName( name ) { } } -// Return a potentially-mapped jQuery.cssProps or vendor prefixed property +// Return a potentially-mapped vendor prefixed property function finalPropName( name ) { - var final = jQuery.cssProps[ name ] || vendorProps[ name ]; + var final = vendorProps[ name ]; if ( final ) { return final; diff --git a/src/deprecated.js b/src/deprecated.js index e24de4818..ecdf9f450 100644 --- a/src/deprecated.js +++ b/src/deprecated.js @@ -71,28 +71,4 @@ jQuery.holdReady = function( hold ) { jQuery.ready( true ); } }; -jQuery.isArray = Array.isArray; -jQuery.parseJSON = JSON.parse; -jQuery.nodeName = nodeName; -jQuery.isFunction = isFunction; -jQuery.isWindow = isWindow; -jQuery.camelCase = cssCamelCase; -jQuery.type = toType; - -jQuery.now = Date.now; - -jQuery.isNumeric = function( obj ) { - - // As of jQuery 3.0, isNumeric is limited to - // strings and numbers (primitives or objects) - // that can be coerced to finite numbers (gh-2662) - var type = jQuery.type( obj ); - return ( type === "number" || type === "string" ) && - - // parseFloat NaNs numeric-cast false positives ("") - // ...but misinterprets leading-number strings, particularly hex literals ("0x...") - // subtraction forces infinities to NaN - !isNaN( obj - parseFloat( obj ) ); -}; - } ); diff --git a/test/unit/css.js b/test/unit/css.js index 150f5b908..74daa2b2d 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -1108,23 +1108,6 @@ QUnit.test( "box model properties incorrectly returning % instead of px, see #10 assert.equal( el2.css( "marginLeft" ), "100px", "css('marginLeft') returning incorrect pixel value, see #12088" ); } ); -QUnit.test( "jQuery.cssProps behavior, (bug #8402)", function( assert ) { - assert.expect( 2 ); - - var div = jQuery( "
" ).appendTo( document.body ).css( { - "position": "absolute", - "top": 0, - "left": 10 - } ); - jQuery.cssProps.top = "left"; - assert.equal( div.css( "top" ), "10px", "the fixed property is used when accessing the computed style" ); - div.css( "top", "100px" ); - assert.equal( div[ 0 ].style.left, "100px", "the fixed property is used when setting the style" ); - - // cleanup jQuery.cssProps - jQuery.cssProps.top = undefined; -} ); - QUnit.test( "widows & orphans #8936", function( assert ) { var $p = jQuery( "

" ).appendTo( "#qunit-fixture" ); @@ -1713,13 +1696,6 @@ QUnit.test( "Do not throw on frame elements from css method (#15098)", function( ( function() { var vendorPrefixes = [ "Webkit", "Moz", "ms" ]; - function resetCssPropsFor( name ) { - delete jQuery.cssProps[ name ]; - jQuery.each( vendorPrefixes, function( index, prefix ) { - delete jQuery.cssProps[ prefix + name[ 0 ].toUpperCase() + name.slice( 1 ) ]; - } ); - } - QUnit.test( "Don't default to a cached previously used wrong prefixed name (gh-2015)", function( assert ) { // Note: this test needs a property we know is only supported in a prefixed version @@ -1753,9 +1729,6 @@ QUnit.test( "Do not throw on frame elements from css method (#15098)", function( assert.expect( !!appearanceName + !!transformName + 1 ); - resetCssPropsFor( "appearance" ); - resetCssPropsFor( "transform" ); - elem = jQuery( "

" ) .css( { msAppearance: "none", diff --git a/test/unit/data.js b/test/unit/data.js index 849b86ee3..07628bfd4 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -755,6 +755,7 @@ QUnit.test( ".data supports interoperable hyphenated/camelCase get/set of proper QUnit.test( ".data supports interoperable removal of hyphenated/camelCase properties", function( assert ) { var div = jQuery( "
", { id: "hyphened" } ).appendTo( "#qunit-fixture" ), + rdashAlpha = /-([a-z])/g, datas = { "non-empty": "a string", "empty-string": "", @@ -773,11 +774,19 @@ QUnit.test( ".data supports interoperable removal of hyphenated/camelCase proper assert.expect( 27 ); + function fcamelCase( all, letter ) { + return letter.toUpperCase(); + } + jQuery.each( datas, function( key, val ) { div.data( key, val ); assert.deepEqual( div.data( key ), val, "get: " + key ); - assert.deepEqual( div.data( jQuery.camelCase( key ) ), val, "get: " + jQuery.camelCase( key ) ); + assert.deepEqual( + div.data( key.replace( rdashAlpha, fcamelCase ) ), + val, + "get: " + key.replace( rdashAlpha, fcamelCase ) + ); div.removeData( key ); diff --git a/test/unit/deprecated.js b/test/unit/deprecated.js index d8b5a5181..fd920fb73 100644 --- a/test/unit/deprecated.js +++ b/test/unit/deprecated.js @@ -117,367 +117,6 @@ QUnit[ jQuery.fn.click ? "test" : "skip" ]( "Event aliases", function( assert ) } ); } ); -QUnit.test( "jQuery.parseJSON", function( assert ) { - assert.expect( 20 ); - - assert.strictEqual( jQuery.parseJSON( null ), null, "primitive null" ); - assert.strictEqual( jQuery.parseJSON( "0.88" ), 0.88, "Number" ); - assert.strictEqual( - jQuery.parseJSON( "\" \\\" \\\\ \\/ \\b \\f \\n \\r \\t \\u007E \\u263a \"" ), - " \" \\ / \b \f \n \r \t ~ \u263A ", - "String escapes" - ); - assert.deepEqual( jQuery.parseJSON( "{}" ), {}, "Empty object" ); - assert.deepEqual( jQuery.parseJSON( "{\"test\":1}" ), { "test": 1 }, "Plain object" ); - assert.deepEqual( jQuery.parseJSON( "[0]" ), [ 0 ], "Simple array" ); - - assert.deepEqual( - jQuery.parseJSON( "[ \"string\", -4.2, 2.7180e0, 3.14E-1, {}, [], true, false, null ]" ), - [ "string", -4.2, 2.718, 0.314, {}, [], true, false, null ], - "Array of all data types" - ); - assert.deepEqual( - jQuery.parseJSON( "{ \"string\": \"\", \"number\": 4.2e+1, \"object\": {}," + - "\"array\": [[]], \"boolean\": [ true, false ], \"null\": null }" ), - { string: "", number: 42, object: {}, array: [ [] ], "boolean": [ true, false ], "null": null }, - "Dictionary of all data types" - ); - - assert.deepEqual( jQuery.parseJSON( "\n{\"test\":1}\t" ), { "test": 1 }, - "Leading and trailing whitespace are ignored" ); - - assert.throws( function() { - jQuery.parseJSON(); - }, null, "Undefined raises an error" ); - assert.throws( function() { - jQuery.parseJSON( "" ); - }, null, "Empty string raises an error" ); - assert.throws( function() { - jQuery.parseJSON( "''" ); - }, null, "Single-quoted string raises an error" ); - - assert.throws( function() { - var result = jQuery.parseJSON( "0101" ); - - // Support: IE <=9 only - // Ensure base-10 interpretation on browsers that erroneously accept leading-zero numbers - if ( result === 101 ) { - throw new Error( "close enough" ); - } - }, null, "Leading-zero number raises an error or is parsed as decimal" ); - assert.throws( function() { - jQuery.parseJSON( "{a:1}" ); - }, null, "Unquoted property raises an error" ); - assert.throws( function() { - jQuery.parseJSON( "{'a':1}" ); - }, null, "Single-quoted property raises an error" ); - assert.throws( function() { - jQuery.parseJSON( "[,]" ); - }, null, "Array element elision raises an error" ); - assert.throws( function() { - jQuery.parseJSON( "{},[]" ); - }, null, "Comma expression raises an error" ); - assert.throws( function() { - jQuery.parseJSON( "[]\n,{}" ); - }, null, "Newline-containing comma expression raises an error" ); - assert.throws( function() { - jQuery.parseJSON( "\"\"\n\"\"" ); - }, null, "Automatic semicolon insertion raises an error" ); - - assert.strictEqual( jQuery.parseJSON( [ 0 ] ), 0, "Input cast to string" ); -} ); - -QUnit.test( "jQuery.isArray", function( assert ) { - assert.expect( 1 ); - - assert.strictEqual( jQuery.isArray, Array.isArray, "Array.isArray equals jQuery.isArray" ); -} ); - -QUnit.test( "jQuery.nodeName", function( assert ) { - assert.expect( 8 ); - - assert.strictEqual( typeof jQuery.nodeName, "function", "jQuery.nodeName is a function" ); - - assert.strictEqual( - jQuery.nodeName( document.createElement( "div" ), "div" ), - true, - "Basic usage (true)" - ); - - assert.strictEqual( - jQuery.nodeName( document.createElement( "div" ), "span" ), - false, - "Basic usage (false)" - ); - - assert.strictEqual( - jQuery.nodeName( document.createElement( "div" ), "DIV" ), - true, - "Ignores case in the name parameter" - ); - - assert.strictEqual( - jQuery.nodeName( document.createElement( "section" ), "section" ), - true, - "Works on HTML5 tags (true)" - ); - - assert.strictEqual( - jQuery.nodeName( document.createElement( "section" ), "article" ), - false, - "Works on HTML5 tags (false)" - ); - - assert.strictEqual( - jQuery.nodeName( document.createElement( "custom-element" ), "custom-element" ), - true, - "Works on custom elements (true)" - ); - - assert.strictEqual( - jQuery.nodeName( document.createElement( "custom-element" ), "my-element" ), - false, - "Works on custom elements (true)" - ); -} ); - - -QUnit.test( "type", function( assert ) { - assert.expect( 28 ); - - assert.equal( jQuery.type( null ), "null", "null" ); - assert.equal( jQuery.type( undefined ), "undefined", "undefined" ); - assert.equal( jQuery.type( true ), "boolean", "Boolean" ); - assert.equal( jQuery.type( false ), "boolean", "Boolean" ); - assert.equal( jQuery.type( Boolean( true ) ), "boolean", "Boolean" ); - assert.equal( jQuery.type( 0 ), "number", "Number" ); - assert.equal( jQuery.type( 1 ), "number", "Number" ); - assert.equal( jQuery.type( Number( 1 ) ), "number", "Number" ); - assert.equal( jQuery.type( "" ), "string", "String" ); - assert.equal( jQuery.type( "a" ), "string", "String" ); - assert.equal( jQuery.type( String( "a" ) ), "string", "String" ); - assert.equal( jQuery.type( {} ), "object", "Object" ); - assert.equal( jQuery.type( /foo/ ), "regexp", "RegExp" ); - assert.equal( jQuery.type( new RegExp( "asdf" ) ), "regexp", "RegExp" ); - assert.equal( jQuery.type( [ 1 ] ), "array", "Array" ); - assert.equal( jQuery.type( new Date() ), "date", "Date" ); - assert.equal( jQuery.type( new Function( "return;" ) ), "function", "Function" ); - assert.equal( jQuery.type( function() {} ), "function", "Function" ); - assert.equal( jQuery.type( new Error() ), "error", "Error" ); - assert.equal( jQuery.type( window ), "object", "Window" ); - assert.equal( jQuery.type( document ), "object", "Document" ); - assert.equal( jQuery.type( document.body ), "object", "Element" ); - assert.equal( jQuery.type( document.createTextNode( "foo" ) ), "object", "TextNode" ); - assert.equal( jQuery.type( document.getElementsByTagName( "*" ) ), "object", "NodeList" ); - - // Avoid Lint complaints - var MyString = String, - MyNumber = Number, - MyBoolean = Boolean, - MyObject = Object; - assert.equal( jQuery.type( new MyBoolean( true ) ), "boolean", "Boolean" ); - assert.equal( jQuery.type( new MyNumber( 1 ) ), "number", "Number" ); - assert.equal( jQuery.type( new MyString( "a" ) ), "string", "String" ); - assert.equal( jQuery.type( new MyObject() ), "object", "Object" ); -} ); - -QUnit[ typeof Symbol === "function" ? "test" : "skip" ]( "type for `Symbol`", function( assert ) { - assert.expect( 2 ); - - assert.equal( jQuery.type( Symbol() ), "symbol", "Symbol" ); - assert.equal( jQuery.type( Object( Symbol() ) ), "symbol", "Symbol" ); -} ); - -QUnit.test( "isFunction", function( assert ) { - assert.expect( 20 ); - - var mystr, myarr, myfunction, fn, obj, nodes, first, input, a; - - // Make sure that false values return false - assert.ok( !jQuery.isFunction(), "No Value" ); - assert.ok( !jQuery.isFunction( null ), "null Value" ); - assert.ok( !jQuery.isFunction( undefined ), "undefined Value" ); - assert.ok( !jQuery.isFunction( "" ), "Empty String Value" ); - assert.ok( !jQuery.isFunction( 0 ), "0 Value" ); - - // Check built-ins - assert.ok( jQuery.isFunction( String ), "String Function(" + String + ")" ); - assert.ok( jQuery.isFunction( Array ), "Array Function(" + Array + ")" ); - assert.ok( jQuery.isFunction( Object ), "Object Function(" + Object + ")" ); - assert.ok( jQuery.isFunction( Function ), "Function Function(" + Function + ")" ); - - // When stringified, this could be misinterpreted - mystr = "function"; - assert.ok( !jQuery.isFunction( mystr ), "Function String" ); - - // When stringified, this could be misinterpreted - myarr = [ "function" ]; - assert.ok( !jQuery.isFunction( myarr ), "Function Array" ); - - // When stringified, this could be misinterpreted - myfunction = { "function": "test" }; - assert.ok( !jQuery.isFunction( myfunction ), "Function Object" ); - - // Make sure normal functions still work - fn = function() {}; - assert.ok( jQuery.isFunction( fn ), "Normal Function" ); - - assert.notOk( jQuery.isFunction( Object.create( fn ) ), "custom Function subclass" ); - - obj = document.createElement( "object" ); - - // Some versions of Firefox and Chrome say this is a function - assert.ok( !jQuery.isFunction( obj ), "Object Element" ); - - // Since 1.3, this isn't supported (#2968) - //assert.ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" ); - - nodes = document.body.childNodes; - - // Safari says this is a function - assert.ok( !jQuery.isFunction( nodes ), "childNodes Property" ); - - first = document.body.firstChild; - - // Normal elements are reported ok everywhere - assert.ok( !jQuery.isFunction( first ), "A normal DOM Element" ); - - input = document.createElement( "input" ); - input.type = "text"; - document.body.appendChild( input ); - - // Since 1.3, this isn't supported (#2968) - //assert.ok( jQuery.isFunction(input.focus), "A default function property" ); - - document.body.removeChild( input ); - - a = document.createElement( "a" ); - a.href = "some-function"; - document.body.appendChild( a ); - - // This serializes with the word 'function' in it - assert.ok( !jQuery.isFunction( a ), "Anchor Element" ); - - document.body.removeChild( a ); - - // Recursive function calls have lengths and array-like properties - function callme( callback ) { - function fn( response ) { - callback( response ); - } - - assert.ok( jQuery.isFunction( fn ), "Recursive Function Call" ); - - fn( { some: "data" } ); - } - - callme( function() { - callme( function() {} ); - } ); -} ); - -QUnit.test( "isFunction(cross-realm function)", function( assert ) { - assert.expect( 1 ); - - var iframe, doc, - done = assert.async(); - - // Functions from other windows should be matched - Globals.register( "iframeDone" ); - window.iframeDone = function( fn, detail ) { - window.iframeDone = undefined; - assert.ok( jQuery.isFunction( fn ), "cross-realm function" + - ( detail ? " - " + detail : "" ) ); - done(); - }; - - iframe = jQuery( "#qunit-fixture" )[ 0 ].appendChild( document.createElement( "iframe" ) ); - doc = iframe.contentDocument || iframe.contentWindow.document; - doc.open(); - doc.write( "" ); - doc.close(); -} ); - -supportjQuery.each( - { - GeneratorFunction: "function*() {}", - AsyncFunction: "async function() {}" - }, - function( subclass, source ) { - var fn; - try { - fn = Function( "return " + source )(); - } catch ( e ) {} - - QUnit[ fn ? "test" : "skip" ]( "isFunction(" + subclass + ")", - function( assert ) { - assert.expect( 1 ); - - assert.equal( jQuery.isFunction( fn ), true, source ); - } - ); - } -); - -QUnit[ typeof Symbol === "function" && Symbol.toStringTag ? "test" : "skip" ]( - "isFunction(custom @@toStringTag)", - function( assert ) { - assert.expect( 2 ); - - var obj = {}, - fn = function() {}; - obj[ Symbol.toStringTag ] = "Function"; - fn[ Symbol.toStringTag ] = "Object"; - - assert.equal( jQuery.isFunction( obj ), false, "function-mimicking object" ); - assert.equal( jQuery.isFunction( fn ), true, "object-mimicking function" ); - } -); - -QUnit.test( "jQuery.isWindow", function( assert ) { - assert.expect( 14 ); - - assert.ok( jQuery.isWindow( window ), "window" ); - assert.ok( jQuery.isWindow( document.getElementsByTagName( "iframe" )[ 0 ].contentWindow ), "iframe.contentWindow" ); - assert.ok( !jQuery.isWindow(), "empty" ); - assert.ok( !jQuery.isWindow( null ), "null" ); - assert.ok( !jQuery.isWindow( undefined ), "undefined" ); - assert.ok( !jQuery.isWindow( document ), "document" ); - assert.ok( !jQuery.isWindow( document.documentElement ), "documentElement" ); - assert.ok( !jQuery.isWindow( "" ), "string" ); - assert.ok( !jQuery.isWindow( 1 ), "number" ); - assert.ok( !jQuery.isWindow( true ), "boolean" ); - assert.ok( !jQuery.isWindow( {} ), "object" ); - assert.ok( !jQuery.isWindow( { setInterval: function() {} } ), "fake window" ); - assert.ok( !jQuery.isWindow( /window/ ), "regexp" ); - assert.ok( !jQuery.isWindow( function() {} ), "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( 7 ); - - jQuery.each( tests, function( key, val ) { - assert.equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val ); - } ); -} ); - -QUnit.test( "jQuery.now", function( assert ) { - assert.expect( 1 ); - - assert.ok( typeof jQuery.now() === "number", "jQuery.now is a function" ); -} ); - QUnit.test( "jQuery.proxy", function( assert ) { assert.expect( 9 ); @@ -525,78 +164,3 @@ QUnit.test( "jQuery.proxy", function( assert ) { cb = jQuery.proxy( fn, null, "arg1", "arg2" ); cb.call( thisObject, "arg3" ); } ); - -QUnit.test( "isNumeric", function( assert ) { - assert.expect( 43 ); - - var t = jQuery.isNumeric, - ToString = function( value ) { - this.toString = function() { - return String( value ); - }; - }; - - assert.ok( t( "-10" ), "Negative integer string" ); - assert.ok( t( "0" ), "Zero string" ); - assert.ok( t( "5" ), "Positive integer string" ); - assert.ok( t( -16 ), "Negative integer number" ); - assert.ok( t( 0 ), "Zero integer number" ); - assert.ok( t( 32 ), "Positive integer number" ); - assert.ok( t( "-1.6" ), "Negative floating point string" ); - assert.ok( t( "4.536" ), "Positive floating point string" ); - assert.ok( t( -2.6 ), "Negative floating point number" ); - assert.ok( t( 3.1415 ), "Positive floating point number" ); - assert.ok( t( 1.5999999999999999 ), "Very precise floating point number" ); - assert.ok( t( 8e5 ), "Exponential notation" ); - assert.ok( t( "123e-2" ), "Exponential notation string" ); - assert.ok( t( "040" ), "Legacy octal integer literal string" ); - assert.ok( t( "0xFF" ), "Hexadecimal integer literal string (0x...)" ); - assert.ok( t( "0Xba" ), "Hexadecimal integer literal string (0X...)" ); - assert.ok( t( 0xFFF ), "Hexadecimal integer literal" ); - - if ( +"0b1" === 1 ) { - assert.ok( t( "0b111110" ), "Binary integer literal string (0b...)" ); - assert.ok( t( "0B111110" ), "Binary integer literal string (0B...)" ); - } else { - assert.ok( true, "Browser does not support binary integer literal (0b...)" ); - assert.ok( true, "Browser does not support binary integer literal (0B...)" ); - } - - if ( +"0o1" === 1 ) { - assert.ok( t( "0o76" ), "Octal integer literal string (0o...)" ); - assert.ok( t( "0O76" ), "Octal integer literal string (0O...)" ); - } else { - assert.ok( true, "Browser does not support octal integer literal (0o...)" ); - assert.ok( true, "Browser does not support octal integer literal (0O...)" ); - } - - assert.equal( t( new ToString( "42" ) ), false, "Only limited to strings and numbers" ); - assert.equal( t( "" ), false, "Empty string" ); - assert.equal( t( " " ), false, "Whitespace characters string" ); - assert.equal( t( "\t\t" ), false, "Tab characters string" ); - assert.equal( t( "abcdefghijklm1234567890" ), false, "Alphanumeric character string" ); - assert.equal( t( "xabcdefx" ), false, "Non-numeric character string" ); - assert.equal( t( true ), false, "Boolean true literal" ); - assert.equal( t( false ), false, "Boolean false literal" ); - assert.equal( t( "bcfed5.2" ), false, "Number with preceding non-numeric characters" ); - assert.equal( t( "7.2acdgs" ), false, "Number with trailing non-numeric characters" ); - assert.equal( t( undefined ), false, "Undefined value" ); - assert.equal( t( null ), false, "Null value" ); - assert.equal( t( NaN ), false, "NaN value" ); - assert.equal( t( Infinity ), false, "Infinity primitive" ); - assert.equal( t( Number.POSITIVE_INFINITY ), false, "Positive Infinity" ); - assert.equal( t( Number.NEGATIVE_INFINITY ), false, "Negative Infinity" ); - assert.equal( t( new ToString( "Devo" ) ), false, "Custom .toString returning non-number" ); - assert.equal( t( {} ), false, "Empty object" ); - assert.equal( t( [] ), false, "Empty array" ); - assert.equal( t( [ 42 ] ), false, "Array with one number" ); - assert.equal( t( function() {} ), false, "Instance of a function" ); - assert.equal( t( new Date() ), false, "Instance of a Date" ); -} ); - -QUnit[ typeof Symbol === "function" ? "test" : "skip" ]( "isNumeric(Symbol)", function( assert ) { - assert.expect( 2 ); - - assert.equal( jQuery.isNumeric( Symbol() ), false, "Symbol" ); - assert.equal( jQuery.isNumeric( Object( Symbol() ) ), false, "Symbol inside an object" ); -} ); -- 2.39.5