Skip to content

Component Argument Expression throws TypeError: Cannot read properties of null (reading 'range') #502

Closed
@TheOnlyRealKat

Description

@TheOnlyRealKat

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

  • I'm using eslint-plugin-svelte. (*.svelte file linting does not work with the parser alone. You should also use eslint-plugin-svelte with it.)
  • I'm sure the problem is a parser problem. (If you are not sure, search for the issue in eslint-plugin-svelte repo and open the issue in eslint-plugin-svelte repo if there is no solution.
  • 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.57.0

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

  • svelte-eslint-parser@0.34.0
  • eslint-plugin-svelte@2.35.1

What did you do?

Configuration
{
    "env": {
        "browser": true,
        "es2021": true
    },
    "extends": [
        "eslint:recommended",
        "plugin:svelte/base",
        "plugin:@typescript-eslint/recommended"
    ],
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "ecmaVersion": "latest",
        "sourceType": "module"
    },
    "overrides": [
        {
            "files": [
                "*.svelte"
            ],
            "parser": "svelte-eslint-parser",
            "parserOptions": {
                "parser": "@typescript-eslint/parser"
            }
        }
    ],
    "plugins": [
        "@typescript-eslint"
    ],
    "rules": {
        "indent": [
            "error",
            4,
            {
                "SwitchCase": 1
            }
        ],
        "linebreak-style": [
            "error",
            "unix"
        ],
        "quotes": [
            "error",
            "double"
        ],
        "semi": [
            "error",
            "always"
        ],
        "eol-last": [
            "error",
            "always"
        ]
    }
}
test.svelte
<script lang="ts">
    import Button from "$lib/Button.svelte";
    import { writable } from "svelte/store";

    interface store {
        map: Map<number, string>;
        number: number;
    }
    const test = new Map<number, string>([
        [1, "a"],
        [2, "b"],
        [3, "c"],
    ]);

    const store = writable<store>({
        map: test,
        number: 1,
    });
</script>

<div>
    {#if $store.map.size > 1}
        {#each $store.map as [index, tab]}
            <Button
                active={$store.number === index}>
                {index} {tab}
            </Button>
        {/each}
    {/if}
</div>

Button.svelte

<script lang="ts">
    export let active: boolean = false;
</script>

<button class:active={active}>
    <slot />
</button>

What did you expect to happen?

Nothing. Should work.

What actually happened?

TypeError: Cannot read properties of null (reading 'range')
Occurred while linting C:~snip~\src\test.svelte:1
Rule: "indent"

Link to GitHub Repo with Minimal Reproducible Example

https://github.com/TheOnlyRealKat/svelte-eslint-bug

Additional comments

It worked with 0.33, and breaks with 0.34.0-next.3 or newer
See reproduction repo branches.

If you remove
active={$store.number === index}
from the Button Component it works, so I guess it has something todo with that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions