@willbooster/tree-sitter-javascript 1.0.23 → 1.0.25

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,15 +73,32 @@ 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
- // 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.
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,
83
+ // Emitted outside statement nodes to preserve their body ranges before trailing comments.
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,
85
102
  ],
86
103
 
87
104
  extras: ($) => [$.comment, $.html_comment, /[\s\p{Zs}\uFEFF\u2028\u2029\u2060\u200B]/u],
@@ -169,7 +186,9 @@ module.exports = grammar({
169
186
  word: ($) => $.identifier,
170
187
 
171
188
  rules: {
172
- program: ($) => seq(optional($.hash_bang_line), repeat($.statement)),
189
+ program: ($) => seq(optional($.hash_bang_line), repeat($._statement)),
190
+
191
+ _statement: ($) => prec.right(seq($.statement, optional($._statement_boundary))),
173
192
 
174
193
  hash_bang_line: () => /#![^\n\r\u2028\u2029]*/,
175
194
 
@@ -309,7 +328,7 @@ module.exports = grammar({
309
328
 
310
329
  using_declaration: ($) =>
311
330
  seq(
312
- field('kind', choice('using', seq('await', 'using'))),
331
+ field('kind', choice('using', seq(alias($._await_keyword, 'await'), 'using'))),
313
332
  commaSep1(alias($._using_declarator, $.variable_declarator)),
314
333
  $._semicolon
315
334
  ),
@@ -323,16 +342,16 @@ module.exports = grammar({
323
342
  optional(choice($._initializer, $._line_break_after_binding))
324
343
  ),
325
344
 
326
- statement_block: ($) => prec.right(seq('{', repeat($.statement), '}', optional($._automatic_semicolon))),
345
+ statement_block: ($) => prec.right(seq('{', repeat($._statement), '}')),
327
346
 
328
- else_clause: ($) => seq('else', $.statement),
347
+ else_clause: ($) => seq('else', $._statement),
329
348
 
330
349
  if_statement: ($) =>
331
350
  prec.right(
332
351
  seq(
333
352
  'if',
334
353
  field('condition', $.parenthesized_expression),
335
- field('consequence', $.statement),
354
+ field('consequence', $._statement),
336
355
  optional(field('alternative', $.else_clause))
337
356
  )
338
357
  ),
@@ -347,7 +366,7 @@ module.exports = grammar({
347
366
  $._for_condition,
348
367
  field('increment', optional($._expressions)),
349
368
  ')',
350
- field('body', $.statement)
369
+ field('body', $._statement)
351
370
  ),
352
371
 
353
372
  // Extracted into rules because tree-sitter expands a `choice` written inline in the `seq` above into one production
@@ -378,12 +397,13 @@ module.exports = grammar({
378
397
 
379
398
  _for_using_declaration: ($) =>
380
399
  seq(
381
- field('kind', choice('using', seq('await', 'using'))),
400
+ field('kind', choice('using', seq(alias($._await_keyword, 'await'), 'using'))),
382
401
  commaSep1(alias($._using_declarator, $.variable_declarator)),
383
402
  ';'
384
403
  ),
385
404
 
386
- for_in_statement: ($) => seq('for', optional('await'), $._for_header, field('body', $.statement)),
405
+ for_in_statement: ($) =>
406
+ seq('for', optional(alias($._await_keyword, 'await')), $._for_header, field('body', $._statement)),
387
407
 
388
408
  _for_header: ($) =>
389
409
  seq(
@@ -400,7 +420,7 @@ module.exports = grammar({
400
420
  field('left', choice($.identifier, alias('of', $.identifier), $._destructuring_pattern))
401
421
  ),
402
422
  seq(
403
- field('kind', choice('using', seq('await', 'using'))),
423
+ field('kind', choice('using', seq(alias($._await_keyword, 'await'), 'using'))),
404
424
  field('left', choice($.identifier, alias('of', $.identifier)))
405
425
  )
406
426
  ),
@@ -409,13 +429,13 @@ module.exports = grammar({
409
429
  ')'
410
430
  ),
411
431
 
412
- while_statement: ($) => seq('while', field('condition', $.parenthesized_expression), field('body', $.statement)),
432
+ while_statement: ($) => seq('while', field('condition', $.parenthesized_expression), field('body', $._statement)),
413
433
 
414
434
  do_statement: ($) =>
415
435
  prec.right(
416
436
  seq(
417
437
  'do',
418
- field('body', $.statement),
438
+ field('body', $._statement),
419
439
  'while',
420
440
  field('condition', $.parenthesized_expression),
421
441
  optional($._semicolon)
@@ -430,7 +450,7 @@ module.exports = grammar({
430
450
  optional(field('finalizer', $.finally_clause))
431
451
  ),
432
452
 
433
- with_statement: ($) => seq('with', field('object', $.parenthesized_expression), field('body', $.statement)),
453
+ with_statement: ($) => seq('with', field('object', $.parenthesized_expression), field('body', $._statement)),
434
454
 
435
455
  break_statement: ($) =>
436
456
  seq(
@@ -459,7 +479,7 @@ module.exports = grammar({
459
479
  seq(
460
480
  field('label', alias(choice($.identifier, $._reserved_identifier), $.statement_identifier)),
461
481
  ':',
462
- field('body', $.statement)
482
+ field('body', $._statement)
463
483
  ),
464
484
 
465
485
  //
@@ -468,9 +488,9 @@ module.exports = grammar({
468
488
 
469
489
  switch_body: ($) => seq('{', repeat(choice($.switch_case, $.switch_default)), '}'),
470
490
 
471
- switch_case: ($) => seq('case', field('value', $._expressions), ':', field('body', repeat($.statement))),
491
+ switch_case: ($) => seq('case', field('value', $._expressions), ':', field('body', repeat($._statement))),
472
492
 
473
- switch_default: ($) => seq('default', ':', field('body', repeat($.statement))),
493
+ switch_default: ($) => seq('default', ':', field('body', repeat($._statement))),
474
494
 
475
495
  catch_clause: ($) =>
476
496
  seq(
@@ -504,10 +524,9 @@ module.exports = grammar({
504
524
  primary_expression: ($) =>
505
525
  choice(
506
526
  $._jsx_element,
507
- $.subscript_expression,
508
- $.member_expression,
509
527
  $.parenthesized_expression,
510
528
  $._identifier,
529
+ alias($._await_yield_identifier, $.identifier),
511
530
  alias($._reserved_identifier, $.identifier),
512
531
  $.this,
513
532
  $.super,
@@ -521,13 +540,15 @@ module.exports = grammar({
521
540
  $.object,
522
541
  $.array,
523
542
  $.function_expression,
524
- $.arrow_function,
525
543
  $.generator_function,
526
544
  $.class,
527
545
  $.meta_property,
546
+ $.subscript_expression,
547
+ $.member_expression,
528
548
  $.call_expression,
529
549
  $.new_expression,
530
- alias($._argumentless_new_expression, $.new_expression)
550
+ alias($._argumentless_new_expression, $.new_expression),
551
+ $.arrow_function
531
552
  ),
532
553
 
533
554
  yield_expression: ($) =>
@@ -704,8 +725,7 @@ module.exports = grammar({
704
725
  'class',
705
726
  field('name', $.identifier),
706
727
  optional($.class_heritage),
707
- field('body', $.class_body),
708
- optional($._automatic_semicolon)
728
+ field('body', $.class_body)
709
729
  )
710
730
  ),
711
731
 
@@ -731,8 +751,7 @@ module.exports = grammar({
731
751
  'function',
732
752
  field('name', $.identifier),
733
753
  $._call_signature,
734
- field('body', $.statement_block),
735
- optional($._automatic_semicolon)
754
+ field('body', $.statement_block)
736
755
  )
737
756
  ),
738
757
 
@@ -758,25 +777,27 @@ module.exports = grammar({
758
777
  '*',
759
778
  field('name', $.identifier),
760
779
  $._call_signature,
761
- field('body', $.statement_block),
762
- optional($._automatic_semicolon)
780
+ field('body', $.statement_block)
763
781
  )
764
782
  ),
765
783
 
766
784
  arrow_function: ($) =>
767
- seq(
768
- optional('async'),
769
- choice(
770
- field('parameter', choice(alias($._reserved_identifier, $.identifier), $.identifier)),
771
- $._call_signature
772
- ),
773
- '=>',
774
- choice(
775
- field('body', $.expression),
776
- seq(
777
- field('body', $.statement_block),
778
- optional(seq($._arrow_function_block_end, optional($._arrow_function_block_continuation)))
779
- )
785
+ prec.right(
786
+ seq(
787
+ optional('async'),
788
+ choice(
789
+ field('parameter', choice(alias($._reserved_identifier, $.identifier), $.identifier)),
790
+ $._call_signature
791
+ ),
792
+ '=>',
793
+ choice(
794
+ field('body', $.expression),
795
+ seq(
796
+ field('body', $.statement_block),
797
+ optional(seq($._arrow_function_block_end, optional($._arrow_function_block_continuation)))
798
+ )
799
+ ),
800
+ optional($._completed_arrow_function)
780
801
  )
781
802
  ),
782
803
 
@@ -810,7 +831,21 @@ module.exports = grammar({
810
831
 
811
832
  _argumentless_new_expression: ($) => prec.right('new', seq('new', field('constructor', $.primary_expression))),
812
833
 
813
- await_expression: ($) => prec.dynamic(2, prec('unary_void', seq('await', $.expression))),
834
+ await_expression: ($) =>
835
+ prec.dynamic(
836
+ 3,
837
+ prec.right(
838
+ 'unary_void',
839
+ seq(
840
+ alias($._await_keyword, 'await'),
841
+ optional($._await_identifier_line_break),
842
+ optional(seq($._await_yield_identifier_start, optional($._await_yield_identifier_context))),
843
+ optional($._line_break_after_await),
844
+ $.expression,
845
+ $._await_operand_end
846
+ )
847
+ )
848
+ ),
814
849
 
815
850
  member_expression: ($) =>
816
851
  prec(
@@ -942,7 +977,7 @@ module.exports = grammar({
942
977
  update_expression: ($) =>
943
978
  prec.left(
944
979
  choice(
945
- seq(field('argument', $.expression), field('operator', choice('++', '--'))),
980
+ seq(field('argument', $.expression), field('operator', choice('++', '--')), $._postfix_update_end),
946
981
  seq(field('operator', choice('++', '--')), field('argument', $.expression))
947
982
  )
948
983
  ),
@@ -1207,7 +1242,7 @@ module.exports = grammar({
1207
1242
  // The body of a method or a static block, a rule of its own rather than statement_block: sharing it let tree-sitter
1208
1243
  // merge the state after the body's `}` with the one after a function expression's `}`, where `in`, `instanceof`,
1209
1244
  // and `extends` are keywords, so a class member with one of those names could not follow.
1210
- _class_member_body: ($) => seq('{', repeat($.statement), '}'),
1245
+ _class_member_body: ($) => seq('{', repeat($._statement), '}'),
1211
1246
 
1212
1247
  pair: ($) => seq(field('key', $._property_name), ':', field('value', $.expression)),
1213
1248
 
@@ -1218,7 +1253,10 @@ module.exports = grammar({
1218
1253
  reserved(
1219
1254
  'properties',
1220
1255
  choice(
1221
- alias(choice($.identifier, ...CONTEXTUAL_KEYWORDS), $.property_identifier),
1256
+ alias(
1257
+ choice($.identifier, ...CONTEXTUAL_KEYWORDS.map((word) => (word === 'await' ? $._await_keyword : word))),
1258
+ $.property_identifier
1259
+ ),
1222
1260
  $.private_property_identifier,
1223
1261
  $.string,
1224
1262
  $.number,
@@ -1240,9 +1278,11 @@ module.exports = grammar({
1240
1278
 
1241
1279
  computed_property_name: ($) => seq('[', $.expression, ']'),
1242
1280
 
1243
- _reserved_identifier: () => choice(...MEMBER_MODIFIERS, ...CONTEXTUAL_KEYWORDS),
1281
+ _reserved_identifier: ($) =>
1282
+ choice(...MEMBER_MODIFIERS, ...CONTEXTUAL_KEYWORDS.map((word) => (word === 'await' ? $._await_keyword : word))),
1244
1283
 
1245
- _semicolon: ($) => choice($._automatic_semicolon, ';'),
1284
+ _semicolon: ($) =>
1285
+ choice($._automatic_semicolon, $._await_identifier_line_break, $._await_yield_identifier_start, ';'),
1246
1286
  },
1247
1287
  });
1248
1288
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-javascript",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
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.23",
27
+ "version": "1.0.25",
28
28
  "license": "MIT",
29
29
  "description": "JavaScript grammar for tree-sitter",
30
30
  "authors": [