Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ export default function ({types: t}) {
// Always trim the Message Descriptor values.
const descriptorValue = evaluatePath(path);

if(typeof descriptorValue === 'string'){
if (typeof descriptorValue === 'string') {
return descriptorValue.trim();
}

return descriptorValue;
}

Expand Down Expand Up @@ -135,10 +136,15 @@ export default function ({types: t}) {
}
}

if (opts.enforceDescriptions && !description) {
throw path.buildCodeFrameError(
'[React Intl] Message must have a `description`.'
);
if (opts.enforceDescriptions) {
if (
!description ||
(typeof description === 'object' && Object.keys(description).length < 1)
) {
throw path.buildCodeFrameError(
'[React Intl] Message must have a `description`.'
);
}
}

let loc;
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/descriptionsAsObjects/actual.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export default class Foo extends Component {
<FormattedMessage
id='foo.bar.baz'
defaultMessage='Hello World!'
description={{ text:'The default message.', metadata:'metadata content'}}
description={{
text: 'Something for the translator.',
metadata: 'Additional metadata content.',
}}
/>
);
}
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/descriptionsAsObjects/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{
"id": "foo.bar.baz",
"description": {
"text": "The default message.",
"metadata": "metadata content"
"text": "Something for the translator.",
"metadata": "Additional metadata content."
},
"defaultMessage": "Hello World!"
}
Expand Down