Skip to content

Commit

Permalink
fix: enable parser error recovery (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
j4k0xb committed Aug 8, 2024
1 parent 9561376 commit 241f946
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/webcrack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ export async function webcrack(
ast = parse(code, {
sourceType: 'unambiguous',
allowReturnOutsideFunction: true,
errorRecovery: true,
plugins: ['jsx'],
});
if (ast.errors.length) {
debug('webcrack:parse')('Errors', ast.errors);
}
},
() => {
applyTransforms(
Expand Down
9 changes: 9 additions & 0 deletions packages/webcrack/test/transforms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@ test('decode malformed bookmarklet', async () => {
})();"
`);
});

test('parser error recovery', async () => {
const code = 'foo()+=1; 1+1;';
const result = await webcrack(code);
expect(result.code).toMatchInlineSnapshot(`
"foo() += 1;
2;"
`);
});

0 comments on commit 241f946

Please sign in to comment.