i'm writing a custom compiler pass for Closure that switches javascript literal strings to hex. So "a" becomes "\x61"

but the code:

node.setString("\\x61");

results in javascript like this:

"\\x61"

instead of:

"\x61"

Of course, if I only use one slash in my java code, then it won't compile. The same is true with \n. It seems that somewhere behind the scenes, Closure / Rhino is automatically escaping the strings. But I can't find where. How can I write a string with special chars?

有帮助吗?

解决方案

I believe this would have to be done during output (code printing). Internally the string will be represented in it's unescaped form. Take a look at the Code Generator.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top