Skip to content
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
7 changes: 6 additions & 1 deletion src/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import { parseScript } from "./script"
import type * as SvAST from "./svelte-ast-types"
import { sort } from "./sort"
import { parseTemplate } from "./template"
import { analyzePropsScope, analyzeStoreScope } from "./analyze-scope"
import {
analyzePropsScope,
analyzeReactiveScope,
analyzeStoreScope,
} from "./analyze-scope"
import { ParseError } from "../errors"

export interface ESLintProgram extends Program {
Expand Down Expand Up @@ -71,6 +75,7 @@ export function parseForESLint(
sort(ctx.tokens)
extractTokens(ctx)
analyzeStoreScope(resultScript.scopeManager!)
analyzeReactiveScope(resultScript.scopeManager!)

// Add $$xxx variable
for (const $$name of ["$$slots", "$$props", "$$restProps"]) {
Expand Down
3 changes: 1 addition & 2 deletions src/parser/script.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ESLintExtendedProgram } from "."
import { analyzeReactiveScope, analyzeScope } from "./analyze-scope"
import { analyzeScope } from "./analyze-scope"
import { traverseNodes } from "../traverse"
import type { ScriptsSourceCode } from "../context"
import { getParser } from "./resolve-parser"
Expand Down Expand Up @@ -34,7 +34,6 @@ export function parseScript(
//
},
})
analyzeReactiveScope(result.scopeManager)

return result
}
Expand Down
18 changes: 18 additions & 0 deletions tests/fixtures/parser/ast/reactive-with-var01-input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script>
import { count, count2 } from './stores.js';
import { writable } from 'svelte/store';

let foo = 0
let bar = writable(0)
$: $count2 = $count * 2
$: foo = $count * 3
$: $bar = $count * 4
$: baz = $count * 5 // ComputedVariable
</script>

<h1>$count: {$count}</h1>
<h1>$count2: {$count2}</h1>
<h1>foo: {foo}</h1>
<h1>$bar: {$bar}</h1>
<h1>baz: {baz}</h1>
<button on:click={()=>$count++}>+1</button>
Loading