Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make error location properties compatible with both svelte and prettier #132

Merged
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
15 changes: 9 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ export const parsers: Record<string, Parser> = {
try {
return <ASTNode>{ ...require(`svelte/compiler`).parse(text), __isRoot: true };
} catch (err) {
err.loc = {
start: err.start,
end: err.end,
};
delete err.start;
delete err.end;
if (err.start != null && err.end != null) {
// Prettier expects error objects to have loc.start and loc.end fields.
// Svelte uses start and end directly on the error.
err.loc = {
start: err.start,
end: err.end,
};
}

throw err;
}
},
Expand Down