@@ -218,15 +218,21 @@ export default function () {
218
218
219
219
CallExpression ( path , state ) {
220
220
const moduleSourceName = getModuleSourceName ( state . opts ) ;
221
+ const callee = path . get ( 'callee' ) ;
221
222
222
- function processMessageObject ( messageObj ) {
223
- if ( ! ( messageObj && messageObj . isObjectExpression ( ) ) ) {
223
+ function assertObjectExpression ( node ) {
224
+ if ( ! ( node && node . isObjectExpression ( ) ) ) {
224
225
throw path . buildCodeFrameError (
225
226
`[React Intl] \`${ callee . node . name } ()\` must be ` +
226
- 'called with message descriptors defined as ' +
227
- 'object expressions.'
227
+ 'called with an object expression with values ' +
228
+ 'that are React Intl Message Descriptors, also ' +
229
+ 'defined as object expressions.'
228
230
) ;
229
231
}
232
+ }
233
+
234
+ function processMessageObject ( messageObj ) {
235
+ assertObjectExpression ( messageObj ) ;
230
236
231
237
let properties = messageObj . get ( 'properties' ) ;
232
238
@@ -246,11 +252,11 @@ export default function () {
246
252
storeMessage ( descriptor , path , state ) ;
247
253
}
248
254
249
- let callee = path . get ( 'callee' ) ;
250
-
251
255
if ( referencesImport ( callee , moduleSourceName , FUNCTION_NAMES ) ) {
252
256
let messagesObj = path . get ( 'arguments' ) [ 0 ] ;
253
257
258
+ assertObjectExpression ( messagesObj ) ;
259
+
254
260
messagesObj . get ( 'properties' )
255
261
. map ( ( prop ) => prop . get ( 'value' ) )
256
262
. forEach ( processMessageObject ) ;
0 commit comments