@willbooster/tree-sitter-javascript 7.1.2 → 8.0.1

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/README.md CHANGED
@@ -77,7 +77,7 @@ In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-
77
77
  ```toml
78
78
  [dependencies]
79
79
  tree-sitter = { package = "willbooster-tree-sitter", version = "7.0.5" }
80
- tree-sitter-javascript = { package = "willbooster-tree-sitter-javascript", version = "7" }
80
+ tree-sitter-javascript = { package = "willbooster-tree-sitter-javascript", version = "8" }
81
81
  ```
82
82
 
83
83
  ```rust
package/grammar.js CHANGED
@@ -125,6 +125,7 @@ module.exports = grammar({
125
125
  sym('_function_signature_start'),
126
126
  sym('_async_function_signature_start'),
127
127
  sym('_call_arguments_context'),
128
+ sym('_async_keyword'),
128
129
  ],
129
130
 
130
131
  extras: ($) => [$.comment, sym('html_comment'), /[\s\p{Zs}\uFEFF\u2028\u2029\u2060\u200B]/u],
@@ -210,7 +211,7 @@ module.exports = grammar({
210
211
  [$.primary_expression, $.method_definition],
211
212
  [$.primary_expression, $.rest_pattern],
212
213
  [$.primary_expression, $.pattern],
213
- [$.primary_expression, $._for_header],
214
+ [$.primary_expression, $.for_in_clause],
214
215
  [$.array, $.array_pattern],
215
216
  [$.object, $.object_pattern],
216
217
  [$.assignment_expression, $.pattern],
@@ -436,20 +437,12 @@ module.exports = grammar({
436
437
 
437
438
  switch_statement: ($) => seq('switch', field('value', $.parenthesized_expression), field('body', $.switch_body)),
438
439
 
439
- for_statement: ($) =>
440
- seq(
441
- 'for',
442
- '(',
443
- $._for_initializer,
444
- $._for_condition,
445
- field('increment', optional($._expressions)),
446
- ')',
447
- field('body', $._single_statement)
448
- ),
440
+ for_statement: ($) => seq('for', field('header', $.for_clause), field('body', $._single_statement)),
441
+
442
+ for_clause: ($) =>
443
+ seq('(', $._for_initializer, $._for_condition, field('increment', optional($._expressions)), ')'),
449
444
 
450
- // Extracted into rules because tree-sitter expands a `choice` written inline in the `seq` above into one production
451
- // per alternative, each repeating the parse states of the rest of the header (about 30 KB of Wasm). They are hidden
452
- // so that `initializer` and `condition` stay fields of `for_statement` and no node type is added.
445
+ // Hidden alternatives avoid duplicating the remaining header states for every initializer form.
453
446
  _for_initializer: ($) =>
454
447
  choice(
455
448
  field(
@@ -488,9 +481,14 @@ module.exports = grammar({
488
481
  ),
489
482
 
490
483
  for_in_statement: ($) =>
491
- seq('for', optional(alias(sym('_await_keyword'), 'await')), $._for_header, field('body', $._single_statement)),
484
+ seq(
485
+ 'for',
486
+ optional(alias(sym('_await_keyword'), 'await')),
487
+ field('header', $.for_in_clause),
488
+ field('body', $._single_statement)
489
+ ),
492
490
 
493
- _for_header: ($) =>
491
+ for_in_clause: ($) =>
494
492
  seq(
495
493
  '(',
496
494
  choice(
@@ -577,7 +575,10 @@ module.exports = grammar({
577
575
 
578
576
  labeled_statement: ($) =>
579
577
  seq(
580
- field('label', alias(choice($.identifier, $.undefined, $._reserved_identifier), sym('statement_identifier'))),
578
+ field(
579
+ 'label',
580
+ aliasWithAsyncKeyword(choice($.identifier, $.undefined, $._reserved_identifier), sym('statement_identifier'))
581
+ ),
581
582
  ':',
582
583
  field('body', $._single_statement)
583
584
  ),
@@ -627,7 +628,7 @@ module.exports = grammar({
627
628
  $.parenthesized_expression,
628
629
  $._identifier,
629
630
  alias(sym('_await_yield_identifier'), $.identifier),
630
- alias($._reserved_identifier, $.identifier),
631
+ aliasWithAsyncKeyword($._reserved_identifier, $.identifier),
631
632
  $.this,
632
633
  $.super,
633
634
  $.number,
@@ -670,7 +671,10 @@ module.exports = grammar({
670
671
  $.pair,
671
672
  $.spread_element,
672
673
  $.method_definition,
673
- alias(choice($.identifier, $._reserved_identifier), sym('shorthand_property_identifier'))
674
+ aliasWithAsyncKeyword(
675
+ choice($.identifier, $._reserved_identifier),
676
+ sym('shorthand_property_identifier')
677
+ )
674
678
  )
675
679
  )
676
680
  ),
@@ -689,7 +693,10 @@ module.exports = grammar({
689
693
  $.pair_pattern,
690
694
  $.rest_pattern,
691
695
  $.object_assignment_pattern,
692
- alias(choice($.identifier, $._reserved_identifier), sym('shorthand_property_identifier_pattern'))
696
+ aliasWithAsyncKeyword(
697
+ choice($.identifier, $._reserved_identifier),
698
+ sym('shorthand_property_identifier_pattern')
699
+ )
693
700
  )
694
701
  )
695
702
  ),
@@ -704,7 +711,10 @@ module.exports = grammar({
704
711
  field(
705
712
  'left',
706
713
  choice(
707
- alias(choice($._reserved_identifier, $.identifier), sym('shorthand_property_identifier_pattern')),
714
+ aliasWithAsyncKeyword(
715
+ choice($._reserved_identifier, $.identifier),
716
+ sym('shorthand_property_identifier_pattern')
717
+ ),
708
718
  $._destructuring_pattern
709
719
  )
710
720
  ),
@@ -847,7 +857,7 @@ module.exports = grammar({
847
857
  'literal',
848
858
  functionContext((async) =>
849
859
  seq(
850
- ...(async ? ['async'] : []),
860
+ ...(async ? [alias(sym('_async_keyword'), 'async')] : []),
851
861
  'function',
852
862
  field('name', optional($.identifier)),
853
863
  functionScope(async, seq($._call_signature, field('body', $.statement_block)))
@@ -863,11 +873,11 @@ module.exports = grammar({
863
873
  choice(
864
874
  seq(
865
875
  sym('_default_declaration_start'),
866
- ...(async ? ['async'] : []),
876
+ ...(async ? [alias(sym('_async_keyword'), 'async')] : []),
867
877
  'function',
868
878
  field('name', optional($.identifier))
869
879
  ),
870
- seq(...(async ? ['async'] : []), 'function', field('name', $.identifier))
880
+ seq(...(async ? [alias(sym('_async_keyword'), 'async')] : []), 'function', field('name', $.identifier))
871
881
  ),
872
882
  functionScope(async, seq($._call_signature, field('body', $.statement_block)))
873
883
  )
@@ -879,7 +889,7 @@ module.exports = grammar({
879
889
  'literal',
880
890
  functionContext((async) =>
881
891
  seq(
882
- ...(async ? ['async'] : []),
892
+ ...(async ? [alias(sym('_async_keyword'), 'async')] : []),
883
893
  'function',
884
894
  '*',
885
895
  field('name', optional($.identifier)),
@@ -896,12 +906,17 @@ module.exports = grammar({
896
906
  choice(
897
907
  seq(
898
908
  sym('_default_declaration_start'),
899
- ...(async ? ['async'] : []),
909
+ ...(async ? [alias(sym('_async_keyword'), 'async')] : []),
900
910
  'function',
901
911
  '*',
902
912
  field('name', optional($.identifier))
903
913
  ),
904
- seq(...(async ? ['async'] : []), 'function', '*', field('name', $.identifier))
914
+ seq(
915
+ ...(async ? [alias(sym('_async_keyword'), 'async')] : []),
916
+ 'function',
917
+ '*',
918
+ field('name', $.identifier)
919
+ )
905
920
  ),
906
921
  functionScope(async, seq($._call_signature, field('body', $.statement_block)), 'generator_function')
907
922
  )
@@ -912,11 +927,15 @@ module.exports = grammar({
912
927
  prec.right(
913
928
  functionContext((async) =>
914
929
  seq(
915
- ...(async ? ['async'] : []),
930
+ ...(async ? [alias(sym('_async_keyword'), 'async')] : []),
916
931
  choice(
917
932
  field(
918
933
  'parameter',
919
- choice(alias($._reserved_identifier, $.identifier), alias($.undefined, $.identifier), $.identifier)
934
+ choice(
935
+ aliasWithAsyncKeyword($._reserved_identifier, $.identifier),
936
+ alias($.undefined, $.identifier),
937
+ $.identifier
938
+ )
920
939
  ),
921
940
  $._call_signature
922
941
  ),
@@ -967,7 +986,7 @@ module.exports = grammar({
967
986
  functionContext((async) =>
968
987
  seq(
969
988
  optional(sym('_constructor_async_function_start')),
970
- ...(async ? ['async'] : []),
989
+ ...(async ? [alias(sym('_async_keyword'), 'async')] : []),
971
990
  'function',
972
991
  field('name', optional($.identifier)),
973
992
  functionScope(async, seq($._call_signature, field('body', $.statement_block)))
@@ -981,7 +1000,7 @@ module.exports = grammar({
981
1000
  functionContext((async) =>
982
1001
  seq(
983
1002
  optional(sym('_constructor_async_function_start')),
984
- ...(async ? ['async'] : []),
1003
+ ...(async ? [alias(sym('_async_keyword'), 'async')] : []),
985
1004
  'function',
986
1005
  '*',
987
1006
  field('name', optional($.identifier)),
@@ -996,7 +1015,7 @@ module.exports = grammar({
996
1015
  $.parenthesized_expression,
997
1016
  $._identifier,
998
1017
  alias(sym('_await_yield_identifier'), $.identifier),
999
- alias($._reserved_identifier, $.identifier),
1018
+ aliasWithAsyncKeyword($._reserved_identifier, $.identifier),
1000
1019
  $.this,
1001
1020
  $.super,
1002
1021
  $.number,
@@ -1125,7 +1144,7 @@ module.exports = grammar({
1125
1144
  $.member_expression,
1126
1145
  $.subscript_expression,
1127
1146
  $._identifier,
1128
- alias($._reserved_identifier, $.identifier),
1147
+ aliasWithAsyncKeyword($._reserved_identifier, $.identifier),
1129
1148
  $._destructuring_pattern
1130
1149
  ),
1131
1150
 
@@ -1139,7 +1158,7 @@ module.exports = grammar({
1139
1158
  choice(
1140
1159
  $.member_expression,
1141
1160
  $.subscript_expression,
1142
- alias($._reserved_identifier, $.identifier),
1161
+ aliasWithAsyncKeyword($._reserved_identifier, $.identifier),
1143
1162
  $._identifier,
1144
1163
  $.parenthesized_expression
1145
1164
  ),
@@ -1505,7 +1524,7 @@ module.exports = grammar({
1505
1524
  seq(
1506
1525
  repeat(field('decorator', $.decorator)),
1507
1526
  optional('static'),
1508
- ...(async ? ['async'] : []),
1527
+ ...(async ? [alias(sym('_async_keyword'), 'async')] : []),
1509
1528
  ...(generator ? ['*'] : [optional(choice('get', 'set'))]),
1510
1529
  field('name', $._property_name),
1511
1530
  choice(
@@ -1545,7 +1564,7 @@ module.exports = grammar({
1545
1564
  reserved(
1546
1565
  'properties',
1547
1566
  choice(
1548
- alias(
1567
+ aliasWithAsyncKeyword(
1549
1568
  choice(
1550
1569
  $.identifier,
1551
1570
  sym('_yield_identifier'),
@@ -1567,7 +1586,7 @@ module.exports = grammar({
1567
1586
  reserved(
1568
1587
  'properties',
1569
1588
  choice(
1570
- alias(choice($.identifier, $._reserved_identifier), sym('property_identifier')),
1589
+ aliasWithAsyncKeyword(choice($.identifier, $._reserved_identifier), sym('property_identifier')),
1571
1590
  $.private_property_identifier,
1572
1591
  $.string,
1573
1592
  $.number,
@@ -1597,6 +1616,14 @@ module.exports = grammar({
1597
1616
  },
1598
1617
  });
1599
1618
 
1619
+ /**
1620
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
1621
+ * @param {import('@willbooster/web-tree-sitter/dsl').SymbolRule<string>} symbol
1622
+ */
1623
+ function aliasWithAsyncKeyword(rule, symbol) {
1624
+ return choice(alias(rule, symbol), alias(sym('_async_keyword'), symbol));
1625
+ }
1626
+
1600
1627
  /**
1601
1628
  * Creates a rule to match one or more of the rules separated by a comma
1602
1629
  *
@@ -1274,19 +1274,81 @@
1274
1274
  }
1275
1275
  },
1276
1276
  {
1277
- "type": "for_in_statement",
1277
+ "type": "for_clause",
1278
1278
  "named": true,
1279
1279
  "fields": {
1280
- "body": {
1281
- "multiple": false,
1280
+ "condition": {
1281
+ "multiple": true,
1282
1282
  "required": true,
1283
1283
  "types": [
1284
1284
  {
1285
- "type": "statement",
1285
+ "type": ";",
1286
+ "named": false
1287
+ },
1288
+ {
1289
+ "type": "empty_statement",
1290
+ "named": true
1291
+ },
1292
+ {
1293
+ "type": "expression",
1294
+ "named": true
1295
+ },
1296
+ {
1297
+ "type": "sequence_expression",
1286
1298
  "named": true
1287
1299
  }
1288
1300
  ]
1289
1301
  },
1302
+ "increment": {
1303
+ "multiple": false,
1304
+ "required": false,
1305
+ "types": [
1306
+ {
1307
+ "type": "expression",
1308
+ "named": true
1309
+ },
1310
+ {
1311
+ "type": "sequence_expression",
1312
+ "named": true
1313
+ }
1314
+ ]
1315
+ },
1316
+ "initializer": {
1317
+ "multiple": false,
1318
+ "required": true,
1319
+ "types": [
1320
+ {
1321
+ "type": "empty_statement",
1322
+ "named": true
1323
+ },
1324
+ {
1325
+ "type": "expression",
1326
+ "named": true
1327
+ },
1328
+ {
1329
+ "type": "lexical_declaration",
1330
+ "named": true
1331
+ },
1332
+ {
1333
+ "type": "sequence_expression",
1334
+ "named": true
1335
+ },
1336
+ {
1337
+ "type": "using_declaration",
1338
+ "named": true
1339
+ },
1340
+ {
1341
+ "type": "variable_declaration",
1342
+ "named": true
1343
+ }
1344
+ ]
1345
+ }
1346
+ }
1347
+ },
1348
+ {
1349
+ "type": "for_in_clause",
1350
+ "named": true,
1351
+ "fields": {
1290
1352
  "kind": {
1291
1353
  "multiple": true,
1292
1354
  "required": false,
@@ -1388,7 +1450,7 @@
1388
1450
  }
1389
1451
  },
1390
1452
  {
1391
- "type": "for_statement",
1453
+ "type": "for_in_statement",
1392
1454
  "named": true,
1393
1455
  "fields": {
1394
1456
  "body": {
@@ -1401,68 +1463,38 @@
1401
1463
  }
1402
1464
  ]
1403
1465
  },
1404
- "condition": {
1405
- "multiple": true,
1466
+ "header": {
1467
+ "multiple": false,
1406
1468
  "required": true,
1407
1469
  "types": [
1408
1470
  {
1409
- "type": ";",
1410
- "named": false
1411
- },
1412
- {
1413
- "type": "empty_statement",
1414
- "named": true
1415
- },
1416
- {
1417
- "type": "expression",
1418
- "named": true
1419
- },
1420
- {
1421
- "type": "sequence_expression",
1471
+ "type": "for_in_clause",
1422
1472
  "named": true
1423
1473
  }
1424
1474
  ]
1425
- },
1426
- "increment": {
1475
+ }
1476
+ }
1477
+ },
1478
+ {
1479
+ "type": "for_statement",
1480
+ "named": true,
1481
+ "fields": {
1482
+ "body": {
1427
1483
  "multiple": false,
1428
- "required": false,
1484
+ "required": true,
1429
1485
  "types": [
1430
1486
  {
1431
- "type": "expression",
1432
- "named": true
1433
- },
1434
- {
1435
- "type": "sequence_expression",
1487
+ "type": "statement",
1436
1488
  "named": true
1437
1489
  }
1438
1490
  ]
1439
1491
  },
1440
- "initializer": {
1492
+ "header": {
1441
1493
  "multiple": false,
1442
1494
  "required": true,
1443
1495
  "types": [
1444
1496
  {
1445
- "type": "empty_statement",
1446
- "named": true
1447
- },
1448
- {
1449
- "type": "expression",
1450
- "named": true
1451
- },
1452
- {
1453
- "type": "lexical_declaration",
1454
- "named": true
1455
- },
1456
- {
1457
- "type": "sequence_expression",
1458
- "named": true
1459
- },
1460
- {
1461
- "type": "using_declaration",
1462
- "named": true
1463
- },
1464
- {
1465
- "type": "variable_declaration",
1497
+ "type": "for_clause",
1466
1498
  "named": true
1467
1499
  }
1468
1500
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-javascript",
3
- "version": "7.1.2",
3
+ "version": "8.0.1",
4
4
  "description": "JavaScript grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -1274,19 +1274,81 @@
1274
1274
  }
1275
1275
  },
1276
1276
  {
1277
- "type": "for_in_statement",
1277
+ "type": "for_clause",
1278
1278
  "named": true,
1279
1279
  "fields": {
1280
- "body": {
1281
- "multiple": false,
1280
+ "condition": {
1281
+ "multiple": true,
1282
1282
  "required": true,
1283
1283
  "types": [
1284
1284
  {
1285
- "type": "statement",
1285
+ "type": ";",
1286
+ "named": false
1287
+ },
1288
+ {
1289
+ "type": "empty_statement",
1290
+ "named": true
1291
+ },
1292
+ {
1293
+ "type": "expression",
1294
+ "named": true
1295
+ },
1296
+ {
1297
+ "type": "sequence_expression",
1286
1298
  "named": true
1287
1299
  }
1288
1300
  ]
1289
1301
  },
1302
+ "increment": {
1303
+ "multiple": false,
1304
+ "required": false,
1305
+ "types": [
1306
+ {
1307
+ "type": "expression",
1308
+ "named": true
1309
+ },
1310
+ {
1311
+ "type": "sequence_expression",
1312
+ "named": true
1313
+ }
1314
+ ]
1315
+ },
1316
+ "initializer": {
1317
+ "multiple": false,
1318
+ "required": true,
1319
+ "types": [
1320
+ {
1321
+ "type": "empty_statement",
1322
+ "named": true
1323
+ },
1324
+ {
1325
+ "type": "expression",
1326
+ "named": true
1327
+ },
1328
+ {
1329
+ "type": "lexical_declaration",
1330
+ "named": true
1331
+ },
1332
+ {
1333
+ "type": "sequence_expression",
1334
+ "named": true
1335
+ },
1336
+ {
1337
+ "type": "using_declaration",
1338
+ "named": true
1339
+ },
1340
+ {
1341
+ "type": "variable_declaration",
1342
+ "named": true
1343
+ }
1344
+ ]
1345
+ }
1346
+ }
1347
+ },
1348
+ {
1349
+ "type": "for_in_clause",
1350
+ "named": true,
1351
+ "fields": {
1290
1352
  "kind": {
1291
1353
  "multiple": true,
1292
1354
  "required": false,
@@ -1388,7 +1450,7 @@
1388
1450
  }
1389
1451
  },
1390
1452
  {
1391
- "type": "for_statement",
1453
+ "type": "for_in_statement",
1392
1454
  "named": true,
1393
1455
  "fields": {
1394
1456
  "body": {
@@ -1401,68 +1463,38 @@
1401
1463
  }
1402
1464
  ]
1403
1465
  },
1404
- "condition": {
1405
- "multiple": true,
1466
+ "header": {
1467
+ "multiple": false,
1406
1468
  "required": true,
1407
1469
  "types": [
1408
1470
  {
1409
- "type": ";",
1410
- "named": false
1411
- },
1412
- {
1413
- "type": "empty_statement",
1414
- "named": true
1415
- },
1416
- {
1417
- "type": "expression",
1418
- "named": true
1419
- },
1420
- {
1421
- "type": "sequence_expression",
1471
+ "type": "for_in_clause",
1422
1472
  "named": true
1423
1473
  }
1424
1474
  ]
1425
- },
1426
- "increment": {
1475
+ }
1476
+ }
1477
+ },
1478
+ {
1479
+ "type": "for_statement",
1480
+ "named": true,
1481
+ "fields": {
1482
+ "body": {
1427
1483
  "multiple": false,
1428
- "required": false,
1484
+ "required": true,
1429
1485
  "types": [
1430
1486
  {
1431
- "type": "expression",
1432
- "named": true
1433
- },
1434
- {
1435
- "type": "sequence_expression",
1487
+ "type": "statement",
1436
1488
  "named": true
1437
1489
  }
1438
1490
  ]
1439
1491
  },
1440
- "initializer": {
1492
+ "header": {
1441
1493
  "multiple": false,
1442
1494
  "required": true,
1443
1495
  "types": [
1444
1496
  {
1445
- "type": "empty_statement",
1446
- "named": true
1447
- },
1448
- {
1449
- "type": "expression",
1450
- "named": true
1451
- },
1452
- {
1453
- "type": "lexical_declaration",
1454
- "named": true
1455
- },
1456
- {
1457
- "type": "sequence_expression",
1458
- "named": true
1459
- },
1460
- {
1461
- "type": "using_declaration",
1462
- "named": true
1463
- },
1464
- {
1465
- "type": "variable_declaration",
1497
+ "type": "for_clause",
1466
1498
  "named": true
1467
1499
  }
1468
1500
  ]
Binary file
Binary file
package/tree-sitter.json CHANGED
@@ -48,7 +48,7 @@
48
48
  }
49
49
  ],
50
50
  "metadata": {
51
- "version": "7.1.2",
51
+ "version": "8.0.1",
52
52
  "license": "MIT",
53
53
  "description": "JavaScript grammar for tree-sitter",
54
54
  "authors": [