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

Generalize support for @xtype, @ptype, @ftype.

parent 6d44108e
Loading
Loading
Loading
Loading
+8 −15
Original line number Diff line number Diff line
@@ -115,9 +115,11 @@ module JsDuck
        elsif look(/@type\b/)
          at_type
        elsif look(/@xtype\b/)
          at_xtype
          at_xtype(/@xtype/, "widget")
        elsif look(/@ftype\b/)
          at_ftype
          at_xtype(/@ftype/, "feature")
        elsif look(/@ptype\b/)
          at_xtype(/@ptype/, "plugin")
        elsif look(/@member\b/)
          at_member
        elsif look(/@inherit[dD]oc\b/)
@@ -316,21 +318,12 @@ module JsDuck
      skip_white
    end

    # matches @xtype name
    def at_xtype
      match(/@xtype/)
    # matches @xtype/ptype/ftype/... name
    def at_xtype(tag, namespace)
      match(tag)
      add_tag(:alias)
      skip_horiz_white
      @current_tag[:name] = "widget." + (ident_chain || "")
      skip_white
    end

    # matches @ftype name
    def at_ftype
      match(/@ftype/)
      add_tag(:alias)
      skip_horiz_white
      @current_tag[:name] = "feature." + (ident_chain || "")
      @current_tag[:name] = namespace + "." + (ident_chain || "")
      skip_white
    end

+28 −0
Original line number Diff line number Diff line
@@ -100,6 +100,34 @@ describe JsDuck::Aggregator do
    end
  end

  describe "class with @ftype" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * @class MyClass
         * @ftype foo
         */
      EOS
    end
    it "detects a feature alias" do
      @doc[:aliases].should == {"feature" => ["foo"]}
    end
  end

  describe "class with @ptype" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * @class MyClass
         * @ptype foo
         */
      EOS
    end
    it "detects a plugin alias" do
      @doc[:aliases].should == {"plugin" => ["foo"]}
    end
  end

  describe "@xtype after @constructor" do
    before do
      @doc = parse(<<-EOS)[0]