Class: Lilac::CLI::TemplateAST::WalkScopes

Inherits:
Object
  • Object
show all
Defined in:
lib/lilac/cli/build/template_ast.rb

Overview

Immutable per-frame walk state: the stacks that get pushed/popped as the walker descends/ascends. Bundled so walk doesn't have to thread individual args through recursion (the accumulators — directives / refs_map — are mutated in place and stay separate).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(each_scope: [], ref_scopes: [{}]) ⇒ WalkScopes

Returns a new instance of WalkScopes.



94
95
96
97
# File 'lib/lilac/cli/build/template_ast.rb', line 94

def initialize(each_scope: [], ref_scopes: [{}])
  @each_scope = each_scope
  @ref_scopes = ref_scopes
end

Instance Attribute Details

#each_scopeObject (readonly)

each_scope: ref_ids of currently-open data-each elements; children's directives carry scope_id = each_scope.last ref_scopes: Stack<{ ref_name => line }> for duplicate ref detection per data-each / data-component scope



92
93
94
# File 'lib/lilac/cli/build/template_ast.rb', line 92

def each_scope
  @each_scope
end

#ref_scopesObject (readonly)

each_scope: ref_ids of currently-open data-each elements; children's directives carry scope_id = each_scope.last ref_scopes: Stack<{ ref_name => line }> for duplicate ref detection per data-each / data-component scope



92
93
94
# File 'lib/lilac/cli/build/template_ast.rb', line 92

def ref_scopes
  @ref_scopes
end

Instance Method Details

#current_each_refObject



113
114
115
# File 'lib/lilac/cli/build/template_ast.rb', line 113

def current_each_ref
  @each_scope.last
end

#current_ref_scopeObject



109
110
111
# File 'lib/lilac/cli/build/template_ast.rb', line 109

def current_ref_scope
  @ref_scopes.last
end

#push_each(ref_id) ⇒ Object

Push helpers return a NEW WalkScopes — frames are immutable so the recursive call doesn't accidentally mutate the parent's stack.



101
102
103
# File 'lib/lilac/cli/build/template_ast.rb', line 101

def push_each(ref_id)
  self.class.new(each_scope: @each_scope + [ref_id], ref_scopes: @ref_scopes)
end

#push_ref_scopeObject



105
106
107
# File 'lib/lilac/cli/build/template_ast.rb', line 105

def push_ref_scope
  self.class.new(each_scope: @each_scope, ref_scopes: @ref_scopes + [{}])
end