Skip to content

#await nested inside an if results in "is not defined" errors #325

Closed
sveltejs/svelte-eslint-parser
#259
@binarious

Description

@binarious

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.

What version of ESLint are you using?

8.29.0

What version of eslint-plugin-svelte are you using?

2.14.1

What did you do?

Configuration
module.exports = {
  parser: '@typescript-eslint/parser',
  extends: [
    'eslint:recommended',
    'plugin:svelte/recommended',
    'plugin:@typescript-eslint/eslint-recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:@typescript-eslint/recommended-requiring-type-checking'
  ],
  parserOptions: {
    ecmaVersion: 2020,
    sourceType: 'module',
    tsconfigRootDir: __dirname,
    project: ['./tsconfig.json'],
    extraFileExtensions: ['.svelte', '.cjs']
  },
  env: {
    es6: true,
    browser: true
  },
  overrides: [
    {
      files: ['*.svelte'],
      parser: 'svelte-eslint-parser',
      parserOptions: {
        parser: '@typescript-eslint/parser',
      },
    }
  ],
  settings: {
    'svelte3/typescript': require('typescript'),
    // ignore style tags in Svelte because of Tailwind CSS
    // See https://github.com/sveltejs/eslint-plugin-svelte3/issues/70
    'svelte3/ignore-styles': () => true
  },
  plugins: ['@typescript-eslint'],
  ignorePatterns: ['node_modules', '.eslintrc.cjs'],
  rules: {
    'indent': ['error', 2],
    'linebreak-style': ['error', 'unix'],
    'quotes': ['error', 'single'],
    'semi': ['error', 'always'],
    'svelte/indent': [
      'error',
      {
        'indent': 2,
        'ignoredNodes': [],
        'switchCase': 1,
        'alignAttributesVertically': false
      },
    ],
    'svelte/button-has-type': 'error',
    'svelte/no-at-debug-tags': 'error',
    'svelte/no-unused-svelte-ignore': 'error',
    '@typescript-eslint/no-unused-vars': ['warn', { 'argsIgnorePattern': "^_" }]
  }
}

<script lang="ts">
  export let message: string|undefined;
  export const formatMessage = async (message: string): Promise<string> => {
    return new Promise(resolve => {
      resolve(message);
    });
  };
</script>

{#if !message}
  No message
{:else}
  {#await formatMessage(message)}
    Loading...
  {:then result}
    {result}
  {/await}
{/if}

What did you expect to happen?

No linting errors should be raised.

What actually happened?

  16:3  error  '$_AwaitThenValue1' is not defined          no-undef
  18:5  error  '$_formatMessage_message_2' is not defined  no-undef

Link to GitHub Repo with Minimal Reproducible Example

https://github.com/binarious/eslint-plugin-svelte-reproduction

https://stackblitz.com/edit/node-s5hzd6?file=src/Reprod.svelte

Additional comments

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions