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

Commit 429956c

Browse files
mattkimeericf
authored andcommitted
Allow object passed to description prop (#87)
* test descriptions as objects * tabs to spaces * pr feedback * remove some whitespace
1 parent 44c26c8 commit 429956c

File tree

5 files changed

+76
-1
lines changed

5 files changed

+76
-1
lines changed

scripts/build-fixtures.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const baseDir = p.resolve(`${__dirname}/../test/fixtures`);
77

88
const fixtures = [
99
'defineMessages',
10+
'descriptionsAsObjects',
1011
['extractSourceLocation', {
1112
extractSourceLocation: true,
1213
}],

src/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ export default function ({types: t}) {
5252
}
5353

5454
// Always trim the Message Descriptor values.
55-
return evaluatePath(path).trim();
55+
const descriptorValue = evaluatePath(path);
56+
57+
if(typeof descriptorValue === 'string'){
58+
return descriptorValue.trim();
59+
}
60+
return descriptorValue;
5661
}
5762

5863
function getICUMessageValue(messagePath, {isJSXSource = false} = {}) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React, {Component} from 'react';
2+
import {FormattedMessage} from 'react-intl';
3+
4+
export default class Foo extends Component {
5+
render() {
6+
return (
7+
<FormattedMessage
8+
id='foo.bar.baz'
9+
defaultMessage='Hello World!'
10+
description={{ text:'The default message.', metadata:'metadata content'}}
11+
/>
12+
);
13+
}
14+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
7+
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; }; }();
8+
9+
var _react = require('react');
10+
11+
var _react2 = _interopRequireDefault(_react);
12+
13+
var _reactIntl = require('react-intl');
14+
15+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16+
17+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18+
19+
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; }
20+
21+
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; }
22+
23+
var Foo = function (_Component) {
24+
_inherits(Foo, _Component);
25+
26+
function Foo() {
27+
_classCallCheck(this, Foo);
28+
29+
return _possibleConstructorReturn(this, (Foo.__proto__ || Object.getPrototypeOf(Foo)).apply(this, arguments));
30+
}
31+
32+
_createClass(Foo, [{
33+
key: 'render',
34+
value: function render() {
35+
return _react2.default.createElement(_reactIntl.FormattedMessage, {
36+
id: 'foo.bar.baz',
37+
defaultMessage: 'Hello World!'
38+
});
39+
}
40+
}]);
41+
42+
return Foo;
43+
}(_react.Component);
44+
45+
exports.default = Foo;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"id": "foo.bar.baz",
4+
"description": {
5+
"text": "The default message.",
6+
"metadata": "metadata content"
7+
},
8+
"defaultMessage": "Hello World!"
9+
}
10+
]

0 commit comments

Comments
 (0)