backtracker
Advanced tools
Comparing version 3.3.1 to 3.3.2
@@ -5,2 +5,7 @@ declare class Frame { | ||
filename: string; | ||
srcPath: string; | ||
srcDir: string; | ||
srcFilename: string; | ||
srcLine: number; | ||
srcColumn: number; | ||
async: boolean; | ||
@@ -19,2 +24,5 @@ scope: string; | ||
anonymous: boolean; | ||
srcPath: string; | ||
srcLine: number; | ||
srcColumn: number; | ||
}); | ||
@@ -21,0 +29,0 @@ toString(): string; |
@@ -10,2 +10,7 @@ "use strict"; | ||
filename; | ||
srcPath; | ||
srcDir; | ||
srcFilename; | ||
srcLine; | ||
srcColumn; | ||
async; | ||
@@ -21,2 +26,7 @@ scope; | ||
this.filename = path_1.default.basename(details.path); | ||
this.srcPath = details.srcPath; | ||
this.srcDir = path_1.default.dirname(details.srcPath); | ||
this.srcFilename = path_1.default.basename(details.srcPath); | ||
this.srcLine = details.srcLine; | ||
this.srcColumn = details.srcColumn; | ||
this.async = details.async; | ||
@@ -23,0 +33,0 @@ this.scope = details.scope; |
@@ -7,2 +7,3 @@ "use strict"; | ||
const Stack_1 = __importDefault(require("./Stack")); | ||
const filenameRegex = /(?:[^( ]+)? ?\(?(?:file\:\/\/\/)?([^*"\(\)]+):(\d+):(\d+)\)?/; | ||
class BackTracker { | ||
@@ -20,2 +21,6 @@ parent; | ||
const s = new Stack_1.default(); | ||
const runtimeFormatted = new Error().stack || ""; | ||
const split = runtimeFormatted.split("\n"); | ||
const firstIndex = split.findIndex(f => f === "Error"); | ||
const stringFrames = split.slice(firstIndex + 1 || 1).map(item => item.trim()); | ||
let index = 0; | ||
@@ -31,9 +36,16 @@ for (const c of es) { | ||
const filename = c.getFileName(); | ||
const match = stringFrames[index]?.match(filenameRegex); | ||
const pathToUse = c.getEvalOrigin() || filename || "<anonymous>"; | ||
const lineToUse = c.getLineNumber() || 0; | ||
const columnToUse = c.getColumnNumber() || 0; | ||
const frame = new Frame_1.default({ | ||
path: c.getEvalOrigin() || filename || "<anonymous>", | ||
path: pathToUse, | ||
async: c.isAsync(), | ||
scope: scope || "<anonymous>", | ||
line: c.getLineNumber() || 0, | ||
column: c.getColumnNumber() || 0, | ||
anonymous: !filename || !scope | ||
line: lineToUse, | ||
column: columnToUse, | ||
anonymous: !filename || !scope, | ||
srcPath: match?.[1] || pathToUse, | ||
srcLine: Number(match?.[2] || lineToUse), | ||
srcColumn: Number(match?.[3] || columnToUse) | ||
}); | ||
@@ -40,0 +52,0 @@ s.push(frame); |
{ | ||
"name": "backtracker", | ||
"version": "3.3.1", | ||
"version": "3.3.2", | ||
"description": "Back track in JS code execution and find where a function was called", | ||
@@ -22,4 +22,4 @@ "main": "dist/index", | ||
"devDependencies": { | ||
"@types/node": "18.7.14", | ||
"typescript": "^4.8.2" | ||
"@types/node": "18.11.9", | ||
"typescript": "^4.9.3" | ||
}, | ||
@@ -26,0 +26,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
36307
12
175