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

Function parseScript

packages/cli-lib/parse_script.ts:9–49  ·  view source on GitHub ↗
(opts: Opts, fn?: string)

Source from the content-addressed store, hash-verified

7 * @param fn filename
8 */
9export function parseScript(opts: Opts, fn?: string) {
10 return (source: string): void => {
11 let output
12 try {
13 debug('Using TS compiler to process file', fn)
14 output = ts.transpileModule(source, {
15 compilerOptions: {
16 allowJs: true,
17 target: ts.ScriptTarget.ESNext,
18 noEmit: true,
19 experimentalDecorators: true,
20 },
21 reportDiagnostics: true,
22 fileName: fn,
23 transformers: {
24 before: [transformWithTs(ts, opts)],
25 },
26 })
27 } catch (e) {
28 if (e instanceof Error) {
29 e.message = `Error processing file ${fn}
30${e.message || ''}`
31 }
32 throw e
33 }
34 if (output.diagnostics) {
35 const errs = output.diagnostics.filter(
36 d => d.category === ts.DiagnosticCategory.Error
37 )
38 if (errs.length) {
39 throw new Error(
40 ts.formatDiagnosticsWithColorAndContext(errs, {
41 getCanonicalFileName: fileName => fileName,
42 getCurrentDirectory: () => process.cwd(),
43 getNewLine: () => ts.sys.newLine,
44 })
45 )
46 }
47 }
48 }
49}

Callers 4

processFileFunction · 0.85
parseFileFunction · 0.85

Calls 2

transformWithTsFunction · 0.90
debugFunction · 0.70

Tested by

no test coverage detected