12
import type {printReactiveFunctionWithOutlined as PrintReactiveFunctionWithOutlined} from 'babel-plugin-react-compiler/src/ReactiveScopes/PrintReactiveFunction';
13
import {TransformResult, transformFixtureInput} from './compiler';
14
import {
15
- COMPILER_PATH,
16
- COMPILER_INDEX_PATH,
17
- PARSE_CONFIG_PRAGMA_PATH,
18
- PRINT_HIR_PATH,
19
- PRINT_REACTIVE_IR_PATH,
15
+ PARSE_CONFIG_PRAGMA_IMPORT,
16
+ PRINT_HIR_IMPORT,
17
+ PRINT_REACTIVE_IR_IMPORT,
18
+ PROJECT_SRC,
19
} from './constants';
20
import {TestFixture, getBasename, isExpectError} from './fixture-utils';
21
import {TestResult, writeOutputToString} from './reporter';
22
import {runSprout} from './sprout';
24
-import {CompilerPipelineValue} from 'babel-plugin-react-compiler/src';
23
+import type {
24
+ CompilerPipelineValue,
25
+ Effect,
26
+ ValueKind,
27
+} from 'babel-plugin-react-compiler/src';
28
import chalk from 'chalk';
29
30
const originalConsoleError = console.error;
64
let compileResult: TransformResult | null = null;
65
let error: string | null = null;
66
try {
67
+ const importedCompilerPlugin = require(PROJECT_SRC) as Record<
68
+ string,
69
+ unknown
70
+ >;
71
+
72
// NOTE: we intentionally require lazily here so that we can clear the require cache
73
// and load fresh versions of the compiler when `compilerVersion` changes.
66
- const {default: BabelPluginReactCompiler} = require(COMPILER_PATH) as {
67
- default: PluginObj;
68
- };
69
- const {Effect: EffectEnum, ValueKind: ValueKindEnum} = require(
70
- COMPILER_INDEX_PATH,
71
- );
72
- const {printFunctionWithOutlined} = require(PRINT_HIR_PATH) as {
73
- printFunctionWithOutlined: typeof PrintFunctionWithOutlined;
74
- };
75
- const {printReactiveFunctionWithOutlined} = require(
76
- PRINT_REACTIVE_IR_PATH,
77
- ) as {
78
- printReactiveFunctionWithOutlined: typeof PrintReactiveFunctionWithOutlined;
79
- };
74
+ const BabelPluginReactCompiler = importedCompilerPlugin[
75
+ 'default'
76
+ ] as PluginObj;
77
+ const EffectEnum = importedCompilerPlugin['Effect'] as typeof Effect;
78
+ const ValueKindEnum = importedCompilerPlugin[
79
+ 'ValueKind'
80
+ ] as typeof ValueKind;
81
+ const printFunctionWithOutlined = importedCompilerPlugin[
82
+ PRINT_HIR_IMPORT
83
+ ] as typeof PrintFunctionWithOutlined;
84
+ const printReactiveFunctionWithOutlined = importedCompilerPlugin[
85
+ PRINT_REACTIVE_IR_IMPORT
86
+ ] as typeof PrintReactiveFunctionWithOutlined;
87
+ const parseConfigPragmaForTests = importedCompilerPlugin[
88
+ PARSE_CONFIG_PRAGMA_IMPORT
89
+ ] as typeof ParseConfigPragma;
90
91
let lastLogged: string | null = null;
92
const debugIRLogger = shouldLog
116
}
117
}
118
: () => {};
109
- const {parseConfigPragmaForTests} = require(PARSE_CONFIG_PRAGMA_PATH) as {
110
- parseConfigPragmaForTests: typeof ParseConfigPragma;
111
- };
119
120
// only try logging if we filtered out all but one fixture,
121
// since console log order is non-deterministic