From 12b3f08c37683e0c6cd1eb31f1692a48fe0cec31 Mon Sep 17 00:00:00 2001 From: Noel Forte Date: Sun, 1 Dec 2024 16:01:00 -0500 Subject: [PATCH] convert all thrown errors in `transformer.ts` to `TransformError` instances prefixed with `[meriyah]` to indicate source of error --- src/transformer.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/transformer.ts b/src/transformer.ts index b6b451f..f87464f 100644 --- a/src/transformer.ts +++ b/src/transformer.ts @@ -153,12 +153,10 @@ export function transformTemplateCode( const matches = [...code.slice(0, start).matchAll(/__pos = (\d+);/g)]; const pos = Number(matches.at(-1)?.[1]); - throw new TransformError({ - message: - `Error transforming template function.\n${message} while transforming:\n\n${annotation}`, - cause: error as ParseError, - pos, - }); + throw new TransformError( + `[meriyah] ${message}\nthrown while parsing compiled template function:\n\n${annotation}`, + { pos }, + ); } const tracker = new ScopeTracker(); @@ -169,11 +167,11 @@ export function transformTemplateCode( ]; if (parsed.type !== "Program") { - throw new Error("Expected a program"); + throw new TransformError("[meriyah] Expected a program"); } if (parsed.body.length === 0) { - throw new Error("Empty program"); + throw new TransformError("[meriyah] Empty program"); } // Transforms an identifier to a MemberExpression