Module: Minjs::ECMA262::UnaryOperation

Included in:
ExpBitwiseNot, ExpDelete, ExpLogicalNot, ExpNegative, ExpPositive, ExpPostDec, ExpPostInc, ExpPreDec, ExpPreInc, ExpTypeof, ExpVoid
Defined in:
lib/minjs/ecma262/expression.rb

Overview

Module of typically unary operation expression.

Typically unary operation expression has one values(val) and operation symbol.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#valObject (readonly)

Returns the value of attribute val.



132
133
134
# File 'lib/minjs/ecma262/expression.rb', line 132

def val
  @val
end

Instance Method Details

#==(obj) ⇒ Object

compare object



152
153
154
# File 'lib/minjs/ecma262/expression.rb', line 152

def ==(obj)
  self.class == obj.class and self.val == obj.val
end

#add_parenObject

add parenthesis if need



143
144
145
146
147
148
149
# File 'lib/minjs/ecma262/expression.rb', line 143

def add_paren
  if @val.priority > self.priority
    @val = ExpParen.new(@val)
  end

  self
end

#deep_dupObject

duplicate object

See Also:



158
159
160
# File 'lib/minjs/ecma262/expression.rb', line 158

def deep_dup
  self.class.new(@val.deep_dup)
end

#remove_parenObject

remove parenthesis if possible



135
136
137
138
139
140
# File 'lib/minjs/ecma262/expression.rb', line 135

def remove_paren
  if @val.kind_of? ExpParen and @val.val.priority <= self.priority
    @val = @val.val
  end
  self
end

#replace(from, to) ⇒ Object

Replaces children object.

See Also:



164
165
166
167
168
# File 'lib/minjs/ecma262/expression.rb', line 164

def replace(from, to)
  if @val .eql? from
    @val = to
  end
end

#side_effect?Boolean

Returns this element has side effect or not.

Returns:



185
186
187
# File 'lib/minjs/ecma262/expression.rb', line 185

def side_effect?
  @val.side_effect?
end

#to_js(options = {}) ⇒ Object

Returns a ECMAScript string containg the representation of element.

See Also:



179
180
181
# File 'lib/minjs/ecma262/expression.rb', line 179

def to_js(options = {})
  concat options, sym, @val
end

#traverse(parent) {|parent, _self| ... } ⇒ Object

Traverses this children and itself with given block.

Yields:

  • (parent, _self)

Yield Parameters:

See Also:



172
173
174
175
# File 'lib/minjs/ecma262/expression.rb', line 172

def traverse(parent, &block)
  @val.traverse(self, &block)
  yield parent, self
end