From 3605bb7b9b96f89a62a6c1f94e47581592fe75be Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Mon, 6 Jul 2020 18:07:57 +0200 Subject: [PATCH] Improve code frame (#52) * Fix error when generating code frame from native * Fix off by one line mappings in code frame --- src/lib/util.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/util.js b/src/lib/util.js index 72b5459..a67a4fe 100644 --- a/src/lib/util.js +++ b/src/lib/util.js @@ -107,7 +107,11 @@ export function cleanStack(str, cwd = process.cwd()) { stack = frames .map((frame) => { // Only show frame for errors in the user's code - if (!nearestFrame && !/node_modules/.test(frame.fileName)) { + if ( + !nearestFrame && + !/node_modules/.test(frame.fileName) && + frame.type !== 'native' + ) { nearestFrame = frame; } @@ -142,7 +146,7 @@ export function cleanStack(str, cwd = process.cwd()) { const { fileName, line, column } = nearestFrame; if (fileName) { const content = fs.readFileSync(fileName, 'utf-8'); - codeFrame = createCodeFrame(content, line, column - 1, { + codeFrame = createCodeFrame(content, line - 1, column - 1, { before: 2, after: 2, });