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

Change field names in output of Ast class.

Now using :tagname instead of :type (just like the :tagname property
produced by DocParser).

And using :type instead of :value_type (for consistency).
parent efe08e56
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -143,7 +143,7 @@ module JsDuck

    def make_class(name, ast=nil)
      cls = {
        :type => :class,
        :tagname => :class,
        :name => name,
      }

@@ -192,7 +192,7 @@ module JsDuck

    def make_method(name, ast=nil)
      return {
        :type => :method,
        :tagname => :method,
        :name => name,
        :params => make_params(ast)
      }
@@ -208,9 +208,9 @@ module JsDuck

    def make_property(name=nil, ast=nil)
      return {
        :type => :property,
        :tagname => :property,
        :name => name,
        :value_type => make_value_type(ast)
        :type => make_value_type(ast)
      }
    end

+2 −2
Original line number Diff line number Diff line
@@ -25,13 +25,13 @@ module JsDuck
      elsif doc_map[:cfg] && doc_map[:cfg].length == 1
        # When just one @cfg, avoid treating it as @class
        :cfg
      elsif code[:type] == :class
      elsif code[:tagname] == :class
        :class
      elsif code[:type] == :css_mixin
        :css_mixin
      elsif doc_map[:cfg]
        :cfg
      elsif code[:type] == :method
      elsif code[:tagname] == :method
        :method
      else
        :property
+9 −9
Original line number Diff line number Diff line
@@ -51,39 +51,39 @@ describe "JsDuck::Ast detects property with" do
    end
  end

  describe "value type in var initialized with" do
  describe "type in var initialized with" do
    it "int" do
      detect("/** */ var foo = 5;")[:value_type].should == "Number"
      detect("/** */ var foo = 5;")[:type].should == "Number"
    end

    it "float" do
      detect("/** */ var foo = 0.5;")[:value_type].should == "Number"
      detect("/** */ var foo = 0.5;")[:type].should == "Number"
    end

    it "string" do
      detect("/** */ var foo = 'haa';")[:value_type].should == "String"
      detect("/** */ var foo = 'haa';")[:type].should == "String"
    end

    it "true" do
      detect("/** */ var foo = true;")[:value_type].should == "Boolean"
      detect("/** */ var foo = true;")[:type].should == "Boolean"
    end

    it "false" do
      detect("/** */ var foo = false;")[:value_type].should == "Boolean"
      detect("/** */ var foo = false;")[:type].should == "Boolean"
    end

    it "array" do
      detect("/** */ var foo = [];")[:value_type].should == "Array"
      detect("/** */ var foo = [];")[:type].should == "Array"
    end

    it "object" do
      detect("/** */ var foo = {};")[:value_type].should == "Object"
      detect("/** */ var foo = {};")[:type].should == "Object"
    end
  end

  describe "no value type in" do
    it "uninitialized var declaration" do
      detect("/** */ var foo;")[:value_type].should == nil
      detect("/** */ var foo;")[:type].should == nil
    end
  end

+1 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ require "jsduck/esprima_parser"
describe JsDuck::Ast do
  def detect(string)
    node = JsDuck::EsprimaParser.new(string).parse[0]
    return JsDuck::Ast.new.detect(node[:code])[:type]
    return JsDuck::Ast.new.detect(node[:code])[:tagname]
  end

  describe "detects as class" do