google / google/closure-compiler

Safari needs a workaround for unary await expressions without parens

Open
#3,505 3 comments 2 reactions 0 assignees View on GitHub
internal-issue-created triage-done
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

If you run `if (!await test()) { return true }` in Safari 10/11, it will throw you a parsing error, needing `await test()` to be wrapped in parentheses so the parser doesn't trip up. CC thinks the parens is unnecessary and strips it out though.

Here's a [replication link](https://closure-compiler.appspot.com/home#code%3D%252F%252F%2520%253D%253DClosureCompiler%253D%253D%250A%252F%252F%2520%2540output_file_name%2520default.js%250A%252F%252F%2520%2540compilation_level%2520ADVANCED_OPTIMIZATIONS%250A%252F%252F%2520%2540language_out%2520ECMASCRIPT_2017%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250A(async%2520()%2520%253D%253E%2520%257B%250A%2520%2520async%2520function%2520test2()%2520%257B%250A%2520%2520%2520%2520return%2520console.log('')%253B%250A%2520%2520%257D%250A%250A%2509if%2520(!(await%2520test()))%2520%257B%2520return%2520true%2520%257D%250A%257D)()%253B) to the CC UI.

This has been [reported in Webkit](https://bugs.webkit.org/show_bug.cgi?id=176685) fixed in later versions, documented and fixed in UglifyJS [here](https://github.com/mishoo/UglifyJS2/issues/2344) and [here](https://github.com/mishoo/UglifyJS2/issues/2308).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.