aboutsummaryrefslogtreecommitdiff
path: root/lib/output.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-12-05 02:43:25 +0800
committerGitHub <noreply@github.com>2019-12-05 02:43:25 +0800
commit04fbb1f94978884128ef1582405a77a1974c6522 (patch)
treeeef527edb15a5cc142ce04eb49ae93936c9c8070 /lib/output.js
parentbf7e4ca1a3b1305308c66fcdf188d31a398c4ba2 (diff)
downloadtracifyjs-04fbb1f94978884128ef1582405a77a1974c6522.tar.gz
tracifyjs-04fbb1f94978884128ef1582405a77a1974c6522.zip
avoid collision with HTML comments (#3625)
fixes #3624
Diffstat (limited to 'lib/output.js')
-rw-r--r--lib/output.js39
1 files changed, 10 insertions, 29 deletions
diff --git a/lib/output.js b/lib/output.js
index 0f8ef1cd..d97778b2 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -269,7 +269,7 @@ function OutputStream(options) {
}
}
newline_insert = -1;
- var prev = last.charAt(last.length - 1);
+ var prev = last.slice(-1);
if (might_need_semicolon) {
might_need_semicolon = false;
@@ -298,16 +298,16 @@ function OutputStream(options) {
}
if (might_need_space) {
- if ((is_identifier_char(prev)
- && (is_identifier_char(ch) || ch == "\\"))
+ if (is_identifier_char(prev) && (is_identifier_char(ch) || ch == "\\")
|| (ch == "/" && ch == prev)
- || ((ch == "+" || ch == "-") && ch == last))
- {
+ || ((ch == "+" || ch == "-") && ch == last)
+ || str == "--" && last == "!"
+ || last == "--" && ch == ">") {
OUTPUT += " ";
current_col++;
current_pos++;
}
- might_need_space = false;
+ if (prev != "<" || str != "!") might_need_space = false;
}
if (mapping_token) {
@@ -322,7 +322,7 @@ function OutputStream(options) {
}
OUTPUT += str;
- has_parens = str[str.length - 1] == "(";
+ has_parens = str.slice(-1) == "(";
current_pos += str.length;
var a = str.split(/\r?\n/), n = a.length - 1;
current_line += n;
@@ -1254,29 +1254,10 @@ function OutputStream(options) {
output.print(self.operator);
});
DEFPRINT(AST_Binary, function(self, output) {
- var op = self.operator;
self.left.print(output);
- if (op[0] == ">" /* ">>" ">>>" ">" ">=" */
- && self.left instanceof AST_UnaryPostfix
- && self.left.operator == "--") {
- // space is mandatory to avoid outputting -->
- output.print(" ");
- } else {
- // the space is optional depending on "beautify"
- output.space();
- }
- output.print(op);
- if ((op == "<" || op == "<<")
- && self.right instanceof AST_UnaryPrefix
- && self.right.operator == "!"
- && self.right.expression instanceof AST_UnaryPrefix
- && self.right.expression.operator == "--") {
- // space is mandatory to avoid outputting <!--
- output.print(" ");
- } else {
- // the space is optional depending on "beautify"
- output.space();
- }
+ output.space();
+ output.print(self.operator);
+ output.space();
self.right.print(output);
});
DEFPRINT(AST_Conditional, function(self, output) {