HELP NEEDED WITH CREATING A LANGUAGE!
A) Validate the input, if it's invalid, throw an exception.
B) Validate the output, if the output isn't valid JS, throw an exception.
Regarding (B), if your output is incorrect, I'd consider it to be a compiler error, parse correctly and this won't happen.
@AJK4 Btw, I'd recommend using Coder100's answer, and using a parsing/lexing library instead of RegEx. You don't have to reinvent the wheel and parse by hand (it may even slow you down in fact), but ECMAScript RegEx won't help, recursive RegEx would be better, ex: PCRE syntax, but JS doesn't have anything else.
Just try to get a better parser that can stop when something isn't correct, so you can handle it yourself, or throw an error and abort the program.