1
1
/* eslint-disable no-param-reassign */
2
- const parse = require ( ' postcss-value-parser' ) ;
3
- const camelizeStyleName = require ( ' fbjs/lib/camelizeStyleName' ) ;
4
- const transforms = require ( ' ./transforms' ) ;
5
- const TokenStream = require ( ' ./TokenStream' ) ;
2
+ const parse = require ( " postcss-value-parser" ) ;
3
+ const camelizeStyleName = require ( " fbjs/lib/camelizeStyleName" ) ;
4
+ const transforms = require ( " ./transforms" ) ;
5
+ const TokenStream = require ( " ./TokenStream" ) ;
6
6
7
7
// Note if this is wrong, you'll need to change tokenTypes.js too
8
8
const numberOrLengthRe = / ^ ( [ + - ] ? (?: \d * \. ) ? \d + (?: [ E e ] [ + - ] ? \d + ) ? ) (?: p x ) ? $ / i;
@@ -11,14 +11,14 @@ const nullRe = /^null$/i;
11
11
const undefinedRe = / ^ u n d e f i n e d $ / i;
12
12
13
13
// Undocumented export
14
- export const transformRawValue = ( input ) => {
14
+ export const transformRawValue = input => {
15
15
const value = input . trim ( ) ;
16
16
17
17
const numberMatch = value . match ( numberOrLengthRe ) ;
18
18
if ( numberMatch !== null ) return Number ( numberMatch [ 1 ] ) ;
19
19
20
20
const boolMatch = input . match ( boolRe ) ;
21
- if ( boolMatch !== null ) return boolMatch [ 0 ] . toLowerCase ( ) === ' true' ;
21
+ if ( boolMatch !== null ) return boolMatch [ 0 ] . toLowerCase ( ) === " true" ;
22
22
23
23
const nullMatch = input . match ( nullRe ) ;
24
24
if ( nullMatch !== null ) return null ;
@@ -35,32 +35,39 @@ const baseTransformShorthandValue = (propName, inputValue) => {
35
35
return transforms [ propName ] ( tokenStream ) ;
36
36
} ;
37
37
38
- const transformShorthandValue = ( process . env . NODE_ENV === 'production' )
39
- ? baseTransformShorthandValue
40
- : ( propName , inputValue ) => {
41
- try {
42
- return baseTransformShorthandValue ( propName , inputValue ) ;
43
- } catch ( e ) {
44
- throw new Error ( `Failed to parse declaration "${ propName } : ${ inputValue } "` ) ;
45
- }
46
- } ;
38
+ const transformShorthandValue =
39
+ process . env . NODE_ENV === "production"
40
+ ? baseTransformShorthandValue
41
+ : ( propName , inputValue ) => {
42
+ try {
43
+ return baseTransformShorthandValue ( propName , inputValue ) ;
44
+ } catch ( e ) {
45
+ throw new Error (
46
+ `Failed to parse declaration "${ propName } : ${ inputValue } "`
47
+ ) ;
48
+ }
49
+ } ;
47
50
48
51
export const getStylesForProperty = ( propName , inputValue , allowShorthand ) => {
49
- const isRawValue = ( allowShorthand === false ) || ! ( propName in transforms ) ;
52
+ const isRawValue = allowShorthand === false || ! ( propName in transforms ) ;
50
53
const propValue = isRawValue
51
54
? transformRawValue ( inputValue )
52
55
: transformShorthandValue ( propName , inputValue . trim ( ) ) ;
53
56
54
- return ( propValue && propValue . $merge )
57
+ return propValue && propValue . $merge
55
58
? propValue . $merge
56
59
: { [ propName ] : propValue } ;
57
60
} ;
58
61
59
62
export const getPropertyName = camelizeStyleName ;
60
63
61
- export default ( rules , shorthandBlacklist = [ ] ) => rules . reduce ( ( accum , rule ) => {
62
- const propertyName = getPropertyName ( rule [ 0 ] ) ;
63
- const value = rule [ 1 ] ;
64
- const allowShorthand = shorthandBlacklist . indexOf ( propertyName ) === - 1 ;
65
- return Object . assign ( accum , getStylesForProperty ( propertyName , value , allowShorthand ) ) ;
66
- } , { } ) ;
64
+ export default ( rules , shorthandBlacklist = [ ] ) =>
65
+ rules . reduce ( ( accum , rule ) => {
66
+ const propertyName = getPropertyName ( rule [ 0 ] ) ;
67
+ const value = rule [ 1 ] ;
68
+ const allowShorthand = shorthandBlacklist . indexOf ( propertyName ) === - 1 ;
69
+ return Object . assign (
70
+ accum ,
71
+ getStylesForProperty ( propertyName , value , allowShorthand )
72
+ ) ;
73
+ } , { } ) ;
0 commit comments