Commit aa441e47 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Move all event detection to Js::Event.

parent 76d86727
Loading
Loading
Loading
Loading
+2 −13
Original line number Diff line number Diff line
require "jsduck/js/method"
require "jsduck/js/event"
require "jsduck/js/node"
require "jsduck/tag_registry"

@@ -108,13 +109,8 @@ module JsDuck
        Js::Method.detect(ast, exp, var)
      end

      # this.fireEvent("foo", ...)
      def detect_event(ast, exp, var)
        if exp && exp.fire_event?
          make_event(exp["arguments"][0].to_value)
        else
          nil
        end
        Js::Event.detect(ast, exp, var)
      end

      def detect_property(ast, exp, var)
@@ -323,13 +319,6 @@ module JsDuck
        Js::Method.make(name, ast)
      end

      def make_event(name)
        return {
          :tagname => :event,
          :name => name,
        }
      end

      def make_property(name=nil, ast=nil, tagname=:property)
        return {
          :tagname => tagname,

lib/jsduck/js/event.rb

0 → 100644
+32 −0
Original line number Diff line number Diff line
require "jsduck/util/singleton"

module JsDuck
  module Js

    # Auto-detection of events.
    class Event
      include Util::Singleton

      # Checks if AST node is an event, and if so, returns doc-hash
      # with event name and various auto-detected properties.
      # When not an event returns nil.
      def detect(ast, exp, var)
        # this.fireEvent("foo", ...)
        if exp && exp.fire_event?
          make(exp["arguments"][0].to_value)
        else
          nil
        end
      end

      # Produces a doc-hash for an event.
      def make(name)
        return {
          :tagname => :event,
          :name => name,
        }
      end

    end
  end
end