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

Commit 38d85ba

Browse files
committed
Add warning when using <FormattedPlural>
This adds a warning when someone is using this Babel plugin and they are using <FormattedPlural> instead of <FormattedMessage> because the default messages will not be extracted. Fixes #11
1 parent 7a3b57b commit 38d85ba

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import printICUMessage from './print-icu-message';
1212
const COMPONENT_NAMES = [
1313
'FormattedMessage',
1414
'FormattedHTMLMessage',
15+
'FormattedPlural',
1516
];
1617

1718
const FUNCTION_NAMES = [
@@ -210,6 +211,17 @@ export default function ({Plugin, types: t}) {
210211

211212
let name = this.get('name');
212213

214+
if (name.referencesImport(moduleSourceName, 'FormattedPlural')) {
215+
let {loc} = node;
216+
file.log.warn(
217+
`[React Intl] Line ${loc.start.line}: ` +
218+
'Default messages are not extracted from ' +
219+
'<FormattedPlural>, use <FormattedMessage> instead.'
220+
);
221+
222+
return;
223+
}
224+
213225
if (referencesImport(name, moduleSourceName, COMPONENT_NAMES)) {
214226
let attributes = this.get('attributes')
215227
.filter((attr) => attr.isJSXAttribute());

0 commit comments

Comments
 (0)