Skip to content
This repository was archived by the owner on May 4, 2020. It is now read-only.

Commit f962fdf

Browse files
author
Long Ho
committed
feat(babel-plugin-react-intl): remove FormattedHTMLMessage extraction
BREAKING CHANGE: As of [email protected], `FormattedHTMLMessage` is no longer supported so we're removing this from our babel plugin as well
1 parent cd95686 commit f962fdf

File tree

5 files changed

+3
-82
lines changed

5 files changed

+3
-82
lines changed

packages/babel-plugin-react-intl/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ $ npm install babel-plugin-react-intl
2424

2525
**This Babel plugin only visits ES6 modules which `import` React Intl.**
2626

27-
The default message descriptors for the app's default language will be extracted from: `defineMessages()`, `<FormattedMessage>`, and `<FormattedHTMLMessage>`; all of which are named exports of the React Intl package.
27+
The default message descriptors for the app's default language will be extracted from: `defineMessages()`, `<FormattedMessage>`; all of which are named exports of the React Intl package.
2828

2929
If a message descriptor has a `description`, it'll be removed from the source after it's extracted to save bytes since it isn't used at runtime.
3030

@@ -57,7 +57,7 @@ If a message descriptor has a `description`, it'll be removed from the source af
5757

5858
- **`removeDefaultMessage`**: Remove `defaultMessage` field in generated js after extraction.
5959

60-
- **`additionalComponentNames`**: Additional component names to extract messages from, e.g: `['FormattedFooBarMessage']`. **NOTE**: By default we check for the fact that `FormattedMessage` & `FormattedHTMLMessage` are imported from `moduleSourceName` to make sure variable alias works. This option does not do that so it's less safe.
60+
- **`additionalComponentNames`**: Additional component names to extract messages from, e.g: `['FormattedFooBarMessage']`. **NOTE**: By default we check for the fact that `FormattedMessage` are imported from `moduleSourceName` to make sure variable alias works. This option does not do that so it's less safe.
6161

6262
- **`extractFromFormatMessageCall`**: Opt-in to extract from `intl.formatMessage` call with the same restrictions, e.g: has to be called with object literal such as `intl.formatMessage({ id: 'foo', defaultMessage: 'bar', description: 'baz'})`
6363

packages/babel-plugin-react-intl/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import validate from 'schema-utils';
2929
import OPTIONS_SCHEMA from './options.schema.json';
3030
import {OptionsSchema} from './options.js';
3131

32-
const DEFAULT_COMPONENT_NAMES = ['FormattedMessage', 'FormattedHTMLMessage'];
32+
const DEFAULT_COMPONENT_NAMES = ['FormattedMessage'];
3333

3434
const EXTRACTED = Symbol('ReactIntlExtracted');
3535
const DESCRIPTOR_PROPS = new Set(['id', 'description', 'defaultMessage']);

packages/babel-plugin-react-intl/test/__snapshots__/index.test.ts.snap

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,5 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`emit asserts for: output match: FormattedHTMLMessage 1`] = `
4-
Object {
5-
"messages": Array [
6-
Object {
7-
"defaultMessage": "<h1>Hello World!</h1>",
8-
"description": "The default message.",
9-
"id": "foo.bar.baz",
10-
},
11-
],
12-
}
13-
`;
14-
15-
exports[`emit asserts for: output match: FormattedHTMLMessage 2`] = `
16-
"\\"use strict\\";
17-
18-
Object.defineProperty(exports, \\"__esModule\\", {
19-
value: true
20-
});
21-
exports.default = void 0;
22-
23-
var _react = _interopRequireWildcard(require(\\"react\\"));
24-
25-
var _reactIntl = require(\\"react-intl\\");
26-
27-
function _getRequireWildcardCache() { if (typeof WeakMap !== \\"function\\") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
28-
29-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== \\"object\\" && typeof obj !== \\"function\\") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
30-
31-
class Foo extends _react.Component {
32-
render() {
33-
return _react.default.createElement(_reactIntl.FormattedHTMLMessage, {
34-
id: \\"foo.bar.baz\\",
35-
defaultMessage: \\"<h1>Hello World!</h1>\\"
36-
});
37-
}
38-
39-
}
40-
41-
exports.default = Foo;"
42-
`;
43-
44-
exports[`emit asserts for: output match: FormattedHTMLMessage 3`] = `
45-
Array [
46-
Object {
47-
"defaultMessage": "<h1>Hello World!</h1>",
48-
"description": "The default message.",
49-
"id": "foo.bar.baz",
50-
},
51-
]
52-
`;
53-
543
exports[`emit asserts for: output match: FormattedMessage 1`] = `
554
Object {
565
"messages": Array [
@@ -502,9 +451,6 @@ class Foo extends _react.Component {
502451
}), _react.default.createElement(_reactIntl.FormattedMessage, {
503452
id: \\"actual.js..5.object\\",
504453
defaultMessage: \\"NO ID\\"
505-
}), _react.default.createElement(_reactIntl.FormattedHTMLMessage, {
506-
id: \\"actual.js.foo.bar.delta.21.string\\",
507-
defaultMessage: \\"<h1>Hello World!</h1>\\"
508454
}));
509455
}
510456
@@ -544,11 +490,6 @@ Array [
544490
},
545491
"id": "actual.js..5.object",
546492
},
547-
Object {
548-
"defaultMessage": "<h1>Hello World!</h1>",
549-
"description": "The default message.",
550-
"id": "actual.js.foo.bar.delta.21.string",
551-
},
552493
]
553494
`;
554495

packages/babel-plugin-react-intl/test/fixtures/FormattedHTMLMessage/actual.js

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

packages/babel-plugin-react-intl/test/fixtures/overrideIdFn/actual.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React, {Component} from 'react';
22
import {
33
defineMessages,
44
FormattedMessage,
5-
FormattedHTMLMessage,
65
} from 'react-intl';
76

87
const msgs = defineMessages({
@@ -46,11 +45,6 @@ export default class Foo extends Component {
4645
metadata: 'Additional metadata content.',
4746
}}
4847
/>
49-
<FormattedHTMLMessage
50-
id="foo.bar.delta"
51-
defaultMessage="<h1>Hello World!</h1>"
52-
description="The default message."
53-
/>
5448
</div>
5549
);
5650
}

0 commit comments

Comments
 (0)