(
source: string,
fn: string,
{idInterpolationPattern, ...opts}: Opts & {idInterpolationPattern?: string}
)
| 163 | } |
| 164 | |
| 165 | async function processFile( |
| 166 | source: string, |
| 167 | fn: string, |
| 168 | {idInterpolationPattern, ...opts}: Opts & {idInterpolationPattern?: string} |
| 169 | ) { |
| 170 | let messages: ExtractedMessageDescriptor[] = [] |
| 171 | let meta: Record<string, string> | undefined |
| 172 | |
| 173 | const onMsgExtracted = opts.onMsgExtracted |
| 174 | const onMetaExtracted = opts.onMetaExtracted |
| 175 | |
| 176 | opts = { |
| 177 | ...opts, |
| 178 | additionalComponentNames: [ |
| 179 | '$formatMessage', |
| 180 | ...(opts.additionalComponentNames || []), |
| 181 | ], |
| 182 | onMsgExtracted(filePath, msgs) { |
| 183 | if (opts.extractSourceLocation) { |
| 184 | msgs = msgs.map(msg => ({ |
| 185 | ...msg, |
| 186 | ...calculateLineColFromOffset(source, msg.start), |
| 187 | })) |
| 188 | } |
| 189 | messages = messages.concat(msgs) |
| 190 | |
| 191 | if (onMsgExtracted) { |
| 192 | onMsgExtracted(filePath, msgs) |
| 193 | } |
| 194 | }, |
| 195 | onMetaExtracted(filePath, m) { |
| 196 | meta = m |
| 197 | |
| 198 | if (onMetaExtracted) { |
| 199 | onMetaExtracted(filePath, m) |
| 200 | } |
| 201 | }, |
| 202 | } |
| 203 | |
| 204 | if (!opts.overrideIdFn && idInterpolationPattern) { |
| 205 | opts = { |
| 206 | ...opts, |
| 207 | overrideIdFn: (id, defaultMessage, description, fileName) => |
| 208 | id || |
| 209 | interpolateName( |
| 210 | { |
| 211 | resourcePath: fileName, |
| 212 | } as any, |
| 213 | idInterpolationPattern, |
| 214 | { |
| 215 | content: description |
| 216 | ? `${defaultMessage}#${ |
| 217 | typeof description === 'string' |
| 218 | ? description |
| 219 | : stringify(description) |
| 220 | }` |
| 221 | : defaultMessage, |
| 222 | } |
no test coverage detected