Skip to content

Commit 3709782

Browse files
committed
feat(react-intl): update react-intl to v4.x
changes - update react-intl plugin to v4 - remove react-intl plugin patch. Plugin v4.x supports extracting from intl.formatMessage. - move react-intl plugin tests to preset
1 parent 9ffb510 commit 3709782

File tree

9 files changed

+108
-516
lines changed

9 files changed

+108
-516
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@babel/preset-flow": "7.0.0",
4242
"@babel/preset-react": "7.0.0",
4343
"@babel/runtime": "7.5.4",
44-
"babel-plugin-react-intl": "3.0.1",
44+
"babel-plugin-react-intl": "4.1.0",
4545
"flow-runtime": "0.17.0",
4646
"lodash": "4.17.14"
4747
},
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`support react-intl correctly throw invalid intl message error 1`] = `
4+
"/test-file.js: [React Intl] Message failed to parse. See: http://formatjs.io/guides/message-syntax/
5+
SyntaxError: Expected \\"'\\", \\"\\\\\\\\#\\", \\"\\\\\\\\\\\\\\\\\\", \\"\\\\\\\\u\\", \\"\\\\\\\\{\\", \\"\\\\\\\\}\\", \\"}\\", or [^{,},\\\\\\\\,\\\\0-\\\\x1F,\\\\x7F, ,\\\\t,\\\\n,\\\\r] but end of input found.
6+
6 | <FormattedMessage
7+
7 | id=\\"test.xyz\\"
8+
> 8 | defaultMessage=\\"{xyz, select, y {test}\\"
9+
| ^
10+
9 | />
11+
10 | );
12+
11 | "
13+
`;

src/__tests__/react-test.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* @flow */
22
import { testParseCode, transform } from './test-utils';
3+
import stripAnsi from 'strip-ansi';
34

45
testParseCode('react jsx', {
56
opts: [undefined, { react: true }],
@@ -79,6 +80,8 @@ var test = function test() {
7980

8081
describe('support react-intl', () => {
8182
const code = `
83+
import { FormattedMessage } from 'react-intl';
84+
8285
const component = () => {
8386
<div>
8487
<FormattedMessage id="some_id" defaultMessage="Some message" />
@@ -95,4 +98,63 @@ describe('support react-intl', () => {
9598
const result = transform(code, { reactIntl: false });
9699
expect(result.metadata['react-intl']).not.toBeDefined();
97100
});
101+
102+
describe('should able to extract messages', () => {
103+
it('<FormattedMessage />', () => {
104+
const result = transform(code);
105+
expect(result.metadata['react-intl']).toEqual({
106+
messages: [
107+
{
108+
id: 'some_id',
109+
description: undefined,
110+
defaultMessage: 'Some message',
111+
},
112+
],
113+
});
114+
});
115+
116+
test('intl.formatMessage', () => {
117+
const result = transform(`
118+
const component = () => {
119+
return (
120+
<div>
121+
{this.props.intl.formatMessage({
122+
id: "some_id",
123+
defaultMessage: "Some message",
124+
})}
125+
</div>
126+
);
127+
}
128+
`);
129+
expect(result.metadata['react-intl']).toEqual({
130+
messages: [
131+
{
132+
id: 'some_id',
133+
description: undefined,
134+
defaultMessage: 'Some message',
135+
},
136+
],
137+
});
138+
});
139+
});
140+
141+
test('correctly throw invalid intl message error', () => {
142+
expect(() => {
143+
try {
144+
transform(`
145+
import React from 'react';
146+
import { FormattedMessage } from 'react-intl';
147+
148+
const Component = (
149+
<FormattedMessage
150+
id="test.xyz"
151+
defaultMessage="{xyz, select, y {test}"
152+
/>
153+
);
154+
`);
155+
} catch (err) {
156+
throw new Error(stripAnsi(err.message));
157+
}
158+
}).toThrowErrorMatchingSnapshot();
159+
});
98160
});

src/plugins/__tests__/__snapshots__/react-intl-test.js.snap

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/plugins/__tests__/data/component.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/plugins/__tests__/react-intl-test.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)