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

Auto-detect singleton classes.

When singleton:true inside Ext.define config.
parent 2bb2665b
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -220,7 +220,7 @@ module JsDuck
      cfg
    end

    # <ext-define-cfg> := "{" ( <extend> | <mixins> | <alternate-class-name> | <alias> | <?> )*
    # <ext-define-cfg> := "{" ( <extend> | <mixins> | <alternate-class-name> | <alias> | <singleton> | <?> )*
    def ext_define_cfg
      match("{")
      cfg = {}
@@ -239,6 +239,9 @@ module JsDuck
        elsif look("alias", ":")
          cfg[:alias] = ext_define_alias
          found = true
        elsif look("singleton", ":", "true")
          cfg[:singleton] = ext_define_singleton
          found = true
        elsif look(:ident, ":")
          match(:ident, ":")
          found = literal
@@ -265,6 +268,12 @@ module JsDuck
      string_or_list
    end

    # <ext-define-singleton> := "singleton" ":" "true"
    def ext_define_singleton
      match("singleton", ":", "true")
      true
    end

    # <string-or-list> := ( <string> | <array-literal> )
    def string_or_list
      lit = literal
+5 −1
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ module JsDuck
        :xtypes => detect_xtypes(doc_map, code),
        :author => detect_author(doc_map),
        :docauthor => detect_docauthor(doc_map),
        :singleton => !!doc_map[:singleton],
        :singleton => detect_singleton(doc_map, code),
        # Used by Aggregator to determine if we're dealing with Ext4 code
        :code_type => code[:type],
      }, doc_map)
@@ -320,6 +320,10 @@ module JsDuck
      doc_map[:deprecated] ? doc_map[:deprecated].first : nil
    end

    def detect_singleton(doc_map, code)
      !!(doc_map[:singleton] || code[:type] == :ext_define && code[:singleton])
    end

    def detect_params(docs, code)
      implicit = detect_implicit_params(code)
      explicit = detect_explicit_params(docs)
+7 −2
Original line number Diff line number Diff line
@@ -198,6 +198,9 @@ describe JsDuck::Aggregator do
    it "detects implied xtype" do
      @doc[:xtypes].should == ["foo"]
    end
    it "detects implied singleton" do
      @doc[:singleton].should == true
    end
  end

  describe "basic Ext.define() in code" do
@@ -211,7 +214,8 @@ describe JsDuck::Aggregator do
            bar: 'Foo.Bar'
          },
          alias: 'widget.foo',
          alternateClassName: 'JustClass'
          alternateClassName: 'JustClass',
          singleton: true
        });
      EOS
    end
@@ -234,9 +238,10 @@ describe JsDuck::Aggregator do
      @doc = parse(<<-EOS)[0]
        /** */
        Ext.define('MyClass', {
          singleton: true,
          blah: true,
          extend: 'Your.Class',
          alias: ['widget.foo', 'something.bar'],
          singleton: true,
          alternateClassName: ['JustClass'],
          requires: ['Hohooo', 'hahaa'],
          mixins: {