Error for incorrect usage of await keyword is not helpful
Reported by
kdzwinel@gmail.com,
Nov 12 2016
|
|||||||
Issue description
UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36
Steps to reproduce the problem:
Run the scripts below in the DevTools console:
#1
async function test(){ return Promise.resolve(); }
await test();
#2
async function test(){ return Promise.resolve(); }
(function() { await test })()
What is the expected behavior?
There should be an error explaining that `await` cannot be used in the top-level scope (#1) and that the wrapper function needs an 'async' keyword (#2)
What went wrong?
Currently, an error being displayed, for both cases, is "Uncaught SyntaxError: Unexpected identifier".
Did this work before? No
Chrome version: 54.0.2840.71 Channel: canary
OS Version: OS X 10.11.6
Flash Version:
,
Nov 14 2016
Tested this issue in Mac 10.11.16 by using chrome reported version #54.0.2840.71 and latest canary #56.0.2919.0.
Steps followed to reproduce the issue are as follows:
-----------
1. Ran the below scripts in the DevTools console:
a. async function test(){ return Promise.resolve(); }
await test();
b. async function test(){ return Promise.resolve(); }
(function() { await test })()
2. Observed error in the reported version as "Uncaught SyntaxError: Unexpected token". The error differed in different chrome versions i.e from M50 till M45.
Attaching screenshots of different chrome versions for reference.
kdzwinel@ - Could you please verify the screenshots of different chrome versions and please let us know the expected result and the actual result.
Thanks...!!
,
Nov 18 2016
Older Chrome versions (54, 50, 45) do not support async/await by default. This bug is valid from version 55 - https://www.chromestatus.com/feature/5643236399906816 . Screenshot for version 56 looks OK. Actual result is showing "Uncaught SyntaxError: Unexpected identifier" error, expected result is showing "`await` cannot be used in the top-level scope" or "`await` cannot be used in a non-async function". Mozilla is working on this bug here: https://bugzilla.mozilla.org/show_bug.cgi?id=1317153
,
Nov 24 2016
Not sure if this is something we want to change?
,
Nov 25 2016
,
Nov 25 2016
FYI Firefox fixed that and will be showing "await is only valid in async functions" message instead. https://bugzilla.mozilla.org/show_bug.cgi?id=1317153
,
Nov 25 2016
I guess we could report a special error if we see that the last parsed token was `await` in the ReportUnidentifiedToken thing, but it seems hard to get it emitting a helpful error all the time.
,
Nov 25 2016
This seems like a good idea to help people learn to use the feature, but I don't think it is essential to improve the message right this second. Not a ship blocker for async/await, but nice to have. Leaving it open as unassigned if anyone wants to work on it.
,
May 25 2017
,
Aug 8 2017
Fixed in 62a7c080d5348bf35a9e1dd3a84449bc51d154b1 |
|||||||
►
Sign in to add a comment |
|||||||
Comment 1 by paulir...@chromium.org
, Nov 13 2016