Loading lib/jsduck/ast.rb +25 −10 Original line number Diff line number Diff line Loading @@ -73,7 +73,7 @@ module JsDuck # Foo = ... elsif exp && assignment?(exp) && class_name?(to_s(exp["left"])) make_class(to_s(exp["left"])) make_class(to_s(exp["left"]), exp["right"]) # var foo = Ext.extend("Parent", {}) elsif var && var["init"] && ext_extend?(var["init"]) Loading @@ -81,7 +81,7 @@ module JsDuck # var Foo = ... elsif var && class_name?(to_s(var["id"])) make_class(to_s(var["id"])) make_class(to_s(var["id"]), var["right"]) # function Foo() {} elsif function?(ast) && class_name?(to_s(ast["id"])) Loading Loading @@ -193,12 +193,14 @@ module JsDuck :name => name, } # apply information from Ext.extend or Ext.define # apply information from Ext.extend, Ext.define, or {} if ast if ext_extend?(ast) cls[:extends] = to_s(ast["arguments"][0]) elsif ext_define?(ast) detect_ext_define(cls, ast) elsif ast["type"] == "ObjectExpression" detect_class_members(cls, ast) end end Loading Loading @@ -248,6 +250,21 @@ module JsDuck when "inheritableStatics" cls[:statics] += make_statics(value, {:inheritable => true}) else detect_method_or_property(cls, key, value, pair) end end end # Detects class members from object literal def detect_class_members(cls, ast) cls[:members] = [] each_pair_in_object_expression(ast) do |key, value, pair| detect_method_or_property(cls, key, value, pair) end end # Detects item in object literal either as method or property def detect_method_or_property(cls, key, value, pair) if function?(value) m = make_method(key, value) cls[:members] << m if apply_autodetected(m, pair) Loading @@ -256,8 +273,6 @@ module JsDuck cls[:members] << p if apply_autodetected(p, pair) end end end end def make_extends(cfg_value) return nil unless cfg_value Loading spec/aggregator_enum_spec.rb +17 −0 Original line number Diff line number Diff line Loading @@ -80,4 +80,21 @@ describe JsDuck::Aggregator do it_should_behave_like "enum" end describe "enum with implicit values" do let(:doc) do parse(<<-EOS)[0] /** * @enum {String} * Some documentation. */ My.enum.Type = { foo: 'a', bar: 'b' }; EOS end it_should_behave_like "enum" end end Loading
lib/jsduck/ast.rb +25 −10 Original line number Diff line number Diff line Loading @@ -73,7 +73,7 @@ module JsDuck # Foo = ... elsif exp && assignment?(exp) && class_name?(to_s(exp["left"])) make_class(to_s(exp["left"])) make_class(to_s(exp["left"]), exp["right"]) # var foo = Ext.extend("Parent", {}) elsif var && var["init"] && ext_extend?(var["init"]) Loading @@ -81,7 +81,7 @@ module JsDuck # var Foo = ... elsif var && class_name?(to_s(var["id"])) make_class(to_s(var["id"])) make_class(to_s(var["id"]), var["right"]) # function Foo() {} elsif function?(ast) && class_name?(to_s(ast["id"])) Loading Loading @@ -193,12 +193,14 @@ module JsDuck :name => name, } # apply information from Ext.extend or Ext.define # apply information from Ext.extend, Ext.define, or {} if ast if ext_extend?(ast) cls[:extends] = to_s(ast["arguments"][0]) elsif ext_define?(ast) detect_ext_define(cls, ast) elsif ast["type"] == "ObjectExpression" detect_class_members(cls, ast) end end Loading Loading @@ -248,6 +250,21 @@ module JsDuck when "inheritableStatics" cls[:statics] += make_statics(value, {:inheritable => true}) else detect_method_or_property(cls, key, value, pair) end end end # Detects class members from object literal def detect_class_members(cls, ast) cls[:members] = [] each_pair_in_object_expression(ast) do |key, value, pair| detect_method_or_property(cls, key, value, pair) end end # Detects item in object literal either as method or property def detect_method_or_property(cls, key, value, pair) if function?(value) m = make_method(key, value) cls[:members] << m if apply_autodetected(m, pair) Loading @@ -256,8 +273,6 @@ module JsDuck cls[:members] << p if apply_autodetected(p, pair) end end end end def make_extends(cfg_value) return nil unless cfg_value Loading
spec/aggregator_enum_spec.rb +17 −0 Original line number Diff line number Diff line Loading @@ -80,4 +80,21 @@ describe JsDuck::Aggregator do it_should_behave_like "enum" end describe "enum with implicit values" do let(:doc) do parse(<<-EOS)[0] /** * @enum {String} * Some documentation. */ My.enum.Type = { foo: 'a', bar: 'b' }; EOS end it_should_behave_like "enum" end end