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

Support for @xtype.

Again one of the most used @tags in ExtJS.

Only supporting it in class declaration, plus some explicit logic to
detect it when it appears after @constructor in class doc-comment.
parent cd035c7e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ List of @tags to support
* @param - OK
* @return - OK
* @static - OK
* @xtype - OK

* @member
* @link
+11 −0
Original line number Diff line number Diff line
@@ -65,6 +65,8 @@ module JsDuck
          at_property
        elsif look(/@type\b/) then
          at_type
        elsif look(/@xtype\b/) then
          at_xtype
        elsif look(/@private\b/) then
          boolean_at_tag(/@private/, :private)
        elsif look(/@ignore\b/) then
@@ -170,6 +172,15 @@ module JsDuck
      skip_white
    end

    # matches @xtype name
    def at_xtype
      match(/@xtype/)
      add_tag(:xtype)
      maybe_type
      maybe_name
      skip_white
    end

    # Used to match @private, @ignore, @hide, ...
    def boolean_at_tag(regex, propname)
      match(regex)
+11 −2
Original line number Diff line number Diff line
@@ -66,7 +66,9 @@ module JsDuck
    end

    # Gathers all tags until first @cfg or @constructor into the first
    # bare :class group.
    # bare :class group.  We have a special case for @xtype which in
    # ExtJS comments often appears after @constructor - so we
    # explicitly place it into :class group.
    #
    # Then gathers each @cfg and tags following it into :cfg group, so
    # that it becomes array of arrays of tags.  This is to allow some
@@ -84,7 +86,9 @@ module JsDuck
          end
        end

        if group_name == :cfg
        if tag[:tagname] == :xtype
          groups[:class] << tag
        elsif group_name == :cfg
          groups[:cfg].last << tag
        else
          groups[group_name] << tag
@@ -100,6 +104,7 @@ module JsDuck
        :name => detect_name(:class, doc_map, code, :full_name),
        :doc => detect_doc(docs),
        :extends => detect_extends(doc_map, code),
        :xtype => detect_xtype(doc_map),
        :singleton => !!doc_map[:singleton],
        :private => !!doc_map[:private],
      }
@@ -190,6 +195,10 @@ module JsDuck
      end
    end

    def detect_xtype(doc_map)
      doc_map[:xtype] ? doc_map[:xtype].first[:name] : nil
    end

    def detect_params(docs, code)
      implicit = detect_implicit_params(code)
      explicit = detect_explicit_params(docs)
+14 −0
Original line number Diff line number Diff line
@@ -250,12 +250,14 @@ mousedown: true,
 * @extends Your.Class
 * A good class indeed.
 * @singleton
 * @xtype nicely
 */")
    assert_equal(:class, docs[0][:tagname])
    assert_equal("My.nice.Class", docs[0][:name])
    assert_equal("Your.Class", docs[0][:extends])
    assert_equal("A good class indeed.", docs[0][:doc])
    assert_equal(true, docs[0][:singleton])
    assert_equal("nicely", docs[0][:xtype])
  end

  def test_implicit_class_name_from_function
@@ -356,6 +358,18 @@ MyClass = Ext.extend(Ext.util.Observable, {
    assert_equal("Number", params[0][:type])
  end

  def test_xtype_after_constructor
    docs = JsDuck.parse("/**
 * @class Foo
 * Comment here.
 * @constructor
 * Often in ExtJS the xtype tag follows constructor tag.
 * @xtype blah
 */")
    assert_equal(:class, docs[0][:tagname])
    assert_equal("blah", docs[0][:xtype])
  end

  def test_cfg
    docs = JsDuck.parse("
/**