Loading lib/jsduck/type_parser.rb +4 −1 Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ module JsDuck end # # <alteration-type> ::= <varargs-type> [ ("/" | "|") <varargs-type> ]* # <alteration-type> ::= <varargs-type> [ ("/" | "|") <varargs-type> ]* [ "=" ] # def alteration_type skip_whitespace Loading @@ -78,6 +78,9 @@ module JsDuck skip_whitespace end @out << "=" if @input.scan(/=/) skip_whitespace true end Loading spec/type_parser_spec.rb +18 −6 Original line number Diff line number Diff line Loading @@ -173,12 +173,12 @@ describe JsDuck::TypeParser do parse("( String | Number )").should == true end # This is handled inside DocParser, when it's detected over there # the "=" is removed from the end of type definition, so it should # never reach TypeParser if there is just one "=" at the end of # type definition. it "doesn't accept optional parameter notation" do parse("String=").should == false # This is handled mainly inside DocParser, when it's detected over # there the "=" is removed from the end of type definition, so it # should never reach TypeParser. But additionally it can be used # inside function type parameter list, so we need to support it. it "matches optional parameter notation" do parse("String=").should == true end it "matches single type argument" do Loading Loading @@ -217,6 +217,18 @@ describe JsDuck::TypeParser do parse("function():Number").should == true end it "matches function type with varargs" do parse("function(...Number)").should == true end it "matches function type with nullable/non-nullable arguments" do parse("function(!String, ?Number)").should == true end it "matches function type with optional argument" do parse("function(Number=)").should == true end it "matches function type with extra whitespace" do parse("function( ) : Array").should == true end Loading Loading
lib/jsduck/type_parser.rb +4 −1 Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ module JsDuck end # # <alteration-type> ::= <varargs-type> [ ("/" | "|") <varargs-type> ]* # <alteration-type> ::= <varargs-type> [ ("/" | "|") <varargs-type> ]* [ "=" ] # def alteration_type skip_whitespace Loading @@ -78,6 +78,9 @@ module JsDuck skip_whitespace end @out << "=" if @input.scan(/=/) skip_whitespace true end Loading
spec/type_parser_spec.rb +18 −6 Original line number Diff line number Diff line Loading @@ -173,12 +173,12 @@ describe JsDuck::TypeParser do parse("( String | Number )").should == true end # This is handled inside DocParser, when it's detected over there # the "=" is removed from the end of type definition, so it should # never reach TypeParser if there is just one "=" at the end of # type definition. it "doesn't accept optional parameter notation" do parse("String=").should == false # This is handled mainly inside DocParser, when it's detected over # there the "=" is removed from the end of type definition, so it # should never reach TypeParser. But additionally it can be used # inside function type parameter list, so we need to support it. it "matches optional parameter notation" do parse("String=").should == true end it "matches single type argument" do Loading Loading @@ -217,6 +217,18 @@ describe JsDuck::TypeParser do parse("function():Number").should == true end it "matches function type with varargs" do parse("function(...Number)").should == true end it "matches function type with nullable/non-nullable arguments" do parse("function(!String, ?Number)").should == true end it "matches function type with optional argument" do parse("function(Number=)").should == true end it "matches function type with extra whitespace" do parse("function( ) : Array").should == true end Loading