Skip to content

Commit

Permalink
Merge pull request #251 from jow-/fix-parsing-kwlabels-after-comments
Browse files Browse the repository at this point in the history
lexer: Preserve keyword, regexp flags until processing non-comment to…
  • Loading branch information
jow- authored Dec 6, 2024
2 parents 3f7035c + 9bcd25f commit 9150505
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1176,8 +1176,10 @@ uc_lexer_next_token(uc_lexer_t *lex)

rv = lex_step(lex);

lex->no_keyword = false;
lex->no_regexp = false;
if (rv && rv->type != TK_COMMENT) {
lex->no_keyword = false;
lex->no_regexp = false;
}

return rv;
}
Expand Down
20 changes: 20 additions & 0 deletions tests/custom/99_bugs/51_preserve_lexer_flags
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Ensure keyword and regexp flags are preserved across comments when lexing
object literals and division operators.

-- Testcase --
{%
printf("%.J\n", [
{ /* comment */ default: true },
4 /* comment */ /2/1
]);
%}
-- End --

-- Expect stdout --
[
{
"default": true
},
2
]
-- End --

0 comments on commit 9150505

Please sign in to comment.