Home / Function/ module() — react Function Reference

module() — react Function Reference

Architecture documentation for the module() function in makeTransform.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  70f7f4e1_1f10_c740_5bd1_3c07c0f7f9c5["module()"]
  f1d5d1b2_14d7_0dd7_7ad6_0df868e68b2c["makeTransform.ts"]
  70f7f4e1_1f10_c740_5bd1_3c07c0f7f9c5 -->|defined in| f1d5d1b2_14d7_0dd7_7ad6_0df868e68b2c
  style 70f7f4e1_1f10_c740_5bd1_3c07c0f7f9c5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/scripts/jest/makeTransform.ts lines 41–112

module.exports = (useForget: boolean) => {
  function createTransformer() {
    return babelJest.createTransformer({
      passPerPreset: true,
      presets: [
        '@babel/preset-typescript',
        {
          plugins: [
            useForget
              ? [
                  BabelPluginReactCompiler,
                  {
                    environment: forgetOptions,
                    /*
                     * Jest hashes the babel config as a cache breaker.
                     * (see https://github.com/jestjs/jest/blob/v29.6.2/packages/babel-jest/src/index.ts#L84)
                     */
                    compilerCacheKey,
                    transformOptionsCacheKey: forgetOptions,
                    e2eTransformerCacheKey,
                  },
                ]
              : '@babel/plugin-syntax-jsx',
          ],
        },
        '@babel/preset-react',
        {
          plugins: [
            [
              function BabelPluginRewriteRequirePath(): {visitor: Visitor} {
                return {
                  visitor: {
                    CallExpression(path: NodePath<CallExpression>): void {
                      const {callee} = path.node;
                      if (
                        callee.type === 'Identifier' &&
                        callee.name === 'require'
                      ) {
                        const arg = path.node.arguments[0];
                        if (arg.type === 'StringLiteral') {
                          /*
                           * The compiler adds requires of "React", which is expected to be a wrapper
                           * around the "react" package. For tests, we just rewrite the require.
                           */
                          if (arg.value === 'React') {
                            arg.value = 'react';
                          }
                        }
                      }
                    },
                  },
                };
              },
            ],
            '@babel/plugin-transform-modules-commonjs',
          ],
        },
      ],
      targets: {
        esmodules: true,
      },
    } as any);
    /*
     * typecast needed as DefinitelyTyped does not have updated Babel configs types yet
     * (missing passPerPreset and targets).
     */
  }

  return {
    createTransformer,
  };
};

Subdomains

Frequently Asked Questions

What does module() do?
module() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/scripts/jest/makeTransform.ts.
Where is module() defined?
module() is defined in compiler/packages/babel-plugin-react-compiler/scripts/jest/makeTransform.ts at line 41.

Analyze Your Own Codebase

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

Try Supermodel Free