All files / react-native-web/src/exports/StyleSheet validate.js

51.72% Statements 15/29
60% Branches 12/20
50% Functions 1/2
51.72% Lines 15/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69                      20x                                 211x 211x 394x 394x 394x   394x       394x       394x 394x         394x     394x     394x       394x         394x          
/**
 * Copyright (c) Nicolas Gallagher.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow strict-local
 */
 
import warning from 'fbjs/lib/warning';
 
const invalidShortforms = {
  background: true,
  borderBottom: true,
  borderLeft: true,
  borderRight: true,
  borderTop: true,
  font: true,
  grid: true,
  outline: true,
  textDecoration: true
};
 
function error(message) {
  warning(false, message);
}
 
export default function validate(key: string, styles: Object) {
  const obj = styles[key];
  for (const k in obj) {
    const prop = k.trim();
    const value = obj[prop];
    let isInvalid = false;
 
    Iif (value === null) {
      continue;
    }
 
    Iif (typeof value === 'string' && value.indexOf('!important') > -1) {
      error(`Invalid style declaration "${prop}:${value}". Values cannot include "!important"`);
      isInvalid = true;
    } else {
      let suggestion = '';
      Iif (prop === 'animation' || prop === 'animationName') {
        suggestion = 'Did you mean "animationKeyframes"?';
        // } else if (prop === 'boxShadow') {
        //  suggestion = 'Did you mean "shadow{Color,Offset,Opacity,Radius}"?';
        isInvalid = true;
      } else Iif (prop === 'direction') {
        suggestion = 'Did you mean "writingDirection"?';
        isInvalid = true;
      } else Iif (prop === 'verticalAlign') {
        suggestion = 'Did you mean "textAlignVertical"?';
        isInvalid = true;
      } else Iif (invalidShortforms[prop]) {
        suggestion = 'Please use long-form properties.';
        isInvalid = true;
      }
      Iif (suggestion !== '') {
        error(`Invalid style property of "${prop}". ${suggestion}`);
      }
    }
 
    Iif (isInvalid) {
      delete obj[k];
    }
  }
}