From 281e6ec24a2778b590c2395088a701e282f4532b Mon Sep 17 00:00:00 2001 From: ota-meshi Date: Tue, 3 Oct 2023 08:50:56 +0900 Subject: [PATCH] fix: "has only a getter" error --- src/ast/errors.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/ast/errors.ts b/src/ast/errors.ts index 3b0e90d6..6d84f0dc 100644 --- a/src/ast/errors.ts +++ b/src/ast/errors.ts @@ -23,6 +23,24 @@ function isAcornStyleParseError( ) } +/** + * Check whether the given value is probably a TSError. + * @param x The value to check. + * @returns `true` if the given value is probably a TSError. + */ +function isTSError( + x: any, +): x is { message: string; index: number; lineNumber: number; column: number } { + return ( + !(x instanceof ParseError) && + typeof x.message === "string" && + typeof x.index === "number" && + typeof x.lineNumber === "number" && + typeof x.column === "number" && + x.name === "TSError" + ) +} + /** * HTML parse errors. */ @@ -53,6 +71,15 @@ export class ParseError extends SyntaxError { * @param x The error object to normalize. */ public static normalize(x: any): ParseError | null { + if (isTSError(x)) { + return new ParseError( + x.message, + undefined, + x.index, + x.lineNumber, + x.column, + ) + } if (ParseError.isParseError(x)) { return x }