@willbooster/tree-sitter-javascript 1.0.19 → 1.0.20

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
@@ -500,7 +500,6 @@ module.exports = grammar({
500
500
  $.binary_expression,
501
501
  $.ternary_expression,
502
502
  $.update_expression,
503
- $.new_expression,
504
503
  $.yield_expression
505
504
  ),
506
505
 
@@ -527,7 +526,9 @@ module.exports = grammar({
527
526
  $.generator_function,
528
527
  $.class,
529
528
  $.meta_property,
530
- $.call_expression
529
+ $.call_expression,
530
+ $.new_expression,
531
+ alias($._argumentless_new_expression, $.new_expression)
531
532
  ),
532
533
 
533
534
  yield_expression: ($) =>
@@ -789,10 +790,7 @@ module.exports = grammar({
789
790
  call_expression: ($) =>
790
791
  choice(
791
792
  prec('call', seq(field('function', choice($.expression, $.import)), field('arguments', $.arguments))),
792
- prec(
793
- 'template_call',
794
- seq(field('function', choice($.primary_expression, $.new_expression)), field('arguments', $.template_string))
795
- ),
793
+ prec('template_call', seq(field('function', $.primary_expression), field('arguments', $.template_string))),
796
794
  prec(
797
795
  'member',
798
796
  seq(
@@ -803,15 +801,15 @@ module.exports = grammar({
803
801
  )
804
802
  ),
805
803
 
804
+ // As in ECMAScript, a member access or index extends the nearest `new` with arguments, while an argument list fills
805
+ // the nearest `new` that still lacks one: `new new A().b` constructs `new A().b`, `new new A().b(2)` constructs
806
+ // `new A().b` with `2`, and `new new A()(2)` constructs `new A()`. The 'member' and 'new' precedences make the parser
807
+ // shift a `.`, `[`, or argument list after a constructor rather than end a `new` without arguments, so that form
808
+ // never takes one. Both forms are primary expressions, so a nested `new` matches the constructor field's type.
806
809
  new_expression: ($) =>
807
- prec.right(
808
- 'new',
809
- seq(
810
- 'new',
811
- field('constructor', choice($.primary_expression, $.new_expression)),
812
- field('arguments', optional(prec.dynamic(1, $.arguments)))
813
- )
814
- ),
810
+ prec('new', seq('new', field('constructor', $.primary_expression), field('arguments', $.arguments))),
811
+
812
+ _argumentless_new_expression: ($) => prec.right('new', seq('new', field('constructor', $.primary_expression))),
815
813
 
816
814
  await_expression: ($) => prec.dynamic(2, prec('unary_void', seq('await', $.expression))),
817
815
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-javascript",
3
- "version": "1.0.19",
3
+ "version": "1.0.20",
4
4
  "description": "JavaScript grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -57,10 +57,6 @@
57
57
  "type": "jsx_self_closing_element",
58
58
  "named": true
59
59
  },
60
- {
61
- "type": "new_expression",
62
- "named": true
63
- },
64
60
  {
65
61
  "type": "primary_expression",
66
62
  "named": true
@@ -165,6 +161,10 @@
165
161
  "type": "meta_property",
166
162
  "named": true
167
163
  },
164
+ {
165
+ "type": "new_expression",
166
+ "named": true
167
+ },
168
168
  {
169
169
  "type": "null",
170
170
  "named": true
@@ -2236,10 +2236,6 @@
2236
2236
  "multiple": false,
2237
2237
  "required": true,
2238
2238
  "types": [
2239
- {
2240
- "type": "new_expression",
2241
- "named": true
2242
- },
2243
2239
  {
2244
2240
  "type": "primary_expression",
2245
2241
  "named": true
Binary file
package/tree-sitter.json CHANGED
@@ -24,7 +24,7 @@
24
24
  }
25
25
  ],
26
26
  "metadata": {
27
- "version": "1.0.19",
27
+ "version": "1.0.20",
28
28
  "license": "MIT",
29
29
  "description": "JavaScript grammar for tree-sitter",
30
30
  "authors": [