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';
const fs = require('fs');
const {evalStringAndTemplateConcat} = require('../shared/evalToString');
const invertObject = require('./invertObject');
const helperModuleImports = require('@babel/helper-module-imports');
const errorMap = invertObject(
JSON.parse(fs.readFileSync(__dirname + '/codes.json', 'utf-8'))
);
const SEEN_SYMBOL = Symbol('transform-error-messages.seen');
module.exports = function (babel) {
const t = babel.types;
function ErrorCallExpression(path, file) {
// Turns this code:
//
// new Error(`A ${adj} message that contains ${noun}`);
//
// or this code (no constructor):
//
// Error(`A ${adj} message that contains ${noun}`);
//
// into this:
//
// Error(formatProdErrorMessage(ERR_CODE, adj, noun));
const node = path.node;
if (node[SEEN_SYMBOL]) {
return;
}
node[SEEN_SYMBOL] = true;
const errorMsgNode = node.arguments[0];
if (errorMsgNode === undefined) {
return;
}
const errorMsgExpressions = [];
const errorMsgLiteral = evalStringAndTemplateConcat(
errorMsgNode,
errorMsgExpressions
);
if (errorMsgLiteral === 'react-stack-top-frame') {
// This is a special case for generating stack traces.
return;
}
let prodErrorId = errorMap[errorMsgLiteral];
if (prodErrorId === undefined) {
// There is no error code for this message. Add an inline comment
// that flags this as an unminified error. This allows the build
// ... (95 more lines)
Domain
Subdomains
Functions
Source
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, Optimization subdomain.
What functions are defined in transform-error-messages.js?
transform-error-messages.js defines 1 function(s): module.
Where is transform-error-messages.js in the architecture?
transform-error-messages.js is located at scripts/error-codes/transform-error-messages.js (domain: BabelCompiler, subdomain: Optimization, directory: scripts/error-codes).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free