Commit e5ba0257 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Initial support for Ext.define() syntax.

parent bbb7b041
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -67,12 +67,15 @@ module JsDuck
    # The following is a recursive-descent parser for JavaScript that
    # can possibly follow a doc-comment

    # <code-block> := <function> | <var-declaration> | <assignment> | <property-literal>
    # <code-block> := <function> | <var-declaration> | <ext-define> |
    #                 <assignment> | <property-literal>
    def code_block
      if look("function")
        function
      elsif look("var")
        var_declaration
      elsif look("Ext", ".", "define", "(")
        ext_define
      elsif look(:ident, ":") || look(:string, ":")
        property_literal
      elsif look(",", :ident, ":") || look(",", :string, ":")
@@ -175,6 +178,16 @@ module JsDuck
      }
    end

    # <ext-define> := "Ext" "." "define" "(" <string> "," ...
    def ext_define
      match("Ext", ".", "define", "(")
      return {
        :type => :function,
        :name => look(:string) ? match(:string) : nil,
        :params => []
      }
    end

    # <property-literal> := ( <ident> | <string> ) ":" <expression>
    def property_literal
      left = look(:ident) ? match(:ident) : match(:string)
+7 −0
Original line number Diff line number Diff line
@@ -97,6 +97,13 @@ describe JsDuck::Aggregator do
    end
  end

  describe "Ext.define() in code" do
    before do
      @doc = parse("/** */ Ext.define('MyClass', {  });")[0]
    end
    it_should_behave_like "class"
  end

  describe "class with cfgs" do
    before do
      @doc = parse(<<-EOS)[0]