Skip to content

Commit 241f946

Browse files
committed
fix: enable parser error recovery (#102)
1 parent 9561376 commit 241f946

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

packages/webcrack/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,12 @@ export async function webcrack(
140140
ast = parse(code, {
141141
sourceType: 'unambiguous',
142142
allowReturnOutsideFunction: true,
143+
errorRecovery: true,
143144
plugins: ['jsx'],
144145
});
146+
if (ast.errors.length) {
147+
debug('webcrack:parse')('Errors', ast.errors);
148+
}
145149
},
146150
() => {
147151
applyTransforms(

packages/webcrack/test/transforms.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,12 @@ test('decode malformed bookmarklet', async () => {
2020
})();"
2121
`);
2222
});
23+
24+
test('parser error recovery', async () => {
25+
const code = 'foo()+=1; 1+1;';
26+
const result = await webcrack(code);
27+
expect(result.code).toMatchInlineSnapshot(`
28+
"foo() += 1;
29+
2;"
30+
`);
31+
});

0 commit comments

Comments
 (0)