MCPcopy Index your code
hub / github.com/formatjs/formatjs / processFile

Function processFile

packages/cli-lib/extract.ts:165–256  ·  view source on GitHub ↗
(
  source: string,
  fn: string,
  {idInterpolationPattern, ...opts}: Opts & {idInterpolationPattern?: string}
)

Source from the content-addressed store, hash-verified

163}
164
165async 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 }

Callers 1

extractFunction · 0.85

Calls 4

interpolateNameFunction · 0.90
parseScriptFunction · 0.85
debugFunction · 0.70
parseFileFunction · 0.70

Tested by

no test coverage detected