Output -- > instead of --> in expressions. Escape <!-- and --> within string literals.

This commit is contained in:
kzc
2015-10-12 00:20:42 -04:00
committed by Mihai Bazon
parent a8e67d157e
commit 9f1f21b810
2 changed files with 26 additions and 2 deletions

View File

@@ -127,6 +127,8 @@ function OutputStream(options) {
var ret = make_string(str, quote);
if (options.inline_script)
ret = ret.replace(/<\x2fscript([>\/\t\n\f\r ])/gi, "<\\/script$1");
ret = ret.replace(/\x3c!--/g, "\\x3c!--");
ret = ret.replace(/--\x3e/g, "--\\x3e");
return ret;
};
@@ -1046,7 +1048,15 @@ function OutputStream(options) {
});
DEFPRINT(AST_Binary, function(self, output){
self.left.print(output);
output.space();
if (self.operator == ">"
&& 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(self.operator);
if (self.operator == "<"
&& self.right instanceof AST_UnaryPrefix
@@ -1054,7 +1064,6 @@ function OutputStream(options) {
&& self.right.expression instanceof AST_UnaryPrefix
&& self.right.expression.operator == "--") {
// space is mandatory to avoid outputting <!--
// http://javascript.spec.whatwg.org/#comment-syntax
output.print(" ");
} else {
// the space is optional depending on "beautify"