From cefd17a17d2e0318a4c982f5958f21307024bc95 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Mon, 2 Dec 2024 09:13:37 +0900 Subject: [PATCH] feat!: change the parser to an ESM-only package (#599) --- .changeset/quick-beers-reflect.md | 5 + README.md | 160 +++----------------- benchmark/index.ts | 4 +- explorer-v2/build-system/shim/module.js | 12 +- package.json | 12 +- src/ast/base.ts | 2 +- src/ast/common.ts | 2 +- src/ast/html.ts | 4 +- src/ast/index.ts | 10 +- src/ast/script.ts | 2 +- src/context/fix-locations.ts | 6 +- src/context/index.ts | 16 +- src/context/let-directive-collection.ts | 4 +- src/context/script-let.ts | 16 +- src/errors.ts | 2 +- src/index.ts | 26 +--- src/main.ts | 24 +++ src/parser/analyze-scope.ts | 12 +- src/parser/compat.ts | 4 +- src/parser/converts/attr.ts | 24 +-- src/parser/converts/block.ts | 14 +- src/parser/converts/const.ts | 10 +- src/parser/converts/element.ts | 32 ++-- src/parser/converts/index.ts | 2 +- src/parser/converts/mustache.ts | 10 +- src/parser/converts/render.ts | 8 +- src/parser/converts/root.ts | 24 +-- src/parser/converts/text.ts | 6 +- src/parser/espree.ts | 36 ++--- src/parser/globals.ts | 2 +- src/parser/html.ts | 4 +- src/parser/index.ts | 43 +++--- src/parser/parser-object.ts | 2 +- src/parser/parser-options.ts | 4 +- src/parser/resolve-parser.ts | 9 +- src/parser/script.ts | 12 +- src/parser/style-context.ts | 4 +- src/parser/svelte-parse-context.ts | 10 +- src/parser/template.ts | 16 +- src/parser/typescript/analyze/index.ts | 33 ++-- src/parser/typescript/context.ts | 6 +- src/parser/typescript/index.ts | 19 ++- src/parser/typescript/restore.ts | 9 +- src/parser/typescript/set-parent.ts | 6 +- src/scope/index.ts | 7 +- src/svelte-config/index.ts | 2 +- src/svelte-config/parser.ts | 8 +- src/traverse.ts | 4 +- src/visitor-keys.ts | 2 +- tests/src/integrations.ts | 13 +- tests/src/meta.ts | 7 +- tests/src/parser/error.ts | 10 +- tests/src/parser/eslint.ts | 12 +- tests/src/parser/parser.ts | 17 ++- tests/src/parser/style-context.ts | 7 +- tests/src/parser/style-location-coverter.ts | 9 +- tests/src/parser/test-utils.ts | 29 ++-- tests/src/parser/typescript/index.ts | 16 +- tests/src/svelte-config/parser.ts | 2 +- tools/update-fixtures.ts | 15 +- tools/update-meta.ts | 8 +- tsconfig.json | 4 +- 62 files changed, 371 insertions(+), 469 deletions(-) create mode 100644 .changeset/quick-beers-reflect.md create mode 100644 src/main.ts diff --git a/.changeset/quick-beers-reflect.md b/.changeset/quick-beers-reflect.md new file mode 100644 index 00000000..8367d818 --- /dev/null +++ b/.changeset/quick-beers-reflect.md @@ -0,0 +1,5 @@ +--- +"svelte-eslint-parser": major +--- + +feat!: change the parser to an ESM-only package diff --git a/README.md b/README.md index f9a55fdd..494035db 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,6 @@ You can check it on [Online DEMO](https://sveltejs.github.io/svelte-eslint-parse > Please refer to the README for the version you are using.\ > For example, -**_Note that this parser has experimental support for Svelte v5, but may break with new versions of Svelte v5._** - [![NPM license](https://img.shields.io/npm/l/svelte-eslint-parser.svg)](https://www.npmjs.com/package/svelte-eslint-parser) [![NPM version](https://img.shields.io/npm/v/svelte-eslint-parser.svg)](https://www.npmjs.com/package/svelte-eslint-parser) [![NPM downloads](https://img.shields.io/badge/dynamic/json.svg?label=downloads&colorB=green&suffix=/day&query=$.downloads&uri=https://api.npmjs.org//downloads/point/last-day/svelte-eslint-parser&maxAge=3600)](http://www.npmtrends.com/svelte-eslint-parser) @@ -41,12 +39,6 @@ It provides many unique check rules by using the template AST. ESLint plugin for internationalization (i18n) with Svelte. It provides rules to help internationalization your application created with Svelte. -## ❗ Attention - -The [svelte-eslint-parser] can not be used with the [eslint-plugin-svelte3]. - -[svelte-eslint-parser]: https://github.com/sveltejs/svelte-eslint-parser - ## 💿 Installation ```bash @@ -74,20 +66,6 @@ export default [ ]; ``` -### ESLint Config (`.eslintrc.*`) - -```json -{ - "extends": "eslint:recommended", - "overrides": [ - { - "files": ["*.svelte"], - "parser": "svelte-eslint-parser" - } - ] -} -``` - ### CLI ```console @@ -101,18 +79,26 @@ $ eslint src --ext .svelte [`parserOptions`] has the same properties as what [espree](https://github.com/eslint/espree#usage), the default parser of ESLint, is supporting. For example: -```json -{ - "parserOptions": { - "sourceType": "module", - "ecmaVersion": 2021, - "ecmaFeatures": { - "globalReturn": false, - "impliedStrict": false, - "jsx": false - } - } -} +```js +import svelteParser from "svelte-eslint-parser"; +export default [ + // ... + { + files: ["**/*.svelte", "*.svelte"], + languageOptions: { + parser: svelteParser, + parserOptions: { + sourceType: "module", + ecmaVersion: 2021, + ecmaFeatures: { + globalReturn: false, + impliedStrict: false, + jsx: false, + }, + }, + }, + }, +]; ``` [`parserOptions`]: https://eslint.org/docs/latest/use/configure/parser#configure-parser-options @@ -139,17 +125,6 @@ export default [ ]; ``` -For example in `.eslintrc.*`: - -```json -{ - "parser": "svelte-eslint-parser", - "parserOptions": { - "parser": "@typescript-eslint/parser" - } -} -``` - If you are using the `"@typescript-eslint/parser"`, and if you want to use TypeScript in `