1+ /** @import { ClassDeclaration, Expression, FunctionDeclaration, Identifier, ImportDeclaration, MemberExpression, Node, Pattern, VariableDeclarator } from 'estree' */
2+ /** @import { Context, Visitor, Visitors } from 'zimmerframe' */
3+ /** @import { AnimateDirective, Binding, DeclarationKind, EachBlock, ElementLike, LetDirective, SvelteNode, TransitionDirective, UseDirective } from '#compiler' */
14import is_reference from 'is-reference' ;
25import { walk } from 'zimmerframe' ;
36import { is_element_node } from './nodes.js' ;
@@ -30,20 +33,20 @@ export class Scope {
3033 /**
3134 * A map of every identifier declared by this scope, and all the
3235 * identifiers that reference it
33- * @type {Map<string, import('#compiler'). Binding> }
36+ * @type {Map<string, Binding> }
3437 */
3538 declarations = new Map ( ) ;
3639
3740 /**
3841 * A map of declarators to the bindings they declare
39- * @type {Map<import('estree'). VariableDeclarator | import('#compiler'). LetDirective, import('#compiler'). Binding[]> }
42+ * @type {Map<VariableDeclarator | LetDirective, Binding[]> }
4043 */
4144 declarators = new Map ( ) ;
4245
4346 /**
4447 * A set of all the names referenced with this scope
4548 * — useful for generating unique names
46- * @type {Map<string, { node: import('estree'). Identifier; path: import('#compiler'). SvelteNode[] }[]> }
49+ * @type {Map<string, { node: Identifier; path: SvelteNode[] }[]> }
4750 */
4851 references = new Map ( ) ;
4952
@@ -67,11 +70,11 @@ export class Scope {
6770 }
6871
6972 /**
70- * @param {import('estree'). Identifier } node
71- * @param {import('#compiler'). Binding['kind'] } kind
72- * @param {import('#compiler'). DeclarationKind } declaration_kind
73- * @param {null | import('estree'). Expression | import('estree'). FunctionDeclaration | import('estree'). ClassDeclaration | import('estree'). ImportDeclaration | import('../types/template.js'). EachBlock } initial
74- * @returns {import('#compiler'). Binding }
73+ * @param {Identifier } node
74+ * @param {Binding['kind'] } kind
75+ * @param {DeclarationKind } declaration_kind
76+ * @param {null | Expression | FunctionDeclaration | ClassDeclaration | ImportDeclaration | EachBlock } initial
77+ * @returns {Binding }
7578 */
7679 declare ( node , kind , declaration_kind , initial = null ) {
7780 if ( node . name === '$' ) {
@@ -103,7 +106,7 @@ export class Scope {
103106 e . declaration_duplicate ( node , node . name ) ;
104107 }
105108
106- /** @type {import('#compiler'). Binding } */
109+ /** @type {Binding } */
107110 const binding = {
108111 node,
109112 references : [ ] ,
@@ -157,15 +160,15 @@ export class Scope {
157160
158161 /**
159162 * @param {string } name
160- * @returns {import('#compiler'). Binding | null }
163+ * @returns {Binding | null }
161164 */
162165 get ( name ) {
163166 return this . declarations . get ( name ) ?? this . parent ?. get ( name ) ?? null ;
164167 }
165168
166169 /**
167- * @param {import('estree'). VariableDeclarator | import('#compiler'). LetDirective } node
168- * @returns {import('#compiler'). Binding[] }
170+ * @param {VariableDeclarator | LetDirective } node
171+ * @returns {Binding[] }
169172 */
170173 get_bindings ( node ) {
171174 const bindings = this . declarators . get ( node ) ;
@@ -184,8 +187,8 @@ export class Scope {
184187 }
185188
186189 /**
187- * @param {import('estree'). Identifier } node
188- * @param {import('#compiler'). SvelteNode[] } path
190+ * @param {Identifier } node
191+ * @param {SvelteNode[] } path
189192 */
190193 reference ( node , path ) {
191194 path = [ ...path ] ; // ensure that mutations to path afterwards don't affect this reference
@@ -231,7 +234,7 @@ export class ScopeRoot {
231234}
232235
233236/**
234- * @param {import('#compiler'). SvelteNode } ast
237+ * @param {SvelteNode } ast
235238 * @param {ScopeRoot } root
236239 * @param {boolean } allow_reactive_declarations
237240 * @param {Scope | null } parent
@@ -241,7 +244,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
241244
242245 /**
243246 * A map of node->associated scope. A node appearing in this map does not necessarily mean that it created a scope
244- * @type {Map<import('#compiler'). SvelteNode, Scope> }
247+ * @type {Map<SvelteNode, Scope> }
245248 */
246249 const scopes = new Map ( ) ;
247250 const scope = new Scope ( root , parent , false ) ;
@@ -250,21 +253,21 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
250253 /** @type {State } */
251254 const state = { scope } ;
252255
253- /** @type {[Scope, { node: import('estree'). Identifier; path: import('#compiler'). SvelteNode[] }][] } */
256+ /** @type {[Scope, { node: Identifier; path: SvelteNode[] }][] } */
254257 const references = [ ] ;
255258
256- /** @type {[Scope, import('estree'). Pattern | import('estree'). MemberExpression][] } */
259+ /** @type {[Scope, Pattern | MemberExpression][] } */
257260 const updates = [ ] ;
258261
259262 /**
260263 * An array of reactive declarations, i.e. the `a` in `$: a = b * 2`
261- * @type {import('estree'). Identifier[] }
264+ * @type {Identifier[] }
262265 */
263266 const possible_implicit_declarations = [ ] ;
264267
265268 /**
266269 * @param {Scope } scope
267- * @param {import('estree'). Pattern[] } params
270+ * @param {Pattern[] } params
268271 */
269272 function add_params ( scope , params ) {
270273 for ( const param of params ) {
@@ -275,7 +278,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
275278 }
276279
277280 /**
278- * @type {import('zimmerframe'). Visitor<import('estree'). Node, State, import('#compiler'). SvelteNode> }
281+ * @type {Visitor<Node, State, SvelteNode> }
279282 */
280283 const create_block_scope = ( node , { state, next } ) => {
281284 const scope = state . scope . child ( true ) ;
@@ -285,7 +288,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
285288 } ;
286289
287290 /**
288- * @type {import('zimmerframe'). Visitor<import('#compiler'). ElementLike, State, import('#compiler'). SvelteNode> }
291+ * @type {Visitor<ElementLike, State, SvelteNode> }
289292 */
290293 const SvelteFragment = ( node , { state, next } ) => {
291294 const [ scope ] = analyze_let_directives ( node , state . scope ) ;
@@ -294,7 +297,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
294297 } ;
295298
296299 /**
297- * @param {import('#compiler'). ElementLike } node
300+ * @param {ElementLike } node
298301 * @param {Scope } parent
299302 */
300303 function analyze_let_directives ( node , parent ) {
@@ -303,7 +306,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
303306
304307 for ( const attribute of node . attributes ) {
305308 if ( attribute . type === 'LetDirective' ) {
306- /** @type {import('#compiler'). Binding[] } */
309+ /** @type {Binding[] } */
307310 const bindings = [ ] ;
308311 scope . declarators . set ( attribute , bindings ) ;
309312
@@ -317,7 +320,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
317320 bindings . push ( binding ) ;
318321 }
319322 } else {
320- /** @type {import('estree'). Identifier } */
323+ /** @type {Identifier } */
321324 const id = {
322325 name : attribute . name ,
323326 type : 'Identifier' ,
@@ -336,7 +339,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
336339 }
337340
338341 /**
339- * @type {import('zimmerframe'). Visitor<import('#compiler'). AnimateDirective | import('#compiler'). TransitionDirective | import('#compiler'). UseDirective, State, import('#compiler'). SvelteNode> }
342+ * @type {Visitor<AnimateDirective | TransitionDirective | UseDirective, State, SvelteNode> }
340343 */
341344 const SvelteDirective = ( node , { state, path, visit } ) => {
342345 state . scope . reference ( b . id ( node . name . split ( '.' ) [ 0 ] ) , path ) ;
@@ -350,7 +353,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
350353 // references
351354 Identifier ( node , { path, state } ) {
352355 const parent = path . at ( - 1 ) ;
353- if ( parent && is_reference ( node , /** @type {import('estree'). Node } */ ( parent ) ) ) {
356+ if ( parent && is_reference ( node , /** @type {Node } */ ( parent ) ) ) {
354357 references . push ( [ state . scope , { node, path : path . slice ( ) } ] ) ;
355358 }
356359 } ,
@@ -432,12 +435,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
432435 } ,
433436
434437 UpdateExpression ( node , { state, next } ) {
435- updates . push ( [
436- state . scope ,
437- /** @type {import('estree').Identifier | import('estree').MemberExpression } */ (
438- node . argument
439- )
440- ] ) ;
438+ updates . push ( [ state . scope , /** @type {Identifier | MemberExpression } */ ( node . argument ) ] ) ;
441439 next ( ) ;
442440 } ,
443441
@@ -489,7 +487,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
489487 VariableDeclaration ( node , { state, path, next } ) {
490488 const is_parent_const_tag = path . at ( - 1 ) ?. type === 'ConstTag' ;
491489 for ( const declarator of node . declarations ) {
492- /** @type {import('#compiler'). Binding[] } */
490+ /** @type {Binding[] } */
493491 const bindings = [ ] ;
494492
495493 state . scope . declarators . set ( declarator , bindings ) ;
@@ -525,7 +523,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
525523
526524 EachBlock ( node , { state, visit } ) {
527525 // Array part is still from the scope above
528- /** @type {Set<import('estree'). Identifier> } */
526+ /** @type {Set<Identifier> } */
529527 const references_within = new Set ( ) ;
530528 const idx = references . length ;
531529 visit ( node . expression ) ;
@@ -600,7 +598,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
600598 item : node . context . type === 'Identifier' ? node . context : b . id ( '$$item' ) ,
601599 declarations : scope . declarations ,
602600 references : [ ...references_within ]
603- . map ( ( id ) => /** @type {import('#compiler'). Binding } */ ( state . scope . get ( id . name ) ) )
601+ . map ( ( id ) => /** @type {Binding } */ ( state . scope . get ( id . name ) ) )
604602 . filter ( Boolean ) ,
605603 is_controlled : false
606604 } ;
@@ -673,9 +671,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
673671 BindDirective ( node , context ) {
674672 updates . push ( [
675673 context . state . scope ,
676- /** @type {import('estree').Identifier | import('estree').MemberExpression } */ (
677- node . expression
678- )
674+ /** @type {Identifier | MemberExpression } */ ( node . expression )
679675 ] ) ;
680676 context . next ( ) ;
681677 } ,
@@ -718,7 +714,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
718714 object = object . object ;
719715 }
720716
721- const binding = scope . get ( /** @type {import('estree'). Identifier } */ ( object ) . name ) ;
717+ const binding = scope . get ( /** @type {Identifier } */ ( object ) . name ) ;
722718 if ( binding ) binding . mutated = true ;
723719 } else {
724720 unwrap_pattern ( node ) . forEach ( ( node ) => {
@@ -742,15 +738,15 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
742738
743739/**
744740 * @template {{ scope: Scope }} State
745- * @param {Map<import('#compiler'). SvelteNode, Scope> } scopes
746- * @returns {import('zimmerframe'). Visitors<import('#compiler'). SvelteNode, State> }
741+ * @param {Map<SvelteNode, Scope> } scopes
742+ * @returns {Visitors<SvelteNode, State> }
747743 */
748744export function set_scope ( scopes ) {
749745 return {
750746 /**
751747 *
752- * @param {import('#compiler'). SvelteNode } node
753- * @param {import('zimmerframe'). Context<import('#compiler'). SvelteNode, State> } context
748+ * @param {SvelteNode } node
749+ * @param {Context<SvelteNode, State> } context
754750 */
755751 _ ( node , { next, state } ) {
756752 const scope = scopes . get ( node ) ;
@@ -761,7 +757,7 @@ export function set_scope(scopes) {
761757
762758/**
763759 * Returns the name of the rune if the given expression is a `CallExpression` using a rune.
764- * @param {import('estree'). Node | import('../types/template.js'). EachBlock | null | undefined } node
760+ * @param {Node | EachBlock | null | undefined } node
765761 * @param {Scope } scope
766762 * @returns {Runes[number] | null }
767763 */
0 commit comments