Class: XRay::JS::Rule::NoGlobalRule
- Inherits:
-
Object
- Object
- XRay::JS::Rule::NoGlobalRule
- Defined in:
- lib/js/rule/no_global.rb
Instance Method Summary collapse
- #visit_expr_assignment(expr) ⇒ Object
- #visit_function_declaration(fun) ⇒ Object
- #visit_function_name(name) ⇒ Object
- #visit_function_parameters(params) ⇒ Object
- #visit_stat_for(stat) ⇒ Object
- #visit_stat_var(stat) ⇒ Object
- #visit_stat_var_declaration(dec) ⇒ Object
Instance Method Details
#visit_expr_assignment(expr) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/js/rule/no_global.rb', line 45 def visit_expr_assignment(expr) if expr.type == '=' id = find_assignment_id(expr.left) if id && use_id_global?(id.text) ['禁止使用未定义的变量(或全局变量)', :error] end end end |
#visit_function_declaration(fun) ⇒ Object
40 41 42 43 |
# File 'lib/js/rule/no_global.rb', line 40 def visit_function_declaration(fun) @scope_index -= 1 nil end |
#visit_function_name(name) ⇒ Object
21 22 23 24 |
# File 'lib/js/rule/no_global.rb', line 21 def visit_function_name(name) current_scope << name.text ['不允许申明全局函数', :error] if @scope_index == 0 end |
#visit_function_parameters(params) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/js/rule/no_global.rb', line 26 def visit_function_parameters(params) @scope_index = (@scope_index || 0) + 1 scope = current_scope(true) params.each do |param| scope << param.text end nil end |
#visit_stat_for(stat) ⇒ Object
35 36 37 38 |
# File 'lib/js/rule/no_global.rb', line 35 def visit_stat_for(stat) first = stat.condition.first nil end |
#visit_stat_var(stat) ⇒ Object
9 10 11 12 13 |
# File 'lib/js/rule/no_global.rb', line 9 def visit_stat_var(stat) unless @scope_index > 0 ['不允许使用全局变量', :error] end end |
#visit_stat_var_declaration(dec) ⇒ Object
15 16 17 18 19 |
# File 'lib/js/rule/no_global.rb', line 15 def visit_stat_var_declaration(dec) scope = current_scope scope << dec.left.text nil end |