72172805ba
The original code attempted to parse the JavaScript as it went along, counting open and close brackets. Unfortunately, this doesn't take comments and string literals into consideration, so it would very likely have failed with more complicated filters. Instead, we'll let the JavaScript compiler handle all the complexity and simply see if the code compiles. If it doesn't, but the error occured in the last line, we assume it can be recovered by adding a new line.