Loading lib/jsduck/doc_parser.rb +15 −4 Original line number Diff line number Diff line Loading @@ -371,7 +371,7 @@ module JsDuck end end # matches: <ident-chain> | "[" <ident-chain> [ "=" <literal> ] "]" # matches: <ident-chain> | "[" <ident-chain> [ "=" <default-value> ] "]" def maybe_name_with_default skip_horiz_white if look(/\[/) Loading @@ -381,7 +381,7 @@ module JsDuck if look(/=/) match(/=/) skip_horiz_white @current_tag[:default] = literal @current_tag[:default] = default_value end skip_horiz_white match(/\]/) Loading Loading @@ -425,9 +425,20 @@ module JsDuck end end def literal # attempts to match javascript literal, # when it fails grabs anything up to closing "]" def default_value start_pos = @input.pos lit = JsLiteralParser.new(@input).literal lit ? JsLiteralBuilder.new.to_s(lit) : nil if lit && look(/ *]/) # When lital matched and there's nothing after it up to the closing "]" JsLiteralBuilder.new.to_s(lit) else # Otherwise reset parsing position to where we started # and rescan up to "]" using simple regex. @input.pos = start_pos match(/[^\]]*/) end end # matches {...} and returns text inside brackets Loading spec/aggregator_default_values_spec.rb +23 −10 Original line number Diff line number Diff line Loading @@ -169,6 +169,19 @@ describe JsDuck::Aggregator do end end describe "cfg with this as default value" do before do @doc = parse(<<-EOS)[0] /** * @cfg {Number} [foo=this] Something */ EOS end it "has this as default value" do @doc[:default].should == 'this' end end describe "cfg with rubbish as default value" do before do @doc = parse(<<-EOS)[0] Loading @@ -177,8 +190,8 @@ describe JsDuck::Aggregator do */ EOS end it "has no default value" do @doc[:default].should == nil it "has the rubbish as default value" do @doc[:default].should == '!haa' end end Loading @@ -190,8 +203,8 @@ describe JsDuck::Aggregator do */ EOS end it "has a correct default value" do @doc[:default].should == '7' it "has everything up to ] as default value" do @doc[:default].should == '7 and me too' end end Loading @@ -203,8 +216,8 @@ describe JsDuck::Aggregator do */ EOS end it "has nil as default value" do @doc[:default].should == nil it "has everything up to ] as default value" do @doc[:default].should == '[ho, ho' end end Loading @@ -216,8 +229,8 @@ describe JsDuck::Aggregator do */ EOS end it "has nil as default value" do @doc[:default].should == nil it "has the bogus object literla as default value" do @doc[:default].should == '{ho:5, ho}' end end Loading @@ -229,8 +242,8 @@ describe JsDuck::Aggregator do */ EOS end it "has nil as default value" do @doc[:default].should == nil it "has the unfinish object literal as default value" do @doc[:default].should == '{ho:5' end end Loading Loading
lib/jsduck/doc_parser.rb +15 −4 Original line number Diff line number Diff line Loading @@ -371,7 +371,7 @@ module JsDuck end end # matches: <ident-chain> | "[" <ident-chain> [ "=" <literal> ] "]" # matches: <ident-chain> | "[" <ident-chain> [ "=" <default-value> ] "]" def maybe_name_with_default skip_horiz_white if look(/\[/) Loading @@ -381,7 +381,7 @@ module JsDuck if look(/=/) match(/=/) skip_horiz_white @current_tag[:default] = literal @current_tag[:default] = default_value end skip_horiz_white match(/\]/) Loading Loading @@ -425,9 +425,20 @@ module JsDuck end end def literal # attempts to match javascript literal, # when it fails grabs anything up to closing "]" def default_value start_pos = @input.pos lit = JsLiteralParser.new(@input).literal lit ? JsLiteralBuilder.new.to_s(lit) : nil if lit && look(/ *]/) # When lital matched and there's nothing after it up to the closing "]" JsLiteralBuilder.new.to_s(lit) else # Otherwise reset parsing position to where we started # and rescan up to "]" using simple regex. @input.pos = start_pos match(/[^\]]*/) end end # matches {...} and returns text inside brackets Loading
spec/aggregator_default_values_spec.rb +23 −10 Original line number Diff line number Diff line Loading @@ -169,6 +169,19 @@ describe JsDuck::Aggregator do end end describe "cfg with this as default value" do before do @doc = parse(<<-EOS)[0] /** * @cfg {Number} [foo=this] Something */ EOS end it "has this as default value" do @doc[:default].should == 'this' end end describe "cfg with rubbish as default value" do before do @doc = parse(<<-EOS)[0] Loading @@ -177,8 +190,8 @@ describe JsDuck::Aggregator do */ EOS end it "has no default value" do @doc[:default].should == nil it "has the rubbish as default value" do @doc[:default].should == '!haa' end end Loading @@ -190,8 +203,8 @@ describe JsDuck::Aggregator do */ EOS end it "has a correct default value" do @doc[:default].should == '7' it "has everything up to ] as default value" do @doc[:default].should == '7 and me too' end end Loading @@ -203,8 +216,8 @@ describe JsDuck::Aggregator do */ EOS end it "has nil as default value" do @doc[:default].should == nil it "has everything up to ] as default value" do @doc[:default].should == '[ho, ho' end end Loading @@ -216,8 +229,8 @@ describe JsDuck::Aggregator do */ EOS end it "has nil as default value" do @doc[:default].should == nil it "has the bogus object literla as default value" do @doc[:default].should == '{ho:5, ho}' end end Loading @@ -229,8 +242,8 @@ describe JsDuck::Aggregator do */ EOS end it "has nil as default value" do @doc[:default].should == nil it "has the unfinish object literal as default value" do @doc[:default].should == '{ho:5' end end Loading