Commit 2f80702a authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Fix auto-detecting default cfg value if it's expression.

Previously the following:

    /** @cfg */
    timeout: 30 * 1000,

would have been detected having default value of 30.

Now such values are just ignored.
parent 4fcfbc95
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -172,7 +172,7 @@ module JsDuck
    # <literal> := ...see JsLiteralParser...
    def my_literal
      lit = literal
      return unless lit
      return unless lit && literal_expression_end?

      cls_map = {
        :string => "String",
@@ -195,6 +195,13 @@ module JsDuck
      {:type => :literal, :class => cls, :value => value}
    end

    # True when we're at the end of literal expression.
    # ",", ";" and "}" are the normal closing symbols, but for
    # our docs purposes doc-comment and file end work too.
    def literal_expression_end?
      look(",") || look(";") || look("}") || look(:doc_comment) || @lex.empty?
    end

    # <ext-extend> := "Ext" "." "extend" "(" <ident-chain> "," ...
    def ext_extend
      match(:ident, ".", "extend", "(")
+28 −0
Original line number Diff line number Diff line
@@ -331,6 +331,34 @@ describe JsDuck::Aggregator do
    end
  end

  describe "cfg with implicit number value given as expression" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * @cfg {Number} foo
         */
        foo: 5 + 5
      EOS
    end
    it "doesn't get the default value from code" do
      @doc[:default].should == nil
    end
  end

  describe "cfg with implicit array value with chained method" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * @cfg {Array} foo
         */
        foo: [1, 2, 3].compact()
      EOS
    end
    it "doesn't get the default value from code" do
      @doc[:default].should == nil
    end
  end

  describe "cfg with implicit name followed by code field with another name" do
    before do
      @doc = parse(<<-EOS)[0]