@willbooster/tree-sitter-javascript 1.0.0 → 1.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
@@ -573,12 +573,24 @@ module.exports = grammar({
573
573
  choice(
574
574
  seq(
575
575
  '"',
576
- repeat(choice(alias($.unescaped_double_jsx_string_fragment, $.string_fragment), $.html_character_reference)),
576
+ repeat(
577
+ choice(
578
+ alias($.unescaped_double_jsx_string_fragment, $.string_fragment),
579
+ $.html_character_reference,
580
+ alias($._jsx_string_ampersand, $.string_fragment)
581
+ )
582
+ ),
577
583
  '"'
578
584
  ),
579
585
  seq(
580
586
  "'",
581
- repeat(choice(alias($.unescaped_single_jsx_string_fragment, $.string_fragment), $.html_character_reference)),
587
+ repeat(
588
+ choice(
589
+ alias($.unescaped_single_jsx_string_fragment, $.string_fragment),
590
+ $.html_character_reference,
591
+ alias($._jsx_string_ampersand, $.string_fragment)
592
+ )
593
+ ),
582
594
  "'"
583
595
  )
584
596
  ),
@@ -587,10 +599,14 @@ module.exports = grammar({
587
599
  // We give names to the token() constructs containing a regexp
588
600
  // so as to obtain a node in the CST.
589
601
  //
590
- unescaped_double_jsx_string_fragment: () => token.immediate(prec(1, /([^"&]|&[^#A-Za-z])+/)),
602
+ unescaped_double_jsx_string_fragment: () => token.immediate(prec(1, /([^"&]|&[^#A-Za-z"&])+/)),
591
603
 
592
604
  // same here
593
- unescaped_single_jsx_string_fragment: () => token.immediate(prec(1, /([^'&]|&[^#A-Za-z])+/)),
605
+ unescaped_single_jsx_string_fragment: () => token.immediate(prec(1, /([^'&]|&[^#A-Za-z'&])+/)),
606
+
607
+ // An `&` that does not start a complete html_character_reference is a literal character, as in HTML. The lexer
608
+ // prefers the longer html_character_reference when one follows.
609
+ _jsx_string_ampersand: () => token.immediate(/&/),
594
610
 
595
611
  _jsx_attribute_value: ($) => choice(alias($._jsx_string, $.string), $.jsx_expression, $._jsx_element),
596
612
 
@@ -896,10 +912,22 @@ module.exports = grammar({
896
912
  template_string: ($) =>
897
913
  seq(
898
914
  '`',
899
- repeat(choice(alias($._template_chars, $.string_fragment), $.escape_sequence, $.template_substitution)),
915
+ repeat(
916
+ choice(
917
+ alias($._template_chars, $.string_fragment),
918
+ $.escape_sequence,
919
+ alias($._invalid_template_escape, $.escape_sequence),
920
+ $.template_substitution
921
+ )
922
+ ),
900
923
  '`'
901
924
  ),
902
925
 
926
+ // Tagged templates allow `\x` and `\u` without the hex digits an escape_sequence needs (the cooked string is
927
+ // undefined). The lexer prefers the longer escape_sequence when the digits follow. Untagged templates reject these
928
+ // escapes, but the lexer cannot tell the two apart.
929
+ _invalid_template_escape: () => token.immediate(seq('\\', /[xu]/)),
930
+
903
931
  template_substitution: ($) => seq('${', $._expressions, '}'),
904
932
 
905
933
  regex: ($) =>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-javascript",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
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.0",
19
+ "version": "1.0.2",
20
20
  "license": "MIT",
21
21
  "description": "JavaScript grammar for tree-sitter",
22
22
  "authors": [