trimJsxText() — react Function Reference
Architecture documentation for the trimJsxText() function in BuildHIR.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 72aeaa10_7d77_cb8d_cf4a_ab588ee6026c["trimJsxText()"] e04c04d6_37a7_1dc3_7fae_7d07660d0af9["BuildHIR.ts"] 72aeaa10_7d77_cb8d_cf4a_ab588ee6026c -->|defined in| e04c04d6_37a7_1dc3_7fae_7d07660d0af9 1528c000_44a0_3a3f_9b4e_59e31922fdd6["lowerJsxElement()"] 1528c000_44a0_3a3f_9b4e_59e31922fdd6 -->|calls| 72aeaa10_7d77_cb8d_cf4a_ab588ee6026c style 72aeaa10_7d77_cb8d_cf4a_ab588ee6026c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts lines 3413–3460
function trimJsxText(original: string): string | null {
const lines = original.split(/\r\n|\n|\r/);
let lastNonEmptyLine = 0;
for (let i = 0; i < lines.length; i++) {
if (lines[i].match(/[^ \t]/)) {
lastNonEmptyLine = i;
}
}
let str = '';
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
const isFirstLine = i === 0;
const isLastLine = i === lines.length - 1;
const isLastNonEmptyLine = i === lastNonEmptyLine;
// replace rendered whitespace tabs with spaces
let trimmedLine = line.replace(/\t/g, ' ');
// trim whitespace touching a newline
if (!isFirstLine) {
trimmedLine = trimmedLine.replace(/^[ ]+/, '');
}
// trim whitespace touching an endline
if (!isLastLine) {
trimmedLine = trimmedLine.replace(/[ ]+$/, '');
}
if (trimmedLine) {
if (!isLastNonEmptyLine) {
trimmedLine += ' ';
}
str += trimmedLine;
}
}
if (str.length !== 0) {
return str;
} else {
return null;
}
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does trimJsxText() do?
trimJsxText() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts.
Where is trimJsxText() defined?
trimJsxText() is defined in compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts at line 3413.
What calls trimJsxText()?
trimJsxText() is called by 1 function(s): lowerJsxElement.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free