diff options
author | Mihai Bazon <mihai@bazon.net> | 2014-01-10 10:33:58 +0200 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2014-01-10 10:33:58 +0200 |
commit | cad1f9cbd112b1117562b942f39a1205e00e2bf0 (patch) | |
tree | f2ac952e21c2c6ea934ee340bcf62f4262c0ec58 | |
parent | c3087dd179bcef93626ae8227bf8f0ac5baa15a2 (diff) | |
download | tracifyjs-cad1f9cbd112b1117562b942f39a1205e00e2bf0.tar.gz tracifyjs-cad1f9cbd112b1117562b942f39a1205e00e2bf0.zip |
Unescape Unicode sequences in regexps when ascii_only is false. #54
-rw-r--r-- | lib/output.js | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/output.js b/lib/output.js index 0c339c44..f778b381 100644 --- a/lib/output.js +++ b/lib/output.js @@ -1120,8 +1120,16 @@ function OutputStream(options) { }); DEFPRINT(AST_RegExp, function(self, output){ var str = self.getValue().toString(); - if (output.option("ascii_only")) + if (output.option("ascii_only")) { str = output.to_ascii(str); + } else { + str = str.split("\\\\").map(function(str){ + return str.replace(/(\\u[0-9a-fA-F]{4}|\\x[0-9a-fA-F]{2})/g, function(s, p1){ + var code = parseInt(p1.substr(2), 16); + return code == 10 || code == 13 || code == 0x2028 || code == 0x2029 ? s : String.fromCharCode(code); + }); + }).join("\\\\"); + } output.print(str); var p = output.parent(); if (p instanceof AST_Binary && /^in/.test(p.operator) && p.left === self) |