diff --git a/lib/jsduck/accessors.rb b/lib/jsduck/accessors.rb index 4a84ebddb08d96c0b6b5aff70514dc6f64e70a23..ed25418312b5dc3dacdef654bf42e9629061cf05 100644 --- a/lib/jsduck/accessors.rb +++ b/lib/jsduck/accessors.rb @@ -9,37 +9,39 @@ module JsDuck # not added. def create(cls) # Grab all configs tagged as @accessor - accessors = cls[:members][:cfg].find_all {|cfg| cfg[:accessor] } + accessors = cls[:members].find_all {|m| m[:tagname] == :cfg && m[:accessor] } # Build lookup tables of method and event names - methods = build_lookup_table(cls[:members][:method]) - events = build_lookup_table(cls[:members][:event]) + methods = build_lookup_table(cls[:members], :method) + events = build_lookup_table(cls[:members], :event) accessors.each do |cfg| # add getter if no method with same name exists get = create_getter(cfg) if !methods[get[:name]] - cls[:members][:method] << get + cls[:members] << get end # add setter if no method with same name exists set = create_setter(cfg) if !methods[set[:name]] - cls[:members][:method] << set + cls[:members] << set end # for evented accessors if cfg[:evented] # add event if no event with same name exists ev = create_event(cfg) if !events[ev[:name]] - cls[:members][:event] << ev + cls[:members] << ev end end end end - def build_lookup_table(members) + def build_lookup_table(members, tagname) map = {} - members.each {|m| map[m[:name]] = m } + members.each do |m| + map[m[:name]] = m if m[:tagname] == tagname + end map end diff --git a/lib/jsduck/aggregator.rb b/lib/jsduck/aggregator.rb index b98b37e9f836f639e31dbf828d3b59b17cda33ad..6ef844d25147c5fad397398b05fac38310a90263 100644 --- a/lib/jsduck/aggregator.rb +++ b/lib/jsduck/aggregator.rb @@ -106,8 +106,7 @@ module JsDuck end old[:doc] = old[:doc].length > 0 ? old[:doc] : new[:doc] # Additionally the doc-comment can contain configs and constructor - old[:members][:cfg] += new[:members][:cfg] - old[:members][:method] += new[:members][:method] + old[:members] += new[:members] end # Tries to place members into classes where they belong. @@ -138,7 +137,7 @@ module JsDuck end def add_to_class(cls, member) - cls[member[:meta][:static] ? :statics : :members][member[:tagname]] << member + cls[:members] << member end def add_orphan(node) @@ -188,8 +187,7 @@ module JsDuck :doc => doc, :mixins => [], :alternateClassNames => [], - :members => Class.default_members_hash, - :statics => Class.default_members_hash, + :members => [], :aliases => {}, :meta => {}, :files => [{:filename => "", :linenr => 0, :href => ""}], @@ -215,7 +213,9 @@ module JsDuck :doc => "The options object passed to {@link Ext.util.Observable#addListener}." } @classes.each_value do |cls| - cls[:members][:event].each {|e| e[:params] << options } + cls[:members].each do |m| + m[:params] << options if m[:tagname] == :event + end end end diff --git a/lib/jsduck/ast.rb b/lib/jsduck/ast.rb index 2a63cf48aeed126b0cbd6f10bf1a99f54390290d..a749674fb90f7a4a2e87dad4c9398d2dab93b608 100644 --- a/lib/jsduck/ast.rb +++ b/lib/jsduck/ast.rb @@ -224,7 +224,6 @@ module JsDuck cls[:mixins] = [] cls[:aliases] = [] cls[:members] = [] - cls[:statics] = [] cls[:code_type] = :ext_define each_pair_in_object_expression(ast["arguments"][1]) do |key, value, pair| @@ -254,9 +253,9 @@ module JsDuck when "eventedConfig" cls[:members] += make_configs(value, {:accessor => true, :evented => true}) when "statics" - cls[:statics] += make_statics(value) + cls[:members] += make_statics(value) when "inheritableStatics" - cls[:statics] += make_statics(value, {:inheritable => true}) + cls[:members] += make_statics(value, {:inheritable => true}) else detect_method_or_property(cls, key, value, pair) end diff --git a/lib/jsduck/class.rb b/lib/jsduck/class.rb index a48c92ca4eb31e1b318584810b3735dede35aafd..6e02694b039811ea830400f4de01e3f13f50e7c3 100644 --- a/lib/jsduck/class.rb +++ b/lib/jsduck/class.rb @@ -18,8 +18,8 @@ module JsDuck # differenciating between existing and missing classes. @doc[:name] = ClassNameString.new(@doc[:name], class_exists) - @doc[:members] = Class.default_members_hash if !@doc[:members] - @doc[:statics] = Class.default_members_hash if !@doc[:statics] + @doc[:members] = [] if !@doc[:members] + @relations = nil end @@ -121,7 +121,7 @@ module JsDuck # # See members_hash for details. def members(type, context=:members) - ms = members_hash(type, context).values #.find_all {|m| !m[:private] } + ms = members_hash(type, context).values ms.sort! {|a,b| a[:name] <=> b[:name] } type == :method ? constructor_first(ms) : ms end @@ -147,10 +147,12 @@ module JsDuck # Singletons have no static members if @doc[:singleton] && context == :statics # Warn if singleton has static members - @doc[context][type].each do |m| - ctx = m[:files][0] - msg = "Singleton class #{@doc[:name]} can't have static members, remove the @static tag." - Logger.instance.warn(:sing_static, msg, ctx[:filename], ctx[:linenr]) + @doc[:members].each do |m| + if m[:meta] && m[:meta][:static] + ctx = m[:files][0] + msg = "Singleton class #{@doc[:name]} can't have static members, remove the @static tag." + Logger.instance.warn(:sing_static, msg, ctx[:filename], ctx[:linenr]) + end end return {} end @@ -172,7 +174,7 @@ module JsDuck # instance members. Otherwise they will be completely excluded # from the docs, as the static members block is not created for # singletons. - if @doc[:singleton] && @doc[:statics][type].length > 0 + if @doc[:singleton] merge!(ms, local_members_hash(type, :statics)) end @@ -230,10 +232,16 @@ module JsDuck # Helper method to get the direct members of this class def local_members_hash(type, context) + is_static = (context == :statics) local_members = {} - (@doc[context][type] || []).each do |m| + + @doc[:members].find_all do |m| + static = (m[:meta] || {})[:static] || false + m[:tagname] == type && static == is_static + end.each do |m| local_members[m[:name]] = m end + local_members end @@ -250,12 +258,8 @@ module JsDuck # build hash of all members unless @members_map @members_map = {} - [:members, :statics].each do |group| - @doc[group].each_key do |type| - members_hash(type, group).each_pair do |key, member| - @members_map[key] = (@members_map[key] || []) + [member] - end - end + all_members.each do |m| + @members_map[m[:name]] = (@members_map[m[:name]] || []) + [m] end end @@ -275,23 +279,16 @@ module JsDuck # Returns all members of class, including the inherited and mixed in ones def all_members all = [] - [:members, :statics].each do |group| - @doc[group].each_key do |type| - all += members(type, group) - end + [:cfg, :property, :method, :event, :css_mixin, :css_var].each do |type| + all += members(type, :members) + all += members(type, :statics) end all end # Returns all local members of class def all_local_members - all = [] - [:members, :statics].each do |group| - @doc[group].each_value do |ms| - all += ms - end - end - all + @doc[:members] end # A way to access full class name with similar syntax to diff --git a/lib/jsduck/class_doc_expander.rb b/lib/jsduck/class_doc_expander.rb index 6aec146e69df3b2b81c7054bfda9df5619e60e47..4495a6f51ca331d3ace692b6032d8334bd9e06a3 100644 --- a/lib/jsduck/class_doc_expander.rb +++ b/lib/jsduck/class_doc_expander.rb @@ -107,14 +107,9 @@ module JsDuck results = [] if docset[:code] - (docset[:code][:members] || []).each do |m| results << code_to_docset(m) unless @constructor_found && m[:name] == "constructor" end - - (docset[:code][:statics] || []).each do |m| - results << code_to_docset(m) - end end results diff --git a/lib/jsduck/class_formatter.rb b/lib/jsduck/class_formatter.rb index 43c5e310f07ca900cb725173b15f803f2dc06b8e..e2eb3da00dbef8864776d8f51cf2e0cc1eef5b52 100644 --- a/lib/jsduck/class_formatter.rb +++ b/lib/jsduck/class_formatter.rb @@ -25,12 +25,8 @@ module JsDuck @formatter.class_context = cls[:name] @formatter.doc_context = cls[:files][0] cls[:doc] = @formatter.format(cls[:doc]) if cls[:doc] - [:members, :statics].each do |group| - cls[group].each_pair do |type, members| - # format all members (except hidden ones) - cls[group][type] = members.map {|m| m[:meta][:hide] ? m : format_member(m) } - end - end + # format all members (except hidden ones) + cls[:members] = cls[:members].map {|m| m[:meta][:hide] ? m : format_member(m) } cls[:html_meta] = format_meta_data(cls) cls end diff --git a/lib/jsduck/enum.rb b/lib/jsduck/enum.rb index 60415f493f5dbfbbe89d166d077c4728ab572744..91c53653a2e4a24ab42bafef8a2871a812114475 100644 --- a/lib/jsduck/enum.rb +++ b/lib/jsduck/enum.rb @@ -25,8 +25,8 @@ module JsDuck # Given an enum class, returns the type infered from its values. def infer_type(cls) - if cls[:members][:property].length > 0 - types = cls[:members][:property].map {|p| p[:type] } + if cls[:members].length > 0 + types = cls[:members].map {|p| p[:type] } types.sort.uniq.join("/") else "Object" @@ -37,7 +37,7 @@ module JsDuck def expand_default(cls) if cls[:enum][:default] =~ /\A(.*)\.\*\Z/ each_alias($1) do |name, owner| - cls[:members][:property] << { + cls[:members] << { :tagname => :property, :id => 'property-' + name, :name => name, @@ -64,7 +64,7 @@ module JsDuck # Remove the auto-inserted inheritdoc tag so the auto-detected enum # values default to being public. def strip_inheritdoc(cls) - cls[:members][:property].each do |p| + cls[:members].each do |p| p[:inheritdoc] = nil if p[:autodetected] end end diff --git a/lib/jsduck/full_exporter.rb b/lib/jsduck/full_exporter.rb index ab921f382943a0f6004df6e90ac4e00f5b6d6306..b646e1aa8dcbd8bf209467c9467bb7ad6aeea787 100644 --- a/lib/jsduck/full_exporter.rb +++ b/lib/jsduck/full_exporter.rb @@ -13,6 +13,7 @@ module JsDuck def export(cls) h = cls.to_hash h[:members] = {} + h[:statics] = {} Class.default_members_hash.each_key do |key| h[:members][key] = cls.members(key) h[:statics][key] = cls.members(key, :statics) diff --git a/lib/jsduck/inherit_doc.rb b/lib/jsduck/inherit_doc.rb index 7cc4d0f0eab09fd128a5cf8fa5d006da2005ed58..1119d74b8cdf8710cdbabdf808d060cc1a6fb66e 100644 --- a/lib/jsduck/inherit_doc.rb +++ b/lib/jsduck/inherit_doc.rb @@ -20,7 +20,7 @@ module JsDuck resolve(member, new_cfgs) end end - move_cfgs(cls, new_cfgs) + move_cfgs(cls, new_cfgs) if new_cfgs.length > 0 end end @@ -52,8 +52,6 @@ module JsDuck def move_cfgs(cls, members) members.each do |m| m[:tagname] = :cfg - cls[:members][:property].delete(m) - cls[:members][:cfg] << m end # The members lookup table inside class is no more valid, so # reset it. diff --git a/lib/jsduck/merger.rb b/lib/jsduck/merger.rb index 26228494aaaddcb9998bceab0a821408864a2a94..9300324298626ec3bc5da64f827e06b3c1b23963 100644 --- a/lib/jsduck/merger.rb +++ b/lib/jsduck/merger.rb @@ -48,8 +48,7 @@ module JsDuck # Used by Aggregator to determine if we're dealing with Ext4 code h[:code_type] = code[:code_type] if code[:code_type] - h[:members] = Class.default_members_hash - h[:statics] = Class.default_members_hash + h[:members] = [] h end diff --git a/lib/jsduck/override.rb b/lib/jsduck/override.rb index 18e67330b38eff6f0615e2ac9635cd347c7e99a8..071a9e64c7dc919d52de84f7bce18fdf31d001d0 100644 --- a/lib/jsduck/override.rb +++ b/lib/jsduck/override.rb @@ -68,15 +68,11 @@ module JsDuck # helpers def each_member(cls) - [:members, :statics].each do |category| - cls[category].each_pair do |key, members| - members.each {|m| yield m } - end - end + cls[:members].each {|m| yield m } end def add_member(cls, m) - cls[m[:static] ? :statics : :members][m[:tagname]] << m + cls[:members] << m end def add_doc(m, doc) diff --git a/lib/jsduck/search_data.rb b/lib/jsduck/search_data.rb index 6eb9399d43e2e1a96bf7b5eeb6b8719a45ed37bd..e34404a6c74604360440f722faa58b7463792ccb 100644 --- a/lib/jsduck/search_data.rb +++ b/lib/jsduck/search_data.rb @@ -22,15 +22,9 @@ module JsDuck end end - [:members, :statics].each do |group| - cls[group].each_key do |type| - cls.members(type, group).each do |m| - # skip inherited items and constructors - if m[:owner] == cls.full_name && m[:name] != cls.short_name - list << member_node(m, cls) - end - end - end + # add all local members, but skip constructors + cls[:members].each do |m| + list << member_node(m, cls) unless m[:name] == cls.short_name end end diff --git a/lib/jsduck/source_file.rb b/lib/jsduck/source_file.rb index ed64b00c4ad4cdc78bd5e88702ace56118c2c75e..45d52d8ee1dc3c47ec737f68d4292adbe2078b5d 100644 --- a/lib/jsduck/source_file.rb +++ b/lib/jsduck/source_file.rb @@ -86,8 +86,7 @@ module JsDuck @links[linenr] << {:doc => doc, :file => file} doc[:files] = [file] if doc[:tagname] == :class - doc[:members][:cfg].each {|cfg| link(linenr, cfg) } - doc[:members][:method].each {|method| link(linenr, method) } + doc[:members].each {|m| link(linenr, m) } end doc end diff --git a/spec/aggregator_accessors_spec.rb b/spec/aggregator_accessors_spec.rb index fb83ceef7b974c19b4aae7a722c52ae00c2e6322..b9d73a272a31bdd33dc74cb5df68f31b2451da1d 100644 --- a/spec/aggregator_accessors_spec.rb +++ b/spec/aggregator_accessors_spec.rb @@ -19,54 +19,54 @@ describe JsDuck::Aggregator do * @accessor */ EOF - @methods = {} - @docs[0][:members][:method].each do |m| - @methods[m[:name]] = m + @members = {} + @docs[0][:members].each do |m| + @members[m[:name]] = m end end it "creates getFoo method" do - @methods.should have_key("getFoo") + @members.should have_key("getFoo") end it "sets getFoo return type to @cfg type" do - @methods["getFoo"][:return][:type].should == "String" + @members["getFoo"][:return][:type].should == "String" end it "sets getFoo to have 0 parameters" do - @methods["getFoo"][:params].length.should == 0 + @members["getFoo"][:params].length.should == 0 end it "sets getFoo owner @cfg owner" do - @methods["getFoo"][:owner].should == "MyClass" + @members["getFoo"][:owner].should == "MyClass" end it "generates dummy docs for getFoo" do - @methods["getFoo"][:doc].should == "Returns the value of {@link #cfg-foo}." + @members["getFoo"][:doc].should == "Returns the value of {@link #cfg-foo}." end it "creates setFoo method" do - @methods.should have_key("setFoo") + @members.should have_key("setFoo") end it "sets setFoo return type to undefined" do - @methods["setFoo"][:return][:type].should == "undefined" + @members["setFoo"][:return][:type].should == "undefined" end it "sets setFoo parameter type to @cfg type" do - @methods["setFoo"][:params][0][:type].should == "String" + @members["setFoo"][:params][0][:type].should == "String" end it "sets setFoo parameter name to @cfg name" do - @methods["setFoo"][:params][0][:name].should == "foo" + @members["setFoo"][:params][0][:name].should == "foo" end it "sets setFoo owner @cfg owner" do - @methods["setFoo"][:owner].should == "MyClass" + @members["setFoo"][:owner].should == "MyClass" end it "generates dummy docs for setFoo" do - @methods["setFoo"][:doc].should == "Sets the value of {@link #cfg-foo}." + @members["setFoo"][:doc].should == "Sets the value of {@link #cfg-foo}." end end @@ -94,26 +94,26 @@ describe JsDuck::Aggregator do * Custom comment. */ EOF - @methods = {} - @docs[0][:members][:method].each do |m| - @methods[m[:name]] = m + @members = {} + @docs[0][:members].each do |m| + @members[m[:name]] = m end end it "doesn't create getter when method already present" do - @methods["getFoo"][:doc].should == "Custom comment." + @members["getFoo"][:doc].should == "Custom comment." end it "doesn't create setter when method already present" do - @methods["setBar"][:doc].should == "Custom comment." + @members["setBar"][:doc].should == "Custom comment." end it "creates getter when method not present" do - @methods.should have_key("getBar") + @members.should have_key("getBar") end it "creates setter when method not present" do - @methods.should have_key("setFoo") + @members.should have_key("setFoo") end end @@ -129,7 +129,8 @@ describe JsDuck::Aggregator do * @evented */ EOF - @accessors = @docs[0][:members][:method] + @accessors = @docs[0][:members].find_all {|m| m[:tagname] == :method } + @events = @docs[0][:members].find_all {|m| m[:tagname] == :event } end it "creates accessors" do @@ -145,7 +146,7 @@ describe JsDuck::Aggregator do end it "creates private event" do - @docs[0][:members][:event][0][:private].should == true + @events[0][:private].should == true end end @@ -160,7 +161,7 @@ describe JsDuck::Aggregator do * @evented */ EOF - @events = @docs[0][:members][:event] + @events = @docs[0][:members].find_all {|m| m[:tagname] == :event } end it "creates foochange event" do @@ -246,7 +247,7 @@ describe JsDuck::Aggregator do * Event comment. */ EOF - @events = @docs[0][:members][:event] + @events = @docs[0][:members].find_all {|m| m[:tagname] == :event } end it "doesn't create any additional events" do diff --git a/spec/aggregator_attributes_spec.rb b/spec/aggregator_attributes_spec.rb index 67eb4d2b74bfce555962559c332ddac05603d2c0..b16f6c0fac11aba83007f745cdc40f98886ca10c 100644 --- a/spec/aggregator_attributes_spec.rb +++ b/spec/aggregator_attributes_spec.rb @@ -102,7 +102,7 @@ describe JsDuck::Aggregator do @doc[:meta][:required].should_not == true end it "contains required config" do - @doc[:members][:cfg][0][:meta][:required].should == true + @doc[:members][0][:meta][:required].should == true end end diff --git a/spec/aggregator_cfg_spec.rb b/spec/aggregator_cfg_spec.rb index 08e710e0e662c1c106fc6e65e08739030d1d88d9..7b5726c070b7188e9cd2cf0adf7ce3b798385756 100644 --- a/spec/aggregator_cfg_spec.rb +++ b/spec/aggregator_cfg_spec.rb @@ -131,7 +131,7 @@ describe JsDuck::Aggregator do end def parse_config_code(propertyName) - parse(<<-EOS)[0][:members][:cfg] + parse(<<-EOS)[0][:members] /** * Some documentation. */ @@ -149,7 +149,7 @@ describe JsDuck::Aggregator do # Generic tests it "finds configs" do - cfg.should be_kind_of(Array) + cfg.all? {|m| m[:tagname] == :cfg }.should == true end it "finds two configs" do @@ -221,7 +221,7 @@ describe JsDuck::Aggregator do describe "detecting Ext.define() with all kind of configs" do let(:cfg) do - parse(<<-EOS)[0][:members][:cfg] + parse(<<-EOS)[0][:members] /** * Some documentation. */ @@ -247,7 +247,7 @@ describe JsDuck::Aggregator do describe "Ext.define() with line-comment before config:" do let(:cfg) do - parse(<<-EOS)[0][:members][:cfg] + parse(<<-EOS)[0][:members] /** * Some documentation. */ diff --git a/spec/aggregator_classes_spec.rb b/spec/aggregator_classes_spec.rb index ae495fde4be8783e03e5345ba48c3b2b50175aa1..c9c11fdd8069636475806002a150d466ddcf0de9 100644 --- a/spec/aggregator_classes_spec.rb +++ b/spec/aggregator_classes_spec.rb @@ -292,15 +292,19 @@ describe JsDuck::Aggregator do end it_should_behave_like "class" - it "has needed number of configs" do - @doc[:members][:cfg].length.should == 2 + it "has needed number of members" do + @doc[:members].length.should == 2 + end + it "detects members as configs" do + @doc[:members][0][:tagname].should == :cfg + @doc[:members][1][:tagname].should == :cfg end it "picks up names of all configs" do - @doc[:members][:cfg][0][:name].should == "foo" - @doc[:members][:cfg][1][:name].should == "bar" + @doc[:members][0][:name].should == "foo" + @doc[:members][1][:name].should == "bar" end it "marks first @cfg as private" do - @doc[:members][:cfg][0][:private].should == true + @doc[:members][0][:private].should == true end end @@ -351,17 +355,21 @@ describe JsDuck::Aggregator do @classes.length.should == 1 end it_should_behave_like "class" - it "should have configs" do - @doc[:members][:cfg].length.should == 1 + + it "should have 4 members" do + @doc[:members].length.should == 4 + end + it "should have a config" do + @doc[:members][0][:tagname].should == :cfg end - it "should have properties" do - @doc[:members][:property].length.should == 1 + it "should have propertiesy" do + @doc[:members][1][:tagname].should == :property end it "should have method" do - @doc[:members][:method].length.should == 1 + @doc[:members][2][:tagname].should == :method end - it "should have events" do - @doc[:members][:event].length.should == 1 + it "should have event" do + @doc[:members][3][:tagname].should == :event end end @@ -450,10 +458,6 @@ describe JsDuck::Aggregator do @classes[0][:private].should == true end - it "combines all configs" do - @classes[0][:members][:cfg].length.should == 3 - end - it "combines all mixins" do @classes[0][:mixins].length.should == 2 end @@ -462,10 +466,8 @@ describe JsDuck::Aggregator do @classes[0][:alternateClassNames].length.should == 1 end - it "combines all methods, events, properties" do - @classes[0][:members][:method].length.should == 3 - @classes[0][:members][:event].length.should == 3 - @classes[0][:members][:property].length.should == 3 + it "combines all members" do + @classes[0][:members].length.should == 3 * 4 end end diff --git a/spec/aggregator_constructor_spec.rb b/spec/aggregator_constructor_spec.rb index d7f863808564d99e8e18f0b84bdb3a30dfc42100..bec3e3f87756e0f47687632a6a72ec0be7f59436 100644 --- a/spec/aggregator_constructor_spec.rb +++ b/spec/aggregator_constructor_spec.rb @@ -28,7 +28,7 @@ describe JsDuck::Aggregator do describe "class with @constructor" do let(:methods) do - parse(<<-EOS)[0][:members][:method] + parse(<<-EOS)[0][:members] /** * @class MyClass * Comment here. @@ -44,7 +44,7 @@ describe JsDuck::Aggregator do describe "class with method named constructor" do let(:methods) do - parse(<<-EOS)[0][:members][:method] + parse(<<-EOS)[0][:members] /** * Comment here. */ @@ -63,7 +63,7 @@ describe JsDuck::Aggregator do describe "class with member containing @constructor" do let(:methods) do - parse(<<-EOS)[0][:members][:method] + parse(<<-EOS)[0][:members] /** * Comment here. */ @@ -82,7 +82,7 @@ describe JsDuck::Aggregator do describe "class with both @constructor tag and constructor property inside Ext.define()" do let(:methods) do - parse(<<-EOS)[0][:members][:method] + parse(<<-EOS)[0][:members] /** * Comment here. * @constructor diff --git a/spec/aggregator_enum_spec.rb b/spec/aggregator_enum_spec.rb index 6618de6bce41c02269a7ba9dedf84fe3b7fcfd07..89265b594eb13ff0c5407a6755ecd3686c642133 100644 --- a/spec/aggregator_enum_spec.rb +++ b/spec/aggregator_enum_spec.rb @@ -29,12 +29,12 @@ describe JsDuck::Aggregator do doc[:doc].should == "Some documentation." end - it "detects two properties" do - doc[:members][:property].length.should == 2 + it "detects two members" do + doc[:members].length.should == 2 end - describe "in first property" do - let(:prop) { doc[:members][:property][0] } + describe "in first member" do + let(:prop) { doc[:members][0] } it "detects name" do prop[:name].should == 'foo' end @@ -165,18 +165,18 @@ describe JsDuck::Aggregator do EOS end - it "gets stripped from :inheritdoc tag in auto-detected property" do - doc[:members][:property][0][:inheritdoc].should == nil + it "gets stripped from :inheritdoc tag in auto-detected member" do + doc[:members][0][:inheritdoc].should == nil end - it "keeps the explicit :inheritdoc tag in doc-commented property" do - doc[:members][:property][1][:inheritdoc].should_not == nil + it "keeps the explicit :inheritdoc tag in doc-commented member" do + doc[:members][1][:inheritdoc].should_not == nil end end describe "enum with array value" do - let(:props) do - parse(<<-EOS)[0][:members][:property] + let(:members) do + parse(<<-EOS)[0][:members] /** @enum */ My.enum.Type = [ "foo", @@ -185,26 +185,30 @@ describe JsDuck::Aggregator do EOS end - it "detects all properties" do - props.length.should == 2 + it "detects all members" do + members.length.should == 2 + end + + it "detects as property" do + members[0][:tagname].should == :property end it "gets name" do - props[0][:name].should == 'foo' + members[0][:name].should == 'foo' end it "gets default value" do - props[0][:default].should == '"foo"' + members[0][:default].should == '"foo"' end it "gets type" do - props[0][:type].should == 'String' + members[0][:type].should == 'String' end end describe "enum with documented array values" do - let(:props) do - parse(<<-EOS)[0][:members][:property] + let(:members) do + parse(<<-EOS)[0][:members] /** @enum */ My.enum.Smartness = [ // A wise choice. @@ -215,12 +219,12 @@ describe JsDuck::Aggregator do EOS end - it "detects docs of first property" do - props[0][:doc].should == 'A wise choice.' + it "detects docs of first member" do + members[0][:doc].should == 'A wise choice.' end - it "detects docs of second property" do - props[1][:doc].should == 'A foolish decision.' + it "detects docs of second member" do + members[1][:doc].should == 'A foolish decision.' end end @@ -238,30 +242,30 @@ describe JsDuck::Aggregator do doc[:enum][:type].should == "String" end - let(:props) { doc[:members][:property] } + let(:members) { doc[:members] } it "gathers all 3 widget.* aliases" do - props.length.should == 3 + members.length.should == 3 end it "lists all widget.* names" do - Set.new(props.map {|p| p[:name] }).should == Set.new(["form", "button", "textarea"]) + Set.new(members.map {|p| p[:name] }).should == Set.new(["form", "button", "textarea"]) end it "auto-generates property default values" do - Set.new(props.map {|p| p[:default] }).should == Set.new(["'form'", "'button'", "'textarea'"]) + Set.new(members.map {|p| p[:default] }).should == Set.new(["'form'", "'button'", "'textarea'"]) end it "sets property type to String" do - props[0][:type].should == "String" + members[0][:type].should == "String" end it "sets enum value from private class as private" do - props.find_all {|p| p[:private] }.map {|p| p[:name] }.should == ["textarea"] + members.find_all {|p| p[:private] }.map {|p| p[:name] }.should == ["textarea"] end it "lists class name in enum property docs" do - props.find_all {|p| p[:name] == 'form' }[0][:doc].should == "Alias for {@link Form}." + members.find_all {|p| p[:name] == 'form' }[0][:doc].should == "Alias for {@link Form}." end end diff --git a/spec/aggregator_ext4_events_spec.rb b/spec/aggregator_ext4_events_spec.rb index 35013717797d2d7ae90bf2e8f91375e324e45d62..2b5bf21579134d3bc6ae277f3f1ebaf9027cbdf6 100644 --- a/spec/aggregator_ext4_events_spec.rb +++ b/spec/aggregator_ext4_events_spec.rb @@ -11,7 +11,7 @@ describe JsDuck::Aggregator do describe "event inside Ext.define get extra parameter" do let(:event) do - parse(<<-EOF)[0][:members][:event][0] + parse(<<-EOF)[0][:members][0] /** */ Ext.define("Blah", { /** @@ -42,7 +42,7 @@ describe JsDuck::Aggregator do describe "When some class defined with Ext.define" do let(:events) do - parse(<<-EOF)[0][:members][:event] + parse(<<-EOF)[0][:members] /** @class Foo */ /** * @event click @@ -65,7 +65,7 @@ describe JsDuck::Aggregator do describe "Without Ext.define-d class" do let(:events) do - parse(<<-EOF)[0][:members][:event] + parse(<<-EOF)[0][:members] /** @class Foo */ /** * @event click diff --git a/spec/aggregator_inheritcfg_spec.rb b/spec/aggregator_inheritcfg_spec.rb index 49ea8dc77c63aad7b37a8b26e6a8df5b78d67ae1..290611323e1ffb6d7a03c18445f3883e0b9365fb 100644 --- a/spec/aggregator_inheritcfg_spec.rb +++ b/spec/aggregator_inheritcfg_spec.rb @@ -30,16 +30,16 @@ describe JsDuck::Aggregator do EOS end - it "detects one property in parent" do - classes["Parent"][:members][:property].length.should == 1 + it "detects a property in parent" do + classes["Parent"][:members][0][:tagname].should == :property end - it "detects one property in child" do - classes["Child"][:members][:property].length.should == 1 + it "detects a property in child" do + classes["Child"][:members][0][:tagname].should == :property end it "detects property in child as public" do - classes["Child"][:members][:property][0][:private].should_not == true + classes["Child"][:members][0][:private].should_not == true end end @@ -60,24 +60,24 @@ describe JsDuck::Aggregator do EOS end - it "detects one config in parent" do - classes["Parent"][:members][:cfg].length.should == 1 + it "detects a config in parent" do + classes["Parent"][:members][0][:tagname].should == :cfg end - it "detects one config in child" do - classes["Child"][:members][:cfg].length.should == 1 + it "detects a config in child" do + classes["Child"][:members][0][:tagname].should == :cfg end it "detects the child config with correct tagname" do - classes["Child"][:members][:cfg][0][:tagname] == :cfg + classes["Child"][:members][0][:tagname] == :cfg end it "detects the child config with correct id" do - classes["Child"][:members][:cfg][0][:id] == "cfg-blah" + classes["Child"][:members][0][:id] == "cfg-blah" end it "detects no properties in child" do - classes["Child"][:members][:property].length.should == 0 + classes["Child"][:members].length.should == 1 end end diff --git a/spec/aggregator_inheritdoc_spec.rb b/spec/aggregator_inheritdoc_spec.rb index 9337f0389d378c9d335868db24fd7f4ed44a6193..20b13e08a7cee8af6cfa138e59fb1445d0826500 100644 --- a/spec/aggregator_inheritdoc_spec.rb +++ b/spec/aggregator_inheritdoc_spec.rb @@ -46,8 +46,8 @@ describe JsDuck::Aggregator do * @inheritdoc Foo#bar */ EOF - @orig = @docs["Foo"][:members][:method][0] - @inheritdoc = @docs["Core"][:members][:method][0] + @orig = @docs["Foo"][:members][0] + @inheritdoc = @docs["Core"][:members][0] end it_behaves_like "@inheritdoc" @@ -78,8 +78,8 @@ describe JsDuck::Aggregator do * #{at_tag} Foo#bar */ EOF - @orig = @docs["Foo"][:members][:method][0] - @inheritdoc = @docs["Core"][:members][:method][0] + @orig = @docs["Foo"][:members][0] + @inheritdoc = @docs["Core"][:members][0] end describe "@inheritDoc" do @@ -116,8 +116,8 @@ describe JsDuck::Aggregator do * @inheritdoc Foo#bar */ EOF - @orig = @docs["Foo"][:members][:event][0] - @inheritdoc = @docs["Core"][:members][:event][0] + @orig = @docs["Foo"][:members][0] + @inheritdoc = @docs["Core"][:members][0] end it_behaves_like "@inheritdoc" @@ -147,8 +147,8 @@ describe JsDuck::Aggregator do * @inheritdoc Foo#bar */ EOF - @orig = @docs["Foo"][:members][:cfg][0] - @inheritdoc = @docs["Core"][:members][:cfg][0] + @orig = @docs["Foo"][:members][0] + @inheritdoc = @docs["Core"][:members][0] end it_behaves_like "@inheritdoc" @@ -180,8 +180,8 @@ describe JsDuck::Aggregator do * @static */ EOF - @orig = @docs["Foo"][:statics][:method][0] - @inheritdoc = @docs["Core"][:statics][:method][0] + @orig = @docs["Foo"][:members][0] + @inheritdoc = @docs["Core"][:members][0] end it_behaves_like "@inheritdoc" @@ -211,8 +211,8 @@ describe JsDuck::Aggregator do * @inheritdoc Foo#cfg-bar */ EOF - @orig = @docs["Foo"][:members][:cfg][0] - @inheritdoc = @docs["Core"][:members][:cfg][0] + @orig = @docs["Foo"][:members][0] + @inheritdoc = @docs["Core"][:members][0] end it_behaves_like "@inheritdoc" @@ -242,8 +242,8 @@ describe JsDuck::Aggregator do * @inheritdoc Foo#bar */ EOF - @orig = @docs["Foo"][:members][:cfg][0] - @inheritdoc = @docs["Core"][:members][:cfg][0] + @orig = @docs["Foo"][:members][0] + @inheritdoc = @docs["Core"][:members][0] end it_behaves_like "@inheritdoc" @@ -270,8 +270,8 @@ describe JsDuck::Aggregator do * @inheritdoc Foo#static-bar */ EOF - @orig = @docs["Foo"][:statics][:method][0] - @inheritdoc = @docs["Core"][:members][:method][0] + @orig = @docs["Foo"][:members][0] + @inheritdoc = @docs["Core"][:members][0] end it_behaves_like "@inheritdoc" @@ -299,8 +299,8 @@ describe JsDuck::Aggregator do * @inheritdoc Foo#bar */ EOF - @orig = @docs["Foo"][:statics][:method][0] - @inheritdoc = @docs["Core"][:statics][:method][0] + @orig = @docs["Foo"][:members][0] + @inheritdoc = @docs["Core"][:members][0] end it_behaves_like "@inheritdoc" @@ -332,9 +332,9 @@ describe JsDuck::Aggregator do * @inheritdoc Foo#bar */ EOF - @orig = @docs["Foo"][:members][:method][0] - @inheritdoc = @docs["Core"][:members][:method][0] - @inheritdoc2 = @docs["HyperCore"][:members][:method][0] + @orig = @docs["Foo"][:members][0] + @inheritdoc = @docs["Core"][:members][0] + @inheritdoc2 = @docs["HyperCore"][:members][0] end it_behaves_like "@inheritdoc" @@ -360,7 +360,7 @@ describe JsDuck::Aggregator do * New comment. */ EOF - @inheritdoc = @docs["Child"][:members][:method][1] + @inheritdoc = @docs["Child"][:members][1] end it "merges comment from referenced member" do @@ -405,7 +405,7 @@ describe JsDuck::Aggregator do * @inheritdoc */ EOF - @method = @docs["Child"][:members][:method][0] + @method = @docs["Child"][:members][0] end it "inherits docs from parent class method" do @@ -424,7 +424,7 @@ describe JsDuck::Aggregator do * @inheritdoc */ EOF - @method = @docs["Child"][:members][:method][0] + @method = @docs["Child"][:members][0] end it "inherits nothing" do @@ -447,7 +447,7 @@ describe JsDuck::Aggregator do * @inheritdoc */ EOF - @method = @docs["Child"][:members][:method][0] + @method = @docs["Child"][:members][0] end it "inherits nothing" do @@ -474,7 +474,7 @@ describe JsDuck::Aggregator do * @inheritdoc */ EOF - @method = @docs["Child"][:members][:method][0] + @method = @docs["Child"][:members][0] end it "inherits docs from mixin" do @@ -546,7 +546,7 @@ describe JsDuck::Aggregator do }); EOF @cls = @docs["Child"] - @cfg = @cls[:members][:cfg][0] + @cfg = @cls[:members][0] end it "inherits docs from parent" do @@ -590,7 +590,7 @@ describe JsDuck::Aggregator do }); EOF @cls = @docs["Child"] - @cfg = @cls[:members][:cfg][0] + @cfg = @cls[:members][0] end it "inherits docs from parent" do @@ -617,7 +617,7 @@ describe JsDuck::Aggregator do }); EOF @cls = @docs["Child"] - @cfg = @cls[:members][:cfg][0] + @cfg = @cls[:members][0] end it "becomes private" do @@ -648,16 +648,16 @@ describe JsDuck::Aggregator do }); EOF @cls = @docs["Child"] - @cfg = @cls[:members][:property][0] + @property = @cls[:members][0] end it "inherits @protected" do - @cfg[:meta][:protected].should == true + @property[:meta][:protected].should == true end it "inherits @deprecated" do - @cfg[:meta][:deprecated][:version].should == "4.0" - @cfg[:meta][:deprecated][:text].should == "Use something else." + @property[:meta][:deprecated][:version].should == "4.0" + @property[:meta][:deprecated][:text].should == "Use something else." end end @@ -682,19 +682,19 @@ describe JsDuck::Aggregator do }); EOF @cls = @docs["Child"] - @cfg = @cls[:members][:property][0] + @property = @cls[:members][0] end it "inherits @protected" do - @cfg[:meta][:protected].should == true + @property[:meta][:protected].should == true end it "keeps @readonly" do - @cfg[:meta][:readonly].should == true + @property[:meta][:readonly].should == true end it "overrides @deprecated of parent with its own @deprecated" do - @cfg[:meta][:deprecated][:version].should == "4.0" + @property[:meta][:deprecated][:version].should == "4.0" end end @@ -718,15 +718,14 @@ describe JsDuck::Aggregator do }); EOF @cls = @docs["Child"] - @cfg = @cls[:members][:property][0] end it "doesn't inherit from parent static method" do - @cls[:members][:method][0][:doc].should_not == "My method." + @cls[:members][0][:doc].should_not == "My method." end it "doesn't inherit from parent static property" do - @cls[:members][:property][0][:doc].should_not == "My property." + @cls[:members][1][:doc].should_not == "My property." end end @@ -752,15 +751,14 @@ describe JsDuck::Aggregator do }); EOF @cls = @docs["Child"] - @cfg = @cls[:members][:property][0] end it "inherits from parent static method" do - @cls[:statics][:method][0][:doc].should == "My method." + @cls[:members][0][:doc].should == "My method." end it "inherits from parent static property" do - @cls[:statics][:property][0][:doc].should == "My property." + @cls[:members][1][:doc].should == "My property." end end end diff --git a/spec/aggregator_members_spec.rb b/spec/aggregator_members_spec.rb index 6404f4f69b821d9fb92d6cb9b5d0ffdd1a861760..17d783bf3a7a5637bfe9e371e01b444acde9699a 100644 --- a/spec/aggregator_members_spec.rb +++ b/spec/aggregator_members_spec.rb @@ -34,8 +34,8 @@ describe JsDuck::Aggregator do * @member Bar */ EOS - items[0][:members][:cfg].length.should == 1 - items[1][:members][:cfg].length.should == 0 + items[0][:members].length.should == 1 + items[1][:members].length.should == 0 end it "when used before the corresponding @class" do @@ -48,7 +48,7 @@ describe JsDuck::Aggregator do * @class Bar */ EOS - items[0][:members][:cfg].length.should == 1 + items[0][:members].length.should == 1 end end diff --git a/spec/aggregator_method_spec.rb b/spec/aggregator_method_spec.rb index 4240731e80e341cc331ce458934ecd01f456f6c9..125db041261db8fe57f2a9806287bc90fb0c4a1e 100644 --- a/spec/aggregator_method_spec.rb +++ b/spec/aggregator_method_spec.rb @@ -186,7 +186,7 @@ describe JsDuck::Aggregator do describe "method without comment inside Ext.define" do let(:method) do - parse(<<-EOS)[0][:members][:method][0] + parse(<<-EOS)[0][:members][0] /** Some documentation. */ Ext.define("MyClass", { foo: function() {} @@ -199,7 +199,7 @@ describe JsDuck::Aggregator do describe "method with line comment inside Ext.define" do let(:method) do - parse(<<-EOS)[0][:members][:method][0] + parse(<<-EOS)[0][:members][0] /** Some documentation. */ Ext.define("MyClass", { // My docs @@ -217,7 +217,7 @@ describe JsDuck::Aggregator do describe "property with value Ext.emptyFn inside Ext.define" do let(:method) do - parse(<<-EOS)[0][:members][:method][0] + parse(<<-EOS)[0][:members][0] /** Some documentation. */ Ext.define("MyClass", { foo: Ext.emptyFn @@ -232,7 +232,7 @@ describe JsDuck::Aggregator do describe "method without comment inside Ext.extend" do let(:method) do - parse(<<-EOS)[0][:members][:method][0] + parse(<<-EOS)[0][:members][0] /** Some documentation. */ MyClass = Ext.extend(Object, { foo: function(){} @@ -245,7 +245,7 @@ describe JsDuck::Aggregator do describe "method with line comment inside Ext.extend" do let(:method) do - parse(<<-EOS)[0][:members][:method][0] + parse(<<-EOS)[0][:members][0] /** Some documentation. */ MyClass = Ext.extend(Object, { // My docs @@ -263,7 +263,7 @@ describe JsDuck::Aggregator do describe "method without comment inside object literal" do let(:method) do - parse(<<-EOS)[0][:members][:method][0] + parse(<<-EOS)[0][:members][0] /** Some documentation. */ MyClass = { foo: function(){} @@ -276,7 +276,7 @@ describe JsDuck::Aggregator do describe "method with line comment inside object literal" do let(:method) do - parse(<<-EOS)[0][:members][:method][0] + parse(<<-EOS)[0][:members][0] /** Some documentation. */ MyClass = { // My docs diff --git a/spec/aggregator_orphans_spec.rb b/spec/aggregator_orphans_spec.rb index 815f7e566703e6da0e93842a136155bb74e1a4ba..82d23ea9cffe8389f339dc1f9d06e93bc340c231 100644 --- a/spec/aggregator_orphans_spec.rb +++ b/spec/aggregator_orphans_spec.rb @@ -17,13 +17,13 @@ describe JsDuck::Aggregator do end it "combines members into itself" do - @classes[0][:members][:method].length.should == 2 + @classes[0][:members].length.should == 2 end it "preserves the order of members" do - methods = @classes[0][:members][:method] - methods[0][:name].should == "foo" - methods[1][:name].should == "bar" + ms = @classes[0][:members] + ms[0][:name].should == "foo" + ms[1][:name].should == "bar" end end diff --git a/spec/aggregator_private_spec.rb b/spec/aggregator_private_spec.rb index 3048fb0340c351a7a08909fd3f2b206c3afc54f0..268a34f2f00a2b52aea0f643946b54e01601a68b 100644 --- a/spec/aggregator_private_spec.rb +++ b/spec/aggregator_private_spec.rb @@ -74,11 +74,11 @@ describe JsDuck::Aggregator do end it "ignores one member" do - @doc[:members][:method].length.should == 1 + @doc[:members].length.should == 1 end it "lets the other member stay" do - @doc[:members][:method][0][:doc].should == "First method docs" + @doc[:members][0][:doc].should == "First method docs" end end diff --git a/spec/aggregator_property_spec.rb b/spec/aggregator_property_spec.rb index 31483fd6a28ec0b98d3078ca05b7ffce76721e8c..22e6fd3d11f86a5e3f3a715daacbfe7c0380076d 100644 --- a/spec/aggregator_property_spec.rb +++ b/spec/aggregator_property_spec.rb @@ -228,7 +228,7 @@ describe JsDuck::Aggregator do describe "property without comment inside Ext.define" do let(:property) do - parse(<<-EOS)[0][:members][:property][0] + parse(<<-EOS)[0][:members][0] /** Some documentation. */ Ext.define("MyClass", { foo: 15 @@ -241,7 +241,7 @@ describe JsDuck::Aggregator do describe "property with line comment inside Ext.define" do let(:property) do - parse(<<-EOS)[0][:members][:property][0] + parse(<<-EOS)[0][:members][0] /** Some documentation. */ Ext.define("MyClass", { // My docs @@ -259,7 +259,7 @@ describe JsDuck::Aggregator do describe "property without comment inside Ext.extend" do let(:property) do - parse(<<-EOS)[0][:members][:property][0] + parse(<<-EOS)[0][:members][0] /** Some documentation. */ MyClass = Ext.extend(Object, { foo: 15 @@ -272,7 +272,7 @@ describe JsDuck::Aggregator do describe "property with line comment inside Ext.extend" do let(:property) do - parse(<<-EOS)[0][:members][:property][0] + parse(<<-EOS)[0][:members][0] /** Some documentation. */ MyClass = Ext.extend(Object, { // My docs @@ -290,7 +290,7 @@ describe JsDuck::Aggregator do describe "property without comment inside object literal" do let(:property) do - parse(<<-EOS)[0][:members][:property][0] + parse(<<-EOS)[0][:members][0] /** Some documentation. */ MyClass = { foo: 15 @@ -303,7 +303,7 @@ describe JsDuck::Aggregator do describe "property with line comment inside object literal" do let(:property) do - parse(<<-EOS)[0][:members][:property][0] + parse(<<-EOS)[0][:members][0] /** Some documentation. */ MyClass = { // My docs diff --git a/spec/aggregator_static_spec.rb b/spec/aggregator_static_spec.rb index 0999a3ff3730667cb4bbd3455991d8b8cdb46348..1faf9e3a46cf7a728b3474920a9f71fc9bf6eaf4 100644 --- a/spec/aggregator_static_spec.rb +++ b/spec/aggregator_static_spec.rb @@ -68,18 +68,14 @@ describe JsDuck::Aggregator do EOS end - it "adds method to statics" do - @doc[:statics][:method][0][:name].should == "bar" - end - - it "adds property to statics" do - @doc[:statics][:property][0][:name].should == "baz" + it "adds static members to :members" do + @doc[:members].length.should == 2 end end describe "Ext.define() with undocumented property in statics:" do - let(:statics) do - parse(<<-EOS)[0][:statics] + let(:member) do + parse(<<-EOS)[0][:members][0] /** * Some documentation. */ @@ -91,38 +87,36 @@ describe JsDuck::Aggregator do EOS end - it "auto-detects one static property" do - statics[:property].length.should == 1 - end - - describe "auto-detects static property" do - let(:property) { statics[:property][0] } + describe "detects a member" do + it "with :property tagname" do + member[:tagname].should == :property + end it "with :static flag" do - property[:meta][:static].should == true + member[:meta][:static].should == true end it "with :autodetected flag" do - property[:autodetected].should == true + member[:autodetected].should == true end it "with owner" do - property[:owner].should == "MyClass" + member[:owner].should == "MyClass" end it "as private" do - property[:private].should == true + member[:private].should == true end it "with :linenr field" do - property[:linenr].should == 6 + member[:linenr].should == 6 end end end describe "Ext.define() with documented method in statics:" do - let(:statics) do - parse(<<-EOS)[0][:statics] + let(:member) do + parse(<<-EOS)[0][:members][0] /** * Some documentation. */ @@ -135,38 +129,36 @@ describe JsDuck::Aggregator do EOS end - it "detects one static method" do - statics[:method].length.should == 1 - end - - describe "detects static method" do - let(:method) { statics[:method][0] } + describe "detects a member" do + it "with :method tagname" do + member[:tagname].should == :method + end it "with :static flag" do - method[:meta][:static].should == true + member[:meta][:static].should == true end it "with docs" do - method[:doc].should == "Docs for bar" + member[:doc].should == "Docs for bar" end it "with owner" do - method[:owner].should == "MyClass" + member[:owner].should == "MyClass" end it "as public" do - method[:private].should_not == true + member[:private].should_not == true end it "with :linenr field" do - method[:linenr].should == 6 + member[:linenr].should == 6 end end end describe "Ext.define() with undocumented method in inheritableStatics:" do - let(:statics) do - parse(<<-EOS)[0][:statics] + let(:member) do + parse(<<-EOS)[0][:members][0] /** * Some documentation. */ @@ -178,30 +170,28 @@ describe JsDuck::Aggregator do EOS end - it "auto-detects one static method" do - statics[:method].length.should == 1 - end - - describe "detects static method" do - let(:method) { statics[:method][0] } + describe "detects a member" do + it "with :method tagname" do + member[:tagname].should == :method + end it "with :static flag" do - method[:meta][:static].should == true + member[:meta][:static].should == true end it "with :inheritable flag" do - method[:inheritable].should == true + member[:inheritable].should == true end it "with :inheritdoc flag" do - method[:inheritdoc].should == {} + member[:inheritdoc].should == {} end end end describe "Ext.define() with line-comment before item in statics:" do - let(:methods) do - parse(<<-EOS)[0][:statics][:method] + let(:member) do + parse(<<-EOS)[0][:members][0] /** * Some documentation. */ @@ -214,22 +204,26 @@ describe JsDuck::Aggregator do EOS end - it "detects one static method" do - methods.length.should == 1 + it "detects a static" do + member[:meta][:static].should == true + end + + it "detects a method" do + member[:tagname].should == :method end it "detects documentation" do - methods[0][:doc].should == "Check this out" + member[:doc].should == "Check this out" end it "detects the method with :autodetected flag" do - methods[0][:autodetected].should == true + member[:autodetected].should == true end end describe "Ext.define() with property having value Ext.emptyFn in statics:" do - let(:methods) do - parse(<<-EOS)[0][:statics][:method] + let(:member) do + parse(<<-EOS)[0][:members][0] /** * Some documentation. */ @@ -241,8 +235,12 @@ describe JsDuck::Aggregator do EOS end - it "detects one static method" do - methods.length.should == 1 + it "detects a static" do + member[:meta][:static].should == true + end + + it "detects a method" do + member[:tagname].should == :method end end diff --git a/spec/ast_statics_spec.rb b/spec/ast_statics_spec.rb index be621fe8f23b2cf7d0cc99cf740279818f6520cb..efc169c38664be4ad11dd3f4cb281262997e959e 100644 --- a/spec/ast_statics_spec.rb +++ b/spec/ast_statics_spec.rb @@ -8,8 +8,8 @@ describe "JsDuck::Ast detecting" do end describe "Ext.define()" do - let (:statics) do - detect(<<-EOS)[:statics] + let (:members) do + detect(<<-EOS)[:members] /** */ Ext.define('MyClass', { statics: { @@ -20,31 +20,31 @@ describe "JsDuck::Ast detecting" do EOS end - it "adds :statics as array" do - statics.should be_kind_of(Array) + it "finds two members" do + members.length.should == 2 end - describe "finds static property" do + describe "finds property" do it "with :property tagname" do - statics[0][:tagname].should == :property + members[0][:tagname].should == :property end it "with name" do - statics[0][:name].should == "foo" + members[0][:name].should == "foo" end it "with :static flag" do - statics[0][:meta][:static].should == true + members[0][:meta][:static].should == true end end - describe "finds static method" do + describe "finds method" do it "with :property tagname" do - statics[1][:tagname].should == :method + members[1][:tagname].should == :method end it "with name" do - statics[1][:name].should == "bar" + members[1][:name].should == "bar" end it "with :static flag" do - statics[1][:meta][:static].should == true + members[1][:meta][:static].should == true end end diff --git a/spec/class_spec.rb b/spec/class_spec.rb index 641c165c0541d51d306bfd00eff09d60697755f3..a1783add7a94b072a5dc5bab1a2ebea2b9989d10 100644 --- a/spec/class_spec.rb +++ b/spec/class_spec.rb @@ -7,81 +7,64 @@ describe JsDuck::Class do before do @classes = {} @parent = JsDuck::Class.new({ - :name => "ParentClass", - :members => { - :method => [ - {:name => "baz", :owner => "ParentClass"}, - {:name => "foo", :owner => "ParentClass"}, - {:name => "constructor", :owner => "ParentClass"}, - {:name => "frank", :owner => "ParentClass", :private => true}, - {:name => "zappa", :owner => "ParentClass", :private => false}, - ] - }, - :statics => { - :method => [ - {:name => "parentA", :owner => "ParentClass"}, - {:name => "parentB", :owner => "ParentClass", :inheritable => true}, - ] - } - }); + :name => "ParentClass", + :members => [ + {:tagname => :method, :name => "baz", :owner => "ParentClass"}, + {:tagname => :method, :name => "foo", :owner => "ParentClass"}, + {:tagname => :method, :name => "constructor", :owner => "ParentClass"}, + {:tagname => :method, :name => "frank", :owner => "ParentClass", :private => true}, + {:tagname => :method, :name => "zappa", :owner => "ParentClass", :private => false}, + {:tagname => :method, :name => "parentA", :owner => "ParentClass", + :meta => {:static => true}}, + {:tagname => :method, :name => "parentB", :owner => "ParentClass", + :inheritable => true, :meta => {:static => true}}, + ] + }); @classes["ParentClass"] = @parent @parent.relations = @classes @mixin = JsDuck::Class.new({ - :name => "MixinClass", - :members => { - :method => [ - {:name => "xxx", :owner => "MixinClass"}, - {:name => "pri", :owner => "MixinClass", :private => true}, - ] - }, - :statics => { - :method => [ - {:name => "mixinA", :owner => "MixinClass"}, - {:name => "mixinB", :owner => "MixinClass", :inheritable => true}, - ] - } - }); + :name => "MixinClass", + :members => [ + {:tagname => :method, :name => "xxx", :owner => "MixinClass"}, + {:tagname => :method, :name => "pri", :owner => "MixinClass", :private => true}, + {:tagname => :method, :name => "mixinA", :owner => "MixinClass", + :meta => {:static => true}}, + {:tagname => :method, :name => "mixinB", :owner => "MixinClass", + :inheritable => true, :meta => {:static => true}}, + ] + }); @classes["MixinClass"] = @mixin @mixin.relations = @classes @child = JsDuck::Class.new({ - :name => "ChildClass", - :extends => "ParentClass", - :mixins => ["MixinClass"], - :members => { - :method => [ - {:name => "foo", :owner => "ChildClass"}, - {:name => "bar", :owner => "ChildClass"}, - {:name => "zappa", :owner => "ChildClass", :private => true}, - ] - }, - :statics => { - :method => [ - {:name => "childA", :owner => "ChildClass"}, - {:name => "childB", :owner => "ChildClass", :inheritable => true}, - ] - } - }); + :name => "ChildClass", + :extends => "ParentClass", + :mixins => ["MixinClass"], + :members => [ + {:tagname => :method, :name => "foo", :owner => "ChildClass"}, + {:tagname => :method, :name => "bar", :owner => "ChildClass"}, + {:tagname => :method, :name => "zappa", :owner => "ChildClass", :private => true}, + {:tagname => :method, :name => "childA", :owner => "ChildClass", + :meta => {:static => true}}, + {:tagname => :method, :name => "childB", :owner => "ChildClass", + :inheritable => true, :meta => {:static => true}}, + ] + }); @classes["ChildClass"] = @child @child.relations = @classes @singletonChild = JsDuck::Class.new({ - :name => "Singleton", - :extends => "ParentClass", - :mixins => ["MixinClass"], - :singleton => true, - :members => { - :method => [ - {:name => "sing", :owner => "Singleton", :files => [{}]}, - ] - }, - :statics => { - :method => [ - {:name => "singStat", :owner => "Singleton", :files => [{}]}, - ] - } - }); + :name => "Singleton", + :extends => "ParentClass", + :mixins => ["MixinClass"], + :singleton => true, + :members => [ + {:tagname => :method, :name => "sing", :owner => "Singleton", :files => [{}]}, + {:tagname => :method, :name => "singStat", :owner => "Singleton", :files => [{}], + :meta => {:static => true}}, + ] + }); @classes["Singleton"] = @singletonChild @singletonChild.relations = @classes end diff --git a/spec/doc_formatter_spec.rb b/spec/doc_formatter_spec.rb index 10058ae6390bab5b9ac1838a8fe51ee9317b055e..f8b32d86c82dc763dfab7d31a18bc98e51594396 100644 --- a/spec/doc_formatter_spec.rb +++ b/spec/doc_formatter_spec.rb @@ -11,24 +11,22 @@ describe JsDuck::DocFormatter do @formatter.relations = JsDuck::Relations.new([ JsDuck::Class.new({ :name => "Context", - :members => { - :method => [{:tagname => :method, :name => "bar", :id => "method-bar"}] - }, - :statics => { - :method => [{:tagname => :method, :name => "id", :id => "static-method-id"}], - }, + :members => [ + {:tagname => :method, :name => "bar", :id => "method-bar"}, + {:tagname => :method, :name => "id", :id => "static-method-id", + :meta => {:static => true}}, + ], }), JsDuck::Class.new({ :name => 'Ext.Msg' }), JsDuck::Class.new({ :name => "Foo", - :members => { - :cfg => [{:tagname => :cfg, :name => "bar", :id => "cfg-bar"}], - }, - :statics => { - :method => [{:tagname => :method, :name => "id", :id => "static-method-id"}], - }, + :members => [ + {:tagname => :cfg, :name => "bar", :id => "cfg-bar"}, + {:tagname => :method, :name => "id", :id => "static-method-id", + :meta => {:static => true}}, + ], :alternateClassNames => ["FooBar"] }), ]) @@ -136,9 +134,9 @@ describe JsDuck::DocFormatter do JsDuck::Class.new({:name => 'Foo.Bar.Blah'}), JsDuck::Class.new({ :name => 'Ext.form.Field', - :members => { - :method => [{:tagname => :method, :name => "getValues", :id => "method-getValues"}] - } + :members => [ + {:tagname => :method, :name => "getValues", :id => "method-getValues"} + ] }), JsDuck::Class.new({ :name => 'Ext.XTemplate', @@ -146,15 +144,15 @@ describe JsDuck::DocFormatter do }), JsDuck::Class.new({ :name => 'Ext', - :members => { - :method => [{:tagname => :method, :name => "encode", :id => "method-encode"}] - } + :members => [ + {:tagname => :method, :name => "encode", :id => "method-encode"} + ] }), JsDuck::Class.new({ :name => "Context", - :members => { - :method => [{:tagname => :method, :name => "bar", :id => "method-bar"}] - }, + :members => [ + {:tagname => :method, :name => "bar", :id => "method-bar"} + ] }), ]) end @@ -300,10 +298,10 @@ describe JsDuck::DocFormatter do @formatter.relations = JsDuck::Relations.new([ JsDuck::Class.new({ :name => 'Foo', - :members => { - :method => [{:tagname => :method, :name => "select", :id => "method-select"}], - :event => [{:tagname => :event, :name => "select", :id => "event-select"}], - } + :members => [ + {:tagname => :method, :name => "select", :id => "method-select"}, + {:tagname => :event, :name => "select", :id => "event-select"}, + ] }) ]) end @@ -324,12 +322,11 @@ describe JsDuck::DocFormatter do @formatter.relations = JsDuck::Relations.new([ JsDuck::Class.new({ :name => 'Foo', - :members => { - :method => [{:tagname => :method, :name => "select", :id => "method-select", :meta => {}}], - }, - :statics => { - :method => [{:tagname => :method, :name => "select", :id => "static-method-select", :meta => {:static => true}}], - } + :members => [ + {:tagname => :method, :name => "select", :id => "method-select", :meta => {}}, + {:tagname => :method, :name => "select", :id => "static-method-select", + :meta => {:static => true}}, + ] }) ]) end diff --git a/spec/hide_spec.rb b/spec/hide_spec.rb index 419b613c558b0e5ed7aa074ba0c5d360f46871bb..cc0b21eb468b877195aacc05644ae4b0e9ec7d30 100644 --- a/spec/hide_spec.rb +++ b/spec/hide_spec.rb @@ -14,13 +14,11 @@ describe JsDuck::Class do @classes = {} @parent = JsDuck::Class.new({ :name => "ParentClass", - :members => { - :method => [ - {:name => "foo", :owner => "ParentClass"}, - {:name => "bar", :owner => "ParentClass"}, - {:name => "zappa", :owner => "ParentClass"}, - ] - } + :members => [ + {:tagname => :method, :name => "foo", :owner => "ParentClass"}, + {:tagname => :method, :name => "bar", :owner => "ParentClass"}, + {:tagname => :method, :name => "zappa", :owner => "ParentClass"}, + ] }); @classes["ParentClass"] = @parent @parent.relations = @classes @@ -28,13 +26,11 @@ describe JsDuck::Class do @child = JsDuck::Class.new({ :name => "ChildClass", :extends => "ParentClass", - :members => { - :method => [ - {:name => "bar", :owner => "ChildClass"}, - {:name => "baz", :owner => "ChildClass"}, - {:name => "zappa", :owner => "ChildClass", :meta => {:hide => true}}, - ] - } + :members => [ + {:tagname => :method, :name => "bar", :owner => "ChildClass"}, + {:tagname => :method, :name => "baz", :owner => "ChildClass"}, + {:tagname => :method, :name => "zappa", :owner => "ChildClass", :meta => {:hide => true}}, + ] }); @classes["ChildClass"] = @child @child.relations = @classes diff --git a/spec/importer_spec.rb b/spec/importer_spec.rb index 48eb938f8ee1a4203bafa42f591c91d6ccbc5b17..cdb9633840d1faadebe95fe5500f71cef6f31b12 100644 --- a/spec/importer_spec.rb +++ b/spec/importer_spec.rb @@ -1,4 +1,5 @@ require "jsduck/importer" +require "jsduck/class" describe "JsDuck::Importer#generate_since_tags" do @@ -23,15 +24,13 @@ describe "JsDuck::Importer#generate_since_tags" do ] @relations = [ - {:name => "VeryOldClass", :meta => {}, :alternateClassNames => [], :members => { - :cfg => [ - {:id => "cfg-foo", :meta => {}}, - {:id => "cfg-bar", :meta => {}}, - {:id => "cfg-baz", :meta => {}}, - {:id => "cfg-zap", :meta => {:since => "1.0"}}, - {:id => "cfg-new", :meta => {:new => true}}, - ], - }}, + {:name => "VeryOldClass", :meta => {}, :alternateClassNames => [], :members => [ + {:tagname => :cfg, :id => "cfg-foo", :meta => {}}, + {:tagname => :cfg, :id => "cfg-bar", :meta => {}}, + {:tagname => :cfg, :id => "cfg-baz", :meta => {}}, + {:tagname => :cfg, :id => "cfg-zap", :meta => {:since => "1.0"}}, + {:tagname => :cfg, :id => "cfg-new", :meta => {:new => true}}, + ]}, {:name => "OldClass", :meta => {}, :alternateClassNames => []}, {:name => "NewClass", :meta => {}, :alternateClassNames => []}, {:name => "ClassWithNewName", :meta => {}, :alternateClassNames => ["ClassWithOldName"]}, @@ -45,8 +44,7 @@ describe "JsDuck::Importer#generate_since_tags" do @stuff = {} @relations.each do |cls| @stuff[cls[:name]] = cls[:meta] - configs = cls[:members] && cls[:members][:cfg] - (configs || []).each do |cfg| + cls[:members].each do |cfg| @stuff[cls[:name]+"#"+cfg[:id]] = cfg[:meta] end end