improve js optimizer compilation error handling, and add comprehensive sanity test