From b6edcfc65847560244c54b7b26708b0e76595511 Mon Sep 17 00:00:00 2001 From: Philipp Spiess Date: Wed, 5 Sep 2018 23:49:42 +0200 Subject: [PATCH] Remove unitless number whitelist --- packages/react-dom/src/shared/CSSProperty.js | 80 ------------------- .../src/shared/dangerousStyleValue.js | 5 +- 2 files changed, 1 insertion(+), 84 deletions(-) delete mode 100644 packages/react-dom/src/shared/CSSProperty.js diff --git a/packages/react-dom/src/shared/CSSProperty.js b/packages/react-dom/src/shared/CSSProperty.js deleted file mode 100644 index d9d92c7d0314e..0000000000000 --- a/packages/react-dom/src/shared/CSSProperty.js +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Copyright (c) 2013-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -/** - * CSS properties which accept numbers but are not in units of "px". - */ -export const isUnitlessNumber = { - animationIterationCount: true, - borderImageOutset: true, - borderImageSlice: true, - borderImageWidth: true, - boxFlex: true, - boxFlexGroup: true, - boxOrdinalGroup: true, - columnCount: true, - columns: true, - flex: true, - flexGrow: true, - flexPositive: true, - flexShrink: true, - flexNegative: true, - flexOrder: true, - gridArea: true, - gridRow: true, - gridRowEnd: true, - gridRowSpan: true, - gridRowStart: true, - gridColumn: true, - gridColumnEnd: true, - gridColumnSpan: true, - gridColumnStart: true, - fontWeight: true, - lineClamp: true, - lineHeight: true, - opacity: true, - order: true, - orphans: true, - tabSize: true, - widows: true, - zIndex: true, - zoom: true, - - // SVG-related properties - fillOpacity: true, - floodOpacity: true, - stopOpacity: true, - strokeDasharray: true, - strokeDashoffset: true, - strokeMiterlimit: true, - strokeOpacity: true, - strokeWidth: true, -}; - -/** - * @param {string} prefix vendor-specific prefix, eg: Webkit - * @param {string} key style name, eg: transitionDuration - * @return {string} style name prefixed with `prefix`, properly camelCased, eg: - * WebkitTransitionDuration - */ -function prefixKey(prefix, key) { - return prefix + key.charAt(0).toUpperCase() + key.substring(1); -} - -/** - * Support style names that may come passed in prefixed by adding permutations - * of vendor prefixes. - */ -const prefixes = ['Webkit', 'ms', 'Moz', 'O']; - -// Using Object.keys here, or else the vanilla for-in loop makes IE8 go into an -// infinite loop, because it iterates over the newly added props too. -Object.keys(isUnitlessNumber).forEach(function(prop) { - prefixes.forEach(function(prefix) { - isUnitlessNumber[prefixKey(prefix, prop)] = isUnitlessNumber[prop]; - }); -}); diff --git a/packages/react-dom/src/shared/dangerousStyleValue.js b/packages/react-dom/src/shared/dangerousStyleValue.js index e369a5babc7c0..650307807c783 100644 --- a/packages/react-dom/src/shared/dangerousStyleValue.js +++ b/packages/react-dom/src/shared/dangerousStyleValue.js @@ -5,8 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -import {isUnitlessNumber} from './CSSProperty'; - /** * Convert a value into the proper css writable value. The style name `name` * should be logical (no hyphens), as specified @@ -35,8 +33,7 @@ function dangerousStyleValue(name, value, isCustomProperty) { if ( !isCustomProperty && typeof value === 'number' && - value !== 0 && - !(isUnitlessNumber.hasOwnProperty(name) && isUnitlessNumber[name]) + value !== 0 ) { return value + 'px'; // Presumes implicit 'px' suffix for unitless numbers }