diff --git a/lib/parse.js b/lib/parse.js index d5d2b69f..9a5e75cb 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -2012,7 +2012,7 @@ function parse($TEXT, options) { case "[": return subscripts(array_(), allow_calls); case "{": - return subscripts(object_or_object_destructuring_(), allow_calls); + return subscripts(object_or_destructuring_(), allow_calls); } unexpected(); } @@ -2109,7 +2109,7 @@ function parse($TEXT, options) { return function_(AST_Accessor, is_generator, is_async); }); - var object_or_object_destructuring_ = embed_tokens(function() { + var object_or_destructuring_ = embed_tokens(function object_or_destructuring_() { var start = S.token, first = true, a = []; expect("{"); while (!is("punc", "}")) { @@ -2231,7 +2231,7 @@ function parse($TEXT, options) { property_token = S.token; name = as_property_name(); } - if (name === "async" && !is("punc", "(")) { + if (name === "async" && !is("punc", "(") && !is("punc", ",") && !is("punc", "}")) { is_async = true; property_token = S.token; name = as_property_name(); diff --git a/test/compress/async.js b/test/compress/async.js index 8c84f94f..5f041d46 100644 --- a/test/compress/async.js +++ b/test/compress/async.js @@ -185,6 +185,51 @@ async_identifiers: { node_version: ">=8" } +async_shorthand_property: { + mangle = { + toplevel: true, + } + input: { + function print(o) { console.log(o.async + " " + o.await); } + var async = "Async", await = "Await"; + + print({ async }); + print({ await }); + print({ async, await }); + print({ await, async }); + + print({ async: async }); + print({ await: await }); + print({ async: async, await: await }); + print({ await: await, async: async }); + } + expect: { + function a(a) { console.log(a.async + " " + a.await); } + var n = "Async", c = "Await"; + + a({ async: n }); + a({ await: c }); + a({ async: n, await: c }); + a({ await: c, async: n }); + + a({ async: n }); + a({ await: c }); + a({ async: n, await: c }); + a({ await: c, async: n }); + } + expect_stdout: [ + "Async undefined", + "undefined Await", + "Async Await", + "Async Await", + "Async undefined", + "undefined Await", + "Async Await", + "Async Await", + ] + node_version: ">=4" +} + /* FIXME: add test when supported by parser async_arrow: { input: {