Ack, there's something missing from that implementation: Nested string handling.
This is working well:
"\\"
'\\';
If you use 'quote to compile a string without escapes, you're fine:
'"foo"
'\'foo\'';
If you do the same thing where the only things to escape are quotes, you're fine, 'cause you call 'js-q, which uses 'nest-lev:
'"'"
'\'\\\'\'';
However, with other escaped things you're in trouble:
'"\\"
'\'\\\'';
I suggest putting 'js-charesc where 'js-q is now and having it use 'nest-lev directly. You might not even need 'js-q, since it could just be (js-charesc #\').
Right. I'm going to use [] as makeshift quotes. The JavaScript ['\'\\\\\''] evaluates to ['\\'], which evaluates to [\]. The JavaScript ['\'\\\''] evaluates to ['\'], which evaluates to an error, 'cause it's an unterminated string.