Commit 0711037d authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Avoid detecting property names too eagerly.

Previously this code:

    /** Some docs */
    doSomething(1, 2, 3);

would have resulted in property "doSomething" being detected.

Now it detects no name, which results in warning of missing name,
and that's what we want.
parent cfbb8686
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -138,13 +138,22 @@ module JsDuck
      maybe_assignment
    end

    # <maybe-assignment> := <ident-chain> [ "=" <expression> ]
    # <maybe-assignment> := <ident-chain> ( "=" <expression> | ";" | "," )
    def maybe_assignment
      left = ident_chain
      if look("=")
        match("=")
        right = expression
      elsif look(";")
        match(";")
        right = nil
      elsif look(",")
        match(",")
        right = nil
      else
        return {:type => :nop}
      end

      return {
        :type => :assignment,
        :left => left,
+42 −0
Original line number Diff line number Diff line
@@ -284,4 +284,46 @@ describe JsDuck::Aggregator do
    it_should_behave_like "cfg or property"
  end

  describe "doc-comment before variable without assignment" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * Some documentation.
         */
        var foo;
      EOS
    end
    it "should detect the variable name" do
      @doc[:name].should == "foo"
    end
  end

  describe "doc-comment before multiple variables" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * Some documentation.
         */
        var foo, bar, baz;
      EOS
    end
    it "should detect the first variable name" do
      @doc[:name].should == "foo"
    end
  end

  describe "doc-comment before function call" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * Some documentation.
         */
        Ext.createAlias(class, "foo", "bar");
      EOS
    end
    it "should fail detecting name of the property" do
      @doc[:name].should == ""
    end
  end

end