( input: string, fixturePath: string, compilerVersion: number, shouldLog: boolean, includeEvaluator: boolean, )
| 44 | } |
| 45 | |
| 46 | async 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': |
no test coverage detected