aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2014-01-21 11:44:00 +0200
committerMihai Bazon <mihai@bazon.net>2014-01-21 11:44:00 +0200
commit931862e97f2b8bc06d2de9b8e7e7e8e04500d063 (patch)
tree4dfee9ca9e0de6f047b680106227a319063e99b9
parent1d0127de2134f2086e1de51d47782118470397ed (diff)
downloadtracifyjs-931862e97f2b8bc06d2de9b8e7e7e8e04500d063.tar.gz
tracifyjs-931862e97f2b8bc06d2de9b8e7e7e8e04500d063.zip
More chars that cannot be unescaped in regexps.
-rw-r--r--lib/output.js30
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/output.js b/lib/output.js
index fce2c1ad..c2f49e9e 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -1118,6 +1118,34 @@ function OutputStream(options) {
DEFPRINT(AST_Number, function(self, output){
output.print(make_num(self.getValue()));
});
+
+ function regexp_safe_literal(code) {
+ return [
+ 0x5c , // \
+ 0x2f , // /
+ 0x2e , // .
+ 0x2b , // +
+ 0x2a , // *
+ 0x3f , // ?
+ 0x28 , // (
+ 0x29 , // )
+ 0x5b , // [
+ 0x5d , // ]
+ 0x7b , // {
+ 0x7d , // }
+ 0x24 , // $
+ 0x5e , // ^
+ 0x3a , // :
+ 0x7c , // |
+ 0x21 , // !
+ 0x0a , // \n
+ 0x0d , // \r
+ 0xfeff , // Unicode BOM
+ 0x2028 , // unicode "line separator"
+ 0x2029 , // unicode "paragraph separator"
+ ].indexOf(code) < 0;
+ };
+
DEFPRINT(AST_RegExp, function(self, output){
var str = self.getValue().toString();
if (output.option("ascii_only")) {
@@ -1126,7 +1154,7 @@ function OutputStream(options) {
str = str.split("\\\\").map(function(str){
return str.replace(/\\u[0-9a-fA-F]{4}|\\x[0-9a-fA-F]{2}/g, function(s){
var code = parseInt(s.substr(2), 16);
- return code == 0xfeff || code == 0x2f || code == 10 || code == 13 || code == 0x2028 || code == 0x2029 ? s : String.fromCharCode(code);
+ return regexp_safe_literal(code) ? String.fromCharCode(code) : s;
});
}).join("\\\\");
}