File tree 2 files changed +12
-0
lines changed
2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -155,3 +155,11 @@ describe("use cases", () => {
155
155
expect ( match . matches [ 3 ] ) . toBe ( "com" ) ;
156
156
} ) ;
157
157
} ) ;
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 {
251
251
nodes . push ( this . parseCharacter ( ) ) ;
252
252
}
253
253
} else if ( isQuantifier ( token ) ) {
254
+ if ( nodes . length === 0 ) {
255
+ throw new Error ( "Invalid regular expression: Nothing to repeat" ) ;
256
+ }
257
+
254
258
const expression = nodes . pop ( ) ;
255
259
const quantifier = this . eatToken ( ) ;
256
260
nodes . push ( new RepetitionNode ( expression , quantifier , this . isGreedy ( ) ) ) ;
You can’t perform that action at this time.
0 commit comments