Unescape Unicode sequences in regexps when ascii_only is false. #54

This commit is contained in:
Mihai Bazon
2014-01-10 10:33:58 +02:00
parent c3087dd179
commit cad1f9cbd1

View File

@@ -1120,8 +1120,16 @@ function OutputStream(options) {
}); });
DEFPRINT(AST_RegExp, function(self, output){ DEFPRINT(AST_RegExp, function(self, output){
var str = self.getValue().toString(); var str = self.getValue().toString();
if (output.option("ascii_only")) if (output.option("ascii_only")) {
str = output.to_ascii(str); 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); output.print(str);
var p = output.parent(); var p = output.parent();
if (p instanceof AST_Binary && /^in/.test(p.operator) && p.left === self) if (p instanceof AST_Binary && /^in/.test(p.operator) && p.left === self)