Class: Herb::AST::ERBStrictLocalsNode

Inherits:
Node
  • Object
show all
Includes:
Colors
Defined in:
lib/herb/ast/nodes.rb,
ext/herb/nodes.c

Overview

: type serialized_erb_strict_locals_node = { | tag_opening: Herb::Token?, | content: Herb::Token?, | tag_closing: Herb::Token?, | analyzed_ruby: nil, | prism_node: String?, | locals: Array?, | }

Constant Summary

Constants included from Colors

Colors::CLEAR_SCREEN, Colors::HIDE_CURSOR, Colors::SHOW_CURSOR

Instance Attribute Summary collapse

Attributes inherited from Node

#errors, #location, #source, #type

Instance Method Summary collapse

Methods included from Colors

bold, bright_magenta, cyan, dimmed, enabled?, fg, fg_bg, green, magenta, red, white, yellow

Methods inherited from Node

#class_name, #inspect_array, #inspect_errors, #node_name, #recursive_errors, #to_json

Constructor Details

#initialize(type, location, errors, tag_opening, content, tag_closing, analyzed_ruby, prism_node, locals) ⇒ ERBStrictLocalsNode

: (String, Location, Array, Herb::Token, Herb::Token, Herb::Token, nil, String, Array) -> void



4056
4057
4058
4059
4060
4061
4062
4063
4064
# File 'lib/herb/ast/nodes.rb', line 4056

def initialize(type, location, errors, tag_opening, content, tag_closing, analyzed_ruby, prism_node, locals)
  super(type, location, errors)
  @tag_opening = tag_opening
  @content = content
  @tag_closing = tag_closing
  @analyzed_ruby = analyzed_ruby
  @prism_node = prism_node
  @locals = locals
end

Instance Attribute Details

#analyzed_rubyObject (readonly)

: nil



4051
4052
4053
# File 'lib/herb/ast/nodes.rb', line 4051

def analyzed_ruby
  @analyzed_ruby
end

#contentObject (readonly)

: Herb::Token?



4049
4050
4051
# File 'lib/herb/ast/nodes.rb', line 4049

def content
  @content
end

#localsObject (readonly)

: Array?



4053
4054
4055
# File 'lib/herb/ast/nodes.rb', line 4053

def locals
  @locals
end

#prism_nodeObject (readonly)

: String?



4052
4053
4054
# File 'lib/herb/ast/nodes.rb', line 4052

def prism_node
  @prism_node
end

#tag_closingObject (readonly)

: Herb::Token?



4050
4051
4052
# File 'lib/herb/ast/nodes.rb', line 4050

def tag_closing
  @tag_closing
end

#tag_openingObject (readonly)

: Herb::Token?



4048
4049
4050
# File 'lib/herb/ast/nodes.rb', line 4048

def tag_opening
  @tag_opening
end

Instance Method Details

#accept(visitor) ⇒ Object

: (Visitor) -> void



4095
4096
4097
# File 'lib/herb/ast/nodes.rb', line 4095

def accept(visitor)
  visitor.visit_erb_strict_locals_node(self)
end

#child_nodesObject

: () -> Array



4100
4101
4102
# File 'lib/herb/ast/nodes.rb', line 4100

def child_nodes
  [*(locals || [])]
end

#compact_child_nodesObject

: () -> Array



4105
4106
4107
# File 'lib/herb/ast/nodes.rb', line 4105

def compact_child_nodes
  child_nodes.compact
end

#deserialized_prism_nodeObject

: () -> Prism::node?



4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
# File 'lib/herb/ast/nodes.rb', line 4067

def deserialized_prism_node
  prism_node = @prism_node
  return nil unless prism_node
  return nil unless source

  begin
    require "prism"
  rescue LoadError
    warn "The 'prism' gem is required to deserialize Prism nodes. Add it to your Gemfile or install it with: gem install prism"
    return nil
  end

  Prism.load(source, prism_node).value
end

#inspectObject

: () -> String



4110
4111
4112
# File 'lib/herb/ast/nodes.rb', line 4110

def inspect
  tree_inspect.rstrip.gsub(/\s+$/, "")
end

#to_hashObject

: () -> serialized_erb_strict_locals_node



4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
# File 'lib/herb/ast/nodes.rb', line 4083

def to_hash
  super.merge({
    tag_opening: tag_opening,
    content: content,
    tag_closing: tag_closing,
    analyzed_ruby: analyzed_ruby,
    prism_node: prism_node,
    locals: locals,
  }) #: Herb::serialized_erb_strict_locals_node
end

#tree_inspect(indent: 0, depth: 0, depth_limit: 10) ⇒ Object

: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String



4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
# File 'lib/herb/ast/nodes.rb', line 4115

def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
  output = +""

  output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
  output += "\n"

  if depth >= depth_limit
    output += dimmed("└── [depth limit reached ...]\n\n")

    return output.gsub(/^/, "    " * indent)
  end

  output += inspect_errors(prefix: "")

  output += white("├── tag_opening: ")
  output += tag_opening ? tag_opening.tree_inspect : magenta("")
  output += "\n"
  output += white("├── content: ")
  output += content ? content.tree_inspect : magenta("")
  output += "\n"
  output += white("├── tag_closing: ")
  output += tag_closing ? tag_closing.tree_inspect : magenta("")
  output += "\n"
  if prism_node && source
    output += white("├── prism_node: ")
    output += Herb::PrismInspect.inspect_prism_serialized(prism_node, source, "")
    output += "\n"
  end
  output += white("└── locals: ")
  output += inspect_array(locals, prefix: "    ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
  output += "\n"

  output.gsub(/^/, "    " * indent)
end