codeFrame() — astro Function Reference
Architecture documentation for the codeFrame() function in printer.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 177904c0_fd11_5ea7_1df2_8e57b83ea2db["codeFrame()"] 7d34d289_ea0e_ec1c_780b_4c297e3a4f60["printer.ts"] 177904c0_fd11_5ea7_1df2_8e57b83ea2db -->|defined in| 7d34d289_ea0e_ec1c_780b_4c297e3a4f60 style 177904c0_fd11_5ea7_1df2_8e57b83ea2db fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/core/errors/printer.ts lines 5–35
export function codeFrame(src: string, loc: ErrorLocation): string {
if (!loc || loc.line === undefined || loc.column === undefined) {
return '';
}
const lines = normalizeLF(src)
.split('\n')
.map((ln) => ln.replace(/\t/g, ' '));
// grab 2 lines before, and 3 lines after focused line
const visibleLines = [];
for (let n = -2; n <= 2; n++) {
if (lines[loc.line + n]) visibleLines.push(loc.line + n);
}
// figure out gutter width
let gutterWidth = 0;
for (const lineNo of visibleLines) {
let w = `> ${lineNo}`;
if (w.length > gutterWidth) gutterWidth = w.length;
}
// print lines
let output = '';
for (const lineNo of visibleLines) {
const isFocusedLine = lineNo === loc.line - 1;
output += isFocusedLine ? '> ' : ' ';
output += `${lineNo + 1} | ${lines[lineNo]}\n`;
if (isFocusedLine)
output += `${Array.from({ length: gutterWidth }).join(' ')} | ${Array.from({
length: loc.column,
}).join(' ')}^\n`;
}
return output;
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does codeFrame() do?
codeFrame() is a function in the astro codebase, defined in packages/astro/src/core/errors/printer.ts.
Where is codeFrame() defined?
codeFrame() is defined in packages/astro/src/core/errors/printer.ts at line 5.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free