Skip to content
Merged
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
29 changes: 17 additions & 12 deletions packages/typescript-estree/src/node-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,16 +649,26 @@ export function convertTokens(ast: ts.SourceFile): TSESTree.Token[] {
return result;
}

export interface TSError {
index: number;
lineNumber: number;
column: number;
message: string;
export class TSError extends Error {
constructor(
message: string,
public readonly fileName: string,
public readonly index: number,
public readonly lineNumber: number,
public readonly column: number,
) {
super(message);
Object.defineProperty(this, 'name', {
value: new.target.name,
enumerable: false,
configurable: true,
});
}
}

/**
* @param ast the AST object
* @param start the index at which the error starts
* @param start the index at which the error starts
* @param message the error message
* @returns converted error object
*/
Expand All @@ -668,12 +678,7 @@ export function createError(
message: string,
): TSError {
const loc = ast.getLineAndCharacterOfPosition(start);
return {
index: start,
lineNumber: loc.line + 1,
column: loc.character,
message,
};
return new TSError(message, ast.fileName, start, loc.line + 1, loc.character);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion packages/typescript-estree/tests/ast-fixtures.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import fs from 'fs';
import glob from 'glob';
import 'jest-specific-snapshot';
import { addSerializer } from 'jest-specific-snapshot';
import makeDir from 'make-dir';
import path from 'path';
import { parseAndGenerateServices } from '../src/parser';
import { isJSXFileType } from '../tools/test-utils';
import { serializer } from '../tools/tserror-serializer';

addSerializer(serializer);

// Assign a segment set to this variable to limit the test to only this segment
// This is super helpful if you need to debug why a specific fixture isn't producing the correct output
Expand Down
Loading