Commit 025762f0 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Handle auto-detecting cachedConfig.

Treat it exactly the same as normal config.
parent a68ba908
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -195,7 +195,11 @@ module JsDuck
          cls[:singleton] = make_singleton(cfg["singleton"])
          cls[:aliases] = make_string_list(cfg["alias"])
          cls[:aliases] += make_string_list(cfg["xtype"]).map {|xtype| "widget."+xtype }
          cls[:members] = make_configs(cfg["config"])

          members = []
          members += make_configs(cfg["config"])
          members += make_configs(cfg["cachedConfig"])
          cls[:members] = members.length > 0 ? members : nil
        end
      end

@@ -232,7 +236,7 @@ module JsDuck
    end

    def make_configs(ast)
      return nil unless ast && ast["type"] == "ObjectExpression"
      return [] unless ast && ast["type"] == "ObjectExpression"

      configs = []

+43 −0
Original line number Diff line number Diff line
@@ -45,6 +45,49 @@ describe JsDuck::Aggregator do
    end
  end

  describe "detecting Ext.define() with cachedConfig in code" do
    let(:cfg) do
      parse(<<-EOS)[0][:members][:cfg]
        /**
         * Some documentation.
         */
        Ext.define("MyClass", {
            cachedConfig: {
                foo: 42,
                bar: "hello"
            }
        });
      EOS
    end

    it "finds also two configs exactly like with config:" do
      cfg.length.should == 2
    end
  end

  describe "detecting Ext.define() with both config and cachedConfig" do
    let(:cfg) do
      parse(<<-EOS)[0][:members][:cfg]
        /**
         * Some documentation.
         */
        Ext.define("MyClass", {
            cachedConfig: {
                foo: 42,
                bar: "hello"
            },
            config: {
                baz: /fafa/
            }
        });
      EOS
    end

    it "merges all configs together" do
      cfg.length.should == 3
    end
  end

  describe "detecting Ext.define() with commented config" do
    let(:docs) do
      parse(<<-EOS)