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

Handle Ext.baseCSSPrefix in default value detection.

Restore functionality present in current JSDuck 3.x
parent 5983d95e
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -26,6 +26,18 @@ module JsDuck
          h[key] = value
        end
        h
      when "BinaryExpression"
        if ast["operator"] == "+"
          to_value(ast["left"]) + to_value(ast["right"])
        else
          throw "Unable to handle operator: " + ast["operator"]
        end
      when "MemberExpression"
        if base_css_prefix?(ast)
          "x-"
        else
          throw "Unable to handle this MemberExpression"
        end
      when "Literal"
        if ast["value"] == nil && ast["raw"] =~ /\A\//
          :regexp
@@ -42,6 +54,15 @@ module JsDuck
      key["type"] == "Identifier" ? key["name"] : key["value"]
    end

    # True when MemberExpression == Ext.baseCSSPrefix
    def base_css_prefix?(ast)
      ast["computed"] == false &&
        ast["object"]["type"] == "Identifier" &&
        ast["object"]["name"] == "Ext" &&
        ast["property"]["type"] == "Identifier" &&
        ast["property"]["name"] == "baseCSSPrefix"
    end

  end

end
+15 −15
Original line number Diff line number Diff line
@@ -374,19 +374,19 @@ describe JsDuck::Aggregator do
    end
  end

  # describe "cfg with implicit string value starting with Ext.baseCSSPrefix" do
  #   before do
  #     @doc = parse(<<-EOS)[0]
  #     ({/**
  #        * @cfg foo Something
  #        */
  #       foo: Ext.baseCSSPrefix + "foo" })
  #     EOS
  #   end
  #   it "replaces Ext.baseCSSPrefix with 'x-'" do
  #     @doc[:default].should == '"x-foo"'
  #   end
  # end
  describe "cfg with implicit string value starting with Ext.baseCSSPrefix" do
    before do
      @doc = parse(<<-EOS)[0]
      ({/**
         * @cfg foo Something
         */
        foo: Ext.baseCSSPrefix + "foo" })
      EOS
    end
    it "replaces Ext.baseCSSPrefix with 'x-'" do
      @doc[:default].should == 'Ext.baseCSSPrefix + "foo"'
    end
  end

  describe "cfg with implicit number value given as expression" do
    before do
@@ -397,8 +397,8 @@ describe JsDuck::Aggregator do
        foo: 5 + 5 })
      EOS
    end
    it "doesn't get the default value from code" do
      @doc[:default].should == nil
    it "detects the literal expression from code" do
      @doc[:default].should == "5 + 5"
    end
  end