@willbooster/tree-sitter-javascript 1.0.1 → 1.0.3

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
@@ -23,6 +23,12 @@ module.exports = grammar({
23
23
  $.escape_sequence,
24
24
  $.regex_pattern,
25
25
  $.jsx_text,
26
+ // Zero-width tokens after an arrow function's block body that a line break (or `}` or the end of input) follows:
27
+ // such a function cannot be called, indexed, or used as an operand, so the statement ends there if it can. The
28
+ // scanner inserts the automatic semicolon right after _arrow_function_block_end, or else emits
29
+ // _arrow_function_block_continuation, since the arrow function may be, e.g., an argument.
30
+ $._arrow_function_block_end,
31
+ $._arrow_function_block_continuation,
26
32
  ],
27
33
 
28
34
  extras: ($) => [$.comment, $.html_comment, /[\s\p{Zs}\uFEFF\u2028\u2029\u2060\u200B]/u],
@@ -697,7 +703,13 @@ module.exports = grammar({
697
703
  $._call_signature
698
704
  ),
699
705
  '=>',
700
- field('body', choice($.expression, $.statement_block))
706
+ choice(
707
+ field('body', $.expression),
708
+ seq(
709
+ field('body', $.statement_block),
710
+ optional(seq($._arrow_function_block_end, optional($._arrow_function_block_continuation)))
711
+ )
712
+ )
701
713
  ),
702
714
 
703
715
  // Override
@@ -912,10 +924,22 @@ module.exports = grammar({
912
924
  template_string: ($) =>
913
925
  seq(
914
926
  '`',
915
- repeat(choice(alias($._template_chars, $.string_fragment), $.escape_sequence, $.template_substitution)),
927
+ repeat(
928
+ choice(
929
+ alias($._template_chars, $.string_fragment),
930
+ $.escape_sequence,
931
+ alias($._invalid_template_escape, $.escape_sequence),
932
+ $.template_substitution
933
+ )
934
+ ),
916
935
  '`'
917
936
  ),
918
937
 
938
+ // Tagged templates allow `\x` and `\u` without the hex digits an escape_sequence needs (the cooked string is
939
+ // undefined). The lexer prefers the longer escape_sequence when the digits follow. Untagged templates reject these
940
+ // escapes, but the lexer cannot tell the two apart.
941
+ _invalid_template_escape: () => token.immediate(seq('\\', /[xu]/)),
942
+
919
943
  template_substitution: ($) => seq('${', $._expressions, '}'),
920
944
 
921
945
  regex: ($) =>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-javascript",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "JavaScript grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
Binary file
package/tree-sitter.json CHANGED
@@ -16,7 +16,7 @@
16
16
  }
17
17
  ],
18
18
  "metadata": {
19
- "version": "1.0.1",
19
+ "version": "1.0.3",
20
20
  "license": "MIT",
21
21
  "description": "JavaScript grammar for tree-sitter",
22
22
  "authors": [