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

<script type="module"> should support top-level-await #247

Closed
loynoir opened this issue Aug 27, 2023 · 1 comment
Closed

<script type="module"> should support top-level-await #247

loynoir opened this issue Aug 27, 2023 · 1 comment

Comments

@loynoir
Copy link

loynoir commented Aug 27, 2023

Description

Setup configuration

  • ESLint version: v8.48.0
  • eslint-plugin-html version: 7.1.0
  • NodeJS version: v20.5.1
  • Operating System name and version:
  • ESLint configuration (.eslintrc):
      {
        "files": [
          "*.html"
        ],
        "globals": {
          "console": "readonly",
          "Promise": "readonly"
        },
        "plugins": [
          "html"
        ],
        "parserOptions": {
          "ecmaVersion": "latest"
        },
        "extends": [
          "eslint:recommended"
        ]
      }

Optional: custom plugin for debugging

      Program(node) {
        console.log(node.sourceType)
  • Editor name and version:
  • Plugin name and version:

Aditional context

    <script>
      const a = 42
    </script>
    <script type="module">
      const b = await Promise.resolve(42)
    </script>

Actual

eslint log

  ...  error  'a' is assigned a value but never used   no-unused-vars
  ...  error  Parsing error: Unexpected token Promise

plugin log

  • With TLA
script

the second script tag not reach plugin

  • Without TLA
script
script

the second script tag reach plugin with wrong node.sourceType

Expected

eslint log

  ...  error  'a' is assigned a value but never used  no-unused-vars
  ...  error  'b' is assigned a value but never used  no-unused-vars

Plugin log

script
module
@BenoitZugmeyer
Copy link
Owner

For simplicity's sake, this plugin relies on the ESLint parserOption.sourceType configuration to consider inline scripts as "traditional" or "module" (see doc). It does not consider type="module" as "module" by default, and you can't have a mix of traditional and "module" inline scripts in a single HTML file.

This might change in the future, see #139

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