Home / File/ transform-error-messages.js — react Source File

transform-error-messages.js — react Source File

Architecture documentation for transform-error-messages.js, a javascript file in the react codebase.

Entity Profile

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.
 */

'use strict';

let babel = require('@babel/core');
let devExpressionWithCodes = require('../transform-error-messages');

function transform(input, options = {}) {
  return babel.transform(input, {
    plugins: [[devExpressionWithCodes, options]],
  }).code;
}

let oldEnv;

describe('error transform', () => {
  beforeEach(() => {
    oldEnv = process.env.NODE_ENV;
    process.env.NODE_ENV = '';
  });

  afterEach(() => {
    process.env.NODE_ENV = oldEnv;
  });

  it('should replace error constructors', () => {
    expect(
      transform(`
new Error('Do not override existing functions.');
`)
    ).toMatchSnapshot();
  });

  it('should replace error constructors (no new)', () => {
    expect(
      transform(`
Error('Do not override existing functions.');
`)
    ).toMatchSnapshot();
  });

  it("should output FIXME for errors that don't have a matching error code", () => {
    expect(
      transform(`
Error('This is not a real error message.');
`)
    ).toMatchSnapshot();
  });

  it(
    "should output FIXME for errors that don't have a matching error " +
      'code, unless opted out with a comment',
    () => {
      // TODO: Since this only detects one of many ways to disable a lint
      // rule, we should instead search for a custom directive (like
// ... (109 more lines)

Domain

Subdomains

Functions

Frequently Asked Questions

What does transform-error-messages.js do?
transform-error-messages.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Entrypoint subdomain.
What functions are defined in transform-error-messages.js?
transform-error-messages.js defines 1 function(s): transform.
Where is transform-error-messages.js in the architecture?
transform-error-messages.js is located at scripts/error-codes/__tests__/transform-error-messages.js (domain: BabelCompiler, subdomain: Entrypoint, directory: scripts/error-codes/__tests__).

Analyze Your Own Codebase

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

Try Supermodel Free