@@ -12,6 +12,9 @@ import CallExpression from './CallExpression';
1212import UnaryExpression from './UnaryExpression' ;
1313import ThisExpression from './ThisExpression' ;
1414import ConditionalExpression from './ConditionalExpression' ;
15+ import BinaryExpression from './BinaryExpression' ;
16+ import ObjectExpression from './ObjectExpression' ;
17+ import NewExpression from './NewExpression' ;
1518
1619
1720
@@ -27,7 +30,10 @@ const TYPES = {
2730 CallExpression,
2831 UnaryExpression,
2932 ThisExpression,
30- ConditionalExpression
33+ ConditionalExpression,
34+ BinaryExpression,
35+ ObjectExpression,
36+ NewExpression
3137} ;
3238
3339const noop = ( ) => null ;
@@ -55,9 +61,16 @@ const LITERAL_TYPES = assign({}, TYPES, {
5561 return extractedVal === undefined ? null : extractedVal ;
5662 } ,
5763 ThisExpression : noop ,
58- ConditionalExpression : noop
64+ ConditionalExpression : noop ,
65+ BinaryExpression : noop ,
66+ ObjectExpression : noop ,
67+ NewExpression : noop
5968} ) ;
6069
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+
6174/**
6275 * This function maps an AST value node
6376 * to its correct extractor function for its
@@ -71,8 +84,13 @@ const LITERAL_TYPES = assign({}, TYPES, {
7184export default function extract ( value ) {
7285 // Value will not have the expression property when we recurse.
7386 const expression = value . expression || value ;
87+ const { type } = expression ;
88+
89+ if ( TYPES [ type ] === undefined ) {
90+ throw new Error ( ERROR_MESSAGE ( type ) ) ;
91+ }
7492
75- return TYPES [ expression . type ] ( expression ) ;
93+ return TYPES [ type ] ( expression ) ;
7694}
7795
7896/**
@@ -86,7 +104,13 @@ export default function extract(value) {
86104 * @returns The extracted value.
87105 */
88106export function extractLiteral ( value ) {
107+ // Value will not have the expression property when we recurse.
89108 const expression = value . expression || value ;
109+ const { type } = expression ;
110+
111+ if ( LITERAL_TYPES [ type ] === undefined ) {
112+ throw new Error ( ERROR_MESSAGE ( type ) ) ;
113+ }
90114
91- return LITERAL_TYPES [ expression . type ] ( expression ) ;
115+ return LITERAL_TYPES [ type ] ( expression ) ;
92116}
0 commit comments