Commit 7f16c452 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Detect aliases in Ast class.

parent a554b529
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -156,11 +156,13 @@ module JsDuck
          cfg = object_expression_to_hash(ast["arguments"][1])

          cls[:extends] = make_extends(cfg["extend"]) || "Ext.Base"
          cls[:requires] = make_requires(cfg["requires"])
          cls[:uses] = make_requires(cfg["uses"])
          cls[:alternateClassNames] = make_requires(cfg["alternateClassName"])
          cls[:requires] = make_string_list(cfg["requires"])
          cls[:uses] = make_string_list(cfg["uses"])
          cls[:alternateClassNames] = make_string_list(cfg["alternateClassName"])
          cls[:mixins] = make_mixins(cfg["mixins"])
          cls[:singleton] = make_singleton(cfg["singleton"])
          cls[:aliases] = make_string_list(cfg["alias"])
          cls[:aliases] += make_string_list(cfg["xtype"]).map {|xtype| "widget."+xtype }
        end
      end

@@ -175,7 +177,7 @@ module JsDuck
      return parent.is_a?(String) ? parent : nil
    end

    def make_requires(cfg_value)
    def make_string_list(cfg_value)
      return [] unless cfg_value

      classes = Array(to_value(cfg_value))
+2 −2
Original line number Diff line number Diff line
@@ -280,8 +280,8 @@ describe JsDuck::Aggregator do
      @doc = parse(<<-EOS)[0]
        /** */
        Ext.define('MyClass', {
          xtype: 'foo',
          alias: 'widget.bar'
          alias: 'widget.foo',
          xtype: 'bar'
        });
      EOS
    end
+40 −0
Original line number Diff line number Diff line
@@ -260,4 +260,44 @@ describe "JsDuck::Ast detects class with" do
      EOS
    end
  end

  describe "aliases in" do
    it "Ext.define() single string alias" do
      detect(<<-EOS)[:aliases].should == ["widget.foo"]
        /** */
        Ext.define('MyClass', {
            alias: "widget.foo"
        });
      EOS
    end

    it "Ext.define() with alias as array" do
      detect(<<-EOS)[:aliases].should == ["widget.foo", "widget.fooeditor"]
        /** */
        Ext.define('MyClass', {
            alias: ["widget.foo", "widget.fooeditor"]
        });
      EOS
    end

    it "Ext.define() with xtype" do
      detect(<<-EOS)[:aliases].should == ["widget.foo"]
        /** */
        Ext.define('MyClass', {
            xtype: "foo"
        });
      EOS
    end

    it "Ext.define() with alias and xtype" do
      detect(<<-EOS)[:aliases].should == ["widget.foo", "widget.fooeditor"]
        /** */
        Ext.define('MyClass', {
            alias: "widget.foo",
            xtype: "fooeditor"
        });
      EOS
    end
  end

end