diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-02-15 05:26:48 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-15 05:26:48 +0000 |
commit | 0d820e4c0a7a1b1eeee25fb632b9496a9780b28a (patch) | |
tree | 53cfd159f60fde0f523e48b982fd4f64c7daaa4c /lib | |
parent | f01f580d6c2312ba556a37144f6fef227bd89f77 (diff) | |
download | tracifyjs-0d820e4c0a7a1b1eeee25fb632b9496a9780b28a.tar.gz tracifyjs-0d820e4c0a7a1b1eeee25fb632b9496a9780b28a.zip |
workaround RegExp formatting bugs (#3720)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/output.js | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/output.js b/lib/output.js index 86c0931e..f05c93df 100644 --- a/lib/output.js +++ b/lib/output.js @@ -1354,11 +1354,18 @@ function OutputStream(options) { DEFPRINT(AST_RegExp, function(self, output) { var regexp = self.value; var str = regexp.toString(); + var end = str.lastIndexOf("/"); if (regexp.raw_source) { - str = "/" + regexp.raw_source + str.slice(str.lastIndexOf("/")); + str = "/" + regexp.raw_source + str.slice(end); + } else if (end == 1) { + str = "/(?:)" + str.slice(end); + } else if (str.indexOf("/", 1) < end) { + str = "/" + str.slice(1, end).replace(/\\\\|[^/]?\//g, function(match) { + return match[0] == "\\" ? match : match.slice(0, -1) + "\\/"; + }) + str.slice(end); } - output.print(output.to_utf8(str).replace(/\\(?:\0(?![0-9])|[^\0])/g, function(seq) { - switch (seq[1]) { + output.print(output.to_utf8(str).replace(/\\(?:\0(?![0-9])|[^\0])/g, function(match) { + switch (match[1]) { case "\n": return "\\n"; case "\r": return "\\r"; case "\t": return "\t"; @@ -1368,7 +1375,7 @@ function OutputStream(options) { case "\x0B": return "\v"; case "\u2028": return "\\u2028"; case "\u2029": return "\\u2029"; - default: return seq; + default: return match; } }).replace(/[\n\r\u2028\u2029]/g, function(c) { switch (c) { |