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

allowAwaitOutsideFunction does not default to true when ecmaVersion >= 2022 #1214

Closed
willdady opened this issue May 6, 2023 · 2 comments
Closed

Comments

@willdady
Copy link

willdady commented May 6, 2023

The README says allowAwaitOutsideFunction defaults to true for ecmaVersion >= 2022:

allowAwaitOutsideFunction: If false, await expressions can only appear inside async functions. Defaults to true for ecmaVersion 2022 and later, false for lower versions. Setting this option to true allows to have top-level await expressions. They are still not allowed in non-async functions, though.

However the following code fails with SyntaxError: Unexpected token (2:16)?

import * as acorn from 'acorn';

const code = `
const x = await foo();
`;

try {
  acorn.parse(code, {
    ecmaVersion: 2022,
    // allowAwaitOutsideFunction: true
  });
} catch (error) {
  console.error(error);
}

Uncommenting allowAwaitOutsideFunction: true resolves the issue though this seems to conflict with what the aforementioned docs are saying.

@marijnh
Copy link
Member

marijnh commented May 6, 2023

It is only implicitly enabled for sourceType: "module". See #1048

@willdady
Copy link
Author

willdady commented May 6, 2023

Good to know. Perhaps the documentation mentioned above could make that more obvious.

@marijnh marijnh closed this as completed in 96c721d May 6, 2023
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

2 participants