Loading lib/jsduck/type_parser.rb +5 −5 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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 Loading spec/type_parser_spec.rb +4 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading
lib/jsduck/type_parser.rb +5 −5 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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 Loading
spec/type_parser_spec.rb +4 −0 Original line number Diff line number Diff line Loading @@ -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 Loading