@@ -47,7 +47,18 @@ static bool scan_template_chars(TSLexer *lexer) {
4747 }
4848}
4949
50- static bool scan_whitespace_and_comments (TSLexer * lexer , bool * scanned_comment ) {
50+ typedef enum {
51+ REJECT , // Semicolon is illegal, ie a syntax error occurred
52+ NO_NEWLINE , // Unclear if semicolon will be legal, continue
53+ ACCEPT , // Semicolon is legal, assuming a comment was encountered
54+ } WhitespaceResult ;
55+
56+ /**
57+ * @param consume If false, only consume enough to check if comment indicates semicolon-legality
58+ */
59+ static WhitespaceResult scan_whitespace_and_comments (TSLexer * lexer , bool * scanned_comment , bool consume ) {
60+ bool saw_block_newline = false;
61+
5162 for (;;) {
5263 while (iswspace (lexer -> lookahead )) {
5364 skip (lexer );
@@ -71,17 +82,25 @@ static bool scan_whitespace_and_comments(TSLexer *lexer, bool *scanned_comment)
7182 if (lexer -> lookahead == '/' ) {
7283 skip (lexer );
7384 * scanned_comment = true;
85+
86+ if (lexer -> lookahead != '/' && !consume ) {
87+ return saw_block_newline ? ACCEPT : NO_NEWLINE ;
88+ }
89+
7490 break ;
7591 }
92+ } else if (lexer -> lookahead == '\n' || lexer -> lookahead == 0x2028 || lexer -> lookahead == 0x2029 ) {
93+ saw_block_newline = true;
94+ skip (lexer );
7695 } else {
7796 skip (lexer );
7897 }
7998 }
8099 } else {
81- return false ;
100+ return REJECT ;
82101 }
83102 } else {
84- return true ;
103+ return ACCEPT ;
85104 }
86105 }
87106}
@@ -96,10 +115,12 @@ static bool scan_automatic_semicolon(TSLexer *lexer, bool comment_condition, boo
96115 }
97116
98117 if (lexer -> lookahead == '/' ) {
99- if (!scan_whitespace_and_comments (lexer , scanned_comment )) {
118+ WhitespaceResult result = scan_whitespace_and_comments (lexer , scanned_comment , false);
119+ if (result == REJECT ) {
100120 return false;
101121 }
102- if (comment_condition && lexer -> lookahead != ',' && lexer -> lookahead != '=' ) {
122+
123+ if (result == ACCEPT && comment_condition && lexer -> lookahead != ',' && lexer -> lookahead != '=' ) {
103124 return true;
104125 }
105126 }
@@ -125,7 +146,7 @@ static bool scan_automatic_semicolon(TSLexer *lexer, bool comment_condition, boo
125146
126147 skip (lexer );
127148
128- if (! scan_whitespace_and_comments (lexer , scanned_comment ) ) {
149+ if (scan_whitespace_and_comments (lexer , scanned_comment , true) == REJECT ) {
129150 return false;
130151 }
131152
0 commit comments