Commit 545bf78d authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Fix crash when auto-detecting anonymous function.

parent b373b507
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ module JsDuck
        make_class(to_s(var["id"]), var["right"])

      # function Foo() {}
      elsif function?(ast) && class_name?(to_s(ast["id"]))
      elsif function?(ast) && ast["id"] && class_name?(to_s(ast["id"]))
        make_class(to_s(ast["id"]))

      # { ... }
@@ -88,7 +88,7 @@ module JsDuck

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

      # foo = function() {}
      elsif exp && assignment?(exp) && function?(exp["right"])
+5 −1
Original line number Diff line number Diff line
@@ -90,10 +90,14 @@ describe JsDuck::Ast do
      detect("/** */ var foo = Ext.emptyFn").should == :method
    end

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

    it "anonymous function as parameter" do
      detect("doSomething('blah', /** */ function(){});").should == :method
    end

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