Module: ParseJS::AST::Scope
- Included in:
- FunctionDeclaration, FunctionExpression, Program
- Defined in:
- lib/parsejs/scope.rb
Instance Attribute Summary collapse
-
#child_scopes ⇒ Object
Returns the value of attribute child_scopes.
-
#parent_scope ⇒ Object
Returns the value of attribute parent_scope.
-
#parent_variables ⇒ Object
Returns the value of attribute parent_variables.
-
#scope_variables ⇒ Object
Returns the value of attribute scope_variables.
-
#variable_access ⇒ Object
Returns the value of attribute variable_access.
Instance Method Summary collapse
- #any_child_references_parent_variable?(name) ⇒ Boolean
-
#available_variable?(name) ⇒ Boolean
determine whether a variable can be added without causing damage to child scopes.
- #parent_variable?(name) ⇒ Boolean
-
#parent_variable_access?(name) ⇒ Boolean
determine whether there is a reference for a particular variable to a parent scope.
- #scope_variable?(name) ⇒ Boolean
- #variable?(name) ⇒ Boolean
- #variable_access?(name) ⇒ Boolean
- #variable_in_scope?(name) ⇒ Boolean
Instance Attribute Details
#child_scopes ⇒ Object
Returns the value of attribute child_scopes.
7 8 9 |
# File 'lib/parsejs/scope.rb', line 7 def child_scopes @child_scopes end |
#parent_scope ⇒ Object
Returns the value of attribute parent_scope.
7 8 9 |
# File 'lib/parsejs/scope.rb', line 7 def parent_scope @parent_scope end |
#parent_variables ⇒ Object
Returns the value of attribute parent_variables.
6 7 8 |
# File 'lib/parsejs/scope.rb', line 6 def parent_variables @parent_variables end |
#scope_variables ⇒ Object
Returns the value of attribute scope_variables.
6 7 8 |
# File 'lib/parsejs/scope.rb', line 6 def scope_variables @scope_variables end |
#variable_access ⇒ Object
Returns the value of attribute variable_access.
6 7 8 |
# File 'lib/parsejs/scope.rb', line 6 def variable_access @variable_access end |
Instance Method Details
#any_child_references_parent_variable?(name) ⇒ Boolean
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/parsejs/scope.rb', line 54 def any_child_references_parent_variable?(name) unless child_scopes.nil? # this should really check if all descendent scopes see a # scope variable before they see a parent refernce return false if child_scopes.all? { |s| s.scope_variable?(name) } child_scopes.any? do |s| s.parent_variable_access?(name) || s.parent_variable?(name) || s.any_child_references_parent_variable?(name) end end end |
#available_variable?(name) ⇒ Boolean
determine whether a variable can be added without causing damage to child scopes.
44 45 46 47 48 49 50 51 52 |
# File 'lib/parsejs/scope.rb', line 44 def available_variable?(name) # if the current scope is already using the variable, it's # unavailable. return false if variable?(name) # if any of the child scopes reference the variable as a # parent variable, it's not available. !any_child_references_parent_variable?(name) end |
#parent_variable?(name) ⇒ Boolean
22 23 24 |
# File 'lib/parsejs/scope.rb', line 22 def parent_variable?(name) parent_variables && parent_variables.include?(name) end |
#parent_variable_access?(name) ⇒ Boolean
determine whether there is a reference for a particular variable to a parent scope.
32 33 34 35 36 37 38 39 40 |
# File 'lib/parsejs/scope.rb', line 32 def parent_variable_access?(name) # if this scope has a "var x = 1" type of declaration for this name, # it is not referencing a parent scope. return false if scope_variable?(name) # otherwise, if there is a variable access for this name, it's # referencing a parent scope. variable_access?(name) end |
#scope_variable?(name) ⇒ Boolean
18 19 20 |
# File 'lib/parsejs/scope.rb', line 18 def scope_variable?(name) scope_variables && scope_variables.include?(name) end |
#variable?(name) ⇒ Boolean
14 15 16 |
# File 'lib/parsejs/scope.rb', line 14 def variable?(name) scope_variable?(name) || parent_variable?(name) || variable_access?(name) end |
#variable_access?(name) ⇒ Boolean
26 27 28 |
# File 'lib/parsejs/scope.rb', line 26 def variable_access?(name) variable_access && variable_access.include?(name) end |
#variable_in_scope?(name) ⇒ Boolean
9 10 11 12 |
# File 'lib/parsejs/scope.rb', line 9 def variable_in_scope?(name) return true if variable?(name) parent_scope && parent_scope.variable_in_scope?(name) end |