Skip to content

Commit

Permalink
Check that terminal part exists when accessing it (#1594)
Browse files Browse the repository at this point in the history
It was previously trying to access properties on undefined when
getTerminalParts would return an empty array due to an error parsing
the RegExp (because the parser doesn't currently support lookbehind).
The error only occurred with hidden terminals
  • Loading branch information
aabounegm authored and msujew committed Aug 7, 2024
1 parent 2bfc044 commit 7409c61
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ function getWhitespaceRules(grammar: Grammar): Rule[] {
const part = RegExpUtils.getTerminalParts(regex)[0];

// check if this is a comment terminal w/ a start & end sequence (multi-line)
if (part.start !== '' && part.end !== '' && GrammarUtils.isCommentTerminal(rule)) {
if (part && part.start !== '' && part.end !== '' && GrammarUtils.isCommentTerminal(rule)) {
// state-based comment rule, only add push to jump into it
rules.push({
regex: part.start,
Expand Down Expand Up @@ -359,7 +359,7 @@ function getCommentRules(grammar: Grammar): Rule[] {
if (GrammarAST.isTerminalRule(rule) && GrammarUtils.isCommentTerminal(rule)) {
const tokenName = 'comment';
const part = RegExpUtils.getTerminalParts(GrammarUtils.terminalRegex(rule))[0];
if (part.start !== '' && part.end !== '') {
if (part && part.start !== '' && part.end !== '') {
// rules to manage comment start/end
// rule order matters

Expand Down

0 comments on commit 7409c61

Please sign in to comment.