Class: Minjs::ECMA262::ExpParen
- Inherits:
-
Expression
- Object
- Base
- Expression
- Minjs::ECMA262::ExpParen
- Defined in:
- lib/minjs/ecma262/expression.rb
Overview
Class of the Grouping operator expression element.
Instance Attribute Summary collapse
-
#val ⇒ Object
readonly
Returns the value of attribute val.
Attributes inherited from Base
Instance Method Summary collapse
-
#==(obj) ⇒ Object
compare object.
-
#add_paren ⇒ Object
add parenthesis if need.
-
#deep_dup ⇒ Object
duplicate object.
-
#ecma262_typeof ⇒ Symbol
return results of ‘typeof’ operator.
-
#initialize(val) ⇒ ExpParen
constructor
A new instance of ExpParen.
-
#left_hand_side_exp? ⇒ Boolean
True if expression is kind of LeftHandSideExpression.
-
#priority ⇒ Fixnum
Expression priority.
-
#remove_paren ⇒ Object
remove parenthesis if possible.
-
#remove_paren? ⇒ Boolean
returns removing parenthesis is possible or not.
-
#replace(from, to) ⇒ Object
Replaces children object.
-
#to_ecma262_boolean ⇒ Boolean
Returns results of ToBoolean().
-
#to_js(options = {}) ⇒ Object
Returns a ECMAScript string containg the representation of element.
-
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
Methods inherited from Expression
Methods inherited from Base
Constructor Details
#initialize(val) ⇒ ExpParen
Returns a new instance of ExpParen.
324 325 326 |
# File 'lib/minjs/ecma262/expression.rb', line 324 def initialize(val) @val = val end |
Instance Attribute Details
#val ⇒ Object (readonly)
Returns the value of attribute val.
322 323 324 |
# File 'lib/minjs/ecma262/expression.rb', line 322 def val @val end |
Instance Method Details
#==(obj) ⇒ Object
compare object
355 356 357 |
# File 'lib/minjs/ecma262/expression.rb', line 355 def ==(obj) self.class == obj.class and @val == obj.val end |
#add_paren ⇒ Object
add parenthesis if need
395 396 397 |
# File 'lib/minjs/ecma262/expression.rb', line 395 def add_paren self end |
#deep_dup ⇒ Object
duplicate object
335 336 337 |
# File 'lib/minjs/ecma262/expression.rb', line 335 def deep_dup self.class.new(@val.deep_dup) end |
#ecma262_typeof ⇒ Symbol
return results of ‘typeof’ operator.
416 417 418 419 420 421 422 |
# File 'lib/minjs/ecma262/expression.rb', line 416 def ecma262_typeof if @val.respond_to? :ecma262_typeof @val.ecma262_typeof else nil end end |
#left_hand_side_exp? ⇒ Boolean
Returns true if expression is kind of LeftHandSideExpression.
366 367 368 |
# File 'lib/minjs/ecma262/expression.rb', line 366 def left_hand_side_exp? true end |
#priority ⇒ Fixnum
Returns expression priority.
329 330 331 |
# File 'lib/minjs/ecma262/expression.rb', line 329 def priority PRIORITY_PRIMARY end |
#remove_paren ⇒ Object
remove parenthesis if possible
387 388 389 390 391 392 |
# File 'lib/minjs/ecma262/expression.rb', line 387 def remove_paren if @val.kind_of? ExpParen @val = @val.val if @val.remove_paren? end self end |
#remove_paren? ⇒ Boolean
returns removing parenthesis is possible or not
ECMA262 expression-statement should not start with “function” or “{”. This method checks inner of the parenthesis’ first literal.
377 378 379 380 381 382 383 384 |
# File 'lib/minjs/ecma262/expression.rb', line 377 def remove_paren? js = @val.to_js if js.match(/^function/) or js.match(/^{/) false else true end end |
#replace(from, to) ⇒ Object
Replaces children object.
341 342 343 344 345 |
# File 'lib/minjs/ecma262/expression.rb', line 341 def replace(from, to) if @val .eql? from @val = to end end |
#to_ecma262_boolean ⇒ Boolean
Returns results of ToBoolean()
Returns true or false if trivial, otherwise nil.
407 408 409 410 411 |
# File 'lib/minjs/ecma262/expression.rb', line 407 def to_ecma262_boolean return nil unless @val.respond_to? :to_ecma262_boolean return nil if @val.to_ecma262_boolean.nil? @val.to_ecma262_boolean end |
#to_js(options = {}) ⇒ Object
Returns a ECMAScript string containg the representation of element.
361 362 363 |
# File 'lib/minjs/ecma262/expression.rb', line 361 def to_js( = {}) "(#{@val.to_js()})" end |
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
349 350 351 352 |
# File 'lib/minjs/ecma262/expression.rb', line 349 def traverse(parent, &block) @val.traverse(self, &block) yield parent, self end |