Commit 60716fba authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Support auto-detecting members inside Ext.extend()

parent 839f88a7
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -196,7 +196,11 @@ module JsDuck
      # apply information from Ext.extend, Ext.define, or {}
      if ast
        if ext_extend?(ast)
          cls[:extends] = to_s(ast["arguments"][0])
          args = ast["arguments"]
          cls[:extends] = to_s(args[0])
          if args.length == 2 && args[1]["type"] == "ObjectExpression"
            detect_class_members_from_object(cls, args[1])
          end
        elsif ext_define?(ast)
          detect_ext_define(cls, ast)
        elsif ast["type"] == "ObjectExpression"
+65 −9
Original line number Diff line number Diff line
@@ -187,9 +187,7 @@ describe JsDuck::Aggregator do
  describe "method without comment inside Ext.define" do
    let(:method) do
      parse(<<-EOS)[0][:members][:method][0]
        /**
         * Some documentation.
         */
        /** Some documentation. */
        Ext.define("MyClass", {
            foo: function() {}
        });
@@ -202,9 +200,7 @@ describe JsDuck::Aggregator do
  describe "method with line comment inside Ext.define" do
    let(:method) do
      parse(<<-EOS)[0][:members][:method][0]
        /**
         * Some documentation.
         */
        /** Some documentation. */
        Ext.define("MyClass", {
            // My docs
            foo: function() {}
@@ -222,9 +218,7 @@ describe JsDuck::Aggregator do
  describe "property with value Ext.emptyFn inside Ext.define" do
    let(:method) do
      parse(<<-EOS)[0][:members][:method][0]
        /**
         * Some documentation.
         */
        /** Some documentation. */
        Ext.define("MyClass", {
            foo: Ext.emptyFn
        });
@@ -236,4 +230,66 @@ describe JsDuck::Aggregator do
    end
  end

  describe "method without comment inside Ext.extend" do
    let(:method) do
      parse(<<-EOS)[0][:members][:method][0]
        /** Some documentation. */
        MyClass = Ext.extend(Object, {
            foo: function(){}
        });
      EOS
    end

    it_should_behave_like "auto detected method"
  end

  describe "method with line comment inside Ext.extend" do
    let(:method) do
      parse(<<-EOS)[0][:members][:method][0]
        /** Some documentation. */
        MyClass = Ext.extend(Object, {
            // My docs
            foo: function(){}
        });
      EOS
    end

    it_should_behave_like "auto detected method"

    it "detects method documentation" do
      method[:doc].should == 'My docs'
    end
  end

  describe "method without comment inside object literal" do
    let(:method) do
      parse(<<-EOS)[0][:members][:method][0]
        /** Some documentation. */
        MyClass = {
            foo: function(){}
        };
      EOS
    end

    it_should_behave_like "auto detected method"
  end

  describe "method with line comment inside object literal" do
    let(:method) do
      parse(<<-EOS)[0][:members][:method][0]
        /** Some documentation. */
        MyClass = {
            // My docs
            foo: function(){}
        };
      EOS
    end

    it_should_behave_like "auto detected method"

    it "detects method documentation" do
      method[:doc].should == 'My docs'
    end
  end

end
+64 −6
Original line number Diff line number Diff line
@@ -229,9 +229,7 @@ describe JsDuck::Aggregator do
  describe "property without comment inside Ext.define" do
    let(:property) do
      parse(<<-EOS)[0][:members][:property][0]
        /**
         * Some documentation.
         */
        /** Some documentation. */
        Ext.define("MyClass", {
            foo: 15
        });
@@ -244,9 +242,7 @@ describe JsDuck::Aggregator do
  describe "property with line comment inside Ext.define" do
    let(:property) do
      parse(<<-EOS)[0][:members][:property][0]
        /**
         * Some documentation.
         */
        /** Some documentation. */
        Ext.define("MyClass", {
            // My docs
            foo: "bar"
@@ -261,4 +257,66 @@ describe JsDuck::Aggregator do
    end
  end

  describe "property without comment inside Ext.extend" do
    let(:property) do
      parse(<<-EOS)[0][:members][:property][0]
        /** Some documentation. */
        MyClass = Ext.extend(Object, {
            foo: 15
        });
      EOS
    end

    it_should_behave_like "auto detected property"
  end

  describe "property with line comment inside Ext.extend" do
    let(:property) do
      parse(<<-EOS)[0][:members][:property][0]
        /** Some documentation. */
        MyClass = Ext.extend(Object, {
            // My docs
            foo: "bar"
        });
      EOS
    end

    it_should_behave_like "auto detected property"

    it "detects property documentation" do
      property[:doc].should == 'My docs'
    end
  end

  describe "property without comment inside object literal" do
    let(:property) do
      parse(<<-EOS)[0][:members][:property][0]
        /** Some documentation. */
        MyClass = {
            foo: 15
        };
      EOS
    end

    it_should_behave_like "auto detected property"
  end

  describe "property with line comment inside object literal" do
    let(:property) do
      parse(<<-EOS)[0][:members][:property][0]
        /** Some documentation. */
        MyClass = {
            // My docs
            foo: "bar"
        };
      EOS
    end

    it_should_behave_like "auto detected property"

    it "detects property documentation" do
      property[:doc].should == 'My docs'
    end
  end

end