Skip to content

Commit

Permalink
fix: permissible text did not properly track text presence in certain…
Browse files Browse the repository at this point in the history
… cases
  • Loading branch information
virchau13 committed Apr 21, 2024
1 parent daeacdd commit 1aab99e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
13 changes: 13 additions & 0 deletions corpus/permissible-text-marks-end-in-string-state.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
===
Permissible text regions properly call mark_end after parsing a string
===

!{<'

-----

(document
(text)
(html_interpolation
(permissible_text)
(MISSING "}")))
12 changes: 12 additions & 0 deletions corpus/unclosed-interpolation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
===
Unclosed interpolation should error
===

{

----

(document
(html_interpolation
(permissible_text)
(MISSING "}")))
13 changes: 8 additions & 5 deletions src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static inline void scan_js_expr_with_delimiter(TSLexer *lexer, enum RawTextEndTy
static inline void scan_js_backtick_string(TSLexer *lexer) {
// Advance past backtick
lexer->advance(lexer, false);
while (lexer->lookahead) {
while (lexer->lookahead != '\0') {
if (lexer->lookahead == '$') {
lexer->advance(lexer, false);
if (lexer->lookahead == '{') {
Expand Down Expand Up @@ -194,7 +194,7 @@ static inline void scan_js_string(TSLexer *lexer) {
// Start and end chars are the same
char str_end_char = (char)lexer->lookahead;
lexer->advance(lexer, false);
while (lexer->lookahead) {
while (lexer->lookahead != '\0') {
// Note that this doesn't take into account newlines in basic
// strings, for the same reason why tree-sitter-javascript
// doesn't.
Expand Down Expand Up @@ -485,7 +485,7 @@ static bool scan_permissible_text(TSLexer *lexer) {
// skip string
scan_js_string(lexer);
there_is_text = true;
continue;
goto text_found;
}
if(lexer->lookahead == '/') {
// check for a comment
Expand All @@ -512,7 +512,7 @@ static bool scan_permissible_text(TSLexer *lexer) {
}
}
}
continue;
goto text_found;
}
if (lexer->lookahead == '<') {
advance(lexer);
Expand All @@ -538,9 +538,12 @@ static bool scan_permissible_text(TSLexer *lexer) {
// (e.g. `<> <p> hi </p> </>`)
break;
}
continue;
// If none of the above conditions pass,
// there's definitely text here.
goto text_found;
}
advance(lexer);
text_found:
there_is_text = true;
lexer->mark_end(lexer);
}
Expand Down

0 comments on commit 1aab99e

Please sign in to comment.