MCPcopy Index your code
hub / github.com/react/react / compile

Function compile

compiler/packages/snap/src/runner-worker.ts:46–164  ·  view source on GitHub ↗
(
  input: string,
  fixturePath: string,
  compilerVersion: number,
  shouldLog: boolean,
  includeEvaluator: boolean,
)

Source from the content-addressed store, hash-verified

44}
45
46async function compile(
47 input: string,
48 fixturePath: string,
49 compilerVersion: number,
50 shouldLog: boolean,
51 includeEvaluator: boolean,
52): Promise<{
53 error: string | null;
54 compileResult: TransformResult | null;
55}> {
56 const seenConsoleErrors: Array<string> = [];
57 console.error = (...messages: Array<string>) => {
58 seenConsoleErrors.push(...messages);
59 };
60 if (version !== null && compilerVersion !== version) {
61 clearRequireCache();
62 }
63 version = compilerVersion;
64
65 let compileResult: TransformResult | null = null;
66 let error: string | null = null;
67 try {
68 const importedCompilerPlugin = require(PROJECT_SRC) as Record<
69 string,
70 unknown
71 >;
72
73 // NOTE: we intentionally require lazily here so that we can clear the require cache
74 // and load fresh versions of the compiler when `compilerVersion` changes.
75 const BabelPluginReactCompiler = importedCompilerPlugin[
76 'default'
77 ] as PluginObj;
78 const EffectEnum = importedCompilerPlugin['Effect'] as typeof Effect;
79 const ValueKindEnum = importedCompilerPlugin[
80 'ValueKind'
81 ] as typeof ValueKind;
82 const ValueReasonEnum = importedCompilerPlugin[
83 'ValueReason'
84 ] as typeof ValueReason;
85 const printFunctionWithOutlined = importedCompilerPlugin[
86 PRINT_HIR_IMPORT
87 ] as typeof PrintFunctionWithOutlined;
88 const printReactiveFunctionWithOutlined = importedCompilerPlugin[
89 PRINT_REACTIVE_IR_IMPORT
90 ] as typeof PrintReactiveFunctionWithOutlined;
91 const parseConfigPragmaForTests = importedCompilerPlugin[
92 PARSE_CONFIG_PRAGMA_IMPORT
93 ] as typeof ParseConfigPragma;
94
95 let lastLogged: string | null = null;
96 const debugIRLogger = shouldLog
97 ? (value: CompilerPipelineValue) => {
98 let printed: string;
99 switch (value.kind) {
100 case 'hir':
101 printed = printFunctionWithOutlined(value.value);
102 break;
103 case 'reactive':

Callers 1

transformFixtureFunction · 0.70

Calls 6

transformFixtureInputFunction · 0.90
clearRequireCacheFunction · 0.85
pushMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected