Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 0 additions & 68 deletions lib/exception.js

This file was deleted.

67 changes: 67 additions & 0 deletions lib/exception.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import type { HasLocation } from './types/ast.js';

export default class Exception extends Error {
readonly lineNumber: number | undefined;
readonly endLineNumber: number | undefined;
readonly column: number | undefined;
readonly endColumn: number | undefined;

readonly description: string | undefined;

constructor(message: string, node?: HasLocation) {
const loc = node?.loc;
let line;
let endLineNumber;
let column;
let endColumn;

if (loc) {
line = loc.start.line;
endLineNumber = loc.end.line;
column = loc.start.column;
endColumn = loc.end.column;

message += ' - ' + line + ':' + column;
}

super(message);

/* istanbul ignore else */
if (hasCaptureStackTrace(Error)) {
Error.captureStackTrace(this, Exception);
}

try {
if (loc) {
this.lineNumber = line;
this.endLineNumber = endLineNumber;

// Work around issue under safari where we can't directly set the column value
/* istanbul ignore next */
if (Object.defineProperty) {
Object.defineProperty(this, 'column', {
value: column,
enumerable: true,
});
Object.defineProperty(this, 'endColumn', {
value: endColumn,
enumerable: true,
});
} else {
this.column = column;
this.endColumn = endColumn;
}
}
} catch (nop) {
/* Ignore if the browser is very particular */
}
}
}

type CapturableError = typeof Error & {
captureStackTrace: (error: Error, constructor: Function) => void;
};

function hasCaptureStackTrace(error: typeof Error): error is CapturableError {
return 'captureStackTrace' in error;
}
237 changes: 0 additions & 237 deletions lib/helpers.js

This file was deleted.

Loading