transform() — react Function Reference
Architecture documentation for the transform() function in print-warnings.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD 561fc100_5fe6_4078_fbeb_f8197f0fe5c6["transform()"] 685d06fd_98ba_ca14_0dfa_e332611ca26a["print-warnings.js"] 561fc100_5fe6_4078_fbeb_f8197f0fe5c6 -->|defined in| 685d06fd_98ba_ca14_0dfa_e332611ca26a style 561fc100_5fe6_4078_fbeb_f8197f0fe5c6 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
scripts/print-warnings/print-warnings.js lines 21–66
function transform(file, enc, cb) {
fs.readFile(file.path, 'utf8', function (err, source) {
if (err) {
cb(err);
return;
}
let ast;
try {
ast = parse(source);
} catch (error) {
console.error('Failed to parse source file:', file.path);
throw error;
}
traverse(ast, {
enter() {},
leave(node) {
if (node.type !== 'CallExpression') {
return;
}
const callee = node.callee;
if (
callee.type === 'MemberExpression' &&
callee.object.type === 'Identifier' &&
callee.object.name === 'console' &&
callee.property.type === 'Identifier' &&
(callee.property.name === 'warn' || callee.property.name === 'error')
) {
// warning messages can be concatenated (`+`) at runtime, so here's
// a trivial partial evaluator that interprets the literal value
try {
const warningMsgLiteral = evalStringConcat(node.arguments[0]);
warnings.add(warningMsgLiteral);
} catch {
// Silently skip over this call. We have a lint rule to enforce
// that all calls are extractable, so if this one fails, assume
// it's intentional.
}
}
},
});
cb(null);
});
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does transform() do?
transform() is a function in the react codebase, defined in scripts/print-warnings/print-warnings.js.
Where is transform() defined?
transform() is defined in scripts/print-warnings/print-warnings.js at line 21.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free