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

Enable Top Level Await #13178

Closed
mudgen opened this issue Apr 13, 2020 · 12 comments
Closed

Enable Top Level Await #13178

mudgen opened this issue Apr 13, 2020 · 12 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion auto closed The bot closed this issue experimental syntax This change is related to experimental syntax (stage 3 or below)

Comments

@mudgen
Copy link

mudgen commented Apr 13, 2020

Please describe what the rule should do:
Provide a setting or rule that enables top level await in code without an error or warning.

V8 now supports top level await: https://v8.dev/features/top-level-await

As a standard top level await is in stage 3: https://github.com/tc39/proposal-top-level-await

I am currently using deno which has top level await, so this new setting/rule would be very useful for me.

@mudgen mudgen added feature This change adds a new feature to ESLint rule Relates to ESLint's core rules triage An ESLint team member will look at this issue soon labels Apr 13, 2020
@mdjermanovic mdjermanovic added experimental syntax This change is related to experimental syntax (stage 3 or below) and removed feature This change adds a new feature to ESLint rule Relates to ESLint's core rules triage An ESLint team member will look at this issue soon labels Apr 13, 2020
@mdjermanovic
Copy link
Member

Hi @mudgen, thanks for the issue!

I assume you're getting parsing errors. ESLint's default parser will support this syntax if and when it reaches stage 4, per our policy about experimental features.

In the meantime, you can use babel-eslint parser.

@nzakas nzakas changed the title Rule to Enable Top Level Await Enable Top Level Await Apr 14, 2020
@eslint-deprecated eslint-deprecated bot added the auto closed The bot closed this issue label May 16, 2020
@eslint-deprecated
Copy link

Unfortunately, it looks like there wasn't enough interest from the team
or community to implement this change. While we wish we'd be able to
accommodate everyone's requests, we do need to prioritize. We've found
that issues failing to reach accepted status after 21 days tend to
never be accepted, and as such, we close those issues.
This doesn't mean the idea isn't interesting or useful, just that it's
not something the team can commit to.

Thanks for contributing to ESLint and we appreciate your understanding.

@mjsalinger
Copy link

@mdjermanovic - We don't use babel, but node.js just added support for top-level await. What is the recommended course if we want to use this feature of node without using Babel?

@anikethsaha
Copy link
Member

anikethsaha commented May 26, 2020

top level await is still in stage 3.

eslint supports stage 4 proposal.

@mdjermanovic
Copy link
Member

@mjsalinger our default parser supports only stage 4 proposals. You could use babel-eslint as a parser for eslint. without using Babel to transpile the code.

@billinghamj
Copy link

Although it is still in stage 3, it has now shipped unflagged in Node and other common JS environments, so might be worth reconsidering

@boggddan
Copy link

@mdjermanovic - We don't use babel, but node.js just added support for top-level await. What is the recommended course if we want to use this feature of node without using Babel?

Hi, Could help me?
I install "@babel/eslint-parser" and "@babel/plugin-syntax-top-level-await", but VS Code write error: Parsing error: Cannot use keyword 'await' outside an async function

2020-09-21_20-46

package.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "type": "module",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "fastify": "^3.4.1"
  },
  "devDependencies": {
    "@babel/core": "^7.11.6",
    "@babel/eslint-parser": "^7.11.5",
    "@babel/plugin-syntax-top-level-await": "^7.10.4",
    "eslint": "^7.9.0",
    "eslint-config-airbnb-base": "^14.2.0",
    "eslint-plugin-import": "^2.22.0",
    "eslint-plugin-node": "^11.1.0"
  }
}

.eslintrc.cjs

module.exports = {
  parserOptions: {
    ecmaVersion: 2021,
    sourceType: 'module',
    parser: "@babel/eslint-parser"
  }
};

babel.config.json

{
  "plugins": ["@babel/plugin-syntax-top-level-await"]
}

Thank's

@mdjermanovic
Copy link
Member

Hi @boggddan!

parser should be at the top level, please try with this .eslintrc.cjs:

module.exports = {
  parser: "@babel/eslint-parser",
  parserOptions: {
    ecmaVersion: 2021,
    sourceType: 'module'
  }
};

@iwaduarte
Copy link

+1 for enabling top level await even if it is not stage 4. Not everything is black and white. We should not be too constrained to rules.

Also another option solution without using babel-parser would also be welcoming, like disabling this specific parse error ?

@pubmikeb
Copy link

pubmikeb commented Nov 12, 2020

The Top Level Await is now supported by the stable (RTM) version of Node.js (15.x) without any flags even at 3rd stage, so it would be great to adopt this rule without waiting another 7 months until this feature will be accepted by TC39.

Alternative solutions could be:

  • to add annotation to silence this error
  • to move Top Level Await from error to warning with the further explanation about the ESLint TC39 stages support policy
  • do not raise this error if the JavaScript version in eslintrc.json is targeted to ES.Next

@ljharb
Copy link
Contributor

ljharb commented Nov 12, 2020

(what is RTM?)

@pubmikeb
Copy link

(what is RTM?)

https://en.wikipedia.org/wiki/Software_release_life_cycle#RTM

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Nov 13, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion auto closed The bot closed this issue experimental syntax This change is related to experimental syntax (stage 3 or below)
Projects
None yet
Development

No branches or pull requests

9 participants