Commit 1196a517 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Fix output of parsed Google closure compiler type annotations.

The output of parsing was only barely tested and so some things were
just completely missing from output.
parent 07183525
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -207,6 +207,7 @@ module JsDuck

      key = @input.scan(/[a-zA-Z0-9_]+/)
      return false unless key
      @out << key

      skip_whitespace
      if @input.scan(/:/)
@@ -321,8 +322,10 @@ module JsDuck

      # All type names besides * can be followed by .<arguments>
      if name != "*" && @input.scan(/\.</)
        @out << ".&lt;"
        return false unless type_arguments
        return false unless @input.scan(/>/)
        @out << "&gt;"
      end

      true
+21 −3
Original line number Diff line number Diff line
@@ -303,11 +303,29 @@ describe JsDuck::TypeParser do
      p.out.should == '<a href="String">string</a>'
    end

    it "preserves whitespace in output" do
    def parse_to_output(input)
      relations = JsDuck::Relations.new([])
      p = JsDuck::TypeParser.new(relations)
      p.parse("( string | number )")
      p.out.should == '( string | number )'
      p.parse(input)
      return p.out
    end

    it "preserves whitespace in output" do
      parse_to_output("( string | number )").should == "( string | number )"
    end

    it "converts < and > to HTML entities in output" do
      parse_to_output("number.<string, *>").should == "number.&lt;string, *&gt;"
    end

    it "preserves function notation in output" do
      input = 'function(this:string, ?number=, !number, ...[number]): boolean'
      parse_to_output(input).should == input
    end

    it "preserves object literal notation in output" do
      input = '{myNum: number, myObject}'
      parse_to_output(input).should == input
    end

  end