From 55b81fa16db21635d5b31fd9177ea200fe35c1cd Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Tue, 27 Dec 2016 13:19:00 -0500 Subject: [PATCH 1/4] test descriptions as objects --- scripts/build-fixtures.js | 1 + src/index.js | 7 ++- test/fixtures/descriptionsAsObjects/actual.js | 14 ++++++ .../descriptionsAsObjects/expected.js | 45 +++++++++++++++++++ .../descriptionsAsObjects/expected.json | 10 +++++ 5 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/descriptionsAsObjects/actual.js create mode 100644 test/fixtures/descriptionsAsObjects/expected.js create mode 100644 test/fixtures/descriptionsAsObjects/expected.json diff --git a/scripts/build-fixtures.js b/scripts/build-fixtures.js index c9c9417..12462be 100644 --- a/scripts/build-fixtures.js +++ b/scripts/build-fixtures.js @@ -15,6 +15,7 @@ const fixtures = [ ['moduleSourceName', { moduleSourceName: 'react-i18n', }], + 'descriptionsAsObjects' ]; fixtures.forEach((fixture) => { diff --git a/src/index.js b/src/index.js index 40b8cde..356796e 100644 --- a/src/index.js +++ b/src/index.js @@ -52,7 +52,12 @@ export default function ({types: t}) { } // Always trim the Message Descriptor values. - return evaluatePath(path).trim(); + let descriptorValue = evaluatePath(path); + + if( typeof descriptorValue === 'string' ){ + descriptorValue = descriptorValue.trim(); + } + return descriptorValue; } function getICUMessageValue(messagePath, {isJSXSource = false} = {}) { diff --git a/test/fixtures/descriptionsAsObjects/actual.js b/test/fixtures/descriptionsAsObjects/actual.js new file mode 100644 index 0000000..543c1d4 --- /dev/null +++ b/test/fixtures/descriptionsAsObjects/actual.js @@ -0,0 +1,14 @@ +import React, {Component} from 'react'; +import {FormattedMessage} from 'react-intl'; + +export default class Foo extends Component { + render() { + return ( + + ); + } +} diff --git a/test/fixtures/descriptionsAsObjects/expected.js b/test/fixtures/descriptionsAsObjects/expected.js new file mode 100644 index 0000000..294f3d2 --- /dev/null +++ b/test/fixtures/descriptionsAsObjects/expected.js @@ -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; diff --git a/test/fixtures/descriptionsAsObjects/expected.json b/test/fixtures/descriptionsAsObjects/expected.json new file mode 100644 index 0000000..2718d31 --- /dev/null +++ b/test/fixtures/descriptionsAsObjects/expected.json @@ -0,0 +1,10 @@ +[ + { + "id": "foo.bar.baz", + "description": { + "text": "The default message.", + "metadata": "metadata content" + }, + "defaultMessage": "Hello World!" + } +] From 33df6db54200ee85dc0c8a5c027b3cf5bcac7002 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Tue, 27 Dec 2016 13:24:06 -0500 Subject: [PATCH 2/4] tabs to spaces --- scripts/build-fixtures.js | 2 +- src/index.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/build-fixtures.js b/scripts/build-fixtures.js index 12462be..73e2302 100644 --- a/scripts/build-fixtures.js +++ b/scripts/build-fixtures.js @@ -15,7 +15,7 @@ const fixtures = [ ['moduleSourceName', { moduleSourceName: 'react-i18n', }], - 'descriptionsAsObjects' + 'descriptionsAsObjects' ]; fixtures.forEach((fixture) => { diff --git a/src/index.js b/src/index.js index 356796e..69d2434 100644 --- a/src/index.js +++ b/src/index.js @@ -52,11 +52,11 @@ export default function ({types: t}) { } // Always trim the Message Descriptor values. - let descriptorValue = evaluatePath(path); + let descriptorValue = evaluatePath(path); - if( typeof descriptorValue === 'string' ){ - descriptorValue = descriptorValue.trim(); - } + if( typeof descriptorValue === 'string' ){ + descriptorValue = descriptorValue.trim(); + } return descriptorValue; } From 0934bca70e26dbf43aa2fdf0008789e4ff02c33a Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Thu, 29 Dec 2016 11:37:30 -0500 Subject: [PATCH 3/4] pr feedback --- scripts/build-fixtures.js | 2 +- src/index.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/build-fixtures.js b/scripts/build-fixtures.js index 73e2302..dea605b 100644 --- a/scripts/build-fixtures.js +++ b/scripts/build-fixtures.js @@ -7,6 +7,7 @@ const baseDir = p.resolve(`${__dirname}/../test/fixtures`); const fixtures = [ 'defineMessages', + 'descriptionsAsObjects', ['extractSourceLocation', { extractSourceLocation: true, }], @@ -15,7 +16,6 @@ const fixtures = [ ['moduleSourceName', { moduleSourceName: 'react-i18n', }], - 'descriptionsAsObjects' ]; fixtures.forEach((fixture) => { diff --git a/src/index.js b/src/index.js index 69d2434..c5d0f4d 100644 --- a/src/index.js +++ b/src/index.js @@ -52,10 +52,10 @@ export default function ({types: t}) { } // Always trim the Message Descriptor values. - let descriptorValue = evaluatePath(path); + const descriptorValue = evaluatePath(path); if( typeof descriptorValue === 'string' ){ - descriptorValue = descriptorValue.trim(); + return descriptorValue.trim(); } return descriptorValue; } From 42017ff47d44ebba5c242e6f6b89385bbea483a4 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Thu, 29 Dec 2016 11:38:11 -0500 Subject: [PATCH 4/4] remove some whitespace --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index c5d0f4d..4680522 100644 --- a/src/index.js +++ b/src/index.js @@ -54,7 +54,7 @@ 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;