Commit 3d61313f authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Support for default value detection in Ast class.

parent 7f16c452
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -218,7 +218,8 @@ module JsDuck
      return {
        :tagname => :property,
        :name => name,
        :type => make_value_type(ast)
        :type => make_value_type(ast),
        :default => ast ? to_s(ast) : nil,
      }
    end

+19 −1
Original line number Diff line number Diff line
@@ -85,10 +85,28 @@ describe "JsDuck::Ast detects property with" do
    end
  end

  describe "no value type in" do
  describe "no type in" do
    it "uninitialized var declaration" do
      detect("/** */ var foo;")[:type].should == nil
    end
  end

  describe "default value in" do
    it "var initialization with string" do
      detect("/** */ var foo = 'bar';")[:default].should == "'bar'"
    end

    it "assignment with number" do
      detect("/** */ foo = 15;")[:default].should == "15"
    end

    it "assignment with object" do
      detect("/** */ foo = {bar: 5};")[:default].should == "{bar: 5}"
    end

    it "object property with array" do
      detect("X = { /** */ foo: [1, 2, 3] };")[:default].should == "[1, 2, 3]"
    end
  end

end