import { Node } from 'estree-walker' ; import { SvelteIdentifier } from '../../interfaces' ; import TemplateScope from './TemplateScope' ; import { SlotHandler } from './slot' ; import { isIdentifier , isDestructuringPatterns } from '../../utils/svelteAst' ; import { extract_identifiers as extractIdentifiers } from 'periscopic' ; import { Directive } from 'svelte/types/compiler/interfaces' ; export function handleScopeAndResolveForSlot ( { identifierDef , initExpression , owner , slotHandler , templateScope } ) { if ( isIdentifier ( identifierDef ) ) { templateScope . add ( identifierDef , owner ) ; slotHandler . resolve ( identifierDef , initExpression , templateScope ) ; } if ( isDestructuringPatterns ( identifierDef ) ) { const identifiers = extractIdentifiers ( identifierDef ) as SvelteIdentifier [ ] ; templateScope . addMany ( identifiers , owner ) ; slotHandler . resolveDestructuringAssignment ( identifierDef , identifiers , initExpression , templateScope ) ; } } export function handleScopeAndResolveLetVarForSlot ( { letNode , component , slotName , templateScope , slotHandler } ) { const { expression } = letNode ; if ( ! expression ) { templateScope . add ( letNode , component ) ; slotHandler . resolveLet ( letNode , letNode , component , slotName ) ; } else { if ( isIdentifier ( expression ) ) { templateScope . add ( expression , component ) ; slotHandler . resolveLet ( letNode , expression , component , slotName ) ; } const expForExtract = { ... expression } ; if ( expression . type === 'ArrayExpression' ) { expForExtract . type = 'ArrayPattern' ; } else if ( expression . type === 'ObjectExpression' ) { expForExtract . type = 'ObjectPattern' ; } if ( isDestructuringPatterns ( expForExtract ) ) { const identifiers = extractIdentifiers ( expForExtract ) as SvelteIdentifier [ ] ; templateScope . addMany ( identifiers , component ) ; slotHandler . resolveDestructuringAssignmentForLet ( expForExtract , identifiers , letNode , component , slotName ) ; } } }