Home / File/ index.ts — react Source File

index.ts — react Source File

Architecture documentation for index.ts, a typescript file in the react codebase. 3 imports, 1 dependents.

File typescript BabelCompiler Optimization 3 imports 1 dependents 4 functions

Entity Profile

Dependency Diagram

graph LR
  f8b6e051_0f7f_6e15_4727_f99783e05cbb["index.ts"]
  e04df78a_8312_1a6c_3ce1_ea408e44a1d7["evaluator.ts"]
  f8b6e051_0f7f_6e15_4727_f99783e05cbb --> e04df78a_8312_1a6c_3ce1_ea408e44a1d7
  48fae59d_a3b3_000a_ab20_5ae63b78731b["EvaluatorResult"]
  f8b6e051_0f7f_6e15_4727_f99783e05cbb --> 48fae59d_a3b3_000a_ab20_5ae63b78731b
  c8090524_9cfa_099d_cf1f_dcf1a93439f8["doEval"]
  f8b6e051_0f7f_6e15_4727_f99783e05cbb --> c8090524_9cfa_099d_cf1f_dcf1a93439f8
  49c99dfe_ec8f_3cb7_769b_a3b735b82b82["runner-worker.ts"]
  49c99dfe_ec8f_3cb7_769b_a3b735b82b82 --> f8b6e051_0f7f_6e15_4727_f99783e05cbb
  style f8b6e051_0f7f_6e15_4727_f99783e05cbb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

import {EvaluatorResult, doEval} from './evaluator';

export type SproutResult =
  | {kind: 'success'; value: string}
  | {kind: 'invalid'; value: string};

function stringify(result: EvaluatorResult): string {
  return `(kind: ${result.kind}) ${result.value}${
    result.logs.length > 0 ? `\nlogs: [${result.logs.toString()}]` : ''
  }`;
}
function makeError(description: string, value: string): SproutResult {
  return {
    kind: 'invalid',
    value: description + '\n' + value,
  };
}
function logsEqual(a: Array<string>, b: Array<string>) {
  if (a.length !== b.length) {
    return false;
  }
  return a.every((val, idx) => val === b[idx]);
}
export function runSprout(
  originalCode: string,
  forgetCode: string,
): SproutResult {
  let forgetResult;
  try {
    (globalThis as any).__SNAP_EVALUATOR_MODE = 'forget';
    forgetResult = doEval(forgetCode);
  } catch (e) {
    throw e;
  } finally {
    (globalThis as any).__SNAP_EVALUATOR_MODE = undefined;
  }
  if (forgetResult.kind === 'UnexpectedError') {
    return makeError('Unexpected error in Forget runner', forgetResult.value);
  }
  if (originalCode.indexOf('@disableNonForgetInSprout') === -1) {
    const nonForgetResult = doEval(originalCode);

    if (nonForgetResult.kind === 'UnexpectedError') {
      return makeError(
        'Unexpected error in non-forget runner',
        nonForgetResult.value,
      );
    } else if (
      forgetResult.kind !== nonForgetResult.kind ||
      forgetResult.value !== nonForgetResult.value ||
      !logsEqual(forgetResult.logs, nonForgetResult.logs)
    ) {
      return makeError(
        'Found differences in evaluator results',
        `Non-forget (expected):
${stringify(nonForgetResult)}
Forget:
${stringify(forgetResult)}
`,
      );
    }
  }
  return {
    kind: 'success',
    value: stringify(forgetResult),
  };
}

Domain

Subdomains

Types

Frequently Asked Questions

What does index.ts do?
index.ts is a source file in the react codebase, written in typescript. It belongs to the BabelCompiler domain, Optimization subdomain.
What functions are defined in index.ts?
index.ts defines 4 function(s): logsEqual, makeError, runSprout, stringify.
What does index.ts depend on?
index.ts imports 3 module(s): EvaluatorResult, doEval, evaluator.ts.
What files import index.ts?
index.ts is imported by 1 file(s): runner-worker.ts.
Where is index.ts in the architecture?
index.ts is located at compiler/packages/snap/src/sprout/index.ts (domain: BabelCompiler, subdomain: Optimization, directory: compiler/packages/snap/src/sprout).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free