@willbooster/tree-sitter-javascript 1.0.24 → 1.0.26

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 CHANGED
@@ -73,17 +73,34 @@ module.exports = grammar({
73
73
  // _arrow_function_block_continuation, since the arrow function may be, e.g., an argument.
74
74
  $._arrow_function_block_end,
75
75
  $._arrow_function_block_continuation,
76
- // The _line_break_* sentinels are never emitted: 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.
76
+ // These never-emitted flags select LineBreakRule in src/scanner.c. Keep them alternatives to what follows:
77
+ // leading optional flags duplicate parse states.
80
78
  $._line_break_ends_statement,
81
79
  $._line_break_after_binding,
82
80
  $._line_break_after_field,
83
81
  $._line_break_after_modifier,
84
82
  $._line_break_before_attributes,
85
-
83
+ // Emitted outside statement nodes to preserve their body ranges before trailing comments.
86
84
  $._statement_boundary,
85
+ // Await flags are optional exceptions: replacing a required operand with a flag makes its published child optional.
86
+ // Never emitted: marks the direct await operand start for line-break and identifier lexing.
87
+ $._line_break_after_await,
88
+ // Preserves operand and identifier-statement paths before a following brace or identifier-headed expression.
89
+ $._await_identifier_line_break,
90
+ // Emitted zero-width boundaries retain canonical expression supertype paths for public queries.
91
+ $._await_operand_end,
92
+ // Never emitted: a completed direct arrow cannot serve as an await operand.
93
+ $._completed_arrow_function,
94
+ // Emitted identifier token at the direct await-operand start, preserving normal yield parsing elsewhere.
95
+ $._await_yield_identifier,
96
+ // Emitted zero-width decision preserves direct operands and identifier statements before yield.
97
+ $._await_yield_identifier_start,
98
+ $._await_yield_identifier_context,
99
+ // Emitted zero-width after a postfix update; carries the pending statement boundary across reuse.
100
+ $._postfix_update_end,
101
+ $._await_keyword,
102
+ $._let,
103
+ $._single_statement_context,
87
104
  ],
88
105
 
89
106
  extras: ($) => [$.comment, $.html_comment, /[\s\p{Zs}\uFEFF\u2028\u2029\u2060\u200B]/u],
@@ -175,6 +192,8 @@ module.exports = grammar({
175
192
 
176
193
  _statement: ($) => prec.right(seq($.statement, optional($._statement_boundary))),
177
194
 
195
+ _single_statement: ($) => seq(optional($._single_statement_context), $._statement),
196
+
178
197
  hash_bang_line: () => /#![^\n\r\u2028\u2029]*/,
179
198
 
180
199
  //
@@ -308,12 +327,14 @@ module.exports = grammar({
308
327
 
309
328
  variable_declaration: ($) => seq('var', commaSep1($.variable_declarator), $._semicolon),
310
329
 
330
+ _let: () => token(prec(-1, /let/)),
331
+
311
332
  lexical_declaration: ($) =>
312
- seq(field('kind', choice('let', 'const')), commaSep1($.variable_declarator), $._semicolon),
333
+ seq(field('kind', choice('let', alias($._let, 'let'), 'const')), commaSep1($.variable_declarator), $._semicolon),
313
334
 
314
335
  using_declaration: ($) =>
315
336
  seq(
316
- field('kind', choice('using', seq('await', 'using'))),
337
+ field('kind', choice('using', seq(alias($._await_keyword, 'await'), 'using'))),
317
338
  commaSep1(alias($._using_declarator, $.variable_declarator)),
318
339
  $._semicolon
319
340
  ),
@@ -329,14 +350,14 @@ module.exports = grammar({
329
350
 
330
351
  statement_block: ($) => prec.right(seq('{', repeat($._statement), '}')),
331
352
 
332
- else_clause: ($) => seq('else', $._statement),
353
+ else_clause: ($) => seq('else', $._single_statement),
333
354
 
334
355
  if_statement: ($) =>
335
356
  prec.right(
336
357
  seq(
337
358
  'if',
338
359
  field('condition', $.parenthesized_expression),
339
- field('consequence', $._statement),
360
+ field('consequence', $._single_statement),
340
361
  optional(field('alternative', $.else_clause))
341
362
  )
342
363
  ),
@@ -351,7 +372,7 @@ module.exports = grammar({
351
372
  $._for_condition,
352
373
  field('increment', optional($._expressions)),
353
374
  ')',
354
- field('body', $._statement)
375
+ field('body', $._single_statement)
355
376
  ),
356
377
 
357
378
  // Extracted into rules because tree-sitter expands a `choice` written inline in the `seq` above into one production
@@ -382,12 +403,13 @@ module.exports = grammar({
382
403
 
383
404
  _for_using_declaration: ($) =>
384
405
  seq(
385
- field('kind', choice('using', seq('await', 'using'))),
406
+ field('kind', choice('using', seq(alias($._await_keyword, 'await'), 'using'))),
386
407
  commaSep1(alias($._using_declarator, $.variable_declarator)),
387
408
  ';'
388
409
  ),
389
410
 
390
- for_in_statement: ($) => seq('for', optional('await'), $._for_header, field('body', $._statement)),
411
+ for_in_statement: ($) =>
412
+ seq('for', optional(alias($._await_keyword, 'await')), $._for_header, field('body', $._single_statement)),
391
413
 
392
414
  _for_header: ($) =>
393
415
  seq(
@@ -404,7 +426,7 @@ module.exports = grammar({
404
426
  field('left', choice($.identifier, alias('of', $.identifier), $._destructuring_pattern))
405
427
  ),
406
428
  seq(
407
- field('kind', choice('using', seq('await', 'using'))),
429
+ field('kind', choice('using', seq(alias($._await_keyword, 'await'), 'using'))),
408
430
  field('left', choice($.identifier, alias('of', $.identifier)))
409
431
  )
410
432
  ),
@@ -413,13 +435,14 @@ module.exports = grammar({
413
435
  ')'
414
436
  ),
415
437
 
416
- while_statement: ($) => seq('while', field('condition', $.parenthesized_expression), field('body', $._statement)),
438
+ while_statement: ($) =>
439
+ seq('while', field('condition', $.parenthesized_expression), field('body', $._single_statement)),
417
440
 
418
441
  do_statement: ($) =>
419
442
  prec.right(
420
443
  seq(
421
444
  'do',
422
- field('body', $._statement),
445
+ field('body', $._single_statement),
423
446
  'while',
424
447
  field('condition', $.parenthesized_expression),
425
448
  optional($._semicolon)
@@ -434,7 +457,7 @@ module.exports = grammar({
434
457
  optional(field('finalizer', $.finally_clause))
435
458
  ),
436
459
 
437
- with_statement: ($) => seq('with', field('object', $.parenthesized_expression), field('body', $._statement)),
460
+ with_statement: ($) => seq('with', field('object', $.parenthesized_expression), field('body', $._single_statement)),
438
461
 
439
462
  break_statement: ($) =>
440
463
  seq(
@@ -463,7 +486,7 @@ module.exports = grammar({
463
486
  seq(
464
487
  field('label', alias(choice($.identifier, $._reserved_identifier), $.statement_identifier)),
465
488
  ':',
466
- field('body', $._statement)
489
+ field('body', $._single_statement)
467
490
  ),
468
491
 
469
492
  //
@@ -508,10 +531,9 @@ module.exports = grammar({
508
531
  primary_expression: ($) =>
509
532
  choice(
510
533
  $._jsx_element,
511
- $.subscript_expression,
512
- $.member_expression,
513
534
  $.parenthesized_expression,
514
535
  $._identifier,
536
+ alias($._await_yield_identifier, $.identifier),
515
537
  alias($._reserved_identifier, $.identifier),
516
538
  $.this,
517
539
  $.super,
@@ -525,13 +547,15 @@ module.exports = grammar({
525
547
  $.object,
526
548
  $.array,
527
549
  $.function_expression,
528
- $.arrow_function,
529
550
  $.generator_function,
530
551
  $.class,
531
552
  $.meta_property,
553
+ $.subscript_expression,
554
+ $.member_expression,
532
555
  $.call_expression,
533
556
  $.new_expression,
534
- alias($._argumentless_new_expression, $.new_expression)
557
+ alias($._argumentless_new_expression, $.new_expression),
558
+ $.arrow_function
535
559
  ),
536
560
 
537
561
  yield_expression: ($) =>
@@ -765,19 +789,22 @@ module.exports = grammar({
765
789
  ),
766
790
 
767
791
  arrow_function: ($) =>
768
- seq(
769
- optional('async'),
770
- choice(
771
- field('parameter', choice(alias($._reserved_identifier, $.identifier), $.identifier)),
772
- $._call_signature
773
- ),
774
- '=>',
775
- choice(
776
- field('body', $.expression),
777
- seq(
778
- field('body', $.statement_block),
779
- optional(seq($._arrow_function_block_end, optional($._arrow_function_block_continuation)))
780
- )
792
+ prec.right(
793
+ seq(
794
+ optional('async'),
795
+ choice(
796
+ field('parameter', choice(alias($._reserved_identifier, $.identifier), $.identifier)),
797
+ $._call_signature
798
+ ),
799
+ '=>',
800
+ choice(
801
+ field('body', $.expression),
802
+ seq(
803
+ field('body', $.statement_block),
804
+ optional(seq($._arrow_function_block_end, optional($._arrow_function_block_continuation)))
805
+ )
806
+ ),
807
+ optional($._completed_arrow_function)
781
808
  )
782
809
  ),
783
810
 
@@ -811,7 +838,21 @@ module.exports = grammar({
811
838
 
812
839
  _argumentless_new_expression: ($) => prec.right('new', seq('new', field('constructor', $.primary_expression))),
813
840
 
814
- await_expression: ($) => prec.dynamic(2, prec('unary_void', seq('await', $.expression))),
841
+ await_expression: ($) =>
842
+ prec.dynamic(
843
+ 3,
844
+ prec.right(
845
+ 'unary_void',
846
+ seq(
847
+ alias($._await_keyword, 'await'),
848
+ optional($._await_identifier_line_break),
849
+ optional(seq($._await_yield_identifier_start, optional($._await_yield_identifier_context))),
850
+ optional($._line_break_after_await),
851
+ $.expression,
852
+ $._await_operand_end
853
+ )
854
+ )
855
+ ),
815
856
 
816
857
  member_expression: ($) =>
817
858
  prec(
@@ -943,7 +984,7 @@ module.exports = grammar({
943
984
  update_expression: ($) =>
944
985
  prec.left(
945
986
  choice(
946
- seq(field('argument', $.expression), field('operator', choice('++', '--'))),
987
+ seq(field('argument', $.expression), field('operator', choice('++', '--')), $._postfix_update_end),
947
988
  seq(field('operator', choice('++', '--')), field('argument', $.expression))
948
989
  )
949
990
  ),
@@ -1219,7 +1260,10 @@ module.exports = grammar({
1219
1260
  reserved(
1220
1261
  'properties',
1221
1262
  choice(
1222
- alias(choice($.identifier, ...CONTEXTUAL_KEYWORDS), $.property_identifier),
1263
+ alias(
1264
+ choice($.identifier, ...CONTEXTUAL_KEYWORDS.map((word) => (word === 'await' ? $._await_keyword : word))),
1265
+ $.property_identifier
1266
+ ),
1223
1267
  $.private_property_identifier,
1224
1268
  $.string,
1225
1269
  $.number,
@@ -1241,9 +1285,11 @@ module.exports = grammar({
1241
1285
 
1242
1286
  computed_property_name: ($) => seq('[', $.expression, ']'),
1243
1287
 
1244
- _reserved_identifier: () => choice(...MEMBER_MODIFIERS, ...CONTEXTUAL_KEYWORDS),
1288
+ _reserved_identifier: ($) =>
1289
+ choice(...MEMBER_MODIFIERS, ...CONTEXTUAL_KEYWORDS.map((word) => (word === 'await' ? $._await_keyword : word))),
1245
1290
 
1246
- _semicolon: ($) => choice($._automatic_semicolon, ';'),
1291
+ _semicolon: ($) =>
1292
+ choice($._automatic_semicolon, $._await_identifier_line_break, $._await_yield_identifier_start, ';'),
1247
1293
  },
1248
1294
  });
1249
1295
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-javascript",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "JavaScript grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
Binary file
package/tree-sitter.json CHANGED
@@ -24,7 +24,7 @@
24
24
  }
25
25
  ],
26
26
  "metadata": {
27
- "version": "1.0.24",
27
+ "version": "1.0.26",
28
28
  "license": "MIT",
29
29
  "description": "JavaScript grammar for tree-sitter",
30
30
  "authors": [