Skip to content

Commit

Permalink
convert all thrown errors in transformer.ts to TransformError ins…
Browse files Browse the repository at this point in the history
…tances prefixed with `[meriyah]` to indicate source of error
  • Loading branch information
noelforte committed Dec 1, 2024
1 parent 4307aee commit 12b3f08
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down

0 comments on commit 12b3f08

Please sign in to comment.