Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow await in global (module) scope #3741

Closed
NiklasGollenstede opened this issue May 30, 2021 · 4 comments · Fixed by #3984
Closed

Allow await in global (module) scope #3741

NiklasGollenstede opened this issue May 30, 2021 · 4 comments · Fixed by #3984
Assignees
Labels
priority:p3 state:verified_fixed type:syntax Issues related to JavaScript syntax (support).
Milestone

Comments

@NiklasGollenstede
Copy link

Describe the problem and steps to reproduce it:

Putting an await in a global module scope causes a syntax error, failing the validation (and thus submission on AMO).
proposal-top-level-await was actually just updated to Stage 4, and works in Firefox 89 (which is to be released any day now) and Chrome.
So as far as mainline Firefox is concerned, this is valid.

I guess one could use this as a test file background.js:

import foo from 'foo';
await null;
export const bar = 42;

What happened?

Critical validation error:

JavaScript syntax error
(Parsing as module error: Cannot use keyword 'await' outside an async function at ...)
(Parsing as script error: 'import' and 'export' may appear only with 'sourceType: module' at ...)

What did you expect to happen?

The JS file should be parsable.

Anything else we should know?

I had actually been holding back on porting my AMD modules to ES modules precisely because of the lack of an await before exporting. Now I ported my code, and can't upload it.

@Rob--W
Copy link
Member

Rob--W commented May 30, 2021

We're relying on eslint to parse the code. Since top-level-await has been promoted to stage 4, I expect eslint to follow shortly:

@NiklasGollenstede
Copy link
Author

Well, that was quick, I assume you had this on your radar already 👍

And true, to use "fancy" syntax with eslint, you have to use a different parser, like babel or tsc.
We'll just have to wait ...

@Rob--W
Copy link
Member

Rob--W commented Jun 10, 2021

Depends on eslint/eslint#14632

@willdurand willdurand self-assigned this Oct 23, 2021
@willdurand willdurand added priority:p3 type:syntax Issues related to JavaScript syntax (support). labels Oct 23, 2021
@willdurand willdurand mentioned this issue Oct 23, 2021
3 tasks
@willdurand willdurand added this to the 2021.11.11 milestone Nov 3, 2021
@ioanarusiczki
Copy link

@willdurand
I tested with the addon attached:
I'm seeing the JavaScript syntax error present on AMO stage.

stage

On AMO dev or linter 4.0.0 I don't see any errors being present:

dev

linter 4 0 0

background.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:p3 state:verified_fixed type:syntax Issues related to JavaScript syntax (support).
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants