@@ -13,19 +13,27 @@ export const transformRawValue = (input) => {
13
13
return value ? Number ( value [ 1 ] ) : input ;
14
14
} ;
15
15
16
- export const getStylesForProperty = ( propName , inputValue , allowShorthand ) => {
17
- // Undocumented: allow ast to be passed in
18
- let propValue ;
16
+ const baseTransformShorthandValue = ( propName , inputValue ) => {
17
+ const ast = parse ( inputValue . trim ( ) ) ;
18
+ const tokenStream = new TokenStream ( ast . nodes ) ;
19
+ return transforms [ propName ] ( tokenStream ) ;
20
+ } ;
19
21
22
+ const transformShorthandValue = ( process . env . NODE_ENV === 'production' )
23
+ ? baseTransformShorthandValue
24
+ : ( propName , inputValue ) => {
25
+ try {
26
+ return baseTransformShorthandValue ( propName , inputValue ) ;
27
+ } catch ( e ) {
28
+ throw new Error ( `Failed to parse declaration "${ propName } : ${ inputValue } "` ) ;
29
+ }
30
+ } ;
31
+
32
+ export const getStylesForProperty = ( propName , inputValue , allowShorthand ) => {
20
33
const isRawValue = ( allowShorthand === false ) || ! ( propName in transforms ) ;
21
- if ( isRawValue ) {
22
- const value = typeof inputValue === 'string' ? inputValue : parse . stringify ( inputValue ) ;
23
- propValue = transformRawValue ( value ) ;
24
- } else {
25
- const ast = typeof inputValue === 'string' ? parse ( inputValue . trim ( ) ) : inputValue ;
26
- const tokenStream = new TokenStream ( ast . nodes ) ;
27
- propValue = transforms [ propName ] ( tokenStream ) ;
28
- }
34
+ const propValue = isRawValue
35
+ ? transformRawValue ( inputValue )
36
+ : transformShorthandValue ( propName , inputValue . trim ( ) ) ;
29
37
30
38
return ( propValue && propValue . $merge )
31
39
? propValue . $merge
0 commit comments