@@ -47,7 +47,18 @@ static bool scan_template_chars(TSLexer *lexer) {
47
47
}
48
48
}
49
49
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
+
51
62
for (;;) {
52
63
while (iswspace (lexer -> lookahead )) {
53
64
skip (lexer );
@@ -71,17 +82,25 @@ static bool scan_whitespace_and_comments(TSLexer *lexer, bool *scanned_comment)
71
82
if (lexer -> lookahead == '/' ) {
72
83
skip (lexer );
73
84
* scanned_comment = true;
85
+
86
+ if (lexer -> lookahead != '/' && !consume ) {
87
+ return saw_block_newline ? ACCEPT : NO_NEWLINE ;
88
+ }
89
+
74
90
break ;
75
91
}
92
+ } else if (lexer -> lookahead == '\n' || lexer -> lookahead == 0x2028 || lexer -> lookahead == 0x2029 ) {
93
+ saw_block_newline = true;
94
+ skip (lexer );
76
95
} else {
77
96
skip (lexer );
78
97
}
79
98
}
80
99
} else {
81
- return false ;
100
+ return REJECT ;
82
101
}
83
102
} else {
84
- return true ;
103
+ return ACCEPT ;
85
104
}
86
105
}
87
106
}
@@ -96,10 +115,12 @@ static bool scan_automatic_semicolon(TSLexer *lexer, bool comment_condition, boo
96
115
}
97
116
98
117
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 ) {
100
120
return false;
101
121
}
102
- if (comment_condition && lexer -> lookahead != ',' && lexer -> lookahead != '=' ) {
122
+
123
+ if (result == ACCEPT && comment_condition && lexer -> lookahead != ',' && lexer -> lookahead != '=' ) {
103
124
return true;
104
125
}
105
126
}
@@ -125,7 +146,7 @@ static bool scan_automatic_semicolon(TSLexer *lexer, bool comment_condition, boo
125
146
126
147
skip (lexer );
127
148
128
- if (! scan_whitespace_and_comments (lexer , scanned_comment ) ) {
149
+ if (scan_whitespace_and_comments (lexer , scanned_comment , true) == REJECT ) {
129
150
return false;
130
151
}
131
152
0 commit comments