Skip to content

Commit

Permalink
fix: don't pretty-print with out-of-range indexes (#298)
Browse files Browse the repository at this point in the history
The code I added to catch ParseErrors from JS code was using (`pos`, `pos + 1`) as
the range, but if the position was at the very end of the string (e.g. due to
unbalanced parens), it would cause a crash because the end position would be
null. To fix, I changed it to instead just use the last character in the code in
that case rather than one after the last.
  • Loading branch information
alangpierce authored and eventualbuddha committed Jul 10, 2016
1 parent 3500774 commit 6cfbff4
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ function runStage(stage: Stage, content: string, filename: string): { code: stri
} catch (err) {
if (err instanceof SyntaxError) {
let { pos } = err;
if (pos === content.length) {
pos--;
}
throw new PatchError(
`${stage.name} failed to parse: ${err.message}`,
content,
Expand Down

0 comments on commit 6cfbff4

Please sign in to comment.