@willbooster/tree-sitter-javascript 1.0.11 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/grammar.js +83 -17
- package/package.json +1 -1
- package/src/node-types.json +4 -4
- package/tree-sitter-javascript.wasm +0 -0
- package/tree-sitter.json +1 -1
package/grammar.js
CHANGED
|
@@ -48,6 +48,10 @@ const RESERVED_WORDS = [
|
|
|
48
48
|
];
|
|
49
49
|
const NAMED_RESERVED_WORDS = new Set(['this', 'super', 'true', 'false', 'null']);
|
|
50
50
|
|
|
51
|
+
// Words that are keywords only in some positions and identifiers elsewhere.
|
|
52
|
+
const MEMBER_MODIFIERS = ['get', 'set', 'static'];
|
|
53
|
+
const CONTEXTUAL_KEYWORDS = ['async', 'await', 'export', 'let', 'using'];
|
|
54
|
+
|
|
51
55
|
// oxlint-disable-next-line unicorn/prefer-module -- This package is CommonJS, so tree-sitter loads grammar.js as CommonJS.
|
|
52
56
|
module.exports = grammar({
|
|
53
57
|
name: 'javascript',
|
|
@@ -69,6 +73,14 @@ module.exports = grammar({
|
|
|
69
73
|
// _arrow_function_block_continuation, since the arrow function may be, e.g., an argument.
|
|
70
74
|
$._arrow_function_block_end,
|
|
71
75
|
$._arrow_function_block_continuation,
|
|
76
|
+
// Sentinels that the scanner never emits: the grammar allows each only where a line break has a fixed meaning, so
|
|
77
|
+
// the scanner can tell from the valid symbols how to treat one there (see LineBreakRule in src/scanner.c). Each is an
|
|
78
|
+
// alternative to what follows its position rather than an optional token before it, since an optional token would
|
|
79
|
+
// duplicate the parse states after it.
|
|
80
|
+
$._line_break_ends_statement,
|
|
81
|
+
$._line_break_after_binding,
|
|
82
|
+
$._line_break_after_field,
|
|
83
|
+
$._line_break_after_modifier,
|
|
72
84
|
],
|
|
73
85
|
|
|
74
86
|
extras: ($) => [$.comment, $.html_comment, /[\s\p{Zs}\uFEFF\u2028\u2029\u2060\u200B]/u],
|
|
@@ -149,7 +161,6 @@ module.exports = grammar({
|
|
|
149
161
|
[$.labeled_statement, $._property_name],
|
|
150
162
|
[$.computed_property_name, $.array],
|
|
151
163
|
[$.binary_expression, $._initializer],
|
|
152
|
-
[$.class_static_block, $._property_name],
|
|
153
164
|
],
|
|
154
165
|
|
|
155
166
|
word: ($) => $.identifier,
|
|
@@ -304,7 +315,7 @@ module.exports = grammar({
|
|
|
304
315
|
variable_declarator: ($) =>
|
|
305
316
|
seq(
|
|
306
317
|
field('name', choice($.identifier, alias('of', $.identifier), $._destructuring_pattern)),
|
|
307
|
-
optional($._initializer)
|
|
318
|
+
optional(choice($._initializer, $._line_break_after_binding))
|
|
308
319
|
),
|
|
309
320
|
|
|
310
321
|
statement_block: ($) => prec.right(seq('{', repeat($.statement), '}', optional($._automatic_semicolon))),
|
|
@@ -417,14 +428,23 @@ module.exports = grammar({
|
|
|
417
428
|
with_statement: ($) => seq('with', field('object', $.parenthesized_expression), field('body', $.statement)),
|
|
418
429
|
|
|
419
430
|
break_statement: ($) =>
|
|
420
|
-
seq(
|
|
431
|
+
seq(
|
|
432
|
+
'break',
|
|
433
|
+
field('label', optional(alias($.identifier, $.statement_identifier))),
|
|
434
|
+
choice($._semicolon, $._line_break_ends_statement)
|
|
435
|
+
),
|
|
421
436
|
|
|
422
437
|
continue_statement: ($) =>
|
|
423
|
-
seq(
|
|
438
|
+
seq(
|
|
439
|
+
'continue',
|
|
440
|
+
field('label', optional(alias($.identifier, $.statement_identifier))),
|
|
441
|
+
choice($._semicolon, $._line_break_ends_statement)
|
|
442
|
+
),
|
|
424
443
|
|
|
425
|
-
debugger_statement: ($) => seq('debugger', $._semicolon),
|
|
444
|
+
debugger_statement: ($) => seq('debugger', choice($._semicolon, $._line_break_ends_statement)),
|
|
426
445
|
|
|
427
|
-
return_statement: ($) =>
|
|
446
|
+
return_statement: ($) =>
|
|
447
|
+
seq('return', choice(seq(optional($._expressions), $._semicolon), $._line_break_ends_statement)),
|
|
428
448
|
|
|
429
449
|
throw_statement: ($) => seq('throw', $._expressions, $._semicolon),
|
|
430
450
|
|
|
@@ -507,7 +527,8 @@ module.exports = grammar({
|
|
|
507
527
|
$.call_expression
|
|
508
528
|
),
|
|
509
529
|
|
|
510
|
-
yield_expression: ($) =>
|
|
530
|
+
yield_expression: ($) =>
|
|
531
|
+
prec.right(seq('yield', choice(seq('*', $.expression), optional($.expression), $._line_break_ends_statement))),
|
|
511
532
|
|
|
512
533
|
object: ($) =>
|
|
513
534
|
prec(
|
|
@@ -1088,7 +1109,8 @@ module.exports = grammar({
|
|
|
1088
1109
|
choice(
|
|
1089
1110
|
$.identifier,
|
|
1090
1111
|
alias($.decorator_member_expression, $.member_expression),
|
|
1091
|
-
alias($.decorator_call_expression, $.call_expression)
|
|
1112
|
+
alias($.decorator_call_expression, $.call_expression),
|
|
1113
|
+
$.parenthesized_expression
|
|
1092
1114
|
)
|
|
1093
1115
|
),
|
|
1094
1116
|
|
|
@@ -1098,7 +1120,10 @@ module.exports = grammar({
|
|
|
1098
1120
|
seq(
|
|
1099
1121
|
field('object', choice($.identifier, alias($.decorator_member_expression, $.member_expression))),
|
|
1100
1122
|
'.',
|
|
1101
|
-
field(
|
|
1123
|
+
field(
|
|
1124
|
+
'property',
|
|
1125
|
+
choice(reserved('properties', alias($.identifier, $.property_identifier)), $.private_property_identifier)
|
|
1126
|
+
)
|
|
1102
1127
|
)
|
|
1103
1128
|
),
|
|
1104
1129
|
|
|
@@ -1106,7 +1131,10 @@ module.exports = grammar({
|
|
|
1106
1131
|
prec(
|
|
1107
1132
|
'call',
|
|
1108
1133
|
seq(
|
|
1109
|
-
field(
|
|
1134
|
+
field(
|
|
1135
|
+
'function',
|
|
1136
|
+
choice($.identifier, alias($.decorator_member_expression, $.member_expression), $.parenthesized_expression)
|
|
1137
|
+
),
|
|
1110
1138
|
field('arguments', $.arguments)
|
|
1111
1139
|
)
|
|
1112
1140
|
),
|
|
@@ -1128,14 +1156,35 @@ module.exports = grammar({
|
|
|
1128
1156
|
field_definition: ($) =>
|
|
1129
1157
|
seq(
|
|
1130
1158
|
repeat(field('decorator', $.decorator)),
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1159
|
+
choice(
|
|
1160
|
+
seq(
|
|
1161
|
+
optional('static'),
|
|
1162
|
+
choice(
|
|
1163
|
+
seq(field('property', $._field_name), optional(choice($._initializer, $._line_break_after_field))),
|
|
1164
|
+
// A line break after `get` or `set` continues a getter or setter. Allowing both sentinels here tells
|
|
1165
|
+
// the scanner that a `*` on the next line cannot continue the member, unlike after `static`.
|
|
1166
|
+
seq(
|
|
1167
|
+
field('property', alias(choice('get', 'set'), $.property_identifier)),
|
|
1168
|
+
optional(choice($._initializer, $._line_break_after_modifier, $._line_break_after_field))
|
|
1169
|
+
)
|
|
1170
|
+
)
|
|
1171
|
+
),
|
|
1172
|
+
// A line break after a leading `static` continues a static member; after `static static`, it ends the field.
|
|
1173
|
+
seq(
|
|
1174
|
+
field('property', alias('static', $.property_identifier)),
|
|
1175
|
+
optional(choice($._initializer, $._line_break_after_modifier))
|
|
1176
|
+
),
|
|
1177
|
+
seq(
|
|
1178
|
+
'static',
|
|
1179
|
+
field('property', alias('static', $.property_identifier)),
|
|
1180
|
+
optional(choice($._initializer, $._line_break_after_field))
|
|
1181
|
+
)
|
|
1182
|
+
)
|
|
1134
1183
|
),
|
|
1135
1184
|
|
|
1136
1185
|
formal_parameters: ($) => seq('(', optional(seq(commaSep1($._formal_parameter), optional(','))), ')'),
|
|
1137
1186
|
|
|
1138
|
-
class_static_block: ($) => seq('static',
|
|
1187
|
+
class_static_block: ($) => seq('static', field('body', alias($._class_member_body, $.statement_block))),
|
|
1139
1188
|
|
|
1140
1189
|
// This negative dynamic precedence ensures that during error recovery,
|
|
1141
1190
|
// unfinished constructs are generally treated as literal expressions,
|
|
@@ -1147,19 +1196,36 @@ module.exports = grammar({
|
|
|
1147
1196
|
method_definition: ($) =>
|
|
1148
1197
|
seq(
|
|
1149
1198
|
repeat(field('decorator', $.decorator)),
|
|
1150
|
-
optional(
|
|
1199
|
+
optional('static'),
|
|
1151
1200
|
optional('async'),
|
|
1152
1201
|
optional(choice('get', 'set', '*')),
|
|
1153
1202
|
field('name', $._property_name),
|
|
1154
1203
|
field('parameters', $.formal_parameters),
|
|
1155
|
-
field('body', $.statement_block)
|
|
1204
|
+
field('body', alias($._class_member_body, $.statement_block))
|
|
1156
1205
|
),
|
|
1157
1206
|
|
|
1207
|
+
// The body of a method or a static block, a rule of its own rather than statement_block: sharing it let tree-sitter
|
|
1208
|
+
// merge the state after the body's `}` with the one after a function expression's `}`, where `in`, `instanceof`,
|
|
1209
|
+
// and `extends` are keywords, so a class member with one of those names could not follow.
|
|
1210
|
+
_class_member_body: ($) => seq('{', repeat($.statement), '}'),
|
|
1211
|
+
|
|
1158
1212
|
pair: ($) => seq(field('key', $._property_name), ':', field('value', $.expression)),
|
|
1159
1213
|
|
|
1160
1214
|
pair_pattern: ($) =>
|
|
1161
1215
|
seq(field('key', $._property_name), ':', field('value', choice($.pattern, $.assignment_pattern))),
|
|
1162
1216
|
|
|
1217
|
+
_field_name: ($) =>
|
|
1218
|
+
reserved(
|
|
1219
|
+
'properties',
|
|
1220
|
+
choice(
|
|
1221
|
+
alias(choice($.identifier, ...CONTEXTUAL_KEYWORDS), $.property_identifier),
|
|
1222
|
+
$.private_property_identifier,
|
|
1223
|
+
$.string,
|
|
1224
|
+
$.number,
|
|
1225
|
+
$.computed_property_name
|
|
1226
|
+
)
|
|
1227
|
+
),
|
|
1228
|
+
|
|
1163
1229
|
_property_name: ($) =>
|
|
1164
1230
|
reserved(
|
|
1165
1231
|
'properties',
|
|
@@ -1174,7 +1240,7 @@ module.exports = grammar({
|
|
|
1174
1240
|
|
|
1175
1241
|
computed_property_name: ($) => seq('[', $.expression, ']'),
|
|
1176
1242
|
|
|
1177
|
-
_reserved_identifier: () => choice(
|
|
1243
|
+
_reserved_identifier: () => choice(...MEMBER_MODIFIERS, ...CONTEXTUAL_KEYWORDS),
|
|
1178
1244
|
|
|
1179
1245
|
_semicolon: ($) => choice($._automatic_semicolon, ';'),
|
|
1180
1246
|
},
|
package/package.json
CHANGED
package/src/node-types.json
CHANGED
|
@@ -1021,6 +1021,10 @@
|
|
|
1021
1021
|
{
|
|
1022
1022
|
"type": "member_expression",
|
|
1023
1023
|
"named": true
|
|
1024
|
+
},
|
|
1025
|
+
{
|
|
1026
|
+
"type": "parenthesized_expression",
|
|
1027
|
+
"named": true
|
|
1024
1028
|
}
|
|
1025
1029
|
]
|
|
1026
1030
|
}
|
|
@@ -3515,10 +3519,6 @@
|
|
|
3515
3519
|
"type": "static",
|
|
3516
3520
|
"named": false
|
|
3517
3521
|
},
|
|
3518
|
-
{
|
|
3519
|
-
"type": "static get",
|
|
3520
|
-
"named": false
|
|
3521
|
-
},
|
|
3522
3522
|
{
|
|
3523
3523
|
"type": "string_fragment",
|
|
3524
3524
|
"named": true
|
|
Binary file
|