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

Error trying to use top-level await? #186

Closed
FredKSchott opened this issue Mar 24, 2021 · 19 comments
Closed

Error trying to use top-level await? #186

FredKSchott opened this issue Mar 24, 2021 · 19 comments

Comments

@FredKSchott
Copy link

>  require('meriyah').parseModule('const foo = (await bar)', {next: true})
Uncaught: [ParseError [SyntaxError]: [1:18]: 'Await' may not be used as an identifier in this context] {
  index: 18,
  line: 1,
  column: 18,
  description: "[1:18]: 'Await' may not be used as an identifier in this context",
  loc: { line: 1, column: 18 }
}

I found #29 but it looks like that issue may have been closed without implementation.

Top-level await is now stage 3, and supported in Node.js v14+.

@3cp
Copy link
Member

3cp commented Mar 27, 2021

@KFlash to support this, is it just removing Context.InAwaitContext from the code base?

@3cp
Copy link
Member

3cp commented Mar 27, 2021

NVM, it seems more complex that that.

@KFlash
Copy link
Contributor

KFlash commented Mar 27, 2021

hmm long time since I was focused on that kind of simple code :)

You can't just remove that context, then tons of async tests will fail.

Validate if you come directly from TopLevel when parsing out await is one option. If not in a func body, but on top level, parse it out. Follow the specs.

But Meriyah is all about no-lookahead, so what if you do it simple and just add a 'await' keyword in 'StatementListItem'. It will only be invoked if on TopLevel. And deal with it from there?

@3cp
Copy link
Member

3cp commented Apr 9, 2021

I will study the spec when I got more time.

@3cp
Copy link
Member

3cp commented Apr 11, 2021

https://tc39.es/proposal-top-level-await/#sec-modules

Adding it to StatementListItem seems not enough, there is also top-level AwaitExpression and few others.

export const output = process((await dynamic).default, await data);

@KFlash
Copy link
Contributor

KFlash commented Apr 11, 2021

PrimaryExpression?

@3cp
Copy link
Member

3cp commented Apr 11, 2021

I don't understand that spec notation well enough to understand what's changed in the above proposed spec change.

@KFlash
Copy link
Contributor

KFlash commented Apr 12, 2021

then open an issue and mark it as "Good first issue" 👍

@KFlash
Copy link
Contributor

KFlash commented May 26, 2021

Any plans to implement this?

@3cp
Copy link
Member

3cp commented May 27, 2021

No. I have not spent any time on this.

@aladdin-add
Copy link
Collaborator

TLA has been stage-4 now. refs: tc39/proposals@99fa42a

@KFlash
Copy link
Contributor

KFlash commented May 27, 2021

@aladdin-add Stage 4? So it needs to be implemented in Kataw too?

@aladdin-add
Copy link
Collaborator

yes!

@aladdin-add
Copy link
Collaborator

and class fields. refs: tc39/ecma262#1668

@FredKSchott
Copy link
Author

Any eta on when this may get looked ? It's completely fine if the answer is "not for a while", we're just looking for a fix in Snowpack and may move back to acorn (at least for now) if that's the case FredKSchott/snowpack#2987

@3cp
Copy link
Member

3cp commented Jun 26, 2021

At least I am not working on this, not much spare time. @KFlash ?

@KFlash
Copy link
Contributor

KFlash commented Jun 26, 2021

Everyone can do a PR. I'm busy with Kataw.

@FredKSchott Acorn's implementation has some flaws / bugs. They recently fixed one bug.

@KFlash
Copy link
Contributor

KFlash commented Jun 26, 2021

It's super easy to get this implemented. Swap this line with this code if (context & (Context.Module | Context.InAwaitContext)) { and it's implemented.

Need ofc. fix the non failing. See Kataw on how I solved that

@3cp 3cp closed this as completed in 7b2a5bd Jul 11, 2021
@3cp
Copy link
Member

3cp commented Jul 12, 2021

v4.2.0 is released with this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants