Commit 5ad57977 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Support for nullability type notation.

The syntax used by Google Closure Compiler.
parent 9d35b6ce
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -59,7 +59,9 @@ module JsDuck

    # The basic type
    #
    #     <varargs-type> ::= [ "..." ] <array-type> | <array-type> [ "..." ]
    #     <varargs-type> ::= [ "..." ] <null-type> | <null-type> [ "..." ]
    #
    #     <null-type> ::= [ "?" | "!" ] <array-type>
    #
    #     <array-type> ::= <type-name> [ "[]" ]
    #
@@ -76,6 +78,10 @@ module JsDuck
        @out << "..."
      end

      if nullability = @input.scan(/[?!]/)
        @out << nullability
      end

      type = @input.scan(/[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*|\*/)

      if !type
+13 −0
Original line number Diff line number Diff line
@@ -129,6 +129,19 @@ describe JsDuck::TypeParser do
      parse("...*...").should == false
    end

    it "matches the nullable notation" do
      parse("?String").should == true
    end

    it "matches the non-nullable notation" do
      parse("!String").should == true
    end

    it "doesn't matches both nullable and non-nullable at the same time" do
      parse("?!String").should == false
      parse("!?String").should == false
    end

  end

end