One option would be to use a Parser that supports
fault tolerance and error recovery.
In hand crafted parsers this error recovery may be added manually (but resulting in a-lot of work...) For example: search for the word "recovery" in the TypeScript parser which is used to provide Language Services for the VSCode IDE. https://github.com/Microsoft/TypeScript/blob/master/src/comp...
Automatic Error Recovery using heuristics can also be implemented by parsing Libraries. In the world of JavaScript I'm familiar with two libraries that support Error Recovery:
Antlr4 - https://github.com/antlr/antlr4
Chevrotain - https://github.com/SAP/chevrotain (disclaimer - I'm the author of Chevrotain)