[Pkg-javascript-commits] [uglifyjs] 39/190: Output `-- >` instead of `-->` in expressions. Escape `<!--` and `-->` within string literals.
Antonio Terceiro
terceiro at moszumanska.debian.org
Sun Aug 7 23:17:11 UTC 2016
This is an automated email from the git hooks/post-receive script.
terceiro pushed a commit to annotated tag upstream/2.7.0
in repository uglifyjs.
commit 9f1f21b810ba3b996236cc7ef6757657757a007a
Author: kzc <zaxxon2011 at gmail.com>
Date: Mon Oct 12 00:20:42 2015 -0400
Output `-- >` instead of `-->` in expressions. Escape `<!--` and `-->` within string literals.
---
lib/output.js | 13 +++++++++++--
test/compress/html_comments.js | 15 +++++++++++++++
2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/lib/output.js b/lib/output.js
index c15f3b2..8ca0dc0 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -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"
diff --git a/test/compress/html_comments.js b/test/compress/html_comments.js
new file mode 100644
index 0000000..6141980
--- /dev/null
+++ b/test/compress/html_comments.js
@@ -0,0 +1,15 @@
+html_comment_in_expression: {
+ input: {
+ function f(a, b, x, y) { return a < !--b && x-- > y; }
+ }
+ expect_exact: "function f(a,b,x,y){return a< !--b&&x-- >y}";
+}
+
+html_comment_in_string_literal: {
+ input: {
+ function f() { return "<!--HTML-->comment in<!--string literal-->"; }
+ }
+ expect_exact: 'function f(){return"\\x3c!--HTML--\\x3ecomment in\\x3c!--string literal--\\x3e"}';
+}
+
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list