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

Detection of regexp return values.

parent c8c820aa
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -77,6 +77,8 @@ module JsDuck
        "Boolean"
      elsif string?(ast)
        "String"
      elsif regexp?(ast)
        "RegExp"
      else
        :other
      end
@@ -130,6 +132,10 @@ module JsDuck
      ast["type"] == "Literal" && ast["value"].is_a?(String)
    end

    def regexp?(ast)
      ast["type"] == "Literal" && ast["raw"] =~ /^\//
    end

    def control_flow?(ast)
      CONTROL_FLOW[ast["type"]]
    end
+6 −0
Original line number Diff line number Diff line
@@ -307,4 +307,10 @@ describe "JsDuck::FunctionAst#return_types" do
    end
  end

  describe "returns ['RegExp'] when function body" do
    it "returns a regex literal" do
      returns("/** */ function foo() { return /.*/; }").should == ["RegExp"]
    end
  end

end