File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -155,3 +155,11 @@ describe("use cases", () => {
155155 expect ( match . matches [ 3 ] ) . toBe ( "com" ) ;
156156 } ) ;
157157} ) ;
158+
159+ describe ( "error cases" , ( ) => {
160+ it ( "throws an explicit error when there is nothing to repeat" , ( ) => {
161+ expect ( ( ) => {
162+ let foo = new RegExp ( "*m" , "" ) ; // eslint-disable-line no-invalid-regexp
163+ } ) . toThrow ( "Invalid regular expression: Nothing to repeat" ) ;
164+ } ) ;
165+ } ) ;
Original file line number Diff line number Diff line change @@ -251,6 +251,10 @@ export class Parser {
251251 nodes . push ( this . parseCharacter ( ) ) ;
252252 }
253253 } else if ( isQuantifier ( token ) ) {
254+ if ( nodes . length === 0 ) {
255+ throw new Error ( "Invalid regular expression: Nothing to repeat" ) ;
256+ }
257+
254258 const expression = nodes . pop ( ) ;
255259 const quantifier = this . eatToken ( ) ;
256260 nodes . push ( new RepetitionNode ( expression , quantifier , this . isGreedy ( ) ) ) ;
You can’t perform that action at this time.
0 commit comments