Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Commit f666e48

Browse files
committed
Merge pull request #51 from yahoo/improve-definemessages-error
Improve the error message for defineMessages()
2 parents 7c2b835 + 1b8678d commit f666e48

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/index.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,21 @@ export default function () {
218218

219219
CallExpression(path, state) {
220220
const moduleSourceName = getModuleSourceName(state.opts);
221+
const callee = path.get('callee');
221222

222-
function processMessageObject(messageObj) {
223-
if (!(messageObj && messageObj.isObjectExpression())) {
223+
function assertObjectExpression(node) {
224+
if (!(node && node.isObjectExpression())) {
224225
throw path.buildCodeFrameError(
225226
`[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.'
228230
);
229231
}
232+
}
233+
234+
function processMessageObject(messageObj) {
235+
assertObjectExpression(messageObj);
230236

231237
let properties = messageObj.get('properties');
232238

@@ -246,11 +252,11 @@ export default function () {
246252
storeMessage(descriptor, path, state);
247253
}
248254

249-
let callee = path.get('callee');
250-
251255
if (referencesImport(callee, moduleSourceName, FUNCTION_NAMES)) {
252256
let messagesObj = path.get('arguments')[0];
253257

258+
assertObjectExpression(messagesObj);
259+
254260
messagesObj.get('properties')
255261
.map((prop) => prop.get('value'))
256262
.forEach(processMessageObject);

0 commit comments

Comments
 (0)