Loading lib/jsduck/type_parser.rb +18 −2 Original line number Diff line number Diff line Loading @@ -54,14 +54,20 @@ module JsDuck # <alteration-type> ::= <varargs-type> [ ("/" | "|") <varargs-type> ]* # def alteration_type skip_whitespace # Return immediately if varargs-type doesn't match return false unless varargs_type skip_whitespace # Go through enumeration of types, separated with "/" or "|" while @input.check(/[\/|]/) @out << @input.scan(/[\/|]/) # Fail if there's no varargs-type after / or | skip_whitespace return false unless varargs_type skip_whitespace end true Loading Loading @@ -148,19 +154,29 @@ module JsDuck # <type-arguments> ::= <alteration-type> [ "," <alteration-type> ]* # def type_arguments skip_whitespace # First argument is required return false unless alteration_type skip_whitespace # Go through additional arguments, separated with "," while @input.check(/,/) @out << @input.scan(/,/) # Fail if there's no alteration-type after "," skip_whitespace return false unless alteration_type skip_whitespace end true end def skip_whitespace @input.scan(/\s*/) end end end spec/type_parser_spec.rb +12 −0 Original line number Diff line number Diff line Loading @@ -147,6 +147,10 @@ describe JsDuck::TypeParser do parse("String|Number|RegExp").should == true end it "matches alteration with extra spacing" do parse(" String | Number ").should == true end it "matches union of one simple type" do parse("(String)").should == true end Loading @@ -163,6 +167,10 @@ describe JsDuck::TypeParser do parse("(String|(Number|RegExp))").should == true end it "matches union with extra spacing" 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 Loading @@ -179,6 +187,10 @@ describe JsDuck::TypeParser do parse("Ext.Element.<String,Number>").should == true end it "matches type arguments with extra spacing" do parse("Ext.Element.< String , Number >").should == true end it "matches nested type arguments" do parse("Array.<Array.<String>|Array.<Number>>").should == true end Loading Loading
lib/jsduck/type_parser.rb +18 −2 Original line number Diff line number Diff line Loading @@ -54,14 +54,20 @@ module JsDuck # <alteration-type> ::= <varargs-type> [ ("/" | "|") <varargs-type> ]* # def alteration_type skip_whitespace # Return immediately if varargs-type doesn't match return false unless varargs_type skip_whitespace # Go through enumeration of types, separated with "/" or "|" while @input.check(/[\/|]/) @out << @input.scan(/[\/|]/) # Fail if there's no varargs-type after / or | skip_whitespace return false unless varargs_type skip_whitespace end true Loading Loading @@ -148,19 +154,29 @@ module JsDuck # <type-arguments> ::= <alteration-type> [ "," <alteration-type> ]* # def type_arguments skip_whitespace # First argument is required return false unless alteration_type skip_whitespace # Go through additional arguments, separated with "," while @input.check(/,/) @out << @input.scan(/,/) # Fail if there's no alteration-type after "," skip_whitespace return false unless alteration_type skip_whitespace end true end def skip_whitespace @input.scan(/\s*/) end end end
spec/type_parser_spec.rb +12 −0 Original line number Diff line number Diff line Loading @@ -147,6 +147,10 @@ describe JsDuck::TypeParser do parse("String|Number|RegExp").should == true end it "matches alteration with extra spacing" do parse(" String | Number ").should == true end it "matches union of one simple type" do parse("(String)").should == true end Loading @@ -163,6 +167,10 @@ describe JsDuck::TypeParser do parse("(String|(Number|RegExp))").should == true end it "matches union with extra spacing" 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 Loading @@ -179,6 +187,10 @@ describe JsDuck::TypeParser do parse("Ext.Element.<String,Number>").should == true end it "matches type arguments with extra spacing" do parse("Ext.Element.< String , Number >").should == true end it "matches nested type arguments" do parse("Array.<Array.<String>|Array.<Number>>").should == true end Loading