@@ -12,6 +12,9 @@ import CallExpression from './CallExpression';
12
12
import UnaryExpression from './UnaryExpression' ;
13
13
import ThisExpression from './ThisExpression' ;
14
14
import ConditionalExpression from './ConditionalExpression' ;
15
+ import BinaryExpression from './BinaryExpression' ;
16
+ import ObjectExpression from './ObjectExpression' ;
17
+ import NewExpression from './NewExpression' ;
15
18
16
19
17
20
@@ -27,7 +30,10 @@ const TYPES = {
27
30
CallExpression,
28
31
UnaryExpression,
29
32
ThisExpression,
30
- ConditionalExpression
33
+ ConditionalExpression,
34
+ BinaryExpression,
35
+ ObjectExpression,
36
+ NewExpression
31
37
} ;
32
38
33
39
const noop = ( ) => null ;
@@ -55,9 +61,16 @@ const LITERAL_TYPES = assign({}, TYPES, {
55
61
return extractedVal === undefined ? null : extractedVal ;
56
62
} ,
57
63
ThisExpression : noop ,
58
- ConditionalExpression : noop
64
+ ConditionalExpression : noop ,
65
+ BinaryExpression : noop ,
66
+ ObjectExpression : noop ,
67
+ NewExpression : noop
59
68
} ) ;
60
69
70
+ const ERROR_MESSAGE = expression =>
71
+ `The prop value with an expression type of ${ expression } could not be resolved.
72
+ Please file issue to get this fixed immediately.` ;
73
+
61
74
/**
62
75
* This function maps an AST value node
63
76
* to its correct extractor function for its
@@ -71,8 +84,13 @@ const LITERAL_TYPES = assign({}, TYPES, {
71
84
export default function extract ( value ) {
72
85
// Value will not have the expression property when we recurse.
73
86
const expression = value . expression || value ;
87
+ const { type } = expression ;
88
+
89
+ if ( TYPES [ type ] === undefined ) {
90
+ throw new Error ( ERROR_MESSAGE ( type ) ) ;
91
+ }
74
92
75
- return TYPES [ expression . type ] ( expression ) ;
93
+ return TYPES [ type ] ( expression ) ;
76
94
}
77
95
78
96
/**
@@ -86,7 +104,13 @@ export default function extract(value) {
86
104
* @returns The extracted value.
87
105
*/
88
106
export function extractLiteral ( value ) {
107
+ // Value will not have the expression property when we recurse.
89
108
const expression = value . expression || value ;
109
+ const { type } = expression ;
110
+
111
+ if ( LITERAL_TYPES [ type ] === undefined ) {
112
+ throw new Error ( ERROR_MESSAGE ( type ) ) ;
113
+ }
90
114
91
- return LITERAL_TYPES [ expression . type ] ( expression ) ;
115
+ return LITERAL_TYPES [ type ] ( expression ) ;
92
116
}
0 commit comments