(
path,
{
opts,
file: {
opts: {filename},
},
}
)
| 22 | PluginPass & State, |
| 23 | t.JSXOpeningElement |
| 24 | > = function ( |
| 25 | path, |
| 26 | { |
| 27 | opts, |
| 28 | file: { |
| 29 | opts: {filename}, |
| 30 | }, |
| 31 | } |
| 32 | ) { |
| 33 | const { |
| 34 | removeDefaultMessage, |
| 35 | idInterpolationPattern, |
| 36 | overrideIdFn, |
| 37 | ast, |
| 38 | preserveWhitespace, |
| 39 | flatten, |
| 40 | throws, |
| 41 | onMsgError, |
| 42 | } = opts as Options |
| 43 | |
| 44 | const {componentNames, messages} = this |
| 45 | if (wasExtracted(path)) { |
| 46 | return |
| 47 | } |
| 48 | |
| 49 | const name = path.get('name') |
| 50 | |
| 51 | if (!componentNames.find(n => name.isJSXIdentifier({name: n}))) { |
| 52 | return |
| 53 | } |
| 54 | |
| 55 | const attributes = path |
| 56 | .get('attributes') |
| 57 | .filter(attr => attr.isJSXAttribute()) |
| 58 | |
| 59 | let descriptorPath: MessageDescriptorPath |
| 60 | let descriptor: MessageDescriptor |
| 61 | try { |
| 62 | descriptorPath = createMessageDescriptor( |
| 63 | attributes.map(attr => [ |
| 64 | attr.get('name') as NodePath<t.JSXIdentifier>, |
| 65 | attr.get('value') as |
| 66 | | NodePath<t.StringLiteral> |
| 67 | | NodePath<t.JSXExpressionContainer>, |
| 68 | ]) |
| 69 | ) |
| 70 | |
| 71 | // In order for a default message to be extracted when |
| 72 | // declaring a JSX element, it must be done with standard |
| 73 | // `key=value` attributes. But it's completely valid to |
| 74 | // write `<FormattedMessage {...descriptor} />`, because it will be |
| 75 | // skipped here and extracted elsewhere. The descriptor will |
| 76 | // be extracted only (storeMessage) if a `defaultMessage` prop. |
| 77 | if (!descriptorPath.defaultMessage) { |
| 78 | return |
| 79 | } |
| 80 | |
| 81 | descriptor = evaluateMessageDescriptor( |
nothing calls this directly
no test coverage detected