javascriptnode.jsesprima

Ignore error while generating JS AST using ESPIRMA


How to instruct esprima to continue generating AST even if there are syntax errors in the JS file?

Example:

var x = ; // syntax error
var y = 5;
x = y;

The normal esprima output (even when enabling tolerant mode):

description: 'Unexpected token ;'


Solution

  • Seems it is not possible with ESPIRMA. However, I could achieve that using acorn-loose which will generate the same AST structure.