diff --git a/src/index.js b/src/index.js index 4680522..706539e 100644 --- a/src/index.js +++ b/src/index.js @@ -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; } @@ -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; diff --git a/test/fixtures/descriptionsAsObjects/actual.js b/test/fixtures/descriptionsAsObjects/actual.js index 543c1d4..e7c4d6b 100644 --- a/test/fixtures/descriptionsAsObjects/actual.js +++ b/test/fixtures/descriptionsAsObjects/actual.js @@ -7,7 +7,10 @@ export default class Foo extends Component { ); } diff --git a/test/fixtures/descriptionsAsObjects/expected.json b/test/fixtures/descriptionsAsObjects/expected.json index 2718d31..1ce5f4a 100644 --- a/test/fixtures/descriptionsAsObjects/expected.json +++ b/test/fixtures/descriptionsAsObjects/expected.json @@ -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!" }