Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More โ†’
Socket
Sign inDemoInstall
Socket

svelte-eslint-parser

Package Overview
Dependencies
Maintainers
4
Versions
113
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-eslint-parser - npm Package Compare versions

Comparing version 0.35.0 to 0.36.0

2

lib/meta.d.ts
export declare const name = "svelte-eslint-parser";
export declare const version = "0.35.0";
export declare const version = "0.36.0";

@@ -8,2 +8,2 @@ "use strict";

exports.name = "svelte-eslint-parser";
exports.version = "0.35.0";
exports.version = "0.36.0";

@@ -13,3 +13,3 @@ /// <reference types="svelte" />

export declare function getModuleFromRoot(svelteAst: Compiler.Root | SvAST.AstLegacy): SvAST.Script | Compiler.Script | null | undefined;
export declare function getOptionsFromRoot(svelteAst: Compiler.Root | SvAST.AstLegacy, code: string): Compiler.SvelteOptionsRaw | null;
export declare function getOptionsFromRoot(svelteAst: Compiler.Root | SvAST.AstLegacy): Compiler.SvelteOptionsRaw | null;
export declare function getChildren(fragment: Required<HasChildren> | {

@@ -16,0 +16,0 @@ nodes: (Child | SvAST.TemplateNode)[];

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDeclaratorFromConstTag = exports.getCatchFromAwaitBlock = exports.getThenFromAwaitBlock = exports.getPendingFromAwaitBlock = exports.getFallbackFromEachBlock = exports.getBodyFromEachBlock = exports.getAlternateFromIfBlock = exports.getConsequentFromIfBlock = exports.getTestFromIfBlock = exports.getModifiers = exports.getFragment = exports.trimChildren = exports.getChildren = exports.getOptionsFromRoot = exports.getModuleFromRoot = exports.getInstanceFromRoot = exports.getFragmentFromRoot = void 0;
const html_1 = require("./html");
// Root

@@ -19,11 +18,18 @@ function getFragmentFromRoot(svelteAst) {

exports.getModuleFromRoot = getModuleFromRoot;
function getOptionsFromRoot(svelteAst, code) {
function getOptionsFromRoot(svelteAst) {
const root = svelteAst;
if (root.options) {
if (root.options.__raw__) {
return root.options.__raw__;
}
// If there is no `__raw__` property in the `SvelteOptions` node,
// we will parse `<svelte:options>` ourselves.
return parseSvelteOptions(root.options, code);
return {
type: "SvelteOptions",
name: "svelte:options",
attributes: root.options.attributes,
fragment: {
type: "Fragment",
nodes: [],
transparent: true,
},
start: root.options.start,
end: root.options.end,
parent: null,
};
}

@@ -166,31 +172,1 @@ return null;

exports.getDeclaratorFromConstTag = getDeclaratorFromConstTag;
function parseSvelteOptions(options, code) {
const { start, end } = options;
const nameEndName = start + "<svelte:options".length;
const { attributes, index: tagEndIndex } = (0, html_1.parseAttributes)(code, nameEndName + 1);
const fragment = {
type: "Fragment",
nodes: [],
transparent: true,
};
if (code.startsWith(">", tagEndIndex)) {
const childEndIndex = code.indexOf("</svelte:options", tagEndIndex);
fragment.nodes.push({
type: "Text",
data: code.slice(tagEndIndex + 1, childEndIndex),
start: tagEndIndex + 1,
end: childEndIndex,
raw: code.slice(tagEndIndex + 1, childEndIndex),
parent: fragment,
});
}
return {
type: "SvelteOptions",
name: "svelte:options",
attributes,
fragment,
start,
end,
parent: null,
};
}

@@ -21,3 +21,3 @@ "use strict";

let children = (0, compat_1.getChildren)(fragment);
const options = (0, compat_1.getOptionsFromRoot)(svelteAst, ctx.code);
const options = (0, compat_1.getOptionsFromRoot)(svelteAst);
if (options) {

@@ -24,0 +24,0 @@ children = [...children];

@@ -1,3 +0,3 @@

export declare const globalsForRunes: readonly ["$state", "$derived", "$effect", "$props", "$bindable", "$inspect"];
export declare const globals: readonly ["$$slots", "$$props", "$$restProps"] | ("$$slots" | "$$props" | "$$restProps" | "$state" | "$derived" | "$effect" | "$props" | "$bindable" | "$inspect")[];
export declare const globalsForSvelteScript: never[] | readonly ["$state", "$derived", "$effect", "$props", "$bindable", "$inspect"];
export declare const globalsForRunes: readonly ["$state", "$derived", "$effect", "$props", "$bindable", "$inspect", "$host"];
export declare const globals: readonly ["$$slots", "$$props", "$$restProps"] | ("$$slots" | "$$props" | "$$restProps" | "$state" | "$derived" | "$effect" | "$props" | "$bindable" | "$inspect" | "$host")[];
export declare const globalsForSvelteScript: never[] | readonly ["$state", "$derived", "$effect", "$props", "$bindable", "$inspect", "$host"];

@@ -13,2 +13,3 @@ "use strict";

"$inspect",
"$host",
];

@@ -15,0 +16,0 @@ const globalsForSvelte5 = [...globalsForSvelte4, ...exports.globalsForRunes];

@@ -13,3 +13,4 @@ "use strict";

try {
const svelteAst = (0, compiler_1.parse)(code, Object.assign({ filename: parserOptions.filePath }, (svelte_version_1.svelteVersion.gte(5) ? { modern: true } : {})));
const options = Object.assign({ filename: parserOptions.filePath }, (svelte_version_1.svelteVersion.gte(5) ? { modern: true } : {}));
const svelteAst = (0, compiler_1.parse)(code, options);
const ast = (0, index_1.convertSvelteRoot)(svelteAst, ctx);

@@ -16,0 +17,0 @@ return {

@@ -166,2 +166,3 @@ "use strict";

case "$inspect":
case "$host":
// Processed by `analyzeRuneVariables`.

@@ -209,3 +210,3 @@ break;

switch (globalName) {
// See https://github.com/sveltejs/svelte/blob/dfc55c18f010f620b966e13eb0ad1f9791b5798f/packages/svelte/types/index.d.ts#L2492
// See https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2585
case "$state": {

@@ -220,5 +221,8 @@ appendDeclareFunctionVirtualScripts(globalName, [

]);
appendDeclareNamespaceVirtualScripts(globalName, [
"export function snapshot<T>(state: T): T;",
]);
break;
}
// See https://github.com/sveltejs/svelte/blob/dfc55c18f010f620b966e13eb0ad1f9791b5798f/packages/svelte/types/index.d.ts#L2535
// See https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2648
case "$derived": {

@@ -233,3 +237,3 @@ appendDeclareFunctionVirtualScripts(globalName, [

}
// See https://github.com/sveltejs/svelte/blob/dfc55c18f010f620b966e13eb0ad1f9791b5798f/packages/svelte/types/index.d.ts#L2574
// See https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2687
case "$effect": {

@@ -246,3 +250,3 @@ appendDeclareFunctionVirtualScripts(globalName, [

}
// See https://github.com/sveltejs/svelte/blob/dfc55c18f010f620b966e13eb0ad1f9791b5798f/packages/svelte/types/index.d.ts#L2655
// See https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2768
case "$props": {

@@ -252,3 +256,3 @@ appendDeclareFunctionVirtualScripts(globalName, ["(): any"]);

}
// See https://github.com/sveltejs/svelte/blob/dfc55c18f010f620b966e13eb0ad1f9791b5798f/packages/svelte/types/index.d.ts#L2666
// See https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2779
case "$bindable": {

@@ -258,3 +262,3 @@ appendDeclareFunctionVirtualScripts(globalName, ["<T>(t?: T): T"]);

}
// See https://github.com/sveltejs/svelte/blob/dfc55c18f010f620b966e13eb0ad1f9791b5798f/packages/svelte/types/index.d.ts#L2686
// See https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2799
case "$inspect": {

@@ -266,2 +270,9 @@ appendDeclareFunctionVirtualScripts(globalName, [

}
// See https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2822
case "$host": {
appendDeclareFunctionVirtualScripts(globalName, [
`<El extends HTMLElement = HTMLElement>(): El`,
]);
break;
}
default: {

@@ -268,0 +279,0 @@ const _ = globalName;

{
"name": "svelte-eslint-parser",
"version": "0.35.0",
"version": "0.36.0",
"description": "Svelte parser for ESLint",

@@ -29,3 +29,3 @@ "repository": "git+https://github.com/sveltejs/svelte-eslint-parser.git",

"peerDependencies": {
"svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.112"
"svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.115"
},

@@ -50,4 +50,4 @@ "peerDependenciesMeta": {

"@types/benchmark": "^2.1.5",
"@types/chai": "^4.3.14",
"@types/eslint": "^8.56.7",
"@types/chai": "^4.3.16",
"@types/eslint": "^8.56.10",
"@types/eslint-scope": "^3.7.7",

@@ -57,11 +57,11 @@ "@types/eslint-visitor-keys": "^3.3.0",

"@types/mocha": "^10.0.6",
"@types/node": "^20.12.5",
"@types/node": "^20.12.11",
"@types/semver": "^7.5.8",
"@typescript-eslint/eslint-plugin": "^7.5.0",
"@typescript-eslint/parser": "~7.6.0",
"@typescript-eslint/types": "~7.6.0",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "~7.8.0",
"@typescript-eslint/types": "~7.8.0",
"benchmark": "^2.1.4",
"chai": "^4.4.1",
"env-cmd": "^10.1.0",
"esbuild": "^0.20.2",
"esbuild": "^0.21.0",
"esbuild-register": "^3.5.0",

@@ -72,12 +72,12 @@ "eslint": "^8.57.0",

"eslint-plugin-json-schema-validator": "^5.1.0",
"eslint-plugin-jsonc": "^2.15.0",
"eslint-plugin-n": "^17.0.0",
"eslint-plugin-node-dependencies": "^0.11.2",
"eslint-plugin-jsonc": "^2.15.1",
"eslint-plugin-n": "^17.5.1",
"eslint-plugin-node-dependencies": "^0.12.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-regexp": "^2.4.0",
"eslint-plugin-svelte": "^2.35.1",
"eslint-plugin-regexp": "^2.5.0",
"eslint-plugin-svelte": "^2.38.0",
"eslint-plugin-yml": "^1.14.0",
"estree-walker": "^3.0.3",
"locate-character": "^3.0.0",
"magic-string": "^0.30.9",
"magic-string": "^0.30.10",
"mocha": "^10.4.0",

@@ -88,8 +88,8 @@ "mocha-chai-jest-snapshot": "^1.1.4",

"prettier-plugin-pkg": "^0.18.1",
"prettier-plugin-svelte": "^3.2.2",
"prettier-plugin-svelte": "^3.2.3",
"rimraf": "^5.0.5",
"semver": "^7.6.0",
"svelte": "^5.0.0-next.112",
"svelte2tsx": "^0.7.6",
"typescript": "~5.4.4",
"semver": "^7.6.1",
"svelte": "^5.0.0-next.125",
"svelte2tsx": "^0.7.8",
"typescript": "~5.4.5",
"typescript-eslint-parser-for-extra-files": "^0.6.0"

@@ -96,0 +96,0 @@ },

@@ -6,3 +6,3 @@ # svelte-eslint-parser

***Note that this parser has experimental support for Svelte v5, but may break with new versions of Svelte v5.***
**_Note that this parser has experimental support for Svelte v5, but may break with new versions of Svelte v5._**

@@ -54,17 +54,37 @@ [![NPM license](https://img.shields.io/npm/l/svelte-eslint-parser.svg)](https://www.npmjs.com/package/svelte-eslint-parser)

1. Write `overrides.parser` option into your `.eslintrc.*` file.
1. Write `parser` option into your ESLint Config file.
2. Use glob patterns or `--ext .svelte` CLI option.
### ESLint Config (`eslint.config.js`)
```js
import js from "@eslint/js";
import svelteParser from "svelte-eslint-parser";
export default [
js.configs.recommended,
{
files: ["**/*.svelte", "*.svelte"],
languageOptions: {
parser: svelteParser,
},
},
];
```
### ESLint Config (`.eslintrc.*`)
```json
{
"extends": "eslint:recommended",
"overrides": [
{
"files": ["*.svelte"],
"parser": "svelte-eslint-parser"
}
]
"extends": "eslint:recommended",
"overrides": [
{
"files": ["*.svelte"],
"parser": "svelte-eslint-parser"
}
]
}
```
### CLI
```console

@@ -78,3 +98,3 @@ $ eslint "src/**/*.{js,svelte}"

`parserOptions` has the same properties as what [espree](https://github.com/eslint/espree#usage), the default parser of ESLint, is supporting.
[`parserOptions`] has the same properties as what [espree](https://github.com/eslint/espree#usage), the default parser of ESLint, is supporting.
For example:

@@ -84,15 +104,16 @@

{
"parser": "svelte-eslint-parser",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2021,
"ecmaFeatures": {
"globalReturn": false,
"impliedStrict": false,
"jsx": false
}
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2021,
"ecmaFeatures": {
"globalReturn": false,
"impliedStrict": false,
"jsx": false
}
}
}
```
[`parserOptions`]: https://eslint.org/docs/latest/use/configure/parser#configure-parser-options
### parserOptions.parser

@@ -102,16 +123,67 @@

Other properties than parser would be given to the specified parser.
For example:
For example in `eslint.config.js`:
```js
import tsParser from "@typescript-eslint/parser";
export default [
{
files: ["**/*.svelte", "*.svelte"],
languageOptions: {
parser: svelteParser,
parserOptions: {
parser: tsParser,
},
},
},
];
```
For example in `.eslintrc.*`:
```json
{
"parser": "svelte-eslint-parser",
"parserOptions": {
"parser": "@typescript-eslint/parser"
}
"parser": "svelte-eslint-parser",
"parserOptions": {
"parser": "@typescript-eslint/parser"
}
}
```
For example, if you are using the `"@typescript-eslint/parser"`, and if you want to use TypeScript in `<script>` of `.svelte`, you need to add more `parserOptions` configuration.
If you are using the `"@typescript-eslint/parser"`, and if you want to use TypeScript in `<script>` of `.svelte`, you need to add more `parserOptions` configuration.
For example in `eslint.config.js`:
```js
import tsParser from "@typescript-eslint/parser";
export default [
// ...
{
// ...
languageOptions: {
parser: tsParser,
parserOptions: {
// ...
project: "path/to/your/tsconfig.json",
extraFileExtensions: [".svelte"], // This is a required setting in `@typescript-eslint/parser` v4.24.0.
},
},
},
{
files: ["**/*.svelte", "*.svelte"],
languageOptions: {
parser: svelteParser,
// Parse the `<script>` in `.svelte` as TypeScript by adding the following configuration.
parserOptions: {
parser: tsParser,
},
},
// ...
},
];
```
For example in `.eslintrc.*`:
```js
module.exports = {

@@ -137,3 +209,3 @@ // ...

// ...
}
};
```

@@ -145,54 +217,79 @@

For example in `eslint.config.js`:
```js
import tsParser from "@typescript-eslint/parser";
import espree from "espree";
export default [
{
files: ["**/*.svelte", "*.svelte"],
languageOptions: {
parser: svelteParser,
parserOptions: {
parser: {
ts: tsParser,
js: espree,
typescript: tsParser,
},
},
},
},
];
```
For example in `.eslintrc.*`:
```json
{
"parser": "svelte-eslint-parser",
"parserOptions": {
"parser": {
"ts": "@typescript-eslint/parser",
"js": "espree",
"typescript": "@typescript-eslint/parser"
}
"parser": "svelte-eslint-parser",
"parserOptions": {
"parser": {
"ts": "@typescript-eslint/parser",
"js": "espree",
"typescript": "@typescript-eslint/parser"
}
}
}
```
#### Parser Object
### parserOptions.svelteFeatures
When using JavaScript configuration (`.eslintrc.js`), you can also give the parser object directly.
You can use `parserOptions.svelteFeatures` property to specify how to parse related to Svelte features. For example:
For example in `eslint.config.js`:
```js
const tsParser = require("@typescript-eslint/parser")
const espree = require("espree")
module.exports = {
parser: "svelte-eslint-parser",
parserOptions: {
// Single parser
parser: tsParser,
// Multiple parser
parser: {
js: espree,
ts: tsParser,
}
export default [
{
files: ["**/*.svelte", "*.svelte"],
languageOptions: {
parser: svelteParser,
parserOptions: {
svelteFeatures: {
/* -- Experimental Svelte Features -- */
/* It may be changed or removed in minor versions without notice. */
// Whether to parse the `generics` attribute.
// See https://github.com/sveltejs/rfcs/pull/38
experimentalGenerics: false,
},
},
},
}
},
];
```
### parserOptions.svelteFeatures
For example in `.eslintrc.*`:
You can use `parserOptions.svelteFeatures` property to specify how to parse related to Svelte features. For example:
```jsonc
{
"parser": "svelte-eslint-parser",
"parserOptions": {
"svelteFeatures": {
/* -- Experimental Svelte Features -- */
/* It may be changed or removed in minor versions without notice. */
// Whether to parse the `generics` attribute.
// See https://github.com/sveltejs/rfcs/pull/38
"experimentalGenerics": false
}
}
"parser": "svelte-eslint-parser",
"parserOptions": {
"svelteFeatures": {
/* -- Experimental Svelte Features -- */
/* It may be changed or removed in minor versions without notice. */
// Whether to parse the `generics` attribute.
// See https://github.com/sveltejs/rfcs/pull/38
"experimentalGenerics": false,
},
},
}

@@ -203,3 +300,3 @@ ```

***This is an experimental feature. It may be changed or removed in minor versions without notice.***
**_This is an experimental feature. It may be changed or removed in minor versions without notice._**

@@ -210,29 +307,67 @@ If you install Svelte v5 the parser will be able to parse runes, and will also be able to parse `*.js` and `*.ts` files.

```json
For example in `eslint.config.js`:
```js
export default [
{
files: ["**/*.svelte", "*.svelte"],
languageOptions: {
parser: svelteParser,
parserOptions: {
parser: "...",
/* ... */
},
},
},
{
files: ["**/*.svelte.js", "*.svelte.js"],
languageOptions: {
parser: svelteParser,
parserOptions: {
/* ... */
},
},
},
{
files: ["**/*.svelte.ts", "*.svelte.ts"],
languageOptions: {
parser: svelteParser,
parserOptions: {
parser: "...(ts parser)...",
/* ... */
},
},
},
];
```
For example in `.eslintrc.*`:
```jsonc
{
"overrides": [
{
"files": ["*.svelte"],
"parser": "svelte-eslint-parser",
"parserOptions": {
"parser": "...",
...
}
},
{
"files": ["*.svelte.js"],
"parser": "svelte-eslint-parser",
"parserOptions": {
...
}
},
{
"files": ["*.svelte.ts"],
"parser": "svelte-eslint-parser",
"parserOptions": {
"parser": "...(ts parser)...",
...
}
}
]
"overrides": [
{
"files": ["*.svelte"],
"parser": "svelte-eslint-parser",
"parserOptions": {
"parser": "...",
/* ... */
},
},
{
"files": ["*.svelte.js"],
"parser": "svelte-eslint-parser",
"parserOptions": {
/* ... */
},
},
{
"files": ["*.svelte.ts"],
"parser": "svelte-eslint-parser",
"parserOptions": {
"parser": "...(ts parser)...",
/* ... */
},
},
],
}

@@ -253,7 +388,3 @@ ```

{
"eslint.validate": [
"javascript",
"javascriptreact",
"svelte"
]
"eslint.validate": ["javascript", "javascriptreact", "svelte"]
}

@@ -274,3 +405,3 @@ ```

See also the documentation for the internal mechanism.
See also the documentation for the internal mechanism.

@@ -277,0 +408,0 @@ - [internal-mechanism.md](./docs/internal-mechanism.md)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc