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

Handle anonymous functions in Ast#detect.

parent 7b940a9f
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -57,6 +57,10 @@ module JsDuck
      elsif var && var["init"] && function?(var["init"])
        make_method(to_s(var["id"]), var["init"])

      # (function() {})
      elsif exp && function?(exp)
        make_method(exp["id"] ? to_s(exp["id"]) : "", exp)

      # foo: function() {}
      elsif property?(ast) && function?(ast["value"])
        make_method(key_value(ast["key"]), ast["value"])
+4 −0
Original line number Diff line number Diff line
@@ -32,6 +32,10 @@ describe "JsDuck::Ast detects method with" do
      detect("/** */ var foo = Ext.emptyFn")[:name].should == "foo"
    end

    it "function expression with name" do
      detect("/** */ (function foo(){})")[:name].should == "foo"
    end

    it "object property initialized with function" do
      detect(<<-EOS)[:name].should == "foo"
        Foo = {
+5 −1
Original line number Diff line number Diff line
@@ -78,10 +78,14 @@ describe JsDuck::Ast do
      detect("/** */ var foo = function() {}").should == :method
    end

    it "vari initialized with Ext.emptyFn" do
    it "var initialized with Ext.emptyFn" do
      detect("/** */ var foo = Ext.emptyFn").should == :method
    end

    it "anonymous function" do
      detect("/** */ (function(){})").should == :method
    end

    it "object property initialized with function" do
      detect(<<-EOS).should == :method
        Foo = {