@@ -174,10 +174,19 @@ export default function ({Plugin, types: t}) {
174
174
175
175
if ( referencesImport ( name , moduleSourceName , COMPONENT_NAMES ) ) {
176
176
let attributes = this . get ( 'attributes' )
177
+ . filter ( ( attr ) => attr . isJSXAttribute ( ) )
177
178
. map ( ( attr ) => [ attr . get ( 'name' ) , attr . get ( 'value' ) ] ) ;
178
179
179
180
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
+ }
181
190
}
182
191
} ,
183
192
@@ -188,21 +197,12 @@ export default function ({Plugin, types: t}) {
188
197
189
198
if ( referencesImport ( callee , moduleSourceName , FUNCTION_NAMES ) ) {
190
199
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
-
198
200
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.`
204
205
) ;
205
- return ;
206
206
}
207
207
208
208
let properties = messageArg . get ( 'properties' )
0 commit comments