Loading lib/jsduck/ast.rb +15 −0 Original line number Diff line number Diff line Loading @@ -106,6 +106,10 @@ module JsDuck elsif property?(ast) && function?(ast["value"]) make_method(key_value(ast["key"]), ast["value"]) # this.fireEvent("foo", ...) elsif exp && fire_event?(exp) make_event(to_value(exp["arguments"][0])) # foo = ... elsif exp && assignment?(exp) make_property(to_s(exp["left"]), exp["right"]) Loading Loading @@ -173,6 +177,10 @@ module JsDuck @ext_patterns.matches?(pattern, to_s(ast)) end def fire_event?(ast) call?(ast) && to_s(ast["callee"]) == "this.fireEvent" end def var?(ast) ast["type"] == "VariableDeclaration" end Loading Loading @@ -437,6 +445,13 @@ module JsDuck end end def make_event(name) return { :tagname => :event, :name => name, } end def make_property(name=nil, ast=nil, tagname=:property) return { :tagname => tagname, Loading spec/aggregator_event_spec.rb +31 −0 Original line number Diff line number Diff line Loading @@ -75,4 +75,35 @@ describe JsDuck::Aggregator do it_should_behave_like "event" end describe "implicit event name inside this.fireEvent()" do before do @doc = parse(<<-EOS)[0] /** * Fires when needed. */ this.fireEvent("mousedown", foo, 7); EOS end it_should_behave_like "event" end describe "doc-comment followed by this.fireEvent without event name" do before do @doc = parse(<<-EOS)[0] /** * Fires when needed. */ this.fireEvent(foo, 7); EOS end it "creates event" do @doc[:tagname].should == :event end it "leaves the name of event empty" do @doc[:name].should == "" end end end Loading
lib/jsduck/ast.rb +15 −0 Original line number Diff line number Diff line Loading @@ -106,6 +106,10 @@ module JsDuck elsif property?(ast) && function?(ast["value"]) make_method(key_value(ast["key"]), ast["value"]) # this.fireEvent("foo", ...) elsif exp && fire_event?(exp) make_event(to_value(exp["arguments"][0])) # foo = ... elsif exp && assignment?(exp) make_property(to_s(exp["left"]), exp["right"]) Loading Loading @@ -173,6 +177,10 @@ module JsDuck @ext_patterns.matches?(pattern, to_s(ast)) end def fire_event?(ast) call?(ast) && to_s(ast["callee"]) == "this.fireEvent" end def var?(ast) ast["type"] == "VariableDeclaration" end Loading Loading @@ -437,6 +445,13 @@ module JsDuck end end def make_event(name) return { :tagname => :event, :name => name, } end def make_property(name=nil, ast=nil, tagname=:property) return { :tagname => tagname, Loading
spec/aggregator_event_spec.rb +31 −0 Original line number Diff line number Diff line Loading @@ -75,4 +75,35 @@ describe JsDuck::Aggregator do it_should_behave_like "event" end describe "implicit event name inside this.fireEvent()" do before do @doc = parse(<<-EOS)[0] /** * Fires when needed. */ this.fireEvent("mousedown", foo, 7); EOS end it_should_behave_like "event" end describe "doc-comment followed by this.fireEvent without event name" do before do @doc = parse(<<-EOS)[0] /** * Fires when needed. */ this.fireEvent(foo, 7); EOS end it "creates event" do @doc[:tagname].should == :event end it "leaves the name of event empty" do @doc[:name].should == "" end end end