Skip to content

Commit 71fe641

Browse files
committed
feat: bump tree-sitter-javascript to 0.23
1 parent 198d035 commit 71fe641

File tree

11 files changed

+352825
-343374
lines changed

11 files changed

+352825
-343374
lines changed

common/define-grammar.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,11 @@ module.exports = function defineGrammar(dialect) {
174174
prec('call', seq(
175175
field('function', choice($.expression, $.import)),
176176
field('type_arguments', optional($.type_arguments)),
177-
field('arguments', choice($.arguments, $.template_string)),
177+
field('arguments', $.arguments),
178+
)),
179+
prec('template_call', seq(
180+
field('function', choice($.primary_expression, $.new_expression)),
181+
field('arguments', $.template_string),
178182
)),
179183
prec('member', seq(
180184
field('function', $.primary_expression),

common/scanner.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ enum TokenType {
1010
LOGICAL_OR,
1111
ESCAPE_SEQUENCE,
1212
REGEX_PATTERN,
13+
JSX_TEXT,
1314
FUNCTION_SIGNATURE_AUTOMATIC_SEMICOLON,
1415
ERROR_RECOVERY,
1516
};
@@ -115,6 +116,7 @@ static bool scan_automatic_semicolon(TSLexer *lexer, const bool *valid_symbols,
115116
}
116117

117118
switch (lexer->lookahead) {
119+
case '`':
118120
case ',':
119121
case '.':
120122
case ';':
@@ -271,13 +273,59 @@ static bool scan_closing_comment(TSLexer *lexer) {
271273
return true;
272274
}
273275

276+
static bool scan_jsx_text(TSLexer *lexer) {
277+
// saw_text will be true if we see any non-whitespace content, or any whitespace content that is not a newline and
278+
// does not immediately follow a newline.
279+
bool saw_text = false;
280+
// at_newline will be true if we are currently at a newline, or if we are at whitespace that is not a newline but
281+
// immediately follows a newline.
282+
bool at_newline = false;
283+
284+
while (lexer->lookahead != 0 && lexer->lookahead != '<' && lexer->lookahead != '>' && lexer->lookahead != '{' &&
285+
lexer->lookahead != '}' && lexer->lookahead != '&') {
286+
bool is_wspace = iswspace(lexer->lookahead);
287+
if (lexer->lookahead == '\n') {
288+
at_newline = true;
289+
} else {
290+
// If at_newline is already true, and we see some whitespace, then it must stay true.
291+
// Otherwise, it should be false.
292+
//
293+
// See the table below to determine the logic for computing `saw_text`.
294+
//
295+
// |------------------------------------|
296+
// | at_newline | is_wspace | saw_text |
297+
// |------------|-----------|-----------|
298+
// | false (0) | false (0) | true (1) |
299+
// | false (0) | true (1) | true (1) |
300+
// | true (1) | false (0) | true (1) |
301+
// | true (1) | true (1) | false (0) |
302+
// |------------------------------------|
303+
304+
at_newline &= is_wspace;
305+
if (!at_newline) {
306+
saw_text = true;
307+
}
308+
}
309+
310+
advance(lexer);
311+
}
312+
313+
lexer->result_symbol = JSX_TEXT;
314+
return saw_text;
315+
}
316+
274317
static inline bool external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) {
275318
if (valid_symbols[TEMPLATE_CHARS]) {
276319
if (valid_symbols[AUTOMATIC_SEMICOLON]) {
277320
return false;
278321
}
279322
return scan_template_chars(lexer);
280323
}
324+
325+
if (valid_symbols[JSX_TEXT] && scan_jsx_text(lexer)) {
326+
return true;
327+
}
328+
281329
if (valid_symbols[AUTOMATIC_SEMICOLON] || valid_symbols[FUNCTION_SIGNATURE_AUTOMATIC_SEMICOLON]) {
282330
bool scanned_comment = false;
283331
bool ret = scan_automatic_semicolon(lexer, valid_symbols, &scanned_comment);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"eslint": ">=8.57.0",
4747
"eslint-config-google": "^0.14.0",
4848
"tree-sitter-cli": "^0.22.6",
49-
"tree-sitter-javascript": "^0.21.4",
49+
"tree-sitter-javascript": "^0.23.0",
5050
"prebuildify": "^6.0.1"
5151
},
5252
"scripts": {

tsx/src/grammar.json

Lines changed: 149 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,29 +1204,51 @@
12041204
"value": "("
12051205
},
12061206
{
1207-
"type": "FIELD",
1208-
"name": "initializer",
1209-
"content": {
1210-
"type": "CHOICE",
1211-
"members": [
1212-
{
1213-
"type": "SYMBOL",
1214-
"name": "lexical_declaration"
1215-
},
1216-
{
1217-
"type": "SYMBOL",
1218-
"name": "variable_declaration"
1219-
},
1220-
{
1221-
"type": "SYMBOL",
1222-
"name": "expression_statement"
1223-
},
1224-
{
1207+
"type": "CHOICE",
1208+
"members": [
1209+
{
1210+
"type": "FIELD",
1211+
"name": "initializer",
1212+
"content": {
1213+
"type": "CHOICE",
1214+
"members": [
1215+
{
1216+
"type": "SYMBOL",
1217+
"name": "lexical_declaration"
1218+
},
1219+
{
1220+
"type": "SYMBOL",
1221+
"name": "variable_declaration"
1222+
}
1223+
]
1224+
}
1225+
},
1226+
{
1227+
"type": "SEQ",
1228+
"members": [
1229+
{
1230+
"type": "FIELD",
1231+
"name": "initializer",
1232+
"content": {
1233+
"type": "SYMBOL",
1234+
"name": "_expressions"
1235+
}
1236+
},
1237+
{
1238+
"type": "STRING",
1239+
"value": ";"
1240+
}
1241+
]
1242+
},
1243+
{
1244+
"type": "FIELD",
1245+
"name": "initializer",
1246+
"content": {
12251247
"type": "SYMBOL",
12261248
"name": "empty_statement"
12271249
}
1228-
]
1229-
}
1250+
}
1251+
]
12301252
},
12311253
{
12321254
"type": "FIELD",
@@ -1235,8 +1257,17 @@
12351257
"type": "CHOICE",
12361258
"members": [
12371259
{
1238-
"type": "SYMBOL",
1239-
"name": "expression_statement"
1260+
"type": "SEQ",
1261+
"members": [
1262+
{
1263+
"type": "SYMBOL",
1264+
"name": "_expressions"
1265+
},
1266+
{
1267+
"type": "STRING",
1268+
"value": ";"
1269+
}
1270+
]
12401271
},
12411272
{
12421273
"type": "SYMBOL",
@@ -1413,6 +1444,18 @@
14131444
}
14141445
]
14151446
}
1447+
},
1448+
{
1449+
"type": "CHOICE",
1450+
"members": [
1451+
{
1452+
"type": "SYMBOL",
1453+
"name": "_automatic_semicolon"
1454+
},
1455+
{
1456+
"type": "BLANK"
1457+
}
1458+
]
14161459
}
14171460
]
14181461
}
@@ -2815,25 +2858,6 @@
28152858
}
28162859
]
28172860
},
2818-
"jsx_text": {
2819-
"type": "CHOICE",
2820-
"members": [
2821-
{
2822-
"type": "IMMEDIATE_TOKEN",
2823-
"content": {
2824-
"type": "PATTERN",
2825-
"value": "[^{}<>&]*[^{}<>\\s\\p{Zs}\\uFEFF\\u2028\\u2029\\u2060\\u200B&][^{}<>&]*"
2826-
}
2827-
},
2828-
{
2829-
"type": "IMMEDIATE_TOKEN",
2830-
"content": {
2831-
"type": "PATTERN",
2832-
"value": "[^{}<>\\n&]+"
2833-
}
2834-
}
2835-
]
2836-
},
28372861
"html_character_reference": {
28382862
"type": "PATTERN",
28392863
"value": "&(#([xX][0-9a-fA-F]{1,6}|[0-9]{1,5})|[A-Za-z]{1,30});"
@@ -3850,19 +3874,44 @@
38503874
{
38513875
"type": "FIELD",
38523876
"name": "arguments",
3877+
"content": {
3878+
"type": "SYMBOL",
3879+
"name": "arguments"
3880+
}
3881+
}
3882+
]
3883+
}
3884+
},
3885+
{
3886+
"type": "PREC",
3887+
"value": "template_call",
3888+
"content": {
3889+
"type": "SEQ",
3890+
"members": [
3891+
{
3892+
"type": "FIELD",
3893+
"name": "function",
38533894
"content": {
38543895
"type": "CHOICE",
38553896
"members": [
38563897
{
38573898
"type": "SYMBOL",
3858-
"name": "arguments"
3899+
"name": "primary_expression"
38593900
},
38603901
{
38613902
"type": "SYMBOL",
3862-
"name": "template_string"
3903+
"name": "new_expression"
38633904
}
38643905
]
38653906
}
3907+
},
3908+
{
3909+
"type": "FIELD",
3910+
"name": "arguments",
3911+
"content": {
3912+
"type": "SYMBOL",
3913+
"name": "template_string"
3914+
}
38663915
}
38673916
]
38683917
}
@@ -6303,19 +6352,41 @@
63036352
}
63046353
},
63056354
"meta_property": {
6306-
"type": "SEQ",
6355+
"type": "CHOICE",
63076356
"members": [
63086357
{
6309-
"type": "STRING",
6310-
"value": "new"
6311-
},
6312-
{
6313-
"type": "STRING",
6314-
"value": "."
6358+
"type": "SEQ",
6359+
"members": [
6360+
{
6361+
"type": "STRING",
6362+
"value": "new"
6363+
},
6364+
{
6365+
"type": "STRING",
6366+
"value": "."
6367+
},
6368+
{
6369+
"type": "STRING",
6370+
"value": "target"
6371+
}
6372+
]
63156373
},
63166374
{
6317-
"type": "STRING",
6318-
"value": "target"
6375+
"type": "SEQ",
6376+
"members": [
6377+
{
6378+
"type": "STRING",
6379+
"value": "import"
6380+
},
6381+
{
6382+
"type": "STRING",
6383+
"value": "."
6384+
},
6385+
{
6386+
"type": "STRING",
6387+
"value": "meta"
6388+
}
6389+
]
63196390
}
63206391
]
63216392
},
@@ -11124,6 +11195,10 @@
1112411195
"primary_expression",
1112511196
"_for_header"
1112611197
],
11198+
[
11199+
"variable_declarator",
11200+
"_for_header"
11201+
],
1112711202
[
1112811203
"array",
1112911204
"array_pattern"
@@ -11310,6 +11385,10 @@
1131011385
"type": "STRING",
1131111386
"value": "member"
1131211387
},
11388+
{
11389+
"type": "STRING",
11390+
"value": "template_call"
11391+
},
1131311392
{
1131411393
"type": "STRING",
1131511394
"value": "call"
@@ -11398,6 +11477,10 @@
1139811477
"type": "STRING",
1139911478
"value": "member"
1140011479
},
11480+
{
11481+
"type": "STRING",
11482+
"value": "template_call"
11483+
},
1140111484
{
1140211485
"type": "STRING",
1140311486
"value": "new"
@@ -11435,6 +11518,16 @@
1143511518
"value": "object"
1143611519
}
1143711520
],
11521+
[
11522+
{
11523+
"type": "SYMBOL",
11524+
"name": "meta_property"
11525+
},
11526+
{
11527+
"type": "SYMBOL",
11528+
"name": "import"
11529+
}
11530+
],
1143811531
[
1143911532
{
1144011533
"type": "SYMBOL",
@@ -11913,6 +12006,10 @@
1191312006
"type": "SYMBOL",
1191412007
"name": "regex_pattern"
1191512008
},
12009+
{
12010+
"type": "SYMBOL",
12011+
"name": "jsx_text"
12012+
},
1191612013
{
1191712014
"type": "SYMBOL",
1191812015
"name": "_function_signature_automatic_semicolon"

0 commit comments

Comments
 (0)