Commit 121e8953 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Support for default param value syntax.

parent 2a256346
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -195,6 +195,10 @@ module JsDuck
        match(/\[/)
        maybe_ident_chain(:name)
        skip_horiz_white
        if look(/=/)
          match(/=/)
          @current_tag[:default] = match(/[^\]]*/).strip
        end
        if look(/\]/)
          match(/\]/)
          @current_tag[:optional] = true
+1 −0
Original line number Diff line number Diff line
@@ -319,6 +319,7 @@ module JsDuck
          :name => ex[:name] || im[:name] || "",
          :doc => doc,
          :optional => ex[:optional] || false,
          :default => ex[:default],
          :properties => ex[:properties] || [],
        }
      end
+30 −0
Original line number Diff line number Diff line
@@ -87,4 +87,34 @@ describe JsDuck::Aggregator do
    it_should_behave_like "optional parameter"
  end

  describe "parameter with explicit default value" do
    before do
      @param = parse(<<-EOS)[0][:params][0]
        /**
         * @param {Number} [foo=42] Something
         */
        function foo() {
      EOS
    end
    it_should_behave_like "optional parameter"
    it "has default value" do
      @param[:default].should == "42"
    end
  end

  describe "parameter with explicit long default value" do
    before do
      @param = parse(<<-EOS)[0][:params][0]
        /**
         * @param {Number} [foo="Hello, my dear!"] Something
         */
        function foo() {
      EOS
    end
    it_should_behave_like "optional parameter"
    it "has default value" do
      @param[:default].should == '"Hello, my dear!"'
    end
  end

end