Class: Minjs::ECMA262::StForInVar
- Defined in:
- lib/minjs/ecma262/statement.rb
Overview
Base class of ECMA262 ‘for(var in)’ IterationStatement element.
Instance Attribute Summary collapse
-
#exp2 ⇒ Object
readonly
Returns the value of attribute exp2.
-
#statement ⇒ Object
readonly
Returns the value of attribute statement.
-
#var_decl ⇒ Object
readonly
Returns the value of attribute var_decl.
-
#var_env ⇒ Object
readonly
Returns the value of attribute var_env.
Attributes inherited from Base
Instance Method Summary collapse
-
#==(obj) ⇒ Object
compare object.
-
#add_paren ⇒ Object
add parenthesis if need.
-
#deep_dup ⇒ Object
duplicate object.
-
#initialize(var_env, var_decl, exp2, statement) ⇒ StForInVar
constructor
A new instance of StForInVar.
-
#remove_paren ⇒ Object
remove parenthesis if possible.
-
#replace(from, to) ⇒ Object
Replaces children object.
-
#to_js(options = {}) ⇒ Object
Returns a ECMAScript string containg the representation of element.
-
#to_st_for_in ⇒ Object
converts for-in-var-statement to for-var-statement.
-
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
Methods inherited from Statement
#empty?, #priority, #to_exp?, #to_return?
Methods inherited from Base
Constructor Details
#initialize(var_env, var_decl, exp2, statement) ⇒ StForInVar
Returns a new instance of StForInVar.
918 919 920 921 922 923 |
# File 'lib/minjs/ecma262/statement.rb', line 918 def initialize(var_env, var_decl, exp2, statement) @var_env = var_env @var_decl = var_decl @exp2 = exp2 @statement = statement end |
Instance Attribute Details
#exp2 ⇒ Object (readonly)
Returns the value of attribute exp2.
916 917 918 |
# File 'lib/minjs/ecma262/statement.rb', line 916 def exp2 @exp2 end |
#statement ⇒ Object (readonly)
Returns the value of attribute statement.
916 917 918 |
# File 'lib/minjs/ecma262/statement.rb', line 916 def statement @statement end |
#var_decl ⇒ Object (readonly)
Returns the value of attribute var_decl.
916 917 918 |
# File 'lib/minjs/ecma262/statement.rb', line 916 def var_decl @var_decl end |
#var_env ⇒ Object (readonly)
Returns the value of attribute var_env.
915 916 917 |
# File 'lib/minjs/ecma262/statement.rb', line 915 def var_env @var_env end |
Instance Method Details
#==(obj) ⇒ Object
compare object
962 963 964 965 966 967 |
# File 'lib/minjs/ecma262/statement.rb', line 962 def ==(obj) self.class == obj.class and @var_decl == obj.var_decl and @exp2 == obj.exp2 and @statement == obj.statement end |
#add_paren ⇒ Object
add parenthesis if need
999 1000 1001 |
# File 'lib/minjs/ecma262/statement.rb', line 999 def add_paren self end |
#deep_dup ⇒ Object
duplicate object
927 928 929 930 931 932 |
# File 'lib/minjs/ecma262/statement.rb', line 927 def deep_dup self.class.new(@var_env, [@var_decl[0].deep_dup, @var_decl[1] ? @var_decl[1].deep_dup : nil], @exp2.deep_dup, @statement.deep_dup) end |
#remove_paren ⇒ Object
remove parenthesis if possible
988 989 990 991 992 993 994 995 996 |
# File 'lib/minjs/ecma262/statement.rb', line 988 def remove_paren if @var_decl[1] and @var_decl[1].kind_of? ExpParen @var_decl[1] = @var_decl[1].val end if @exp2.kind_of? ExpParen @exp2 = @exp2.val end self end |
#replace(from, to) ⇒ Object
Replaces children object.
945 946 947 948 949 |
# File 'lib/minjs/ecma262/statement.rb', line 945 def replace(from, to) if from .eql? @statement @statement = to end end |
#to_js(options = {}) ⇒ Object
Returns a ECMAScript string containg the representation of element.
971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 |
# File 'lib/minjs/ecma262/statement.rb', line 971 def to_js( = {}) if @statement.kind_of? StBlock and @statement.statement_list.length == 1 statement = @statement.statement_list.statement_list[0] else statement = @statement end if @var_decl[1] #with initialiser _var_decl = concat(, @var_decl[0], '=', @var_decl[1]) else _var_decl = concat(, @var_decl[0]) end concat , :for, "(", :var, _var_decl, :in, @exp2, ")", statement end |
#to_st_for_in ⇒ Object
converts for-in-var-statement to for-var-statement
952 953 954 955 956 957 958 959 |
# File 'lib/minjs/ecma262/statement.rb', line 952 def to_st_for_in if @var_decl[1] t = ExpAssign.new(@var_decl[0], @var_decl[1]) else t = @var_decl[0] end StForIn.new(t, @exp2, @statement) end |
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
935 936 937 938 939 940 941 |
# File 'lib/minjs/ecma262/statement.rb', line 935 def traverse(parent, &block) @var_decl[0].traverse(self, &block) @var_decl[1].traverse(self, &block) if @var_decl[1] @exp2.traverse(self, &block) @statement.traverse(self, &block) yield parent, self end |