Skip to content

Commit

Permalink
add comments to TransformError-generating code
Browse files Browse the repository at this point in the history
  • Loading branch information
noelforte committed Dec 4, 2024
1 parent ca834ee commit 0fe3383
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,14 @@ export function transformTemplateCode(
} catch (error) {
const { message, start, loc } = error as ParseError;

// Use information from `meriyah` to annotate the part of
// the compiled template function that triggered the ParseError
const annotation = code.split("\n")[loc.start.line - 1] + "\n" +
" ".repeat(loc.start.column) + "\x1b[31m^\x1b[0m";

// Grab the last instance of Vento's `__pos` variable before the
// error was thrown. Pass this back to Vento's createError to
// tie this error with problmatic template code
const matches = [...code.slice(0, start).matchAll(/__pos = (\d+);/g)];
const pos = Number(matches.at(-1)?.[1]);

Expand Down

0 comments on commit 0fe3383

Please sign in to comment.