Skip to content

CSS: Fix the logic to trigger warnings on jQuery.cssNumber access #467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 35 additions & 14 deletions src/jquery/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { jQueryVersionSince } from "../compareVersions.js";
import { migrateWarn, migratePatchFunc } from "../main.js";
import { camelCase } from "../utils.js";

var origFnCss,
var origFnCss, internalCssNumber,
internalSwapCall = false,
ralphaStart = /^[a-z]/,

Expand Down Expand Up @@ -84,8 +84,11 @@ if ( jQueryVersionSince( "3.4.0" ) && typeof Proxy !== "undefined" ) {
// https://github.com/jquery/jquery/blob/3.6.0/src/css.js#L212-L233
// This way, number values for the CSS properties below won't start triggering
// Migrate warnings when jQuery gets updated to >=4.0.0 (gh-438).
if ( jQueryVersionSince( "4.0.0" ) && typeof Proxy !== "undefined" ) {
jQuery.cssNumber = new Proxy( {
if ( jQueryVersionSince( "4.0.0" ) ) {

// We need to keep this as a local variable as we need it internally
// in a `jQuery.fn.css` patch and this usage shouldn't warn.
internalCssNumber = {
animationIterationCount: true,
columnCount: true,
fillOpacity: true,
Expand All @@ -106,16 +109,31 @@ if ( jQueryVersionSince( "4.0.0" ) && typeof Proxy !== "undefined" ) {
widows: true,
zIndex: true,
zoom: true
}, {
get: function() {
migrateWarn( "css-number", "jQuery.cssNumber is deprecated" );
return Reflect.get.apply( this, arguments );
},
set: function() {
migrateWarn( "css-number", "jQuery.cssNumber is deprecated" );
return Reflect.set.apply( this, arguments );
}
} );
};

if ( typeof Proxy !== "undefined" ) {
jQuery.cssNumber = new Proxy( internalCssNumber, {
get: function() {
migrateWarn( "css-number", "jQuery.cssNumber is deprecated" );
return Reflect.get.apply( this, arguments );
},
set: function() {
migrateWarn( "css-number", "jQuery.cssNumber is deprecated" );
return Reflect.set.apply( this, arguments );
}
} );
} else {

// Support: IE 9-11+
// IE doesn't support proxies, but we still want to restore the legacy
// jQuery.cssNumber there.
jQuery.cssNumber = internalCssNumber;
}
} else {

// Make `internalCssNumber` defined for jQuery <4 as well as it's needed
// in the `jQuery.fn.css` patch below.
internalCssNumber = jQuery.cssNumber;
}

function isAutoPx( prop ) {
Expand All @@ -142,7 +160,10 @@ migratePatchFunc( jQuery.fn, "css", function( name, value ) {

if ( typeof value === "number" ) {
camelName = camelCase( name );
if ( !isAutoPx( camelName ) && !jQuery.cssNumber[ camelName ] ) {

// Use `internalCssNumber` to avoid triggering our warnings in this
// internal check.
if ( !isAutoPx( camelName ) && !internalCssNumber[ camelName ] ) {
migrateWarn( "css-number",
"Number-typed values are deprecated for jQuery.fn.css( \"" +
name + "\", value )" );
Expand Down