Skip to content

Commit 5f237d2

Browse files
authored
fix: wrong AST and type due to newline after = to reactive variable (#234)
* fix: wrong AST and type due to newline after `=` to reactive variable * Create tall-lions-invite.md
1 parent 423722a commit 5f237d2

10 files changed

+11544
-1
lines changed

.changeset/tall-lions-invite.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte-eslint-parser": patch
3+
---
4+
5+
fix: wrong AST and type due to newline after `=` to reactive variable

src/parser/typescript/analyze/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,11 @@ function transformForDeclareReactiveVar(
305305
ctx.skipUntilOriginalOffset(id.range[0]);
306306
ctx.appendVirtualScript("let ");
307307
ctx.appendOriginal(eq ? eq.range[1] : expression.right.range[0]);
308-
ctx.appendVirtualScript(`${functionId}();\nfunction ${functionId}(){return `);
308+
ctx.appendVirtualScript(
309+
`${functionId}();\nfunction ${functionId}(){return (`
310+
);
311+
ctx.appendOriginal(expression.right.range[1]);
312+
ctx.appendVirtualScript(`)`);
309313
for (const token of closeParens) {
310314
ctx.appendOriginal(token.range[0]);
311315
ctx.skipOriginalOffset(token.range[1] - token.range[0]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script lang="ts">
2+
$: aWithNewline =
3+
42;
4+
$: bWithNewline =
5+
42
6+
$: cWithNewline =
7+
(42);
8+
$: dWithNewline =(
9+
42)
10+
$: eWithNewline =
11+
(42)
12+
</script>
13+
14+
{aWithNewline}{bWithNewline}{cWithNewline}{dWithNewline}{eWithNewline}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* eslint eslint-comments/require-description: 0, @typescript-eslint/explicit-module-boundary-types: 0 */
2+
import type { Linter } from "eslint";
3+
import { BASIC_PARSER_OPTIONS } from "../../../src/parser/test-utils";
4+
import { rules } from "@typescript-eslint/eslint-plugin";
5+
export function setupLinter(linter: Linter) {
6+
linter.defineRule(
7+
"@typescript-eslint/no-confusing-void-expression",
8+
rules["no-confusing-void-expression"] as never
9+
);
10+
linter.defineRule(
11+
"@typescript-eslint/explicit-function-return-type",
12+
rules["explicit-function-return-type"] as never
13+
);
14+
}
15+
16+
export function getConfig() {
17+
return {
18+
parser: "svelte-eslint-parser",
19+
parserOptions: BASIC_PARSER_OPTIONS,
20+
rules: {
21+
"@typescript-eslint/no-confusing-void-expression": "error",
22+
"@typescript-eslint/explicit-function-return-type": "error",
23+
"no-unreachable": "error",
24+
},
25+
env: {
26+
browser: true,
27+
es2021: true,
28+
},
29+
};
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script lang="ts">
2+
$: aWithNewline =
3+
42;
4+
$: bWithNewline =
5+
42
6+
$: cWithNewline =
7+
(42);
8+
$: dWithNewline =(
9+
42)
10+
$: eWithNewline =
11+
(42)
12+
</script>
13+
14+
{aWithNewline}{bWithNewline}{cWithNewline}{dWithNewline}{eWithNewline}
15+

0 commit comments

Comments
 (0)