Loading lib/jsduck/doc_parser.rb +4 −0 Original line number Diff line number Diff line Loading @@ -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 Loading lib/jsduck/merger.rb +1 −0 Original line number Diff line number Diff line Loading @@ -319,6 +319,7 @@ module JsDuck :name => ex[:name] || im[:name] || "", :doc => doc, :optional => ex[:optional] || false, :default => ex[:default], :properties => ex[:properties] || [], } end Loading spec/aggregator_default_values_spec.rb +30 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
lib/jsduck/doc_parser.rb +4 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
lib/jsduck/merger.rb +1 −0 Original line number Diff line number Diff line Loading @@ -319,6 +319,7 @@ module JsDuck :name => ex[:name] || im[:name] || "", :doc => doc, :optional => ex[:optional] || false, :default => ex[:default], :properties => ex[:properties] || [], } end Loading
spec/aggregator_default_values_spec.rb +30 −0 Original line number Diff line number Diff line Loading @@ -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