@willbooster/tree-sitter-javascript 1.0.8 → 1.0.9

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
@@ -292,7 +292,14 @@ module.exports = grammar({
292
292
  seq(field('kind', choice('let', 'const')), commaSep1($.variable_declarator), $._semicolon),
293
293
 
294
294
  using_declaration: ($) =>
295
- seq(field('kind', choice('using', seq('await', 'using'))), commaSep1($.variable_declarator), $._semicolon),
295
+ seq(
296
+ field('kind', choice('using', seq('await', 'using'))),
297
+ commaSep1(alias($._using_declarator, $.variable_declarator)),
298
+ $._semicolon
299
+ ),
300
+
301
+ _using_declarator: ($) =>
302
+ seq(field('name', choice($.identifier, alias('of', $.identifier))), optional($._initializer)),
296
303
 
297
304
  variable_declarator: ($) =>
298
305
  seq(
@@ -320,31 +327,46 @@ module.exports = grammar({
320
327
  seq(
321
328
  'for',
322
329
  '(',
323
- choice(
324
- field(
325
- 'initializer',
326
- choice(
327
- alias($.for_lexical_declaration, $.lexical_declaration),
328
- alias($.for_variable_declaration, $.variable_declaration)
329
- )
330
- ),
331
- seq(field('initializer', $._expressions), ';'),
332
- field('initializer', $.empty_statement)
333
- ),
334
- field('condition', choice(seq($._expressions, ';'), $.empty_statement)),
330
+ $._for_initializer,
331
+ $._for_condition,
335
332
  field('increment', optional($._expressions)),
336
333
  ')',
337
334
  field('body', $.statement)
338
335
  ),
339
336
 
337
+ // Extracted into rules because tree-sitter expands a `choice` written inline in the `seq` above into one production
338
+ // per alternative, each repeating the parse states of the rest of the header (about 30 KB of Wasm). They are hidden
339
+ // so that `initializer` and `condition` stay fields of `for_statement` and no node type is added.
340
+ _for_initializer: ($) =>
341
+ choice(
342
+ field(
343
+ 'initializer',
344
+ choice(
345
+ alias($.for_lexical_declaration, $.lexical_declaration),
346
+ alias($.for_variable_declaration, $.variable_declaration),
347
+ alias($._for_using_declaration, $.using_declaration)
348
+ )
349
+ ),
350
+ seq(field('initializer', $._expressions), ';'),
351
+ field('initializer', $.empty_statement)
352
+ ),
353
+
354
+ _for_condition: ($) => field('condition', choice(seq($._expressions, ';'), $.empty_statement)),
355
+
340
356
  // ECMAScript inserts no semicolon inside a for header, so these declarations end only with `;`. Accepting an
341
357
  // automatic semicolon there made `for (let x\n of y)` ambiguous until `of`, and an incremental reparse could
342
- // reuse a declaration built when that ambiguity was resolved differently. The rules are visible and only used
343
- // through aliases: a hidden rule would make `for_statement` inherit their `kind` field.
358
+ // reuse a declaration built when that ambiguity was resolved differently.
344
359
  for_lexical_declaration: ($) => seq(field('kind', choice('let', 'const')), commaSep1($.variable_declarator), ';'),
345
360
 
346
361
  for_variable_declaration: ($) => seq('var', commaSep1($.variable_declarator), ';'),
347
362
 
363
+ _for_using_declaration: ($) =>
364
+ seq(
365
+ field('kind', choice('using', seq('await', 'using'))),
366
+ commaSep1(alias($._using_declarator, $.variable_declarator)),
367
+ ';'
368
+ ),
369
+
348
370
  for_in_statement: ($) => seq('for', optional('await'), $._for_header, field('body', $.statement)),
349
371
 
350
372
  _for_header: ($) =>
@@ -363,7 +385,7 @@ module.exports = grammar({
363
385
  ),
364
386
  seq(
365
387
  field('kind', choice('using', seq('await', 'using'))),
366
- field('left', choice($.identifier, alias('of', $.identifier), $._destructuring_pattern))
388
+ field('left', choice($.identifier, alias('of', $.identifier)))
367
389
  )
368
390
  ),
369
391
  field('operator', choice('in', 'of')),
@@ -1152,7 +1174,7 @@ module.exports = grammar({
1152
1174
 
1153
1175
  computed_property_name: ($) => seq('[', $.expression, ']'),
1154
1176
 
1155
- _reserved_identifier: () => choice('get', 'set', 'async', 'await', 'static', 'export', 'let'),
1177
+ _reserved_identifier: () => choice('get', 'set', 'async', 'await', 'static', 'export', 'let', 'using'),
1156
1178
 
1157
1179
  _semicolon: ($) => choice($._automatic_semicolon, ';'),
1158
1180
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-javascript",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "JavaScript grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -1451,6 +1451,10 @@
1451
1451
  "type": "sequence_expression",
1452
1452
  "named": true
1453
1453
  },
1454
+ {
1455
+ "type": "using_declaration",
1456
+ "named": true
1457
+ },
1454
1458
  {
1455
1459
  "type": "variable_declaration",
1456
1460
  "named": true
Binary file
package/tree-sitter.json CHANGED
@@ -16,7 +16,7 @@
16
16
  }
17
17
  ],
18
18
  "metadata": {
19
- "version": "1.0.8",
19
+ "version": "1.0.9",
20
20
  "license": "MIT",
21
21
  "description": "JavaScript grammar for tree-sitter",
22
22
  "authors": [