sveltejs / eslint-plugin-svelte

ESLint plugin for Svelte using AST
https://sveltejs.github.io/eslint-plugin-svelte/
MIT License
282 stars 30 forks source link

"Unexpected token ." when using optional chaining #611

Closed hopperelec closed 8 months ago

hopperelec commented 8 months ago

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

What version of ESLint are you using?

8.53.0

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

What did you do?

package.json

{
  "scripts": {
    "lint": "npx eslint ."
  },
  "devDependencies": {
    "eslint": "^8.53.0",
    "eslint-plugin-svelte": "^2.35.0",
    "svelte-eslint-parser": "^0.33.1"
  }
}

.eslintrc.js

module.exports = {
    extends: [
        'plugin:svelte/recommended'
    ],
};

test.svelte

<script>
  const exampleObject = {
    exampleOptionaKey: "example optional value"
  };
  exampleObject?.exampleOptionaKey;
</script>

What did you expect to happen?

No error, because that is valid JS syntax

What actually happened?

...\src\test.svelte
5:19 error Parsing error: Unexpected token .

Link to GitHub Repo with Minimal Reproducible Example

https://github.com/HopperElec/svelte-eslint-parser-mre

Additional comments

No response

JounQin commented 8 months ago

You need to set a correct ecmaVersion for ESLint. Maybe we can add ecmaVersion: 'latest' into the base config? cc @ota-meshi

ota-meshi commented 8 months ago

This plugin still supports ESLint v7, so we can't use "latest". The next major version will drop support for old ESLint and we'll be able to use it.

hopperelec commented 8 months ago

Ah, thank you! For some reason I thought that parser-related settings in the ESLint root only applied to the the built-in parser, hence me thinking it was an issue with this plugin. I think if I had a bit more experience with ESLint I probably would have recognized this, so I don't think this really needs "fixed" by the plugin.