Loading lib/jsduck/aggregator.rb +3 −3 Original line number Diff line number Diff line Loading @@ -230,10 +230,10 @@ module JsDuck end # Loops through all enums and auto-detects their types if needed. def infer_enum_types def process_enums @classes.each_value do |cls| if cls[:enum] && !cls[:enum][:type] Enum.infer_type(cls) if cls[:enum] Enum.process(cls) end end end Loading lib/jsduck/app.rb +1 −1 Original line number Diff line number Diff line Loading @@ -125,7 +125,7 @@ module JsDuck agr.remove_ignored_classes agr.create_accessors agr.append_ext4_event_options agr.infer_enum_types agr.process_enums agr.result end Loading lib/jsduck/enum.rb +18 −2 Original line number Diff line number Diff line Loading @@ -3,16 +3,32 @@ require 'jsduck/logger' module JsDuck class Enum # Applies additional processing to enum-class. def self.process(cls) cls[:enum][:type] = self.infer_type(cls) unless cls[:enum][:type] self.unsure_public(cls) end private # Given an enum class, returns the type infered from its values. def self.infer_type(cls) if cls[:members][:property].length > 0 types = cls[:members][:property].map {|p| p[:type] } cls[:enum][:type] = types.sort.uniq.join("/") types.sort.uniq.join("/") else 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) "Object" end end # Ensures that enum values are all public. # For this we remove the auto-inserted inheritdoc tag. def self.unsure_public(cls) cls[:members][:property].each do |p| p[:inheritdoc] = nil if p[:autodetected] end end end Loading lib/jsduck/inherit_doc.rb +1 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ module JsDuck new_cfgs = [] cls.all_local_members.each do |member| if member[:inheritdoc] || member[:autodetected] if member[:inheritdoc] resolve(member, new_cfgs) end end Loading spec/aggregator_enum_spec.rb +22 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ describe JsDuck::Aggregator do def parse(string) agr = JsDuck::Aggregator.new agr.aggregate(JsDuck::SourceFile.new(string)) agr.infer_enum_types agr.process_enums agr.result end Loading Loading @@ -153,4 +153,25 @@ describe JsDuck::Aggregator do end end describe "enum two properties" do let(:doc) do parse(<<-EOS)[0] /** @enum */ My.enum.Type = { foo: "hello", /** @inheritdoc */ bar: 8 }; EOS end it "gets stripped from :inheritdoc tag in auto-detected property" do doc[:members][:property][0][:inheritdoc].should == nil end it "keeps the explicit :inheritdoc tag in doc-commented property" do doc[:members][:property][1][:inheritdoc].should_not == nil end end end Loading
lib/jsduck/aggregator.rb +3 −3 Original line number Diff line number Diff line Loading @@ -230,10 +230,10 @@ module JsDuck end # Loops through all enums and auto-detects their types if needed. def infer_enum_types def process_enums @classes.each_value do |cls| if cls[:enum] && !cls[:enum][:type] Enum.infer_type(cls) if cls[:enum] Enum.process(cls) end end end Loading
lib/jsduck/app.rb +1 −1 Original line number Diff line number Diff line Loading @@ -125,7 +125,7 @@ module JsDuck agr.remove_ignored_classes agr.create_accessors agr.append_ext4_event_options agr.infer_enum_types agr.process_enums agr.result end Loading
lib/jsduck/enum.rb +18 −2 Original line number Diff line number Diff line Loading @@ -3,16 +3,32 @@ require 'jsduck/logger' module JsDuck class Enum # Applies additional processing to enum-class. def self.process(cls) cls[:enum][:type] = self.infer_type(cls) unless cls[:enum][:type] self.unsure_public(cls) end private # Given an enum class, returns the type infered from its values. def self.infer_type(cls) if cls[:members][:property].length > 0 types = cls[:members][:property].map {|p| p[:type] } cls[:enum][:type] = types.sort.uniq.join("/") types.sort.uniq.join("/") else 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) "Object" end end # Ensures that enum values are all public. # For this we remove the auto-inserted inheritdoc tag. def self.unsure_public(cls) cls[:members][:property].each do |p| p[:inheritdoc] = nil if p[:autodetected] end end end Loading
lib/jsduck/inherit_doc.rb +1 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ module JsDuck new_cfgs = [] cls.all_local_members.each do |member| if member[:inheritdoc] || member[:autodetected] if member[:inheritdoc] resolve(member, new_cfgs) end end Loading
spec/aggregator_enum_spec.rb +22 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ describe JsDuck::Aggregator do def parse(string) agr = JsDuck::Aggregator.new agr.aggregate(JsDuck::SourceFile.new(string)) agr.infer_enum_types agr.process_enums agr.result end Loading Loading @@ -153,4 +153,25 @@ describe JsDuck::Aggregator do end end describe "enum two properties" do let(:doc) do parse(<<-EOS)[0] /** @enum */ My.enum.Type = { foo: "hello", /** @inheritdoc */ bar: 8 }; EOS end it "gets stripped from :inheritdoc tag in auto-detected property" do doc[:members][:property][0][:inheritdoc].should == nil end it "keeps the explicit :inheritdoc tag in doc-commented property" do doc[:members][:property][1][:inheritdoc].should_not == nil end end end