[Pkg-javascript-commits] [uglifyjs] 363/491: parse LF & comment correctly (#2653)
Jonas Smedegaard
dr at jones.dk
Wed Feb 14 19:51:53 UTC 2018
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.
commit 0fe259e9c5deb78e853946a81b4c537ec67e9a3b
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Tue Dec 26 01:38:01 2017 +0800
parse LF & comment correctly (#2653)
fixes #2652
---
lib/parse.js | 23 ++++++++++++++---------
test/compress/issue-2652.js | 33 +++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 9 deletions(-)
diff --git a/lib/parse.js b/lib/parse.js
index c042a60..5eb7544 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -774,10 +774,15 @@ function parse($TEXT, options) {
function expect(punc) { return expect_token("punc", punc); };
+ function has_newline_before(token) {
+ return token.nlb || !all(token.comments_before, function(comment) {
+ return !comment.nlb;
+ });
+ }
+
function can_insert_semicolon() {
- return !options.strict && (
- S.token.nlb || is("eof") || is("punc", "}")
- );
+ return !options.strict
+ && (is("eof") || is("punc", "}") || has_newline_before(S.token));
};
function semicolon(optional) {
@@ -817,10 +822,10 @@ function parse($TEXT, options) {
if (S.in_directives) {
var token = peek();
if (S.token.raw.indexOf("\\") == -1
- && (token.nlb
- || is_token(token, "eof")
- || is_token(token, "punc", ";")
- || is_token(token, "punc", "}"))) {
+ && (is_token(token, "punc", ";")
+ || is_token(token, "punc", "}")
+ || has_newline_before(token)
+ || is_token(token, "eof"))) {
S.input.add_directive(S.token.value);
} else {
S.in_directives = false;
@@ -927,7 +932,7 @@ function parse($TEXT, options) {
case "throw":
next();
- if (S.token.nlb)
+ if (has_newline_before(S.token))
croak("Illegal newline after 'throw'");
var value = expression(true);
semicolon();
@@ -1503,7 +1508,7 @@ function parse($TEXT, options) {
return ex;
}
var val = expr_atom(allow_calls);
- while (is("operator") && UNARY_POSTFIX(S.token.value) && !S.token.nlb) {
+ while (is("operator") && UNARY_POSTFIX(S.token.value) && !has_newline_before(S.token)) {
val = make_unary(AST_UnaryPostfix, S.token, val);
val.start = start;
val.end = S.token;
diff --git a/test/compress/issue-2652.js b/test/compress/issue-2652.js
new file mode 100644
index 0000000..d315974
--- /dev/null
+++ b/test/compress/issue-2652.js
@@ -0,0 +1,33 @@
+insert_semicolon: {
+ beautify = {
+ beautify: true,
+ comments: "all",
+ }
+ input: {
+ var a
+ /* foo */ var b
+ }
+ expect_exact: [
+ "var a",
+ "/* foo */;",
+ "",
+ "var b;",
+ ]
+}
+
+unary_postfix: {
+ beautify = {
+ beautify: true,
+ comments: "all",
+ }
+ input: {
+ a
+ /* foo */++b
+ }
+ expect_exact: [
+ "a",
+ "/* foo */;",
+ "",
+ "++b;",
+ ]
+}
--
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