class JsDuck::Js::Fires
Looks the AST of a FunctionDeclaration or FunctionExpression for uses of this.fireEvent().
Public Instance Methods
detect(function_node)
click to toggle source
Returns
array of event names fired by the given function. When no events fired, empty array is returned.
# File lib/jsduck/js/fires.rb, line 14 def detect(function_node) @traverser = Js::ScopedTraverser.new events = [] @traverser.traverse(function_node["body"]) do |node| if fire_event?(node) events << node["arguments"][0].to_value end end events.sort.uniq end
Private Instance Methods
fire_event?(node)
click to toggle source
True when node is this.fireEvent(“name”) call. Also true for me.fireEvent() when me == this.
# File lib/jsduck/js/fires.rb, line 31 def fire_event?(node) node.call_expression? && node["callee"].member_expression? && @traverser.this?(node["callee"]["object"].to_s) && node["callee"]["property"].to_s == "fireEvent" && node["arguments"].length > 0 && node["arguments"][0].value_type == "String" end