refactor(src): remove redundant coloring from createCodeFrame() (#3049)
`src/runtime/server/preact_hooks.tsx` is the only place that `createCodeFrame()` is used which stripped the ANSI codes anyway.
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import * as path from "@std/path";
|
import * as path from "@std/path";
|
||||||
import * as colors from "@std/fmt/colors";
|
|
||||||
|
|
||||||
function tabs2Spaces(str: string) {
|
function tabs2Spaces(str: string) {
|
||||||
return str.replace(/^\t+/, (tabs) => " ".repeat(tabs.length));
|
return str.replace(/^\t+/, (tabs) => " ".repeat(tabs.length));
|
||||||
@@ -55,21 +54,18 @@ export function createCodeFrame(
|
|||||||
activeLine.length - lines[lineNum].length + columnNum,
|
activeLine.length - lines[lineNum].length + columnNum,
|
||||||
);
|
);
|
||||||
|
|
||||||
const sep = colors.dim("|");
|
const sep = "|";
|
||||||
let out = "";
|
let out = "";
|
||||||
|
|
||||||
for (let i = 0; i < spaceLines.length; i++) {
|
for (let i = 0; i < spaceLines.length; i++) {
|
||||||
const line = spaceLines[i];
|
const line = spaceLines[i];
|
||||||
const currentLine = colors.dim(
|
const currentLine = (padding + (i + start + 1)).slice(-maxLineNum);
|
||||||
(padding + (i + start + 1)).slice(-maxLineNum),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Line where the error occurred
|
// Line where the error occurred
|
||||||
if (i === lineNum - start) {
|
if (i === lineNum - start) {
|
||||||
out += colors.red(">") +
|
out += ">" + ` ${currentLine} ${sep} ${line}\n`;
|
||||||
` ${currentLine} ${sep} ${line}\n`;
|
|
||||||
|
|
||||||
const columnMarker = colors.bold(colors.red("^"));
|
const columnMarker = "^";
|
||||||
out += ` ${padding} ${sep} ${" ".repeat(count)}${columnMarker}\n`;
|
out += ` ${padding} ${sep} ${" ".repeat(count)}${columnMarker}\n`;
|
||||||
} else {
|
} else {
|
||||||
out += ` ${currentLine} ${sep} ${line}\n`;
|
out += ` ${currentLine} ${sep} ${line}\n`;
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import {
|
|||||||
DEV_ERROR_OVERLAY_URL,
|
DEV_ERROR_OVERLAY_URL,
|
||||||
PARTIAL_SEARCH_PARAM,
|
PARTIAL_SEARCH_PARAM,
|
||||||
} from "../../constants.ts";
|
} from "../../constants.ts";
|
||||||
import * as colors from "@std/fmt/colors";
|
|
||||||
import { escape as escapeHtml } from "@std/html";
|
import { escape as escapeHtml } from "@std/html";
|
||||||
import { HttpError } from "../../error.ts";
|
import { HttpError } from "../../error.ts";
|
||||||
import { getCodeFrame } from "../../dev/middlewares/error_overlay/code_frame.tsx";
|
import { getCodeFrame } from "../../dev/middlewares/error_overlay/code_frame.tsx";
|
||||||
@@ -527,7 +526,7 @@ export function ShowErrorOverlay() {
|
|||||||
searchParams.append("stack", error.stack);
|
searchParams.append("stack", error.stack);
|
||||||
const codeFrame = getCodeFrame(error.stack, ctx.config.root);
|
const codeFrame = getCodeFrame(error.stack, ctx.config.root);
|
||||||
if (codeFrame !== undefined) {
|
if (codeFrame !== undefined) {
|
||||||
searchParams.append("code-frame", colors.stripAnsiCode(codeFrame));
|
searchParams.append("code-frame", codeFrame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user