Merge branch 'master' into harmony-v3.3.2

This commit is contained in:
alexlamsl
2017-12-26 01:46:22 +08:00
3 changed files with 49 additions and 11 deletions

View File

@@ -934,10 +934,15 @@ function parse($TEXT, options) {
function expect(punc) { return expect_token("punc", punc); }; 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() { function can_insert_semicolon() {
return !options.strict && ( return !options.strict
S.token.nlb || is("eof") || is("punc", "}") && (is("eof") || is("punc", "}") || has_newline_before(S.token));
);
}; };
function is_in_generator() { function is_in_generator() {
@@ -985,10 +990,10 @@ function parse($TEXT, options) {
if (S.in_directives) { if (S.in_directives) {
var token = peek(); var token = peek();
if (S.token.raw.indexOf("\\") == -1 if (S.token.raw.indexOf("\\") == -1
&& (token.nlb && (is_token(token, "punc", ";")
|| is_token(token, "eof") || is_token(token, "punc", "}")
|| is_token(token, "punc", ";") || has_newline_before(token)
|| is_token(token, "punc", "}"))) { || is_token(token, "eof"))) {
S.input.add_directive(S.token.value); S.input.add_directive(S.token.value);
} else { } else {
S.in_directives = false; S.in_directives = false;
@@ -1111,7 +1116,7 @@ function parse($TEXT, options) {
case "throw": case "throw":
next(); next();
if (S.token.nlb) if (has_newline_before(S.token))
croak("Illegal newline after 'throw'"); croak("Illegal newline after 'throw'");
var value = expression(true); var value = expression(true);
semicolon(); semicolon();
@@ -1287,7 +1292,7 @@ function parse($TEXT, options) {
}; };
var arrow_function = function(start, argnames, is_async) { var arrow_function = function(start, argnames, is_async) {
if (S.token.nlb) { if (has_newline_before(S.token)) {
croak("Unexpected newline before arrow (=>)"); croak("Unexpected newline before arrow (=>)");
} }
@@ -2738,7 +2743,7 @@ function parse($TEXT, options) {
return ex; return ex;
} }
var val = expr_atom(allow_calls, allow_arrows); var val = expr_atom(allow_calls, allow_arrows);
while (is("operator") && UNARY_POSTFIX(S.token.value) && !S.token.nlb) { while (is("operator") && UNARY_POSTFIX(S.token.value) && !has_newline_before(S.token)) {
if (val instanceof AST_Arrow) unexpected(); if (val instanceof AST_Arrow) unexpected();
val = make_unary(AST_UnaryPostfix, S.token, val); val = make_unary(AST_UnaryPostfix, S.token, val);
val.start = start; val.start = start;

View File

@@ -4,7 +4,7 @@
"homepage": "https://github.com/mishoo/UglifyJS2/tree/harmony", "homepage": "https://github.com/mishoo/UglifyJS2/tree/harmony",
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)", "author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
"license": "BSD-2-Clause", "license": "BSD-2-Clause",
"version": "3.3.1", "version": "3.3.2",
"engines": { "engines": {
"node": ">=0.8.0" "node": ">=0.8.0"
}, },

View File

@@ -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;",
]
}