Open Bug 1772653 Opened 3 years ago Updated 3 years ago

ESLint doesn't allow top-level awaits in <script type=module> in html files

Categories

(Developer Infrastructure :: Lint and Formatting, defect, P3)

Tracking

(Not tracked)

People

(Reporter: saschanaz, Unassigned)

Details

> ./mach lint --outgoing --fix -l eslint
C:/Users/sasch/Documents/GitHub/gecko-dev/dom/workers/test/test_subworkers_suspended.html
  20:4  error  Parsing error: 'await' is only allowed within async functions and at the top levels of modules. (10:2)  (eslint)

✖ 1 problem (1 error, 0 warnings, 0 fixed)

Looks like some configuration issue as I can't reproduce this on a minimal configuration:

{
  "name": "test-eslint",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@babel/core": "^7.18.2",
    "@babel/eslint-parser": "^7.18.2",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-fetch-options": "^0.0.5",
    "eslint-plugin-html": "^6.2.0",
    "eslint-plugin-no-unsanitized": "^4.0.1",
    "eslint-plugin-prettier": "^4.0.0",
    "prettier": "^2.6.2"
  },
  "devDependencies": {
    "eslint": "^8.17.0"
  }
}
module.exports = {
  env: {
    browser: true,
    es2022: true,
  },
  parser: "@babel/eslint-parser",
  extends: "eslint:recommended",
  plugins: ["html"],
  parserOptions: {
    ecmaVersion: 2022
  },
};

Please can you provide the code that triggered this? As far as I can tell, what's in test_subworkers_suspended.html currently isn't a worker nor a module.

Flags: needinfo?(krosylight)

Ah yeah, try adding script=module on the file and it still says await is disallowed.

Flags: needinfo?(krosylight)

Ok, this is actually an issue with the eslint-plugin-html add-on. It is touched on in this issue, but basically it is relying on the ESLint configuration to determine the source type (module vs non-module), rather than the script tags.

I suspect the reason this works in your test case is that Babel's probably handling it, though I'm not quite sure.

We can probably fix eslint-plugin-html with a simpler solution than suggested in that issue, especially as that is more of a rewrite and has some issues of its own.

Severity: -- → N/A
Priority: -- → P3
Summary: Await statements inside <script type=module> is still disallowed → ESLint doesn't allow top-level awaits in <script type=module> in html files

The severity field is not set for this bug.
:andi, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(bpostelnicu)
Severity: N/A → S3
Flags: needinfo?(bpostelnicu)
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.