-
Notifications
You must be signed in to change notification settings - Fork 120
allow object passed to description prop #87
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattkime this is great, I'm glad it was such a simple change! Thanks for adding the test too. I added a few minor comments about formatting stuff. If you don't have a change to make these changes, let me know and I can just make them.
@@ -15,6 +15,7 @@ const fixtures = [ | |||
['moduleSourceName', { | |||
moduleSourceName: 'react-i18n', | |||
}], | |||
'descriptionsAsObjects' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this right after defineMessages
so the fixtures remain in alpha order?
@@ -52,7 +52,12 @@ export default function ({types: t}) { | |||
} | |||
|
|||
// Always trim the Message Descriptor values. | |||
return evaluatePath(path).trim(); | |||
let descriptorValue = evaluatePath(path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
return evaluatePath(path).trim(); | ||
let descriptorValue = evaluatePath(path); | ||
|
||
if( typeof descriptorValue === 'string' ){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update formatting to match rest of file:
if (condition) {
let descriptorValue = evaluatePath(path); | ||
|
||
if( typeof descriptorValue === 'string' ){ | ||
descriptorValue = descriptorValue.trim(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be an early return:
if (typeof descriptorValue === 'string') {
return descriptorValue.trim();
}
Follow up to #85 (comment)
Allows objects to be passed to the
description
prop.Only code change required was to check the description type before
.trim()
Added test to verify this works.