Loading lib/jsduck/aggregator.rb +1 −1 Original line number Diff line number Diff line Loading @@ -232,7 +232,7 @@ module JsDuck # Loops through all enums and auto-detects their types if needed. def infer_enum_types @classes.each_value do |cls| if cls[:enum] && !cls[:type] if cls[:enum] && !cls[:enum][:type] Enum.infer_type(cls) end end Loading lib/jsduck/doc_ast.rb +9 −3 Original line number Diff line number Diff line Loading @@ -51,9 +51,7 @@ module JsDuck :singleton => !!doc_map[:singleton], :requires => detect_list(:requires, doc_map), :uses => detect_list(:uses, doc_map), # properties of enum-classes :enum => extract(doc_map, :class, :enum), :type => extract(doc_map, :class, :type), :enum => detect_enum(doc_map), }, doc_map) end Loading Loading @@ -279,6 +277,14 @@ module JsDuck end end def detect_enum(doc_map) return nil unless extract(doc_map, :class, :enum) return { :type => extract(doc_map, :class, :type) } end # Combines :doc-s of most tags # Ignores tags that have doc comment themselves and subproperty tags def detect_doc(docs) Loading lib/jsduck/enum.rb +2 −2 Original line number Diff line number Diff line Loading @@ -7,9 +7,9 @@ module JsDuck def self.infer_type(cls) if cls[:members][:property].length > 0 types = cls[:members][:property].map {|p| p[:type] } cls[:type] = types.sort.uniq.join("/") cls[:enum][:type] = types.sort.uniq.join("/") else cls[:type] = "Object" cls[:enum][:type] = "Object" file = cls[:files][0][:filename] line = cls[:files][0][:linenr] Logger.instance.warn(:enum, "Enum #{cls[:name]} defined without values in it", file, line) Loading spec/aggregator_enum_spec.rb +6 −6 Original line number Diff line number Diff line Loading @@ -13,14 +13,14 @@ describe JsDuck::Aggregator do it "creates class" do doc[:tagname].should == :class end it "sets :enum flag to true" do doc[:enum].should == true it "sets :enum field" do doc[:enum].should_not == nil end it "detects name" do doc[:name].should == "My.enum.Type" end it "detects type" do doc[:type].should == "String" doc[:enum][:type].should == "String" end it "detects no extends" do doc[:extends].should == nil Loading Loading @@ -113,7 +113,7 @@ describe JsDuck::Aggregator do end it "infers type from code" do doc[:type].should == 'String' doc[:enum][:type].should == 'String' end end Loading @@ -129,7 +129,7 @@ describe JsDuck::Aggregator do end it "defaults to Object type" do doc[:type].should == 'Object' doc[:enum][:type].should == 'Object' end end Loading @@ -149,7 +149,7 @@ describe JsDuck::Aggregator do end it "defaults to auto-generated type union" do doc[:type].should == 'Number/String' doc[:enum][:type].should == 'Number/String' end end Loading Loading
lib/jsduck/aggregator.rb +1 −1 Original line number Diff line number Diff line Loading @@ -232,7 +232,7 @@ module JsDuck # Loops through all enums and auto-detects their types if needed. def infer_enum_types @classes.each_value do |cls| if cls[:enum] && !cls[:type] if cls[:enum] && !cls[:enum][:type] Enum.infer_type(cls) end end Loading
lib/jsduck/doc_ast.rb +9 −3 Original line number Diff line number Diff line Loading @@ -51,9 +51,7 @@ module JsDuck :singleton => !!doc_map[:singleton], :requires => detect_list(:requires, doc_map), :uses => detect_list(:uses, doc_map), # properties of enum-classes :enum => extract(doc_map, :class, :enum), :type => extract(doc_map, :class, :type), :enum => detect_enum(doc_map), }, doc_map) end Loading Loading @@ -279,6 +277,14 @@ module JsDuck end end def detect_enum(doc_map) return nil unless extract(doc_map, :class, :enum) return { :type => extract(doc_map, :class, :type) } end # Combines :doc-s of most tags # Ignores tags that have doc comment themselves and subproperty tags def detect_doc(docs) Loading
lib/jsduck/enum.rb +2 −2 Original line number Diff line number Diff line Loading @@ -7,9 +7,9 @@ module JsDuck def self.infer_type(cls) if cls[:members][:property].length > 0 types = cls[:members][:property].map {|p| p[:type] } cls[:type] = types.sort.uniq.join("/") cls[:enum][:type] = types.sort.uniq.join("/") else cls[:type] = "Object" cls[:enum][:type] = "Object" file = cls[:files][0][:filename] line = cls[:files][0][:linenr] Logger.instance.warn(:enum, "Enum #{cls[:name]} defined without values in it", file, line) Loading
spec/aggregator_enum_spec.rb +6 −6 Original line number Diff line number Diff line Loading @@ -13,14 +13,14 @@ describe JsDuck::Aggregator do it "creates class" do doc[:tagname].should == :class end it "sets :enum flag to true" do doc[:enum].should == true it "sets :enum field" do doc[:enum].should_not == nil end it "detects name" do doc[:name].should == "My.enum.Type" end it "detects type" do doc[:type].should == "String" doc[:enum][:type].should == "String" end it "detects no extends" do doc[:extends].should == nil Loading Loading @@ -113,7 +113,7 @@ describe JsDuck::Aggregator do end it "infers type from code" do doc[:type].should == 'String' doc[:enum][:type].should == 'String' end end Loading @@ -129,7 +129,7 @@ describe JsDuck::Aggregator do end it "defaults to Object type" do doc[:type].should == 'Object' doc[:enum][:type].should == 'Object' end end Loading @@ -149,7 +149,7 @@ describe JsDuck::Aggregator do end it "defaults to auto-generated type union" do doc[:type].should == 'Number/String' doc[:enum][:type].should == 'Number/String' end end Loading