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

allow object passed to description prop #87

Merged
merged 4 commits into from
Dec 29, 2016
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
1 change: 1 addition & 0 deletions scripts/build-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const baseDir = p.resolve(`${__dirname}/../test/fixtures`);

const fixtures = [
'defineMessages',
'descriptionsAsObjects',
['extractSourceLocation', {
extractSourceLocation: true,
}],
Expand Down
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ export default function ({types: t}) {
}

// Always trim the Message Descriptor values.
return evaluatePath(path).trim();
const descriptorValue = evaluatePath(path);

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

function getICUMessageValue(messagePath, {isJSXSource = false} = {}) {
Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/descriptionsAsObjects/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React, {Component} from 'react';
import {FormattedMessage} from 'react-intl';

export default class Foo extends Component {
render() {
return (
<FormattedMessage
id='foo.bar.baz'
defaultMessage='Hello World!'
description={{ text:'The default message.', metadata:'metadata content'}}
/>
);
}
}
45 changes: 45 additions & 0 deletions test/fixtures/descriptionsAsObjects/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactIntl = require('react-intl');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var Foo = function (_Component) {
_inherits(Foo, _Component);

function Foo() {
_classCallCheck(this, Foo);

return _possibleConstructorReturn(this, (Foo.__proto__ || Object.getPrototypeOf(Foo)).apply(this, arguments));
}

_createClass(Foo, [{
key: 'render',
value: function render() {
return _react2.default.createElement(_reactIntl.FormattedMessage, {
id: 'foo.bar.baz',
defaultMessage: 'Hello World!'
});
}
}]);

return Foo;
}(_react.Component);

exports.default = Foo;
10 changes: 10 additions & 0 deletions test/fixtures/descriptionsAsObjects/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"id": "foo.bar.baz",
"description": {
"text": "The default message.",
"metadata": "metadata content"
},
"defaultMessage": "Hello World!"
}
]