Commit 0f676471 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Support both / and | as type union separators.

In supporting Google Closure Compiler syntax.
parent 5ad57977
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ module JsDuck

    # Parses the type definition
    #
    #     <type> ::= <varargs-type> [ "/" <type> ]*
    #     <type> ::= <varargs-type> [ ("/" | "|") <type> ]*
    #
    def parse(str)
      @input = StringScanner.new(str)
@@ -43,10 +43,10 @@ module JsDuck
      # Return immediately if varargs-type doesn't match
      return false unless varargs_type

      # Go through enumeration of types, separated with "/"
      while @input.check(/\//)
        @out << @input.scan(/\//)
        # Fail if there's no varargs-type after "/"
      # Go through enumeration of types, separated with "/" or "|"
      while @input.check(/[\/|]/)
        @out << @input.scan(/[\/|]/)
        # Fail if there's no varargs-type after / or |
        return false unless varargs_type
      end

+4 −0
Original line number Diff line number Diff line
@@ -142,6 +142,10 @@ describe JsDuck::TypeParser do
      parse("!?String").should == false
    end

    it "matches alteration with pipe" do
      parse("String|Number|RegExp").should == true
    end

  end

end