doEval() — react Function Reference
Architecture documentation for the doEval() function in evaluator.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD c8090524_9cfa_099d_cf1f_dcf1a93439f8["doEval()"] e04df78a_8312_1a6c_3ce1_ea408e44a1d7["evaluator.ts"] c8090524_9cfa_099d_cf1f_dcf1a93439f8 -->|defined in| e04df78a_8312_1a6c_3ce1_ea408e44a1d7 81e68010_37f1_e748_b452_7cc28e601cad["runSprout()"] 81e68010_37f1_e748_b452_7cc28e601cad -->|calls| c8090524_9cfa_099d_cf1f_dcf1a93439f8 15af1288_5ce1_7a3d_304e_01b40e750f72["push()"] c8090524_9cfa_099d_cf1f_dcf1a93439f8 -->|calls| 15af1288_5ce1_7a3d_304e_01b40e750f72 850ee738_6992_b2d7_3104_159fba313678["evaluateFixtureExport()"] c8090524_9cfa_099d_cf1f_dcf1a93439f8 -->|calls| 850ee738_6992_b2d7_3104_159fba313678 style c8090524_9cfa_099d_cf1f_dcf1a93439f8 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/snap/src/sprout/evaluator.ts lines 205–310
export function doEval(source: string): EvaluatorResult {
'use strict';
const originalConsole = globalThis.console;
const logs: Array<string> = [];
const mockedLog = (...args: Array<any>) => {
logs.push(
`${args.map(arg => {
if (arg instanceof Error) {
return arg.toString();
} else {
return util.inspect(arg);
}
})}`,
);
};
(globalThis.console as any) = {
info: mockedLog,
log: mockedLog,
warn: mockedLog,
error: (...args: Array<any>) => {
if (
typeof args[0] === 'string' &&
args[0].includes('ReactDOMTestUtils.act` is deprecated')
) {
// remove this once @testing-library/react is upgraded to React 19.
return;
}
const stack = new Error().stack?.split('\n', 5) ?? [];
for (const stackFrame of stack) {
// React warns on exceptions thrown during render, we avoid printing
// here to reduce noise in test fixture outputs.
if (
(stackFrame.includes('at logCaughtError') &&
stackFrame.includes('react-dom-client.development.js')) ||
(stackFrame.includes('at defaultOnRecoverableError') &&
stackFrame.includes('react-dom-client.development.js'))
) {
return;
}
}
mockedLog(...args);
},
table: mockedLog,
trace: () => {},
};
try {
// source needs to be evaluated in the same scope as invoke
const evalResult: any = eval(`
(() => {
// Exports should be overwritten by source
let exports = {
FIXTURE_ENTRYPOINT: {
fn: globalThis.placeholderFn,
params: [],
},
};
let reachedInvoke = false;
try {
// run in an iife to avoid naming collisions
(() => {${source}})();
reachedInvoke = true;
if (exports.FIXTURE_ENTRYPOINT?.fn === globalThis.placeholderFn) {
return {
kind: "exception",
value: "Fixture not implemented",
};
}
return evaluateFixtureExport(exports);
} catch (e) {
if (!reachedInvoke) {
return {
kind: "UnexpectedError",
value: e.message,
};
} else {
return {
kind: "exception",
value: e.message,
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does doEval() do?
doEval() is a function in the react codebase, defined in compiler/packages/snap/src/sprout/evaluator.ts.
Where is doEval() defined?
doEval() is defined in compiler/packages/snap/src/sprout/evaluator.ts at line 205.
What does doEval() call?
doEval() calls 2 function(s): evaluateFixtureExport, push.
What calls doEval()?
doEval() is called by 1 function(s): runSprout.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free