Loading lib/jsduck/doc_parser.rb +33 −24 Original line number Diff line number Diff line Loading @@ -189,29 +189,8 @@ module JsDuck match(/@param/) add_tag(:param) maybe_type skip_horiz_white if look(/\[/) match(/\[/) maybe_ident_chain(:name) skip_horiz_white if look(/=/) match(/=/) @current_tag[:default] = match(/[^\]]*/).strip end if look(/\]/) match(/\]/) @current_tag[:optional] = true end else maybe_ident_chain(:name) end skip_horiz_white if look(/\(optional\)/i) match(/\(optional\)/i) @current_tag[:optional] = true end maybe_name_with_default maybe_optional skip_white end Loading @@ -234,7 +213,8 @@ module JsDuck match(/@cfg/) add_tag(:cfg) maybe_type maybe_ident_chain(:name) maybe_name_with_default maybe_optional skip_white end Loading Loading @@ -365,6 +345,35 @@ module JsDuck end end # matches: <ident-chain> | "[" <ident-chain> [ "=" <default-value> ] "]" def maybe_name_with_default skip_horiz_white if look(/\[/) match(/\[/) maybe_ident_chain(:name) skip_horiz_white if look(/=/) match(/=/) @current_tag[:default] = match(/[^\]]*/).strip end if look(/\]/) match(/\]/) end @current_tag[:optional] = true else maybe_ident_chain(:name) end end # matches: "(optional)" def maybe_optional skip_horiz_white if look(/\(optional\)/i) match(/\(optional\)/i) @current_tag[:optional] = true end end # matches identifier name if possible and sets it on @current_tag def maybe_name skip_horiz_white Loading lib/jsduck/merger.rb +8 −0 Original line number Diff line number Diff line Loading @@ -164,6 +164,7 @@ module JsDuck :owner => detect_owner(doc_map) || owner, :type => detect_type(:cfg, doc_map, code), :doc => detect_doc(docs), :default => detect_default(:cfg, doc_map), :properties => detect_subproperties(docs, :cfg), }, doc_map) end Loading Loading @@ -271,6 +272,13 @@ module JsDuck end end def detect_default(tagname, doc_map) main_tag = doc_map[tagname] ? doc_map[tagname].first : {} if main_tag[:default] main_tag[:default] end end # for detecting mixins and alternateClassNames def detect_list(type, doc_map, code) if doc_map[type] Loading spec/aggregator_default_values_spec.rb +26 −0 Original line number Diff line number Diff line Loading @@ -117,4 +117,30 @@ describe JsDuck::Aggregator do end end describe "cfg with explicit default value" do before do @doc = parse(<<-EOS)[0] /** * @cfg {Number} [foo=128.6] Something */ EOS end it "has default value" do @doc[:default].should == "128.6" end end describe "cfg with explicit long default value" do before do @doc = parse(<<-EOS)[0] /** * @cfg {Number} [foo=/hmm.../] Something */ EOS end it "has default value" do @doc[:default].should == "/hmm.../" end end end Loading
lib/jsduck/doc_parser.rb +33 −24 Original line number Diff line number Diff line Loading @@ -189,29 +189,8 @@ module JsDuck match(/@param/) add_tag(:param) maybe_type skip_horiz_white if look(/\[/) match(/\[/) maybe_ident_chain(:name) skip_horiz_white if look(/=/) match(/=/) @current_tag[:default] = match(/[^\]]*/).strip end if look(/\]/) match(/\]/) @current_tag[:optional] = true end else maybe_ident_chain(:name) end skip_horiz_white if look(/\(optional\)/i) match(/\(optional\)/i) @current_tag[:optional] = true end maybe_name_with_default maybe_optional skip_white end Loading @@ -234,7 +213,8 @@ module JsDuck match(/@cfg/) add_tag(:cfg) maybe_type maybe_ident_chain(:name) maybe_name_with_default maybe_optional skip_white end Loading Loading @@ -365,6 +345,35 @@ module JsDuck end end # matches: <ident-chain> | "[" <ident-chain> [ "=" <default-value> ] "]" def maybe_name_with_default skip_horiz_white if look(/\[/) match(/\[/) maybe_ident_chain(:name) skip_horiz_white if look(/=/) match(/=/) @current_tag[:default] = match(/[^\]]*/).strip end if look(/\]/) match(/\]/) end @current_tag[:optional] = true else maybe_ident_chain(:name) end end # matches: "(optional)" def maybe_optional skip_horiz_white if look(/\(optional\)/i) match(/\(optional\)/i) @current_tag[:optional] = true end end # matches identifier name if possible and sets it on @current_tag def maybe_name skip_horiz_white Loading
lib/jsduck/merger.rb +8 −0 Original line number Diff line number Diff line Loading @@ -164,6 +164,7 @@ module JsDuck :owner => detect_owner(doc_map) || owner, :type => detect_type(:cfg, doc_map, code), :doc => detect_doc(docs), :default => detect_default(:cfg, doc_map), :properties => detect_subproperties(docs, :cfg), }, doc_map) end Loading Loading @@ -271,6 +272,13 @@ module JsDuck end end def detect_default(tagname, doc_map) main_tag = doc_map[tagname] ? doc_map[tagname].first : {} if main_tag[:default] main_tag[:default] end end # for detecting mixins and alternateClassNames def detect_list(type, doc_map, code) if doc_map[type] Loading
spec/aggregator_default_values_spec.rb +26 −0 Original line number Diff line number Diff line Loading @@ -117,4 +117,30 @@ describe JsDuck::Aggregator do end end describe "cfg with explicit default value" do before do @doc = parse(<<-EOS)[0] /** * @cfg {Number} [foo=128.6] Something */ EOS end it "has default value" do @doc[:default].should == "128.6" end end describe "cfg with explicit long default value" do before do @doc = parse(<<-EOS)[0] /** * @cfg {Number} [foo=/hmm.../] Something */ EOS end it "has default value" do @doc[:default].should == "/hmm.../" end end end