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

Support for @private.

parent 6cfbc011
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -55,6 +55,8 @@ module JsDuck
          at_extends
        elsif look(/@singleton\b/) then
          at_singleton
        elsif look(/@private\b/) then
          at_private
        elsif look(/@event\b/) then
          at_event
        elsif look(/@method\b/) then
@@ -128,6 +130,17 @@ module JsDuck
      skip_white
    end

    # matches @private
    # sets :private property to true on the root tag
    def at_private
      match(/@private/)
      tagname = [:class, :method, :event, :property, :default].find {|name| @tags[name]}
      if tagname
        @tags[tagname][:private] = true
      end
      skip_white
    end

    # matches @event name ...
    def at_event
      match(/@event/)
+47 −0
Original line number Diff line number Diff line
@@ -229,5 +229,52 @@ class TestDocCommentParser < Test::Unit::TestCase
    assert_equal(nil, doc[:param][0][:name])
    assert_equal("My parameter.", doc[:param][0][:doc])
  end

  def test_private_class
    doc = parse_single("/**
 * @class Foo
 * Blah blah
 * @private
 */")
    assert(doc[:class][:private])
  end

  def test_private_method
    doc = parse_single("/**
 * @method foo
 * Some method
 * @param {type} x
 * @private
 */")
    assert(doc[:method][:private])
  end

  def test_private_event
    doc = parse_single("/**
 * @event foo
 * Some prop
 * @param {type} x
 * @private
 */")
    assert(doc[:event][:private])
  end

  def test_private_property
    doc = parse_single("/**
 * @property foo
 * Some prop
 * @private
 */")
    assert(doc[:property][:private])
  end

  def test_private_default
    doc = parse_single("/**
 * Some docs
 * @private
 */")
    assert(doc[:default][:private])
  end

end