Skip to content

Commit

Permalink
Merge pull request #145 from babel/improve-regexp-invalid-modifiers-e…
Browse files Browse the repository at this point in the history
…rrors

Improve regexp invalid modifiers errors
  • Loading branch information
jviereck authored Oct 3, 2024
2 parents ccc838b + a376130 commit 6ad7019
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
18 changes: 13 additions & 5 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,15 @@
// --------------------------------------------------------------
//
// Atom ::
// ( ? RegularExpressionFlags : Disjunction )
// ( ? RegularExpressionFlags - RegularExpressionFlags : Disjunction )
// ( ? RegularExpressionModifiers : Disjunction )
// ( ? RegularExpressionModifiers - RegularExpressionModifiers : Disjunction )
//
// RegularExpressionModifiers:
// [empty]
// RegularExpressionModifiers RegularExpressionModifier
//
// RegularExpressionModifier:
// one of i m s

"use strict";
(function() {
Expand Down Expand Up @@ -747,8 +753,8 @@
// \ AtomEscape
// CharacterClass
// ( GroupSpecifier Disjunction )
// ( ? RegularExpressionFlags : Disjunction )
// ( ? RegularExpressionFlags - RegularExpressionFlags : Disjunction )
// ( ? RegularExpressionModifiers : Disjunction )
// ( ? RegularExpressionModifiers - RegularExpressionModifiers : Disjunction )
// ExtendedAtom ::
// ExtendedPatternCharacter
// ExtendedPatternCharacter ::
Expand Down Expand Up @@ -840,7 +846,9 @@
bail('flags cannot be duplicated for modifiers group');
}

skip(":");
if(!match(":")) {
bail('Invalid flags for modifiers group');
}

var modifiersGroup = finishGroup("ignore", from);

Expand Down
24 changes: 24 additions & 0 deletions test/test-data-modifiers-group.json
Original file line number Diff line number Diff line change
Expand Up @@ -510,5 +510,29 @@
"name": "SyntaxError",
"message": "Invalid flags for modifiers group at position 9\n ^[a-z](?-:[a-z])$\n ^",
"input": "^[a-z](?-:[a-z])$"
},
"^[a-z](?ui:[a-z])$": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid flags for modifiers group at position 8\n ^[a-z](?ui:[a-z])$\n ^",
"input": "^[a-z](?ui:[a-z])$"
},
"^[a-z](?-ui:[a-z])$": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid flags for modifiers group at position 9\n ^[a-z](?-ui:[a-z])$\n ^",
"input": "^[a-z](?-ui:[a-z])$"
},
"^[a-z](?iu:[a-z])$": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid flags for modifiers group at position 9\n ^[a-z](?iu:[a-z])$\n ^",
"input": "^[a-z](?iu:[a-z])$"
},
"^[a-z](?-iu:[a-z])$": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid flags for modifiers group at position 10\n ^[a-z](?-iu:[a-z])$\n ^",
"input": "^[a-z](?-iu:[a-z])$"
}
}

0 comments on commit 6ad7019

Please sign in to comment.