Skip to content

Commit e16c147

Browse files
authored
Fix incorect scope for reactive statement with predefined variables. (#89)
1 parent 3b854a0 commit e16c147

6 files changed

+7111
-3
lines changed

src/parser/index.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import { parseScript } from "./script"
88
import type * as SvAST from "./svelte-ast-types"
99
import { sort } from "./sort"
1010
import { parseTemplate } from "./template"
11-
import { analyzePropsScope, analyzeStoreScope } from "./analyze-scope"
11+
import {
12+
analyzePropsScope,
13+
analyzeReactiveScope,
14+
analyzeStoreScope,
15+
} from "./analyze-scope"
1216
import { ParseError } from "../errors"
1317

1418
export interface ESLintProgram extends Program {
@@ -71,6 +75,7 @@ export function parseForESLint(
7175
sort(ctx.tokens)
7276
extractTokens(ctx)
7377
analyzeStoreScope(resultScript.scopeManager!)
78+
analyzeReactiveScope(resultScript.scopeManager!)
7479

7580
// Add $$xxx variable
7681
for (const $$name of ["$$slots", "$$props", "$$restProps"]) {

src/parser/script.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ESLintExtendedProgram } from "."
2-
import { analyzeReactiveScope, analyzeScope } from "./analyze-scope"
2+
import { analyzeScope } from "./analyze-scope"
33
import { traverseNodes } from "../traverse"
44
import type { ScriptsSourceCode } from "../context"
55
import { getParser } from "./resolve-parser"
@@ -34,7 +34,6 @@ export function parseScript(
3434
//
3535
},
3636
})
37-
analyzeReactiveScope(result.scopeManager)
3837

3938
return result
4039
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<script>
2+
import { count, count2 } from './stores.js';
3+
import { writable } from 'svelte/store';
4+
5+
let foo = 0
6+
let bar = writable(0)
7+
$: $count2 = $count * 2
8+
$: foo = $count * 3
9+
$: $bar = $count * 4
10+
$: baz = $count * 5 // ComputedVariable
11+
</script>
12+
13+
<h1>$count: {$count}</h1>
14+
<h1>$count2: {$count2}</h1>
15+
<h1>foo: {foo}</h1>
16+
<h1>$bar: {$bar}</h1>
17+
<h1>baz: {baz}</h1>
18+
<button on:click={()=>$count++}>+1</button>

0 commit comments

Comments
 (0)