Module: Jade::Frontend::SemanticAnalysis::Body

Extended by:
Body, Helper
Included in:
Body
Defined in:
lib/jade/frontend/semantic_analysis/body.rb

Instance Method Summary collapse

Methods included from Helper

analyze_duplicate_fields, analyze_in_parallel, analyze_in_sequence, analyze_node, bind, collect_vars, lookup, validate_type_symbol

Instance Method Details

#analyze(node, registry, scope, entry) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jade/frontend/semantic_analysis/body.rb', line 8

def analyze(node, registry, scope, entry)
  node => AST::Body(expressions:)

  duplicate_errors = expressions
    .select { it.is_a?(AST::FunctionDeclaration) }
    .group_by(&:name)
    .filter_map do |name, decls|
      next nil if decls.size < 2

      first, *rest = decls
      Error::DuplicateFunctionDeclaration.new(
        entry.name,
        first.range,
        name,
        duplicate_spans: rest.map(&:range),
      )
    end

  analyze_in_sequence(expressions, registry, scope, entry)
    .add_errors(duplicate_errors)
    .map_node { node.with(expressions: it) }
end