Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sveltejs/svelte-eslint-parser
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.40.0
Choose a base ref
...
head repository: sveltejs/svelte-eslint-parser
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.41.0
Choose a head ref
  • 2 commits
  • 5 files changed
  • 3 contributors

Commits on Jul 19, 2024

  1. feat: support for svelte 5.0.0-next.191 (#550)

    ota-meshi authored Jul 19, 2024
    Copy the full SHA
    ef24a69 View commit details
  2. chore: release svelte-eslint-parser (#551)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    github-actions[bot] and github-actions[bot] authored Jul 19, 2024
    Copy the full SHA
    3b85054 View commit details
Showing with 54 additions and 46 deletions.
  1. +6 −0 CHANGELOG.md
  2. +13 −13 package.json
  3. +1 −1 src/meta.ts
  4. +33 −31 src/parser/converts/attr.ts
  5. +1 −1 src/parser/svelte-ast-types.ts
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# svelte-eslint-parser

## 0.41.0

### Minor Changes

- [#550](https://github.com/sveltejs/svelte-eslint-parser/pull/550) [`ef24a69`](https://github.com/sveltejs/svelte-eslint-parser/commit/ef24a69b805b7cff6744be4cbdbc9c2349cfe04d) Thanks [@ota-meshi](https://github.com/ota-meshi)! - feat: support for svelte 5.0.0-next.191

## 0.40.0

### Minor Changes
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svelte-eslint-parser",
"version": "0.40.0",
"version": "0.41.0",
"description": "Svelte parser for ESLint",
"repository": "git+https://github.com/sveltejs/svelte-eslint-parser.git",
"homepage": "https://github.com/sveltejs/svelte-eslint-parser#readme",
@@ -47,7 +47,7 @@
"version:ci": "env-cmd -e version-ci pnpm run build:meta && changeset version"
},
"peerDependencies": {
"svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.181"
"svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.191"
},
"peerDependenciesMeta": {
"svelte": {
@@ -73,11 +73,11 @@
"@types/eslint-visitor-keys": "^3.3.0",
"@types/estree": "^1.0.5",
"@types/mocha": "^10.0.7",
"@types/node": "^20.14.10",
"@types/node": "^20.14.11",
"@types/semver": "^7.5.8",
"@typescript-eslint/eslint-plugin": "^7.16.0",
"@typescript-eslint/parser": "~7.16.0",
"@typescript-eslint/types": "~7.16.0",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"@typescript-eslint/parser": "~7.16.1",
"@typescript-eslint/types": "~7.16.1",
"benchmark": "^2.1.4",
"chai": "^4.4.1",
"env-cmd": "^10.1.0",
@@ -90,22 +90,22 @@
"eslint-plugin-jsonc": "^2.16.0",
"eslint-plugin-n": "^17.9.0",
"eslint-plugin-node-dependencies": "^0.12.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-regexp": "^2.6.0",
"eslint-plugin-svelte": "^2.41.0",
"eslint-plugin-svelte": "^2.42.0",
"eslint-plugin-yml": "^1.14.0",
"estree-walker": "^3.0.3",
"locate-character": "^3.0.0",
"magic-string": "^0.30.10",
"mocha": "^10.6.0",
"mocha-chai-jest-snapshot": "^1.1.4",
"nyc": "^17.0.0",
"prettier": "~3.3.2",
"prettier": "~3.3.3",
"prettier-plugin-pkg": "^0.18.1",
"prettier-plugin-svelte": "^3.2.5",
"rimraf": "^6.0.0",
"semver": "^7.6.2",
"svelte": "^5.0.0-next.181",
"prettier-plugin-svelte": "^3.2.6",
"rimraf": "^6.0.1",
"semver": "^7.6.3",
"svelte": "^5.0.0-next.191",
"svelte2tsx": "^0.7.13",
"typescript": "~5.5.3",
"typescript-eslint-parser-for-extra-files": "^0.7.0"
2 changes: 1 addition & 1 deletion src/meta.ts
Original file line number Diff line number Diff line change
@@ -2,4 +2,4 @@
// This file has been automatically generated,
// in order to update its content execute "pnpm run build:meta"
export const name = "svelte-eslint-parser";
export const version = "0.40.0";
export const version = "0.41.0";
64 changes: 33 additions & 31 deletions src/parser/converts/attr.ts
Original file line number Diff line number Diff line change
@@ -150,20 +150,10 @@ function convertAttribute(
ctx.addToken("HTMLIdentifier", keyRange);
return attribute;
}
const value = node.value as (
| Compiler.Text
| Compiler.ExpressionTag
| SvAST.Text
| SvAST.MustacheTag
| SvAST.AttributeShorthand
)[];
const value = node.value;
const shorthand =
value.find((v) => v.type === "AttributeShorthand") ||
// for Svelte v5
(value.length === 1 &&
value[0].type === "ExpressionTag" &&
ctx.code[node.start] === "{" &&
ctx.code[node.end - 1] === "}");
isAttributeShorthandForSvelteV4(value) ||
isAttributeShorthandForSvelteV5(value);
if (shorthand) {
const key: ESTree.Identifier = {
...attribute.key,
@@ -193,34 +183,46 @@ function convertAttribute(
// Not required for shorthands. Therefore, register the token here.
ctx.addToken("HTMLIdentifier", keyRange);

processAttributeValue(
node.value as (
| SvAST.Text
| SvAST.MustacheTag
| Compiler.Text
| Compiler.ExpressionTag
)[],
attribute,
parent,
ctx,
);
processAttributeValue(value, attribute, parent, ctx);

return attribute;

function isAttributeShorthandForSvelteV4(
value: Exclude<(SvAST.Attribute | Compiler.Attribute)["value"], boolean>,
): value is [SvAST.AttributeShorthand] {
return Array.isArray(value) && value[0]?.type === "AttributeShorthand";
}

function isAttributeShorthandForSvelteV5(
value: Exclude<
(SvAST.Attribute | Compiler.Attribute)["value"],
boolean | [SvAST.AttributeShorthand]
>,
): boolean {
return (
!Array.isArray(value) &&
value.type === "ExpressionTag" &&
ctx.code[node.start] === "{" &&
ctx.code[node.end - 1] === "}"
);
}
}

/** Common process attribute value */
function processAttributeValue(
nodeValue: (
| SvAST.Text
| SvAST.MustacheTag
| Compiler.Text
| Compiler.ExpressionTag
)[],
nodeValue:
| (
| SvAST.Text
| SvAST.MustacheTag
| Compiler.Text
| Compiler.ExpressionTag
)[]
| Compiler.ExpressionTag,
attribute: SvelteAttribute | SvelteStyleDirectiveLongform,
attributeParent: (SvelteAttribute | SvelteStyleDirectiveLongform)["parent"],
ctx: Context,
) {
const nodes = nodeValue
const nodes = (Array.isArray(nodeValue) ? nodeValue : [nodeValue])
.filter(
(v) =>
v.type !== "Text" ||
2 changes: 1 addition & 1 deletion src/parser/svelte-ast-types.ts
Original file line number Diff line number Diff line change
@@ -192,7 +192,7 @@ export interface Comment extends BaseNode {
export interface Attribute extends BaseNode {
type: "Attribute";
name: string;
value: (Text | AttributeShorthand | MustacheTag)[] | true;
value: (Text | MustacheTag)[] | [AttributeShorthand] | true;
}
export interface Spread extends BaseNode {
type: "Spread";