@willbooster/tree-sitter-javascript 6.0.0 → 6.0.2

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
@@ -113,6 +113,11 @@ module.exports = grammar({
113
113
  sym('_regex_flags_start'),
114
114
  sym('_argumentless_new_end'),
115
115
  sym('_constructor_async_function_start'),
116
+ sym('_sync_function_start'),
117
+ sym('_async_function_start'),
118
+ sym('_function_context_end'),
119
+ sym('_arrow_context_end'),
120
+ sym('_await_identifier'),
116
121
  ],
117
122
 
118
123
  extras: ($) => [$.comment, sym('html_comment'), /[\s\p{Zs}\uFEFF\u2028\u2029\u2060\u200B]/u],
@@ -830,85 +835,97 @@ module.exports = grammar({
830
835
  function_expression: ($) =>
831
836
  prec(
832
837
  'literal',
833
- seq(
834
- optional('async'),
835
- 'function',
836
- field('name', optional($.identifier)),
837
- $._call_signature,
838
- field('body', $.statement_block)
838
+ functionContext((async) =>
839
+ seq(
840
+ ...(async ? ['async'] : []),
841
+ 'function',
842
+ field('name', optional($.identifier)),
843
+ $._call_signature,
844
+ contextBody(async, field('body', $.statement_block))
845
+ )
839
846
  )
840
847
  ),
841
848
 
842
849
  function_declaration: ($) =>
843
850
  prec.right(
844
851
  'declaration',
845
- seq(
846
- choice(
847
- seq(
848
- sym('_default_declaration_start'),
849
- optional('async'),
850
- 'function',
851
- field('name', optional($.identifier))
852
+ functionContext((async) =>
853
+ seq(
854
+ choice(
855
+ seq(
856
+ sym('_default_declaration_start'),
857
+ ...(async ? ['async'] : []),
858
+ 'function',
859
+ field('name', optional($.identifier))
860
+ ),
861
+ seq(...(async ? ['async'] : []), 'function', field('name', $.identifier))
852
862
  ),
853
- seq(optional('async'), 'function', field('name', $.identifier))
854
- ),
855
- $._call_signature,
856
- field('body', $.statement_block)
863
+ $._call_signature,
864
+ contextBody(async, field('body', $.statement_block))
865
+ )
857
866
  )
858
867
  ),
859
868
 
860
869
  generator_function: ($) =>
861
870
  prec(
862
871
  'literal',
863
- seq(
864
- optional('async'),
865
- 'function',
866
- '*',
867
- field('name', optional($.identifier)),
868
- $._call_signature,
869
- field('body', $.statement_block)
872
+ functionContext((async) =>
873
+ seq(
874
+ ...(async ? ['async'] : []),
875
+ 'function',
876
+ '*',
877
+ field('name', optional($.identifier)),
878
+ $._call_signature,
879
+ contextBody(async, field('body', $.statement_block))
880
+ )
870
881
  )
871
882
  ),
872
883
 
873
884
  generator_function_declaration: ($) =>
874
885
  prec.right(
875
886
  'declaration',
876
- seq(
877
- choice(
878
- seq(
879
- sym('_default_declaration_start'),
880
- optional('async'),
881
- 'function',
882
- '*',
883
- field('name', optional($.identifier))
887
+ functionContext((async) =>
888
+ seq(
889
+ choice(
890
+ seq(
891
+ sym('_default_declaration_start'),
892
+ ...(async ? ['async'] : []),
893
+ 'function',
894
+ '*',
895
+ field('name', optional($.identifier))
896
+ ),
897
+ seq(...(async ? ['async'] : []), 'function', '*', field('name', $.identifier))
884
898
  ),
885
- seq(optional('async'), 'function', '*', field('name', $.identifier))
886
- ),
887
- $._call_signature,
888
- field('body', $.statement_block)
899
+ $._call_signature,
900
+ contextBody(async, field('body', $.statement_block))
901
+ )
889
902
  )
890
903
  ),
891
904
 
892
905
  arrow_function: ($) =>
893
906
  prec.right(
894
- seq(
895
- optional('async'),
896
- choice(
897
- field(
898
- 'parameter',
899
- choice(alias($._reserved_identifier, $.identifier), alias($.undefined, $.identifier), $.identifier)
907
+ functionContext((async) =>
908
+ seq(
909
+ ...(async ? ['async'] : []),
910
+ choice(
911
+ field(
912
+ 'parameter',
913
+ choice(alias($._reserved_identifier, $.identifier), alias($.undefined, $.identifier), $.identifier)
914
+ ),
915
+ $._call_signature
900
916
  ),
901
- $._call_signature
902
- ),
903
- '=>',
904
- choice(
905
- field('body', $.expression),
906
- seq(
907
- field('body', $.statement_block),
908
- optional(seq(sym('_arrow_function_block_end'), optional(sym('_arrow_function_block_continuation'))))
909
- )
910
- ),
911
- optional(sym('_completed_arrow_function'))
917
+ '=>',
918
+ sym(async ? '_async_function_start' : '_sync_function_start'),
919
+ choice(
920
+ seq(field('body', $.expression), sym('_arrow_context_end')),
921
+ seq(
922
+ field('body', $.statement_block),
923
+ optional(seq(sym('_arrow_function_block_end'), optional(sym('_arrow_function_block_continuation')))),
924
+ sym('_function_context_end')
925
+ )
926
+ ),
927
+ optional(sym('_completed_arrow_function'))
928
+ )
912
929
  )
913
930
  ),
914
931
 
@@ -941,27 +958,31 @@ module.exports = grammar({
941
958
  _constructor_function_expression: ($) =>
942
959
  prec(
943
960
  'literal',
944
- seq(
945
- optional(sym('_constructor_async_function_start')),
946
- optional('async'),
947
- 'function',
948
- field('name', optional($.identifier)),
949
- $._call_signature,
950
- field('body', $.statement_block)
961
+ functionContext((async) =>
962
+ seq(
963
+ optional(sym('_constructor_async_function_start')),
964
+ ...(async ? ['async'] : []),
965
+ 'function',
966
+ field('name', optional($.identifier)),
967
+ $._call_signature,
968
+ contextBody(async, field('body', $.statement_block))
969
+ )
951
970
  )
952
971
  ),
953
972
 
954
973
  _constructor_generator_function: ($) =>
955
974
  prec(
956
975
  'literal',
957
- seq(
958
- optional(sym('_constructor_async_function_start')),
959
- optional('async'),
960
- 'function',
961
- '*',
962
- field('name', optional($.identifier)),
963
- $._call_signature,
964
- field('body', $.statement_block)
976
+ functionContext((async) =>
977
+ seq(
978
+ optional(sym('_constructor_async_function_start')),
979
+ ...(async ? ['async'] : []),
980
+ 'function',
981
+ '*',
982
+ field('name', optional($.identifier)),
983
+ $._call_signature,
984
+ contextBody(async, field('body', $.statement_block))
985
+ )
965
986
  )
966
987
  ),
967
988
 
@@ -1465,14 +1486,16 @@ module.exports = grammar({
1465
1486
  rest_pattern: ($) => prec.right(seq('...', choice($._lhs_expression, $.parenthesized_expression))),
1466
1487
 
1467
1488
  method_definition: ($) =>
1468
- seq(
1469
- repeat(field('decorator', $.decorator)),
1470
- optional('static'),
1471
- optional('async'),
1472
- optional(choice('get', 'set', '*')),
1473
- field('name', $._property_name),
1474
- field('parameters', $.formal_parameters),
1475
- field('body', alias($._class_member_body, $.statement_block))
1489
+ functionContext((async) =>
1490
+ seq(
1491
+ repeat(field('decorator', $.decorator)),
1492
+ optional('static'),
1493
+ ...(async ? ['async'] : []),
1494
+ optional(choice('get', 'set', '*')),
1495
+ field('name', $._property_name),
1496
+ field('parameters', $.formal_parameters),
1497
+ contextBody(async, field('body', alias($._class_member_body, $.statement_block)))
1498
+ )
1476
1499
  ),
1477
1500
 
1478
1501
  // The body of a method or a static block, a rule of its own rather than statement_block: sharing it let tree-sitter
@@ -1493,7 +1516,9 @@ module.exports = grammar({
1493
1516
  choice(
1494
1517
  $.identifier,
1495
1518
  $._escaped_let,
1496
- ...CONTEXTUAL_KEYWORDS.map((word) => (word === 'await' ? sym('_await_keyword') : word))
1519
+ ...CONTEXTUAL_KEYWORDS.map((word) =>
1520
+ word === 'await' ? choice(sym('_await_keyword'), sym('_await_identifier')) : word
1521
+ )
1497
1522
  ),
1498
1523
  sym('property_identifier')
1499
1524
  ),
@@ -1522,7 +1547,9 @@ module.exports = grammar({
1522
1547
  choice(
1523
1548
  ...MEMBER_MODIFIERS,
1524
1549
  $._escaped_let,
1525
- ...CONTEXTUAL_KEYWORDS.map((word) => (word === 'await' ? sym('_await_keyword') : word))
1550
+ ...CONTEXTUAL_KEYWORDS.map((word) =>
1551
+ word === 'await' ? choice(sym('_await_keyword'), sym('_await_identifier')) : word
1552
+ )
1526
1553
  ),
1527
1554
 
1528
1555
  _semicolon: () =>
@@ -1556,3 +1583,15 @@ function commaSep1(rule) {
1556
1583
  function commaSep(rule) {
1557
1584
  return optional(commaSep1(rule));
1558
1585
  }
1586
+
1587
+ /** @param {(isAsync: boolean) => import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} makeRule */
1588
+ function functionContext(makeRule) {
1589
+ return choice(makeRule(false), makeRule(true));
1590
+ }
1591
+ /**
1592
+ * @param {boolean} async
1593
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} body
1594
+ */
1595
+ function contextBody(async, body) {
1596
+ return seq(sym(async ? '_async_function_start' : '_sync_function_start'), body, sym('_function_context_end'));
1597
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-javascript",
3
- "version": "6.0.0",
3
+ "version": "6.0.2",
4
4
  "description": "JavaScript grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -59,12 +59,10 @@
59
59
  (#match? @constant "^[A-Z_][A-Z\\d_]+$"))
60
60
 
61
61
  ((identifier) @variable.builtin
62
- (#match? @variable.builtin "^(arguments|module|console|window|document)$")
63
- (#is-not? local))
62
+ (#match? @variable.builtin "^(arguments|module|console|window|document)$"))
64
63
 
65
64
  ((identifier) @function.builtin
66
- (#eq? @function.builtin "require")
67
- (#is-not? local))
65
+ (#eq? @function.builtin "require"))
68
66
 
69
67
  ; Literals
70
68
  ;---------
Binary file
package/tree-sitter.json CHANGED
@@ -24,7 +24,7 @@
24
24
  }
25
25
  ],
26
26
  "metadata": {
27
- "version": "6.0.0",
27
+ "version": "6.0.2",
28
28
  "license": "MIT",
29
29
  "description": "JavaScript grammar for tree-sitter",
30
30
  "authors": [