Commit 59ad951d authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Initial support for extend: in Ext.define.

Support for the simplest case where "extend:" is the first item
in the config object passed to Ext.define.
parent 6031c423
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -217,6 +217,8 @@ module JsDuck
        doc_map[:extends].first[:extends]
      elsif code[:type] == :assignment && code[:right] && code[:right][:type] == :ext_extend
        code[:right][:extend].join(".")
      elsif code[:type] == :ext_define
        code[:extend]
      end
    end

+21 −4
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ module JsDuck
        function
      elsif look("var")
        var_declaration
      elsif look("Ext", ".", "define", "(")
      elsif look("Ext", ".", "define", "(", :string)
        ext_define
      elsif look(:ident, ":") || look(:string, ":")
        property_literal
@@ -178,15 +178,32 @@ module JsDuck
      }
    end

    # <ext-define> := "Ext" "." "define" "(" <string> "," ...
    # <ext-define> := "Ext" "." "define" "(" <string> "," <ext-define-cfg>
    def ext_define
      match("Ext", ".", "define", "(")
      name = match("Ext", ".", "define", "(", :string)
      cfg = {}

      if look(",")
        match(",")
        cfg = ext_define_cfg
      end

      return {
        :type => :ext_define,
        :name => look(:string) ? match(:string) : nil,
        :name => name,
        :extend => cfg[:extend],
      }
    end

    # <ext-define-cfg> := "{" "extend" ":" <string> "," ...
    def ext_define_cfg
      cfg = {}
      if look("{", "extend", ":", :string)
        cfg[:extend] = match("{", "extend", ":", :string)
      end
      cfg
    end

    # <property-literal> := ( <ident> | <string> ) ":" <expression>
    def property_literal
      left = look(:ident) ? match(:ident) : match(:string)
+5 −2
Original line number Diff line number Diff line
@@ -93,15 +93,18 @@ describe JsDuck::Aggregator do
    end
    it_should_behave_like "class"
    it "detects implied extends" do
      @doc[:extends] == "Your.Class"
      @doc[:extends].should == "Your.Class"
    end
  end

  describe "Ext.define() in code" do
    before do
      @doc = parse("/** */ Ext.define('MyClass', {  });")[0]
      @doc = parse("/** */ Ext.define('MyClass', { extend: 'Your.Class' });")[0]
    end
    it_should_behave_like "class"
    it "detects implied extends" do
      @doc[:extends].should == "Your.Class"
    end
  end

  describe "class with cfgs" do