Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!filename || filename.endsWith('node_modules/babel-register/lib/node.js')) {
return chalk.gray(stackLine.trim());
}
if (!existsSync(filename)) {
return chalk.gray(stackLine.trim()); // + ` (${filename} not found)`;
}
const lineNumber = parseInt(lineAsString, 10) - 1;
const fileContents = readFileSync(filename, { encoding: 'UTF-8' }).toString() + '//EOF';
const lines = fileContents.split('\n');
const linesAbove = !lines[lineNumber - 2] ? 1 : 2;
const linesBelow = !lines[lineNumber + 2] ? 1 : 2;
const linesToShow = lines.slice(lineNumber - linesAbove, lineNumber + linesBelow + 1).join('\n');
const unIndentCount = minIndent(linesToShow);
const modifiedFileContents = [
...lines.slice(0, lineNumber - linesAbove),
stripIndent(linesToShow),
...lines.slice(lineNumber + linesBelow)
].join('\n');
const annotatedCode = codeFrameColumns(
modifiedFileContents,
{ start: { line: lineNumber + 1, column: parseInt(character, 10) - unIndentCount } },
{
forceColor: true,
highlightCode: true,
linesAbove,
linesBelow,
message
}
);