@willbooster/tree-sitter-javascript 1.0.24 → 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,17 +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
- // 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,
87
102
  ],
88
103
 
89
104
  extras: ($) => [$.comment, $.html_comment, /[\s\p{Zs}\uFEFF\u2028\u2029\u2060\u200B]/u],
@@ -313,7 +328,7 @@ module.exports = grammar({
313
328
 
314
329
  using_declaration: ($) =>
315
330
  seq(
316
- field('kind', choice('using', seq('await', 'using'))),
331
+ field('kind', choice('using', seq(alias($._await_keyword, 'await'), 'using'))),
317
332
  commaSep1(alias($._using_declarator, $.variable_declarator)),
318
333
  $._semicolon
319
334
  ),
@@ -382,12 +397,13 @@ module.exports = grammar({
382
397
 
383
398
  _for_using_declaration: ($) =>
384
399
  seq(
385
- field('kind', choice('using', seq('await', 'using'))),
400
+ field('kind', choice('using', seq(alias($._await_keyword, 'await'), 'using'))),
386
401
  commaSep1(alias($._using_declarator, $.variable_declarator)),
387
402
  ';'
388
403
  ),
389
404
 
390
- 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)),
391
407
 
392
408
  _for_header: ($) =>
393
409
  seq(
@@ -404,7 +420,7 @@ module.exports = grammar({
404
420
  field('left', choice($.identifier, alias('of', $.identifier), $._destructuring_pattern))
405
421
  ),
406
422
  seq(
407
- field('kind', choice('using', seq('await', 'using'))),
423
+ field('kind', choice('using', seq(alias($._await_keyword, 'await'), 'using'))),
408
424
  field('left', choice($.identifier, alias('of', $.identifier)))
409
425
  )
410
426
  ),
@@ -508,10 +524,9 @@ module.exports = grammar({
508
524
  primary_expression: ($) =>
509
525
  choice(
510
526
  $._jsx_element,
511
- $.subscript_expression,
512
- $.member_expression,
513
527
  $.parenthesized_expression,
514
528
  $._identifier,
529
+ alias($._await_yield_identifier, $.identifier),
515
530
  alias($._reserved_identifier, $.identifier),
516
531
  $.this,
517
532
  $.super,
@@ -525,13 +540,15 @@ module.exports = grammar({
525
540
  $.object,
526
541
  $.array,
527
542
  $.function_expression,
528
- $.arrow_function,
529
543
  $.generator_function,
530
544
  $.class,
531
545
  $.meta_property,
546
+ $.subscript_expression,
547
+ $.member_expression,
532
548
  $.call_expression,
533
549
  $.new_expression,
534
- alias($._argumentless_new_expression, $.new_expression)
550
+ alias($._argumentless_new_expression, $.new_expression),
551
+ $.arrow_function
535
552
  ),
536
553
 
537
554
  yield_expression: ($) =>
@@ -765,19 +782,22 @@ module.exports = grammar({
765
782
  ),
766
783
 
767
784
  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
- )
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)
781
801
  )
782
802
  ),
783
803
 
@@ -811,7 +831,21 @@ module.exports = grammar({
811
831
 
812
832
  _argumentless_new_expression: ($) => prec.right('new', seq('new', field('constructor', $.primary_expression))),
813
833
 
814
- 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
+ ),
815
849
 
816
850
  member_expression: ($) =>
817
851
  prec(
@@ -943,7 +977,7 @@ module.exports = grammar({
943
977
  update_expression: ($) =>
944
978
  prec.left(
945
979
  choice(
946
- seq(field('argument', $.expression), field('operator', choice('++', '--'))),
980
+ seq(field('argument', $.expression), field('operator', choice('++', '--')), $._postfix_update_end),
947
981
  seq(field('operator', choice('++', '--')), field('argument', $.expression))
948
982
  )
949
983
  ),
@@ -1219,7 +1253,10 @@ module.exports = grammar({
1219
1253
  reserved(
1220
1254
  'properties',
1221
1255
  choice(
1222
- 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
+ ),
1223
1260
  $.private_property_identifier,
1224
1261
  $.string,
1225
1262
  $.number,
@@ -1241,9 +1278,11 @@ module.exports = grammar({
1241
1278
 
1242
1279
  computed_property_name: ($) => seq('[', $.expression, ']'),
1243
1280
 
1244
- _reserved_identifier: () => choice(...MEMBER_MODIFIERS, ...CONTEXTUAL_KEYWORDS),
1281
+ _reserved_identifier: ($) =>
1282
+ choice(...MEMBER_MODIFIERS, ...CONTEXTUAL_KEYWORDS.map((word) => (word === 'await' ? $._await_keyword : word))),
1245
1283
 
1246
- _semicolon: ($) => choice($._automatic_semicolon, ';'),
1284
+ _semicolon: ($) =>
1285
+ choice($._automatic_semicolon, $._await_identifier_line_break, $._await_yield_identifier_start, ';'),
1247
1286
  },
1248
1287
  });
1249
1288
 
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.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.24",
27
+ "version": "1.0.25",
28
28
  "license": "MIT",
29
29
  "description": "JavaScript grammar for tree-sitter",
30
30
  "authors": [