Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace declaration property of SvelteConstTag with declarations property #641

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lovely-crabs-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-eslint-parser": minor
---

feat: replace `declaration` property of SvelteConstTag with `declarations` property
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"chai": "^5.0.0",
"env-cmd": "^10.1.0",
"esbuild": "^0.24.0",
"eslint": "~9.16.0",
"eslint": "~9.18.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-jsdoc": "^50.6.0",
Expand Down
6 changes: 5 additions & 1 deletion src/ast/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,11 @@
/** Node of const tag. e.g. `{@const}` */
export interface SvelteConstTag extends BaseNode {
type: "SvelteConstTag";
declaration: ESTree.VariableDeclarator;
/**
* @deprecated Use `declarations` instead.
*/
declaration: ESTree.VariableDeclarator; // TODO Remove in v2 and later.

Check warning on line 268 in src/ast/html.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected 'todo' comment: 'TODO Remove in v2 and later.'
declarations: [ESTree.VariableDeclarator];
parent:
| SvelteProgram
| SvelteElement
Expand Down
16 changes: 15 additions & 1 deletion src/parser/converts/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,28 @@
const mustache: SvelteConstTag = {
type: "SvelteConstTag",
declaration: null as any,
declarations: [] as any,
parent,
...ctx.getConvertLocation(node),
};

// Link declaration and declarations for backward compatibility.
// TODO Remove in v2 and later.

Check warning on line 22 in src/parser/converts/const.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected 'todo' comment: 'TODO Remove in v2 and later.'
Object.defineProperty(mustache, "declaration", {
get() {
return mustache.declarations[0];
},
set(value) {
mustache.declarations = [value];
},
enumerable: false,
});

ctx.scriptLet.addVariableDeclarator(
getDeclaratorFromConstTag(node),
mustache,
(declaration) => {
mustache.declaration = declaration;
mustache.declarations = [declaration];
},
);
const atConstStart = ctx.code.indexOf("@const", mustache.range[0]);
Expand Down
2 changes: 1 addition & 1 deletion src/visitor-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const svelteKeys: SvelteKeysType = {
SvelteLiteral: [],
SvelteMustacheTag: ["expression"],
SvelteDebugTag: ["identifiers"],
SvelteConstTag: ["declaration"],
SvelteConstTag: ["declarations"],
SvelteRenderTag: ["expression"],
SvelteIfBlock: ["expression", "children", "else"],
SvelteElseBlock: ["children"],
Expand Down
106 changes: 54 additions & 52 deletions tests/fixtures/parser/ast/at-const01-within-component-output.json
Original file line number Diff line number Diff line change
Expand Up @@ -300,59 +300,75 @@
},
{
"type": "SvelteConstTag",
"declaration": {
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "a",
"range": [
101,
102
],
"loc": {
"start": {
"line": 6,
"column": 10
},
"end": {
"line": 6,
"column": 11
}
}
},
"init": {
"type": "BinaryExpression",
"left": {
"declarations": [
{
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "b",
"name": "a",
"range": [
105,
106
101,
102
],
"loc": {
"start": {
"line": 6,
"column": 14
"column": 10
},
"end": {
"line": 6,
"column": 15
"column": 11
}
}
},
"operator": "*",
"right": {
"type": "Literal",
"raw": "2",
"value": 2,
"init": {
"type": "BinaryExpression",
"left": {
"type": "Identifier",
"name": "b",
"range": [
105,
106
],
"loc": {
"start": {
"line": 6,
"column": 14
},
"end": {
"line": 6,
"column": 15
}
}
},
"operator": "*",
"right": {
"type": "Literal",
"raw": "2",
"value": 2,
"range": [
109,
110
],
"loc": {
"start": {
"line": 6,
"column": 18
},
"end": {
"line": 6,
"column": 19
}
}
},
"range": [
109,
105,
110
],
"loc": {
"start": {
"line": 6,
"column": 18
"column": 14
},
"end": {
"line": 6,
Expand All @@ -361,35 +377,21 @@
}
},
"range": [
105,
101,
110
],
"loc": {
"start": {
"line": 6,
"column": 14
"column": 10
},
"end": {
"line": 6,
"column": 19
}
}
},
"range": [
101,
110
],
"loc": {
"start": {
"line": 6,
"column": 10
},
"end": {
"line": 6,
"column": 19
}
}
},
],
"range": [
93,
111
Expand Down
Loading
Loading