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

Commit ed905dd

Browse files
committed
Support JSXSpreadAttributes by ignoring them
1 parent ea1e8d7 commit ed905dd

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/index.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,19 @@ export default function ({Plugin, types: t}) {
174174

175175
if (referencesImport(name, moduleSourceName, COMPONENT_NAMES)) {
176176
let attributes = this.get('attributes')
177+
.filter((attr) => attr.isJSXAttribute())
177178
.map((attr) => [attr.get('name'), attr.get('value')]);
178179

179180
let descriptor = getMessageDescriptor(new Map(attributes));
180-
storeMessage(descriptor, node, file);
181+
182+
// In order for a default message to be extracted when
183+
// declaring a JSX element, it must be done with standard
184+
// `key=value` attributes. But it's completely valid to
185+
// write `<FormattedMessage {...descriptor} />`, because it
186+
// will be skipped here and extracted elsewhere.
187+
if (descriptor.id) {
188+
storeMessage(descriptor, node, file);
189+
}
181190
}
182191
},
183192

@@ -188,21 +197,12 @@ export default function ({Plugin, types: t}) {
188197

189198
if (referencesImport(callee, moduleSourceName, FUNCTION_NAMES)) {
190199
let messageArg = this.get('arguments')[0];
191-
if (!messageArg) {
192-
throw file.errorWithNode(node,
193-
`[React Intl] \`${callee.node.name}()\` requires ` +
194-
`a message descriptor as the second argument.`
195-
);
196-
}
197-
198200
if (!(messageArg && messageArg.isObjectExpression())) {
199-
let {loc} = messageArg.node;
200-
file.log.warn(
201-
`[React Intl] Line ${loc.start.line}: ` +
202-
`\`${callee.node.name}()\` must use an inline ` +
203-
`object expression for the message to be extracted.`
201+
throw file.errorWithNode(node,
202+
`[React Intl] \`${callee.node.name}()\` must be ` +
203+
`called with message descriptor defined via an ` +
204+
`object expression.`
204205
);
205-
return;
206206
}
207207

208208
let properties = messageArg.get('properties')

0 commit comments

Comments
 (0)