yuku-codegen 0.5.11 → 0.5.15

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.
Files changed (5) hide show
  1. package/README.md +26 -17
  2. package/encode.js +294 -50
  3. package/index.d.ts +10 -5
  4. package/index.js +29 -12
  5. package/package.json +13 -13
package/encode.js CHANGED
@@ -10,15 +10,11 @@ const NODE_FIELD0_OFFSET = 4;
10
10
  const NODE_HEADER_U32S = 2;
11
11
  const NODE_SPAN_START_U32 = 10;
12
12
  const NODE_SPAN_END_U32 = 11;
13
- const COMMENT_SIZE = 20;
14
- const COMMENT_TYPE_OFFSET = 0;
15
- const COMMENT_KIND_OFFSET = 1;
16
- const COMMENT_FLAGS_OFFSET = 2;
17
- const COMMENT_START_OFFSET = 4;
18
- const COMMENT_END_OFFSET = 8;
19
- const COMMENT_VALUE_START_OFFSET = 12;
20
- const COMMENT_VALUE_END_OFFSET = 16;
21
- const COMMENT_KINDS_INV = {"normal": 0, "legal": 1, "jsdoc": 2, "annotation": 3, "pure": 4, "no_side_effects": 5};
13
+ const COMMENT_SIZE = 12;
14
+ const COMMENT_FLAGS_OFFSET = 0;
15
+ const COMMENT_VALUE_START_OFFSET = 4;
16
+ const COMMENT_VALUE_END_OFFSET = 8;
17
+ const FLAG_ATTACH_COMMENTS = 2;
22
18
  const BINARY_OPS_INV = {"==": 0, "!=": 1, "===": 2, "!==": 3, "<": 4, "<=": 5, ">": 6, ">=": 7, "+": 8, "-": 9, "*": 10, "/": 11, "%": 12, "**": 13, "|": 14, "^": 15, "&": 16, "<<": 17, ">>": 18, ">>>": 19, "in": 20, "instanceof": 21};
23
19
  const LOGICAL_OPS_INV = {"&&": 0, "||": 1, "??": 2};
24
20
  const UNARY_OPS_INV = {"-": 0, "+": 1, "!": 2, "~": 3, "typeof": 4, "void": 5, "delete": 6};
@@ -32,10 +28,16 @@ const TS_TYPE_OPERATORS_INV = {"keyof": 0, "unique": 1, "readonly": 2};
32
28
  const TS_METHOD_SIGNATURE_KINDS_INV = {"method": 0, "get": 1, "set": 2};
33
29
  const TS_MODULE_KINDS_INV = {"namespace": 0, "module": 1};
34
30
  const IMPORT_PHASE_INV = {"source": 0, "defer": 1};
35
- const ACCESSIBILITY_INV = (v) => v == null ? 0 : v === "public" ? 1 : v === "private" ? 2 : 3;
31
+ const ACCESSIBILITY_INV = (v) =>
32
+ v == null ? 0
33
+ : v === "public" ? 1
34
+ : v === "private" ? 2
35
+ : 3;
36
36
  const TS_MAPPED_OPTIONAL_INV = (v) => v === true ? 1 : v === "+" ? 2 : v === "-" ? 3 : 0;
37
37
  const TS_MAPPED_READONLY_INV = (v) => v === true ? 1 : v === "+" ? 2 : v === "-" ? 3 : 0;
38
- function encode(estree, comments, lineStarts) {
38
+ function encode(result) {
39
+ const root = result.program;
40
+ const lineStarts = result.lineStarts;
39
41
  let nodeCap = 512;
40
42
  let nodeAB = new ArrayBuffer(nodeCap * NODE_SIZE);
41
43
  let nU8 = new Uint8Array(nodeAB);
@@ -105,7 +107,10 @@ function encode(estree, comments, lineStarts) {
105
107
  if (!arr || arr.length === 0) return { start: 0, len: 0 };
106
108
  const len = arr.length;
107
109
  const ids = new Array(len);
108
- for (let i = 0; i < len; i++) { const e = arr[i]; ids[i] = e == null ? NULL : encEach(e); }
110
+ for (let i = 0; i < len; i++) {
111
+ const e = arr[i];
112
+ ids[i] = e == null ? NULL : encEach(e);
113
+ }
109
114
  const start = extraCount;
110
115
  for (let i = 0; i < len; i++) pushExtra(ids[i]);
111
116
  return { start, len };
@@ -128,6 +133,12 @@ function encode(estree, comments, lineStarts) {
128
133
  }
129
134
  function asStart(n) { return (n && typeof n.start === "number") ? n.start : 0; }
130
135
  function asEnd(n) { return (n && typeof n.end === "number") ? n.end : 0; }
136
+ // called by every enc_* to register the node's `.comments` array
137
+ function recordComments(n, idx) {
138
+ if (idx !== NULL && n && Array.isArray(n.comments) && n.comments.length > 0) {
139
+ commentsByIdx.set(idx, n.comments);
140
+ }
141
+ }
131
142
  function encBindingTarget(n) {
132
143
  if (n == null) return NULL;
133
144
  if (n.type === "Identifier") return enc_binding_identifier(n);
@@ -149,6 +160,7 @@ function encode(estree, comments, lineStarts) {
149
160
  f0At(idx, c_expressions.len);
150
161
  slotAt(idx, 0, c_expressions.start);
151
162
  spanAt(idx, asStart(n), asEnd(n));
163
+ recordComments(n, idx);
152
164
  return idx;
153
165
  }
154
166
  function enc_parenthesized_expression(n) {
@@ -157,6 +169,7 @@ function encode(estree, comments, lineStarts) {
157
169
  tagAt(idx, 1);
158
170
  slotAt(idx, 0, c_expression);
159
171
  spanAt(idx, asStart(n), asEnd(n));
172
+ recordComments(n, idx);
160
173
  return idx;
161
174
  }
162
175
  function enc_arrow_function_expression(n) {
@@ -172,6 +185,7 @@ function encode(estree, comments, lineStarts) {
172
185
  slotAt(idx, 3, rt_);
173
186
  flagsAt(idx, (n.expression ? 1 : 0) | (n.async ? 2 : 0));
174
187
  spanAt(idx, asStart(n), asEnd(n));
188
+ recordComments(n, idx);
175
189
  return idx;
176
190
  }
177
191
  function enc_function(n, kind) {
@@ -187,8 +201,13 @@ function encode(estree, comments, lineStarts) {
187
201
  slotAt(idx, 2, body);
188
202
  slotAt(idx, 3, tp);
189
203
  slotAt(idx, 4, rt_);
190
- flagsAt(idx, ((kind & 3) << 0) | (n.generator ? 4 : 0) | (n.async ? 8 : 0) | (n.declare ? 16 : 0));
204
+ flagsAt(idx,
205
+ ((kind & 3) << 0)
206
+ | (n.generator ? 4 : 0)
207
+ | (n.async ? 8 : 0)
208
+ | (n.declare ? 16 : 0));
191
209
  spanAt(idx, asStart(n), asEnd(n));
210
+ recordComments(n, idx);
192
211
  return idx;
193
212
  }
194
213
  function enc_block_statement(n) {
@@ -198,6 +217,7 @@ function encode(estree, comments, lineStarts) {
198
217
  f0At(idx, c_body.len);
199
218
  slotAt(idx, 0, c_body.start);
200
219
  spanAt(idx, asStart(n), asEnd(n));
220
+ recordComments(n, idx);
201
221
  return idx;
202
222
  }
203
223
  function encFormalParameters(params) {
@@ -213,7 +233,8 @@ function encode(estree, comments, lineStarts) {
213
233
  const p = params[i];
214
234
  if (p && p.type === "RestElement") rest = enc_binding_rest_element(p);
215
235
  else if (p && p.type === "TSParameterProperty") items.push(encNode(p));
216
- else if (p && p.type === "Identifier" && p.name === "this") items.push(enc_ts_this_parameter(p));
236
+ else if (p && p.type === "Identifier" && p.name === "this")
237
+ items.push(enc_ts_this_parameter(p));
217
238
  else items.push(enc_formal_parameter(p));
218
239
  }
219
240
  const ids = items;
@@ -233,6 +254,7 @@ function encode(estree, comments, lineStarts) {
233
254
  tagAt(idx, 7);
234
255
  slotAt(idx, 0, pat);
235
256
  spanAt(idx, asStart(p), asEnd(p));
257
+ recordComments(p, idx);
236
258
  return idx;
237
259
  }
238
260
  function enc_binary_expression(n) {
@@ -244,6 +266,7 @@ function encode(estree, comments, lineStarts) {
244
266
  slotAt(idx, 1, c_right);
245
267
  flagsAt(idx, 0 | (BINARY_OPS_INV[n.operator] | 0));
246
268
  spanAt(idx, asStart(n), asEnd(n));
269
+ recordComments(n, idx);
247
270
  return idx;
248
271
  }
249
272
  function enc_logical_expression(n) {
@@ -255,6 +278,7 @@ function encode(estree, comments, lineStarts) {
255
278
  slotAt(idx, 1, c_right);
256
279
  flagsAt(idx, 0 | (LOGICAL_OPS_INV[n.operator] | 0));
257
280
  spanAt(idx, asStart(n), asEnd(n));
281
+ recordComments(n, idx);
258
282
  return idx;
259
283
  }
260
284
  function enc_conditional_expression(n) {
@@ -267,6 +291,7 @@ function encode(estree, comments, lineStarts) {
267
291
  slotAt(idx, 1, c_consequent);
268
292
  slotAt(idx, 2, c_alternate);
269
293
  spanAt(idx, asStart(n), asEnd(n));
294
+ recordComments(n, idx);
270
295
  return idx;
271
296
  }
272
297
  function enc_unary_expression(n) {
@@ -276,6 +301,7 @@ function encode(estree, comments, lineStarts) {
276
301
  slotAt(idx, 0, a);
277
302
  flagsAt(idx, UNARY_OPS_INV[n.operator] | 0);
278
303
  spanAt(idx, asStart(n), asEnd(n));
304
+ recordComments(n, idx);
279
305
  return idx;
280
306
  }
281
307
  function enc_update_expression(n) {
@@ -285,6 +311,7 @@ function encode(estree, comments, lineStarts) {
285
311
  slotAt(idx, 0, c_argument);
286
312
  flagsAt(idx, 0 | (UPDATE_OPS_INV[n.operator] | 0) | (n.prefix ? 2 : 0));
287
313
  spanAt(idx, asStart(n), asEnd(n));
314
+ recordComments(n, idx);
288
315
  return idx;
289
316
  }
290
317
  function enc_assignment_expression(n) {
@@ -296,6 +323,7 @@ function encode(estree, comments, lineStarts) {
296
323
  slotAt(idx, 1, c_right);
297
324
  flagsAt(idx, 0 | (ASSIGNMENT_OPS_INV[n.operator] | 0));
298
325
  spanAt(idx, asStart(n), asEnd(n));
326
+ recordComments(n, idx);
299
327
  return idx;
300
328
  }
301
329
  function enc_array_expression(n) {
@@ -305,6 +333,7 @@ function encode(estree, comments, lineStarts) {
305
333
  f0At(idx, c_elements.len);
306
334
  slotAt(idx, 0, c_elements.start);
307
335
  spanAt(idx, asStart(n), asEnd(n));
336
+ recordComments(n, idx);
308
337
  return idx;
309
338
  }
310
339
  function enc_object_expression(n) {
@@ -314,6 +343,7 @@ function encode(estree, comments, lineStarts) {
314
343
  f0At(idx, c_properties.len);
315
344
  slotAt(idx, 0, c_properties.start);
316
345
  spanAt(idx, asStart(n), asEnd(n));
346
+ recordComments(n, idx);
317
347
  return idx;
318
348
  }
319
349
  function enc_spread_element(n) {
@@ -322,26 +352,37 @@ function encode(estree, comments, lineStarts) {
322
352
  tagAt(idx, 16);
323
353
  slotAt(idx, 0, c_argument);
324
354
  spanAt(idx, asStart(n), asEnd(n));
355
+ recordComments(n, idx);
325
356
  return idx;
326
357
  }
327
358
  function enc_object_property(n) {
328
- const k = n.key == null ? NULL : (n.computed ? encNode(n.key) : encPropertyKey(n.key));
359
+ const k = n.key == null
360
+ ? NULL
361
+ : (n.computed ? encNode(n.key) : encPropertyKey(n.key));
329
362
  const v = n.value == null ? NULL : encNode(n.value);
330
363
  const idx = alloc();
331
364
  tagAt(idx, 17);
332
365
  slotAt(idx, 0, k); slotAt(idx, 1, v);
333
- flagsAt(idx, ((PROPERTY_KINDS_INV[n.kind] | 0) << 0) | (n.method ? 4 : 0) | (n.shorthand ? 8 : 0) | (n.computed ? 16 : 0));
366
+ flagsAt(idx,
367
+ ((PROPERTY_KINDS_INV[n.kind] | 0) << 0)
368
+ | (n.method ? 4 : 0)
369
+ | (n.shorthand ? 8 : 0)
370
+ | (n.computed ? 16 : 0));
334
371
  spanAt(idx, asStart(n), asEnd(n));
372
+ recordComments(n, idx);
335
373
  return idx;
336
374
  }
337
375
  function enc_member_expression(n) {
338
376
  const o = n.object == null ? NULL : encNode(n.object);
339
- const p = n.property == null ? NULL : (n.computed ? encNode(n.property) : encPropertyKey(n.property));
377
+ const p = n.property == null
378
+ ? NULL
379
+ : (n.computed ? encNode(n.property) : encPropertyKey(n.property));
340
380
  const idx = alloc();
341
381
  tagAt(idx, 18);
342
382
  slotAt(idx, 0, o); slotAt(idx, 1, p);
343
383
  flagsAt(idx, (n.computed ? 1 : 0) | (n.optional ? 2 : 0));
344
384
  spanAt(idx, asStart(n), asEnd(n));
385
+ recordComments(n, idx);
345
386
  return idx;
346
387
  }
347
388
  function enc_call_expression(n) {
@@ -356,6 +397,7 @@ function encode(estree, comments, lineStarts) {
356
397
  slotAt(idx, 2, c_type_arguments);
357
398
  flagsAt(idx, 0 | (n.optional ? 1 : 0));
358
399
  spanAt(idx, asStart(n), asEnd(n));
400
+ recordComments(n, idx);
359
401
  return idx;
360
402
  }
361
403
  function enc_chain_expression(n) {
@@ -364,6 +406,7 @@ function encode(estree, comments, lineStarts) {
364
406
  tagAt(idx, 20);
365
407
  slotAt(idx, 0, c_expression);
366
408
  spanAt(idx, asStart(n), asEnd(n));
409
+ recordComments(n, idx);
367
410
  return idx;
368
411
  }
369
412
  function enc_tagged_template_expression(n) {
@@ -376,6 +419,7 @@ function encode(estree, comments, lineStarts) {
376
419
  slotAt(idx, 1, c_quasi);
377
420
  slotAt(idx, 2, c_type_arguments);
378
421
  spanAt(idx, asStart(n), asEnd(n));
422
+ recordComments(n, idx);
379
423
  return idx;
380
424
  }
381
425
  function enc_new_expression(n) {
@@ -389,6 +433,7 @@ function encode(estree, comments, lineStarts) {
389
433
  slotAt(idx, 1, c_arguments.start);
390
434
  slotAt(idx, 2, c_type_arguments);
391
435
  spanAt(idx, asStart(n), asEnd(n));
436
+ recordComments(n, idx);
392
437
  return idx;
393
438
  }
394
439
  function enc_await_expression(n) {
@@ -397,6 +442,7 @@ function encode(estree, comments, lineStarts) {
397
442
  tagAt(idx, 23);
398
443
  slotAt(idx, 0, c_argument);
399
444
  spanAt(idx, asStart(n), asEnd(n));
445
+ recordComments(n, idx);
400
446
  return idx;
401
447
  }
402
448
  function enc_yield_expression(n) {
@@ -406,6 +452,7 @@ function encode(estree, comments, lineStarts) {
406
452
  slotAt(idx, 0, c_argument);
407
453
  flagsAt(idx, 0 | (n.delegate ? 1 : 0));
408
454
  spanAt(idx, asStart(n), asEnd(n));
455
+ recordComments(n, idx);
409
456
  return idx;
410
457
  }
411
458
  function enc_meta_property(n) {
@@ -416,6 +463,7 @@ function encode(estree, comments, lineStarts) {
416
463
  slotAt(idx, 0, c_meta);
417
464
  slotAt(idx, 1, c_property);
418
465
  spanAt(idx, asStart(n), asEnd(n));
466
+ recordComments(n, idx);
419
467
  return idx;
420
468
  }
421
469
  function enc_decorator(n) {
@@ -424,6 +472,7 @@ function encode(estree, comments, lineStarts) {
424
472
  tagAt(idx, 26);
425
473
  slotAt(idx, 0, c_expression);
426
474
  spanAt(idx, asStart(n), asEnd(n));
475
+ recordComments(n, idx);
427
476
  return idx;
428
477
  }
429
478
  function enc_class(n, kind) {
@@ -447,6 +496,7 @@ function encode(estree, comments, lineStarts) {
447
496
  slotAt(idx, 7, imps.len);
448
497
  flagsAt(idx, ((kind & 1) << 0) | (n.abstract ? 2 : 0) | (n.declare ? 4 : 0));
449
498
  spanAt(idx, asStart(n), asEnd(n));
499
+ recordComments(n, idx);
450
500
  return idx;
451
501
  }
452
502
  function enc_class_body(n) {
@@ -456,6 +506,7 @@ function encode(estree, comments, lineStarts) {
456
506
  f0At(idx, c_body.len);
457
507
  slotAt(idx, 0, c_body.start);
458
508
  spanAt(idx, asStart(n), asEnd(n));
509
+ recordComments(n, idx);
459
510
  return idx;
460
511
  }
461
512
  function enc_method_definition(n, abstract) {
@@ -477,6 +528,7 @@ function encode(estree, comments, lineStarts) {
477
528
  (abstract ? 64 : 0) |
478
529
  (ACCESSIBILITY_INV(n.accessibility) << 7));
479
530
  spanAt(idx, asStart(n), asEnd(n));
531
+ recordComments(n, idx);
480
532
  return idx;
481
533
  }
482
534
  function enc_property_definition(n, accessor, abstract) {
@@ -503,6 +555,7 @@ function encode(estree, comments, lineStarts) {
503
555
  (abstract ? 256 : 0) |
504
556
  (ACCESSIBILITY_INV(n.accessibility) << 9));
505
557
  spanAt(idx, asStart(n), asEnd(n));
558
+ recordComments(n, idx);
506
559
  return idx;
507
560
  }
508
561
  function enc_static_block(n) {
@@ -512,12 +565,14 @@ function encode(estree, comments, lineStarts) {
512
565
  f0At(idx, c_body.len);
513
566
  slotAt(idx, 0, c_body.start);
514
567
  spanAt(idx, asStart(n), asEnd(n));
568
+ recordComments(n, idx);
515
569
  return idx;
516
570
  }
517
571
  function enc_super(n) {
518
572
  const idx = alloc();
519
573
  tagAt(idx, 32);
520
574
  spanAt(idx, asStart(n), asEnd(n));
575
+ recordComments(n, idx);
521
576
  return idx;
522
577
  }
523
578
  function enc_string_literal(n) {
@@ -526,6 +581,7 @@ function encode(estree, comments, lineStarts) {
526
581
  tagAt(idx, 33);
527
582
  slotAt(idx, 0, s.start); slotAt(idx, 1, s.end);
528
583
  spanAt(idx, asStart(n), asEnd(n));
584
+ recordComments(n, idx);
529
585
  return idx;
530
586
  }
531
587
  function enc_numeric_literal(n) {
@@ -543,6 +599,7 @@ function encode(estree, comments, lineStarts) {
543
599
  flagsAt(idx, kind);
544
600
  slotAt(idx, 0, r.start); slotAt(idx, 1, r.end);
545
601
  spanAt(idx, asStart(n), asEnd(n));
602
+ recordComments(n, idx);
546
603
  return idx;
547
604
  }
548
605
  function enc_bigint_literal(n) {
@@ -552,6 +609,7 @@ function encode(estree, comments, lineStarts) {
552
609
  tagAt(idx, 35);
553
610
  slotAt(idx, 0, r.start); slotAt(idx, 1, r.end);
554
611
  spanAt(idx, asStart(n), asEnd(n));
612
+ recordComments(n, idx);
555
613
  return idx;
556
614
  }
557
615
  function enc_boolean_literal(n) {
@@ -559,18 +617,21 @@ function encode(estree, comments, lineStarts) {
559
617
  tagAt(idx, 36);
560
618
  flagsAt(idx, n.value ? 1 : 0);
561
619
  spanAt(idx, asStart(n), asEnd(n));
620
+ recordComments(n, idx);
562
621
  return idx;
563
622
  }
564
623
  function enc_null_literal(n) {
565
624
  const idx = alloc();
566
625
  tagAt(idx, 37);
567
626
  spanAt(idx, asStart(n), asEnd(n));
627
+ recordComments(n, idx);
568
628
  return idx;
569
629
  }
570
630
  function enc_this_expression(n) {
571
631
  const idx = alloc();
572
632
  tagAt(idx, 38);
573
633
  spanAt(idx, asStart(n), asEnd(n));
634
+ recordComments(n, idx);
574
635
  return idx;
575
636
  }
576
637
  function enc_regexp_literal(n) {
@@ -581,6 +642,7 @@ function encode(estree, comments, lineStarts) {
581
642
  slotAt(idx, 0, p.start); slotAt(idx, 1, p.end);
582
643
  slotAt(idx, 2, fl.start); slotAt(idx, 3, fl.end);
583
644
  spanAt(idx, asStart(n), asEnd(n));
645
+ recordComments(n, idx);
584
646
  return idx;
585
647
  }
586
648
  function enc_template_literal(n) {
@@ -593,6 +655,7 @@ function encode(estree, comments, lineStarts) {
593
655
  slotAt(idx, 1, c_expressions.start);
594
656
  slotAt(idx, 2, c_expressions.len);
595
657
  spanAt(idx, asStart(n), asEnd(n));
658
+ recordComments(n, idx);
596
659
  return idx;
597
660
  }
598
661
  function enc_template_element(n) {
@@ -604,6 +667,7 @@ function encode(estree, comments, lineStarts) {
604
667
  flagsAt(idx, (n.tail ? 1 : 0) | (undef ? 2 : 0));
605
668
  slotAt(idx, 0, c.start); slotAt(idx, 1, c.end);
606
669
  spanAt(idx, asStart(n), asEnd(n));
670
+ recordComments(n, idx);
607
671
  return idx;
608
672
  }
609
673
  function enc_identifier_reference(n) {
@@ -613,6 +677,7 @@ function encode(estree, comments, lineStarts) {
613
677
  slotAt(idx, 0, c_name.start);
614
678
  slotAt(idx, 1, c_name.end);
615
679
  spanAt(idx, asStart(n), asEnd(n));
680
+ recordComments(n, idx);
616
681
  return idx;
617
682
  }
618
683
  function enc_private_identifier(n) {
@@ -622,6 +687,7 @@ function encode(estree, comments, lineStarts) {
622
687
  slotAt(idx, 0, c_name.start);
623
688
  slotAt(idx, 1, c_name.end);
624
689
  spanAt(idx, asStart(n), asEnd(n));
690
+ recordComments(n, idx);
625
691
  return idx;
626
692
  }
627
693
  function enc_binding_identifier(n) {
@@ -637,6 +703,7 @@ function encode(estree, comments, lineStarts) {
637
703
  slotAt(idx, 3, c_type_annotation);
638
704
  flagsAt(idx, 0 | (n.optional ? 1 : 0));
639
705
  spanAt(idx, asStart(n), asEnd(n));
706
+ recordComments(n, idx);
640
707
  return idx;
641
708
  }
642
709
  function enc_identifier_name(n) {
@@ -646,6 +713,7 @@ function encode(estree, comments, lineStarts) {
646
713
  slotAt(idx, 0, c_name.start);
647
714
  slotAt(idx, 1, c_name.end);
648
715
  spanAt(idx, asStart(n), asEnd(n));
716
+ recordComments(n, idx);
649
717
  return idx;
650
718
  }
651
719
  function enc_label_identifier(n) {
@@ -655,6 +723,7 @@ function encode(estree, comments, lineStarts) {
655
723
  slotAt(idx, 0, c_name.start);
656
724
  slotAt(idx, 1, c_name.end);
657
725
  spanAt(idx, asStart(n), asEnd(n));
726
+ recordComments(n, idx);
658
727
  return idx;
659
728
  }
660
729
  function enc_expression_statement(n) {
@@ -663,6 +732,7 @@ function encode(estree, comments, lineStarts) {
663
732
  tagAt(idx, 47);
664
733
  slotAt(idx, 0, c_expression);
665
734
  spanAt(idx, asStart(n), asEnd(n));
735
+ recordComments(n, idx);
666
736
  return idx;
667
737
  }
668
738
  function enc_if_statement(n) {
@@ -675,6 +745,7 @@ function encode(estree, comments, lineStarts) {
675
745
  slotAt(idx, 1, c_consequent);
676
746
  slotAt(idx, 2, c_alternate);
677
747
  spanAt(idx, asStart(n), asEnd(n));
748
+ recordComments(n, idx);
678
749
  return idx;
679
750
  }
680
751
  function enc_switch_statement(n) {
@@ -686,6 +757,7 @@ function encode(estree, comments, lineStarts) {
686
757
  f0At(idx, c_cases.len);
687
758
  slotAt(idx, 1, c_cases.start);
688
759
  spanAt(idx, asStart(n), asEnd(n));
760
+ recordComments(n, idx);
689
761
  return idx;
690
762
  }
691
763
  function enc_switch_case(n) {
@@ -697,6 +769,7 @@ function encode(estree, comments, lineStarts) {
697
769
  f0At(idx, c_consequent.len);
698
770
  slotAt(idx, 1, c_consequent.start);
699
771
  spanAt(idx, asStart(n), asEnd(n));
772
+ recordComments(n, idx);
700
773
  return idx;
701
774
  }
702
775
  function enc_for_statement(n) {
@@ -711,6 +784,7 @@ function encode(estree, comments, lineStarts) {
711
784
  slotAt(idx, 2, c_update);
712
785
  slotAt(idx, 3, c_body);
713
786
  spanAt(idx, asStart(n), asEnd(n));
787
+ recordComments(n, idx);
714
788
  return idx;
715
789
  }
716
790
  function enc_for_in_statement(n) {
@@ -723,6 +797,7 @@ function encode(estree, comments, lineStarts) {
723
797
  slotAt(idx, 1, c_right);
724
798
  slotAt(idx, 2, c_body);
725
799
  spanAt(idx, asStart(n), asEnd(n));
800
+ recordComments(n, idx);
726
801
  return idx;
727
802
  }
728
803
  function enc_for_of_statement(n) {
@@ -736,6 +811,7 @@ function encode(estree, comments, lineStarts) {
736
811
  slotAt(idx, 2, c_body);
737
812
  flagsAt(idx, 0 | (n.await ? 1 : 0));
738
813
  spanAt(idx, asStart(n), asEnd(n));
814
+ recordComments(n, idx);
739
815
  return idx;
740
816
  }
741
817
  function enc_while_statement(n) {
@@ -746,6 +822,7 @@ function encode(estree, comments, lineStarts) {
746
822
  slotAt(idx, 0, c_test);
747
823
  slotAt(idx, 1, c_body);
748
824
  spanAt(idx, asStart(n), asEnd(n));
825
+ recordComments(n, idx);
749
826
  return idx;
750
827
  }
751
828
  function enc_do_while_statement(n) {
@@ -756,6 +833,7 @@ function encode(estree, comments, lineStarts) {
756
833
  slotAt(idx, 0, c_body);
757
834
  slotAt(idx, 1, c_test);
758
835
  spanAt(idx, asStart(n), asEnd(n));
836
+ recordComments(n, idx);
759
837
  return idx;
760
838
  }
761
839
  function enc_break_statement(n) {
@@ -764,6 +842,7 @@ function encode(estree, comments, lineStarts) {
764
842
  tagAt(idx, 56);
765
843
  slotAt(idx, 0, c_label);
766
844
  spanAt(idx, asStart(n), asEnd(n));
845
+ recordComments(n, idx);
767
846
  return idx;
768
847
  }
769
848
  function enc_continue_statement(n) {
@@ -772,6 +851,7 @@ function encode(estree, comments, lineStarts) {
772
851
  tagAt(idx, 57);
773
852
  slotAt(idx, 0, c_label);
774
853
  spanAt(idx, asStart(n), asEnd(n));
854
+ recordComments(n, idx);
775
855
  return idx;
776
856
  }
777
857
  function enc_labeled_statement(n) {
@@ -782,6 +862,7 @@ function encode(estree, comments, lineStarts) {
782
862
  slotAt(idx, 0, c_label);
783
863
  slotAt(idx, 1, c_body);
784
864
  spanAt(idx, asStart(n), asEnd(n));
865
+ recordComments(n, idx);
785
866
  return idx;
786
867
  }
787
868
  function enc_with_statement(n) {
@@ -792,6 +873,7 @@ function encode(estree, comments, lineStarts) {
792
873
  slotAt(idx, 0, c_object);
793
874
  slotAt(idx, 1, c_body);
794
875
  spanAt(idx, asStart(n), asEnd(n));
876
+ recordComments(n, idx);
795
877
  return idx;
796
878
  }
797
879
  function enc_return_statement(n) {
@@ -800,6 +882,7 @@ function encode(estree, comments, lineStarts) {
800
882
  tagAt(idx, 60);
801
883
  slotAt(idx, 0, c_argument);
802
884
  spanAt(idx, asStart(n), asEnd(n));
885
+ recordComments(n, idx);
803
886
  return idx;
804
887
  }
805
888
  function enc_throw_statement(n) {
@@ -808,6 +891,7 @@ function encode(estree, comments, lineStarts) {
808
891
  tagAt(idx, 61);
809
892
  slotAt(idx, 0, c_argument);
810
893
  spanAt(idx, asStart(n), asEnd(n));
894
+ recordComments(n, idx);
811
895
  return idx;
812
896
  }
813
897
  function enc_try_statement(n) {
@@ -820,6 +904,7 @@ function encode(estree, comments, lineStarts) {
820
904
  slotAt(idx, 1, c_handler);
821
905
  slotAt(idx, 2, c_finalizer);
822
906
  spanAt(idx, asStart(n), asEnd(n));
907
+ recordComments(n, idx);
823
908
  return idx;
824
909
  }
825
910
  function enc_catch_clause(n) {
@@ -830,18 +915,21 @@ function encode(estree, comments, lineStarts) {
830
915
  slotAt(idx, 0, c_param);
831
916
  slotAt(idx, 1, c_body);
832
917
  spanAt(idx, asStart(n), asEnd(n));
918
+ recordComments(n, idx);
833
919
  return idx;
834
920
  }
835
921
  function enc_debugger_statement(n) {
836
922
  const idx = alloc();
837
923
  tagAt(idx, 64);
838
924
  spanAt(idx, asStart(n), asEnd(n));
925
+ recordComments(n, idx);
839
926
  return idx;
840
927
  }
841
928
  function enc_empty_statement(n) {
842
929
  const idx = alloc();
843
930
  tagAt(idx, 65);
844
931
  spanAt(idx, asStart(n), asEnd(n));
932
+ recordComments(n, idx);
845
933
  return idx;
846
934
  }
847
935
  function enc_variable_declaration(n) {
@@ -852,6 +940,7 @@ function encode(estree, comments, lineStarts) {
852
940
  slotAt(idx, 0, c_declarators.start);
853
941
  flagsAt(idx, 0 | (VAR_KINDS_INV[n.kind] | 0) | (n.declare ? 8 : 0));
854
942
  spanAt(idx, asStart(n), asEnd(n));
943
+ recordComments(n, idx);
855
944
  return idx;
856
945
  }
857
946
  function enc_variable_declarator(n) {
@@ -863,6 +952,7 @@ function encode(estree, comments, lineStarts) {
863
952
  slotAt(idx, 1, c_init);
864
953
  flagsAt(idx, 0 | (n.definite ? 1 : 0));
865
954
  spanAt(idx, asStart(n), asEnd(n));
955
+ recordComments(n, idx);
866
956
  return idx;
867
957
  }
868
958
  function enc_directive(n) {
@@ -873,6 +963,7 @@ function encode(estree, comments, lineStarts) {
873
963
  slotAt(idx, 0, e);
874
964
  slotAt(idx, 1, dv.start); slotAt(idx, 2, dv.end);
875
965
  spanAt(idx, asStart(n), asEnd(n));
966
+ recordComments(n, idx);
876
967
  return idx;
877
968
  }
878
969
  function enc_assignment_pattern(n) {
@@ -889,6 +980,7 @@ function encode(estree, comments, lineStarts) {
889
980
  slotAt(idx, 3, c_type_annotation);
890
981
  flagsAt(idx, 0 | (n.optional ? 1 : 0));
891
982
  spanAt(idx, asStart(n), asEnd(n));
983
+ recordComments(n, idx);
892
984
  return idx;
893
985
  }
894
986
  function enc_binding_rest_element(n) {
@@ -903,6 +995,7 @@ function encode(estree, comments, lineStarts) {
903
995
  slotAt(idx, 2, c_type_annotation);
904
996
  flagsAt(idx, 0 | (n.optional ? 1 : 0));
905
997
  spanAt(idx, asStart(n), asEnd(n));
998
+ recordComments(n, idx);
906
999
  return idx;
907
1000
  }
908
1001
  function enc_array_pattern(n) {
@@ -927,6 +1020,7 @@ function encode(estree, comments, lineStarts) {
927
1020
  slotAt(idx, 4, ta);
928
1021
  flagsAt(idx, n.optional ? 1 : 0);
929
1022
  spanAt(idx, asStart(n), asEnd(n));
1023
+ recordComments(n, idx);
930
1024
  return idx;
931
1025
  }
932
1026
  function enc_object_pattern(n) {
@@ -950,10 +1044,13 @@ function encode(estree, comments, lineStarts) {
950
1044
  slotAt(idx, 4, ta);
951
1045
  flagsAt(idx, n.optional ? 1 : 0);
952
1046
  spanAt(idx, asStart(n), asEnd(n));
1047
+ recordComments(n, idx);
953
1048
  return idx;
954
1049
  }
955
1050
  function enc_binding_property(p) {
956
- const k = p.key == null ? NULL : (p.computed ? encNode(p.key) : encPropertyKey(p.key));
1051
+ const k = p.key == null
1052
+ ? NULL
1053
+ : (p.computed ? encNode(p.key) : encPropertyKey(p.key));
957
1054
  const v = p.value == null ? NULL : encBindingTarget(p.value);
958
1055
  const idx = alloc();
959
1056
  tagAt(idx, 73);
@@ -964,7 +1061,9 @@ function encode(estree, comments, lineStarts) {
964
1061
  }
965
1062
  function enc_program(n) {
966
1063
  const body = encArr(n.body, encNode);
967
- const hb = n.hashbang && typeof n.hashbang.value === "string" ? encStr(n.hashbang.value) : null;
1064
+ const hb = n.hashbang && typeof n.hashbang.value === "string"
1065
+ ? encStr(n.hashbang.value)
1066
+ : null;
968
1067
  const idx = alloc();
969
1068
  tagAt(idx, 74);
970
1069
  f0At(idx, body.len);
@@ -972,6 +1071,7 @@ function encode(estree, comments, lineStarts) {
972
1071
  if (hb) { slotAt(idx, 1, hb.start); slotAt(idx, 2, hb.end); }
973
1072
  flagsAt(idx, (n.sourceType === "script" ? 0 : 1) | (hb ? 2 : 0));
974
1073
  spanAt(idx, asStart(n), asEnd(n));
1074
+ recordComments(n, idx);
975
1075
  return idx;
976
1076
  }
977
1077
  function enc_import_expression(n) {
@@ -983,6 +1083,7 @@ function encode(estree, comments, lineStarts) {
983
1083
  slotAt(idx, 1, c_options);
984
1084
  flagsAt(idx, 0 | (n.phase != null ? 1 | ((IMPORT_PHASE_INV[n.phase] | 0) << 1) : 0));
985
1085
  spanAt(idx, asStart(n), asEnd(n));
1086
+ recordComments(n, idx);
986
1087
  return idx;
987
1088
  }
988
1089
  function enc_import_declaration(n) {
@@ -998,6 +1099,7 @@ function encode(estree, comments, lineStarts) {
998
1099
  slotAt(idx, 3, c_attributes.len);
999
1100
  flagsAt(idx, 0 | (n.phase != null ? 1 | ((IMPORT_PHASE_INV[n.phase] | 0) << 1) : 0) | ((IMPORT_EXPORT_KINDS_INV[n.importKind] | 0) << 2));
1000
1101
  spanAt(idx, asStart(n), asEnd(n));
1102
+ recordComments(n, idx);
1001
1103
  return idx;
1002
1104
  }
1003
1105
  function enc_import_specifier(n) {
@@ -1009,6 +1111,7 @@ function encode(estree, comments, lineStarts) {
1009
1111
  slotAt(idx, 1, c_local);
1010
1112
  flagsAt(idx, 0 | (IMPORT_EXPORT_KINDS_INV[n.importKind] | 0));
1011
1113
  spanAt(idx, asStart(n), asEnd(n));
1114
+ recordComments(n, idx);
1012
1115
  return idx;
1013
1116
  }
1014
1117
  function enc_import_default_specifier(n) {
@@ -1017,6 +1120,7 @@ function encode(estree, comments, lineStarts) {
1017
1120
  tagAt(idx, 78);
1018
1121
  slotAt(idx, 0, c_local);
1019
1122
  spanAt(idx, asStart(n), asEnd(n));
1123
+ recordComments(n, idx);
1020
1124
  return idx;
1021
1125
  }
1022
1126
  function enc_import_namespace_specifier(n) {
@@ -1025,6 +1129,7 @@ function encode(estree, comments, lineStarts) {
1025
1129
  tagAt(idx, 79);
1026
1130
  slotAt(idx, 0, c_local);
1027
1131
  spanAt(idx, asStart(n), asEnd(n));
1132
+ recordComments(n, idx);
1028
1133
  return idx;
1029
1134
  }
1030
1135
  function enc_import_attribute(n) {
@@ -1035,6 +1140,7 @@ function encode(estree, comments, lineStarts) {
1035
1140
  slotAt(idx, 0, c_key);
1036
1141
  slotAt(idx, 1, c_value);
1037
1142
  spanAt(idx, asStart(n), asEnd(n));
1143
+ recordComments(n, idx);
1038
1144
  return idx;
1039
1145
  }
1040
1146
  function enc_export_named_declaration(n) {
@@ -1052,6 +1158,7 @@ function encode(estree, comments, lineStarts) {
1052
1158
  slotAt(idx, 4, c_attributes.len);
1053
1159
  flagsAt(idx, 0 | (IMPORT_EXPORT_KINDS_INV[n.exportKind] | 0));
1054
1160
  spanAt(idx, asStart(n), asEnd(n));
1161
+ recordComments(n, idx);
1055
1162
  return idx;
1056
1163
  }
1057
1164
  function enc_export_default_declaration(n) {
@@ -1060,6 +1167,7 @@ function encode(estree, comments, lineStarts) {
1060
1167
  tagAt(idx, 82);
1061
1168
  slotAt(idx, 0, c_declaration);
1062
1169
  spanAt(idx, asStart(n), asEnd(n));
1170
+ recordComments(n, idx);
1063
1171
  return idx;
1064
1172
  }
1065
1173
  function enc_export_all_declaration(n) {
@@ -1074,6 +1182,7 @@ function encode(estree, comments, lineStarts) {
1074
1182
  slotAt(idx, 2, c_attributes.start);
1075
1183
  flagsAt(idx, 0 | (IMPORT_EXPORT_KINDS_INV[n.exportKind] | 0));
1076
1184
  spanAt(idx, asStart(n), asEnd(n));
1185
+ recordComments(n, idx);
1077
1186
  return idx;
1078
1187
  }
1079
1188
  function enc_export_specifier(n) {
@@ -1085,6 +1194,7 @@ function encode(estree, comments, lineStarts) {
1085
1194
  slotAt(idx, 1, c_exported);
1086
1195
  flagsAt(idx, 0 | (IMPORT_EXPORT_KINDS_INV[n.exportKind] | 0));
1087
1196
  spanAt(idx, asStart(n), asEnd(n));
1197
+ recordComments(n, idx);
1088
1198
  return idx;
1089
1199
  }
1090
1200
  function enc_ts_type_annotation(n) {
@@ -1093,90 +1203,105 @@ function encode(estree, comments, lineStarts) {
1093
1203
  tagAt(idx, 85);
1094
1204
  slotAt(idx, 0, c_type_annotation);
1095
1205
  spanAt(idx, asStart(n), asEnd(n));
1206
+ recordComments(n, idx);
1096
1207
  return idx;
1097
1208
  }
1098
1209
  function enc_ts_any_keyword(n) {
1099
1210
  const idx = alloc();
1100
1211
  tagAt(idx, 86);
1101
1212
  spanAt(idx, asStart(n), asEnd(n));
1213
+ recordComments(n, idx);
1102
1214
  return idx;
1103
1215
  }
1104
1216
  function enc_ts_unknown_keyword(n) {
1105
1217
  const idx = alloc();
1106
1218
  tagAt(idx, 87);
1107
1219
  spanAt(idx, asStart(n), asEnd(n));
1220
+ recordComments(n, idx);
1108
1221
  return idx;
1109
1222
  }
1110
1223
  function enc_ts_never_keyword(n) {
1111
1224
  const idx = alloc();
1112
1225
  tagAt(idx, 88);
1113
1226
  spanAt(idx, asStart(n), asEnd(n));
1227
+ recordComments(n, idx);
1114
1228
  return idx;
1115
1229
  }
1116
1230
  function enc_ts_void_keyword(n) {
1117
1231
  const idx = alloc();
1118
1232
  tagAt(idx, 89);
1119
1233
  spanAt(idx, asStart(n), asEnd(n));
1234
+ recordComments(n, idx);
1120
1235
  return idx;
1121
1236
  }
1122
1237
  function enc_ts_null_keyword(n) {
1123
1238
  const idx = alloc();
1124
1239
  tagAt(idx, 90);
1125
1240
  spanAt(idx, asStart(n), asEnd(n));
1241
+ recordComments(n, idx);
1126
1242
  return idx;
1127
1243
  }
1128
1244
  function enc_ts_undefined_keyword(n) {
1129
1245
  const idx = alloc();
1130
1246
  tagAt(idx, 91);
1131
1247
  spanAt(idx, asStart(n), asEnd(n));
1248
+ recordComments(n, idx);
1132
1249
  return idx;
1133
1250
  }
1134
1251
  function enc_ts_string_keyword(n) {
1135
1252
  const idx = alloc();
1136
1253
  tagAt(idx, 92);
1137
1254
  spanAt(idx, asStart(n), asEnd(n));
1255
+ recordComments(n, idx);
1138
1256
  return idx;
1139
1257
  }
1140
1258
  function enc_ts_number_keyword(n) {
1141
1259
  const idx = alloc();
1142
1260
  tagAt(idx, 93);
1143
1261
  spanAt(idx, asStart(n), asEnd(n));
1262
+ recordComments(n, idx);
1144
1263
  return idx;
1145
1264
  }
1146
1265
  function enc_ts_bigint_keyword(n) {
1147
1266
  const idx = alloc();
1148
1267
  tagAt(idx, 94);
1149
1268
  spanAt(idx, asStart(n), asEnd(n));
1269
+ recordComments(n, idx);
1150
1270
  return idx;
1151
1271
  }
1152
1272
  function enc_ts_boolean_keyword(n) {
1153
1273
  const idx = alloc();
1154
1274
  tagAt(idx, 95);
1155
1275
  spanAt(idx, asStart(n), asEnd(n));
1276
+ recordComments(n, idx);
1156
1277
  return idx;
1157
1278
  }
1158
1279
  function enc_ts_symbol_keyword(n) {
1159
1280
  const idx = alloc();
1160
1281
  tagAt(idx, 96);
1161
1282
  spanAt(idx, asStart(n), asEnd(n));
1283
+ recordComments(n, idx);
1162
1284
  return idx;
1163
1285
  }
1164
1286
  function enc_ts_object_keyword(n) {
1165
1287
  const idx = alloc();
1166
1288
  tagAt(idx, 97);
1167
1289
  spanAt(idx, asStart(n), asEnd(n));
1290
+ recordComments(n, idx);
1168
1291
  return idx;
1169
1292
  }
1170
1293
  function enc_ts_intrinsic_keyword(n) {
1171
1294
  const idx = alloc();
1172
1295
  tagAt(idx, 98);
1173
1296
  spanAt(idx, asStart(n), asEnd(n));
1297
+ recordComments(n, idx);
1174
1298
  return idx;
1175
1299
  }
1176
1300
  function enc_ts_this_type(n) {
1177
1301
  const idx = alloc();
1178
1302
  tagAt(idx, 99);
1179
1303
  spanAt(idx, asStart(n), asEnd(n));
1304
+ recordComments(n, idx);
1180
1305
  return idx;
1181
1306
  }
1182
1307
  function enc_ts_type_reference(n) {
@@ -1187,6 +1312,7 @@ function encode(estree, comments, lineStarts) {
1187
1312
  slotAt(idx, 0, c_type_name);
1188
1313
  slotAt(idx, 1, c_type_arguments);
1189
1314
  spanAt(idx, asStart(n), asEnd(n));
1315
+ recordComments(n, idx);
1190
1316
  return idx;
1191
1317
  }
1192
1318
  function enc_ts_qualified_name(n) {
@@ -1197,6 +1323,7 @@ function encode(estree, comments, lineStarts) {
1197
1323
  slotAt(idx, 0, c_left);
1198
1324
  slotAt(idx, 1, c_right);
1199
1325
  spanAt(idx, asStart(n), asEnd(n));
1326
+ recordComments(n, idx);
1200
1327
  return idx;
1201
1328
  }
1202
1329
  function enc_ts_type_query(n) {
@@ -1207,6 +1334,7 @@ function encode(estree, comments, lineStarts) {
1207
1334
  slotAt(idx, 0, c_expr_name);
1208
1335
  slotAt(idx, 1, c_type_arguments);
1209
1336
  spanAt(idx, asStart(n), asEnd(n));
1337
+ recordComments(n, idx);
1210
1338
  return idx;
1211
1339
  }
1212
1340
  function enc_ts_import_type(n) {
@@ -1221,6 +1349,7 @@ function encode(estree, comments, lineStarts) {
1221
1349
  slotAt(idx, 2, c_qualifier);
1222
1350
  slotAt(idx, 3, c_type_arguments);
1223
1351
  spanAt(idx, asStart(n), asEnd(n));
1352
+ recordComments(n, idx);
1224
1353
  return idx;
1225
1354
  }
1226
1355
  function enc_ts_type_parameter(n) {
@@ -1234,6 +1363,7 @@ function encode(estree, comments, lineStarts) {
1234
1363
  slotAt(idx, 2, c_default);
1235
1364
  flagsAt(idx, 0 | (n.in ? 1 : 0) | (n.out ? 2 : 0) | (n.const ? 4 : 0));
1236
1365
  spanAt(idx, asStart(n), asEnd(n));
1366
+ recordComments(n, idx);
1237
1367
  return idx;
1238
1368
  }
1239
1369
  function enc_ts_type_parameter_declaration(n) {
@@ -1243,6 +1373,7 @@ function encode(estree, comments, lineStarts) {
1243
1373
  f0At(idx, c_params.len);
1244
1374
  slotAt(idx, 0, c_params.start);
1245
1375
  spanAt(idx, asStart(n), asEnd(n));
1376
+ recordComments(n, idx);
1246
1377
  return idx;
1247
1378
  }
1248
1379
  function enc_ts_type_parameter_instantiation(n) {
@@ -1252,6 +1383,7 @@ function encode(estree, comments, lineStarts) {
1252
1383
  f0At(idx, c_params.len);
1253
1384
  slotAt(idx, 0, c_params.start);
1254
1385
  spanAt(idx, asStart(n), asEnd(n));
1386
+ recordComments(n, idx);
1255
1387
  return idx;
1256
1388
  }
1257
1389
  function enc_ts_literal_type(n) {
@@ -1260,6 +1392,7 @@ function encode(estree, comments, lineStarts) {
1260
1392
  tagAt(idx, 107);
1261
1393
  slotAt(idx, 0, c_literal);
1262
1394
  spanAt(idx, asStart(n), asEnd(n));
1395
+ recordComments(n, idx);
1263
1396
  return idx;
1264
1397
  }
1265
1398
  function enc_ts_template_literal_type(n) {
@@ -1272,6 +1405,7 @@ function encode(estree, comments, lineStarts) {
1272
1405
  slotAt(idx, 1, c_types.start);
1273
1406
  slotAt(idx, 2, c_types.len);
1274
1407
  spanAt(idx, asStart(n), asEnd(n));
1408
+ recordComments(n, idx);
1275
1409
  return idx;
1276
1410
  }
1277
1411
  function enc_ts_array_type(n) {
@@ -1280,6 +1414,7 @@ function encode(estree, comments, lineStarts) {
1280
1414
  tagAt(idx, 109);
1281
1415
  slotAt(idx, 0, c_element_type);
1282
1416
  spanAt(idx, asStart(n), asEnd(n));
1417
+ recordComments(n, idx);
1283
1418
  return idx;
1284
1419
  }
1285
1420
  function enc_ts_indexed_access_type(n) {
@@ -1290,6 +1425,7 @@ function encode(estree, comments, lineStarts) {
1290
1425
  slotAt(idx, 0, c_object_type);
1291
1426
  slotAt(idx, 1, c_index_type);
1292
1427
  spanAt(idx, asStart(n), asEnd(n));
1428
+ recordComments(n, idx);
1293
1429
  return idx;
1294
1430
  }
1295
1431
  function enc_ts_tuple_type(n) {
@@ -1299,6 +1435,7 @@ function encode(estree, comments, lineStarts) {
1299
1435
  f0At(idx, c_element_types.len);
1300
1436
  slotAt(idx, 0, c_element_types.start);
1301
1437
  spanAt(idx, asStart(n), asEnd(n));
1438
+ recordComments(n, idx);
1302
1439
  return idx;
1303
1440
  }
1304
1441
  function enc_ts_named_tuple_member(n) {
@@ -1310,6 +1447,7 @@ function encode(estree, comments, lineStarts) {
1310
1447
  slotAt(idx, 1, c_element_type);
1311
1448
  flagsAt(idx, 0 | (n.optional ? 1 : 0));
1312
1449
  spanAt(idx, asStart(n), asEnd(n));
1450
+ recordComments(n, idx);
1313
1451
  return idx;
1314
1452
  }
1315
1453
  function enc_ts_optional_type(n) {
@@ -1318,6 +1456,7 @@ function encode(estree, comments, lineStarts) {
1318
1456
  tagAt(idx, 113);
1319
1457
  slotAt(idx, 0, c_type_annotation);
1320
1458
  spanAt(idx, asStart(n), asEnd(n));
1459
+ recordComments(n, idx);
1321
1460
  return idx;
1322
1461
  }
1323
1462
  function enc_ts_rest_type(n) {
@@ -1326,6 +1465,7 @@ function encode(estree, comments, lineStarts) {
1326
1465
  tagAt(idx, 114);
1327
1466
  slotAt(idx, 0, c_type_annotation);
1328
1467
  spanAt(idx, asStart(n), asEnd(n));
1468
+ recordComments(n, idx);
1329
1469
  return idx;
1330
1470
  }
1331
1471
  function enc_ts_jsdoc_nullable_type(n) {
@@ -1335,6 +1475,7 @@ function encode(estree, comments, lineStarts) {
1335
1475
  slotAt(idx, 0, c_type_annotation);
1336
1476
  flagsAt(idx, 0 | (n.postfix ? 1 : 0));
1337
1477
  spanAt(idx, asStart(n), asEnd(n));
1478
+ recordComments(n, idx);
1338
1479
  return idx;
1339
1480
  }
1340
1481
  function enc_ts_jsdoc_non_nullable_type(n) {
@@ -1344,12 +1485,14 @@ function encode(estree, comments, lineStarts) {
1344
1485
  slotAt(idx, 0, c_type_annotation);
1345
1486
  flagsAt(idx, 0 | (n.postfix ? 1 : 0));
1346
1487
  spanAt(idx, asStart(n), asEnd(n));
1488
+ recordComments(n, idx);
1347
1489
  return idx;
1348
1490
  }
1349
1491
  function enc_ts_jsdoc_unknown_type(n) {
1350
1492
  const idx = alloc();
1351
1493
  tagAt(idx, 117);
1352
1494
  spanAt(idx, asStart(n), asEnd(n));
1495
+ recordComments(n, idx);
1353
1496
  return idx;
1354
1497
  }
1355
1498
  function enc_ts_union_type(n) {
@@ -1359,6 +1502,7 @@ function encode(estree, comments, lineStarts) {
1359
1502
  f0At(idx, c_types.len);
1360
1503
  slotAt(idx, 0, c_types.start);
1361
1504
  spanAt(idx, asStart(n), asEnd(n));
1505
+ recordComments(n, idx);
1362
1506
  return idx;
1363
1507
  }
1364
1508
  function enc_ts_intersection_type(n) {
@@ -1368,6 +1512,7 @@ function encode(estree, comments, lineStarts) {
1368
1512
  f0At(idx, c_types.len);
1369
1513
  slotAt(idx, 0, c_types.start);
1370
1514
  spanAt(idx, asStart(n), asEnd(n));
1515
+ recordComments(n, idx);
1371
1516
  return idx;
1372
1517
  }
1373
1518
  function enc_ts_conditional_type(n) {
@@ -1382,6 +1527,7 @@ function encode(estree, comments, lineStarts) {
1382
1527
  slotAt(idx, 2, c_true_type);
1383
1528
  slotAt(idx, 3, c_false_type);
1384
1529
  spanAt(idx, asStart(n), asEnd(n));
1530
+ recordComments(n, idx);
1385
1531
  return idx;
1386
1532
  }
1387
1533
  function enc_ts_infer_type(n) {
@@ -1390,6 +1536,7 @@ function encode(estree, comments, lineStarts) {
1390
1536
  tagAt(idx, 121);
1391
1537
  slotAt(idx, 0, c_type_parameter);
1392
1538
  spanAt(idx, asStart(n), asEnd(n));
1539
+ recordComments(n, idx);
1393
1540
  return idx;
1394
1541
  }
1395
1542
  function enc_ts_type_operator(n) {
@@ -1399,6 +1546,7 @@ function encode(estree, comments, lineStarts) {
1399
1546
  slotAt(idx, 0, c_type_annotation);
1400
1547
  flagsAt(idx, 0 | (TS_TYPE_OPERATORS_INV[n.operator] | 0));
1401
1548
  spanAt(idx, asStart(n), asEnd(n));
1549
+ recordComments(n, idx);
1402
1550
  return idx;
1403
1551
  }
1404
1552
  function enc_ts_parenthesized_type(n) {
@@ -1407,6 +1555,7 @@ function encode(estree, comments, lineStarts) {
1407
1555
  tagAt(idx, 123);
1408
1556
  slotAt(idx, 0, c_type_annotation);
1409
1557
  spanAt(idx, asStart(n), asEnd(n));
1558
+ recordComments(n, idx);
1410
1559
  return idx;
1411
1560
  }
1412
1561
  function enc_ts_function_type(n) {
@@ -1417,6 +1566,7 @@ function encode(estree, comments, lineStarts) {
1417
1566
  tagAt(idx, 124);
1418
1567
  slotAt(idx, 0, tp); slotAt(idx, 1, params); slotAt(idx, 2, rt_);
1419
1568
  spanAt(idx, asStart(n), asEnd(n));
1569
+ recordComments(n, idx);
1420
1570
  return idx;
1421
1571
  }
1422
1572
  function enc_ts_constructor_type(n) {
@@ -1428,6 +1578,7 @@ function encode(estree, comments, lineStarts) {
1428
1578
  slotAt(idx, 0, tp); slotAt(idx, 1, params); slotAt(idx, 2, rt_);
1429
1579
  flagsAt(idx, n.abstract ? 1 : 0);
1430
1580
  spanAt(idx, asStart(n), asEnd(n));
1581
+ recordComments(n, idx);
1431
1582
  return idx;
1432
1583
  }
1433
1584
  function enc_ts_type_predicate(n) {
@@ -1439,6 +1590,7 @@ function encode(estree, comments, lineStarts) {
1439
1590
  slotAt(idx, 1, c_type_annotation);
1440
1591
  flagsAt(idx, 0 | (n.asserts ? 1 : 0));
1441
1592
  spanAt(idx, asStart(n), asEnd(n));
1593
+ recordComments(n, idx);
1442
1594
  return idx;
1443
1595
  }
1444
1596
  function enc_ts_type_literal(n) {
@@ -1448,6 +1600,7 @@ function encode(estree, comments, lineStarts) {
1448
1600
  f0At(idx, c_members.len);
1449
1601
  slotAt(idx, 0, c_members.start);
1450
1602
  spanAt(idx, asStart(n), asEnd(n));
1603
+ recordComments(n, idx);
1451
1604
  return idx;
1452
1605
  }
1453
1606
  function enc_ts_mapped_type(n) {
@@ -1458,8 +1611,11 @@ function encode(estree, comments, lineStarts) {
1458
1611
  const idx = alloc();
1459
1612
  tagAt(idx, 128);
1460
1613
  slotAt(idx, 0, k); slotAt(idx, 1, c); slotAt(idx, 2, nt); slotAt(idx, 3, ta);
1461
- flagsAt(idx, (TS_MAPPED_OPTIONAL_INV(n.optional) << 0) | (TS_MAPPED_READONLY_INV(n.readonly) << 2));
1614
+ flagsAt(idx,
1615
+ (TS_MAPPED_OPTIONAL_INV(n.optional) << 0)
1616
+ | (TS_MAPPED_READONLY_INV(n.readonly) << 2));
1462
1617
  spanAt(idx, asStart(n), asEnd(n));
1618
+ recordComments(n, idx);
1463
1619
  return idx;
1464
1620
  }
1465
1621
  function enc_ts_property_signature(n) {
@@ -1468,8 +1624,12 @@ function encode(estree, comments, lineStarts) {
1468
1624
  const idx = alloc();
1469
1625
  tagAt(idx, 129);
1470
1626
  slotAt(idx, 0, k); slotAt(idx, 1, ta);
1471
- flagsAt(idx, (n.computed ? 1 : 0) | (n.optional ? 2 : 0) | (n.readonly ? 4 : 0));
1627
+ flagsAt(idx,
1628
+ (n.computed ? 1 : 0)
1629
+ | (n.optional ? 2 : 0)
1630
+ | (n.readonly ? 4 : 0));
1472
1631
  spanAt(idx, asStart(n), asEnd(n));
1632
+ recordComments(n, idx);
1473
1633
  return idx;
1474
1634
  }
1475
1635
  function enc_ts_method_signature(n) {
@@ -1479,9 +1639,16 @@ function encode(estree, comments, lineStarts) {
1479
1639
  const rt_ = n.returnType == null ? NULL : encNode(n.returnType);
1480
1640
  const idx = alloc();
1481
1641
  tagAt(idx, 130);
1482
- slotAt(idx, 0, k); slotAt(idx, 1, tp); slotAt(idx, 2, params); slotAt(idx, 3, rt_);
1483
- flagsAt(idx, (n.computed ? 4 : 0) | (n.optional ? 8 : 0) | ((TS_METHOD_SIGNATURE_KINDS_INV[n.kind] | 0) << 0));
1642
+ slotAt(idx, 0, k);
1643
+ slotAt(idx, 1, tp);
1644
+ slotAt(idx, 2, params);
1645
+ slotAt(idx, 3, rt_);
1646
+ flagsAt(idx,
1647
+ (n.computed ? 4 : 0)
1648
+ | (n.optional ? 8 : 0)
1649
+ | ((TS_METHOD_SIGNATURE_KINDS_INV[n.kind] | 0) << 0));
1484
1650
  spanAt(idx, asStart(n), asEnd(n));
1651
+ recordComments(n, idx);
1485
1652
  return idx;
1486
1653
  }
1487
1654
  function enc_ts_call_signature_declaration(n) {
@@ -1492,6 +1659,7 @@ function encode(estree, comments, lineStarts) {
1492
1659
  tagAt(idx, 131);
1493
1660
  slotAt(idx, 0, tp); slotAt(idx, 1, params); slotAt(idx, 2, rt_);
1494
1661
  spanAt(idx, asStart(n), asEnd(n));
1662
+ recordComments(n, idx);
1495
1663
  return idx;
1496
1664
  }
1497
1665
  function enc_ts_construct_signature_declaration(n) {
@@ -1502,6 +1670,7 @@ function encode(estree, comments, lineStarts) {
1502
1670
  tagAt(idx, 132);
1503
1671
  slotAt(idx, 0, tp); slotAt(idx, 1, params); slotAt(idx, 2, rt_);
1504
1672
  spanAt(idx, asStart(n), asEnd(n));
1673
+ recordComments(n, idx);
1505
1674
  return idx;
1506
1675
  }
1507
1676
  function enc_ts_index_signature(n) {
@@ -1514,6 +1683,7 @@ function encode(estree, comments, lineStarts) {
1514
1683
  slotAt(idx, 1, ta);
1515
1684
  flagsAt(idx, (n.readonly ? 1 : 0) | (n.static ? 2 : 0));
1516
1685
  spanAt(idx, asStart(n), asEnd(n));
1686
+ recordComments(n, idx);
1517
1687
  return idx;
1518
1688
  }
1519
1689
  function enc_ts_type_alias_declaration(n) {
@@ -1527,6 +1697,7 @@ function encode(estree, comments, lineStarts) {
1527
1697
  slotAt(idx, 2, c_type_annotation);
1528
1698
  flagsAt(idx, 0 | (n.declare ? 1 : 0));
1529
1699
  spanAt(idx, asStart(n), asEnd(n));
1700
+ recordComments(n, idx);
1530
1701
  return idx;
1531
1702
  }
1532
1703
  function enc_ts_interface_declaration(n) {
@@ -1543,6 +1714,7 @@ function encode(estree, comments, lineStarts) {
1543
1714
  slotAt(idx, 3, c_body);
1544
1715
  flagsAt(idx, 0 | (n.declare ? 1 : 0));
1545
1716
  spanAt(idx, asStart(n), asEnd(n));
1717
+ recordComments(n, idx);
1546
1718
  return idx;
1547
1719
  }
1548
1720
  function enc_ts_interface_body(n) {
@@ -1552,6 +1724,7 @@ function encode(estree, comments, lineStarts) {
1552
1724
  f0At(idx, c_body.len);
1553
1725
  slotAt(idx, 0, c_body.start);
1554
1726
  spanAt(idx, asStart(n), asEnd(n));
1727
+ recordComments(n, idx);
1555
1728
  return idx;
1556
1729
  }
1557
1730
  function enc_ts_interface_heritage(n) {
@@ -1562,6 +1735,7 @@ function encode(estree, comments, lineStarts) {
1562
1735
  slotAt(idx, 0, c_expression);
1563
1736
  slotAt(idx, 1, c_type_arguments);
1564
1737
  spanAt(idx, asStart(n), asEnd(n));
1738
+ recordComments(n, idx);
1565
1739
  return idx;
1566
1740
  }
1567
1741
  function enc_ts_class_implements(n) {
@@ -1572,6 +1746,7 @@ function encode(estree, comments, lineStarts) {
1572
1746
  slotAt(idx, 0, c_expression);
1573
1747
  slotAt(idx, 1, c_type_arguments);
1574
1748
  spanAt(idx, asStart(n), asEnd(n));
1749
+ recordComments(n, idx);
1575
1750
  return idx;
1576
1751
  }
1577
1752
  function enc_ts_enum_declaration(n) {
@@ -1583,6 +1758,7 @@ function encode(estree, comments, lineStarts) {
1583
1758
  slotAt(idx, 1, c_body);
1584
1759
  flagsAt(idx, 0 | (n.const ? 1 : 0) | (n.declare ? 2 : 0));
1585
1760
  spanAt(idx, asStart(n), asEnd(n));
1761
+ recordComments(n, idx);
1586
1762
  return idx;
1587
1763
  }
1588
1764
  function enc_ts_enum_body(n) {
@@ -1592,6 +1768,7 @@ function encode(estree, comments, lineStarts) {
1592
1768
  f0At(idx, c_members.len);
1593
1769
  slotAt(idx, 0, c_members.start);
1594
1770
  spanAt(idx, asStart(n), asEnd(n));
1771
+ recordComments(n, idx);
1595
1772
  return idx;
1596
1773
  }
1597
1774
  function enc_ts_enum_member(n) {
@@ -1602,6 +1779,7 @@ function encode(estree, comments, lineStarts) {
1602
1779
  slotAt(idx, 0, id); slotAt(idx, 1, init);
1603
1780
  flagsAt(idx, n.computed ? 1 : 0);
1604
1781
  spanAt(idx, asStart(n), asEnd(n));
1782
+ recordComments(n, idx);
1605
1783
  return idx;
1606
1784
  }
1607
1785
  function enc_ts_module_declaration(n) {
@@ -1613,6 +1791,7 @@ function encode(estree, comments, lineStarts) {
1613
1791
  slotAt(idx, 1, body);
1614
1792
  flagsAt(idx, ((TS_MODULE_KINDS_INV[n.kind] | 0) << 0) | (n.declare ? 2 : 0));
1615
1793
  spanAt(idx, asStart(n), asEnd(n));
1794
+ recordComments(n, idx);
1616
1795
  return idx;
1617
1796
  }
1618
1797
  function enc_ts_module_block(n) {
@@ -1622,6 +1801,7 @@ function encode(estree, comments, lineStarts) {
1622
1801
  f0At(idx, c_body.len);
1623
1802
  slotAt(idx, 0, c_body.start);
1624
1803
  spanAt(idx, asStart(n), asEnd(n));
1804
+ recordComments(n, idx);
1625
1805
  return idx;
1626
1806
  }
1627
1807
  function enc_ts_global_declaration(n) {
@@ -1633,6 +1813,7 @@ function encode(estree, comments, lineStarts) {
1633
1813
  slotAt(idx, 1, body);
1634
1814
  flagsAt(idx, n.declare ? 1 : 0);
1635
1815
  spanAt(idx, asStart(n), asEnd(n));
1816
+ recordComments(n, idx);
1636
1817
  return idx;
1637
1818
  }
1638
1819
  function enc_ts_parameter_property(n) {
@@ -1645,6 +1826,7 @@ function encode(estree, comments, lineStarts) {
1645
1826
  slotAt(idx, 1, c_parameter);
1646
1827
  flagsAt(idx, 0 | (n.override ? 1 : 0) | (n.readonly ? 2 : 0) | (ACCESSIBILITY_INV(n.accessibility) << 2));
1647
1828
  spanAt(idx, asStart(n), asEnd(n));
1829
+ recordComments(n, idx);
1648
1830
  return idx;
1649
1831
  }
1650
1832
  function enc_ts_this_parameter(n) {
@@ -1653,6 +1835,7 @@ function encode(estree, comments, lineStarts) {
1653
1835
  tagAt(idx, 146);
1654
1836
  slotAt(idx, 0, ta);
1655
1837
  spanAt(idx, asStart(n), asEnd(n));
1838
+ recordComments(n, idx);
1656
1839
  return idx;
1657
1840
  }
1658
1841
  function enc_ts_as_expression(n) {
@@ -1663,6 +1846,7 @@ function encode(estree, comments, lineStarts) {
1663
1846
  slotAt(idx, 0, c_expression);
1664
1847
  slotAt(idx, 1, c_type_annotation);
1665
1848
  spanAt(idx, asStart(n), asEnd(n));
1849
+ recordComments(n, idx);
1666
1850
  return idx;
1667
1851
  }
1668
1852
  function enc_ts_satisfies_expression(n) {
@@ -1673,6 +1857,7 @@ function encode(estree, comments, lineStarts) {
1673
1857
  slotAt(idx, 0, c_expression);
1674
1858
  slotAt(idx, 1, c_type_annotation);
1675
1859
  spanAt(idx, asStart(n), asEnd(n));
1860
+ recordComments(n, idx);
1676
1861
  return idx;
1677
1862
  }
1678
1863
  function enc_ts_type_assertion(n) {
@@ -1683,6 +1868,7 @@ function encode(estree, comments, lineStarts) {
1683
1868
  slotAt(idx, 0, c_type_annotation);
1684
1869
  slotAt(idx, 1, c_expression);
1685
1870
  spanAt(idx, asStart(n), asEnd(n));
1871
+ recordComments(n, idx);
1686
1872
  return idx;
1687
1873
  }
1688
1874
  function enc_ts_non_null_expression(n) {
@@ -1691,6 +1877,7 @@ function encode(estree, comments, lineStarts) {
1691
1877
  tagAt(idx, 150);
1692
1878
  slotAt(idx, 0, c_expression);
1693
1879
  spanAt(idx, asStart(n), asEnd(n));
1880
+ recordComments(n, idx);
1694
1881
  return idx;
1695
1882
  }
1696
1883
  function enc_ts_instantiation_expression(n) {
@@ -1701,6 +1888,7 @@ function encode(estree, comments, lineStarts) {
1701
1888
  slotAt(idx, 0, c_expression);
1702
1889
  slotAt(idx, 1, c_type_arguments);
1703
1890
  spanAt(idx, asStart(n), asEnd(n));
1891
+ recordComments(n, idx);
1704
1892
  return idx;
1705
1893
  }
1706
1894
  function enc_ts_export_assignment(n) {
@@ -1709,6 +1897,7 @@ function encode(estree, comments, lineStarts) {
1709
1897
  tagAt(idx, 152);
1710
1898
  slotAt(idx, 0, c_expression);
1711
1899
  spanAt(idx, asStart(n), asEnd(n));
1900
+ recordComments(n, idx);
1712
1901
  return idx;
1713
1902
  }
1714
1903
  function enc_ts_namespace_export_declaration(n) {
@@ -1717,6 +1906,7 @@ function encode(estree, comments, lineStarts) {
1717
1906
  tagAt(idx, 153);
1718
1907
  slotAt(idx, 0, c_id);
1719
1908
  spanAt(idx, asStart(n), asEnd(n));
1909
+ recordComments(n, idx);
1720
1910
  return idx;
1721
1911
  }
1722
1912
  function enc_ts_import_equals_declaration(n) {
@@ -1728,6 +1918,7 @@ function encode(estree, comments, lineStarts) {
1728
1918
  slotAt(idx, 1, c_module_reference);
1729
1919
  flagsAt(idx, 0 | (IMPORT_EXPORT_KINDS_INV[n.importKind] | 0));
1730
1920
  spanAt(idx, asStart(n), asEnd(n));
1921
+ recordComments(n, idx);
1731
1922
  return idx;
1732
1923
  }
1733
1924
  function enc_ts_external_module_reference(n) {
@@ -1736,6 +1927,7 @@ function encode(estree, comments, lineStarts) {
1736
1927
  tagAt(idx, 155);
1737
1928
  slotAt(idx, 0, c_expression);
1738
1929
  spanAt(idx, asStart(n), asEnd(n));
1930
+ recordComments(n, idx);
1739
1931
  return idx;
1740
1932
  }
1741
1933
  function enc_jsx_element(n) {
@@ -1749,6 +1941,7 @@ function encode(estree, comments, lineStarts) {
1749
1941
  slotAt(idx, 1, c_children.start);
1750
1942
  slotAt(idx, 2, c_closing_element);
1751
1943
  spanAt(idx, asStart(n), asEnd(n));
1944
+ recordComments(n, idx);
1752
1945
  return idx;
1753
1946
  }
1754
1947
  function enc_jsx_opening_element(n) {
@@ -1763,6 +1956,7 @@ function encode(estree, comments, lineStarts) {
1763
1956
  slotAt(idx, 2, c_type_arguments);
1764
1957
  flagsAt(idx, 0 | (n.selfClosing ? 1 : 0));
1765
1958
  spanAt(idx, asStart(n), asEnd(n));
1959
+ recordComments(n, idx);
1766
1960
  return idx;
1767
1961
  }
1768
1962
  function enc_jsx_closing_element(n) {
@@ -1771,6 +1965,7 @@ function encode(estree, comments, lineStarts) {
1771
1965
  tagAt(idx, 158);
1772
1966
  slotAt(idx, 0, c_name);
1773
1967
  spanAt(idx, asStart(n), asEnd(n));
1968
+ recordComments(n, idx);
1774
1969
  return idx;
1775
1970
  }
1776
1971
  function enc_jsx_fragment(n) {
@@ -1784,18 +1979,21 @@ function encode(estree, comments, lineStarts) {
1784
1979
  slotAt(idx, 1, c_children.start);
1785
1980
  slotAt(idx, 2, c_closing_fragment);
1786
1981
  spanAt(idx, asStart(n), asEnd(n));
1982
+ recordComments(n, idx);
1787
1983
  return idx;
1788
1984
  }
1789
1985
  function enc_jsx_opening_fragment(n) {
1790
1986
  const idx = alloc();
1791
1987
  tagAt(idx, 160);
1792
1988
  spanAt(idx, asStart(n), asEnd(n));
1989
+ recordComments(n, idx);
1793
1990
  return idx;
1794
1991
  }
1795
1992
  function enc_jsx_closing_fragment(n) {
1796
1993
  const idx = alloc();
1797
1994
  tagAt(idx, 161);
1798
1995
  spanAt(idx, asStart(n), asEnd(n));
1996
+ recordComments(n, idx);
1799
1997
  return idx;
1800
1998
  }
1801
1999
  function enc_jsx_identifier(n) {
@@ -1805,6 +2003,7 @@ function encode(estree, comments, lineStarts) {
1805
2003
  slotAt(idx, 0, c_name.start);
1806
2004
  slotAt(idx, 1, c_name.end);
1807
2005
  spanAt(idx, asStart(n), asEnd(n));
2006
+ recordComments(n, idx);
1808
2007
  return idx;
1809
2008
  }
1810
2009
  function enc_jsx_namespaced_name(n) {
@@ -1815,6 +2014,7 @@ function encode(estree, comments, lineStarts) {
1815
2014
  slotAt(idx, 0, c_namespace);
1816
2015
  slotAt(idx, 1, c_name);
1817
2016
  spanAt(idx, asStart(n), asEnd(n));
2017
+ recordComments(n, idx);
1818
2018
  return idx;
1819
2019
  }
1820
2020
  function enc_jsx_member_expression(n) {
@@ -1825,6 +2025,7 @@ function encode(estree, comments, lineStarts) {
1825
2025
  slotAt(idx, 0, c_object);
1826
2026
  slotAt(idx, 1, c_property);
1827
2027
  spanAt(idx, asStart(n), asEnd(n));
2028
+ recordComments(n, idx);
1828
2029
  return idx;
1829
2030
  }
1830
2031
  function enc_jsx_attribute(n) {
@@ -1835,6 +2036,7 @@ function encode(estree, comments, lineStarts) {
1835
2036
  slotAt(idx, 0, c_name);
1836
2037
  slotAt(idx, 1, c_value);
1837
2038
  spanAt(idx, asStart(n), asEnd(n));
2039
+ recordComments(n, idx);
1838
2040
  return idx;
1839
2041
  }
1840
2042
  function enc_jsx_spread_attribute(n) {
@@ -1843,6 +2045,7 @@ function encode(estree, comments, lineStarts) {
1843
2045
  tagAt(idx, 166);
1844
2046
  slotAt(idx, 0, c_argument);
1845
2047
  spanAt(idx, asStart(n), asEnd(n));
2048
+ recordComments(n, idx);
1846
2049
  return idx;
1847
2050
  }
1848
2051
  function enc_jsx_expression_container(n) {
@@ -1851,12 +2054,14 @@ function encode(estree, comments, lineStarts) {
1851
2054
  tagAt(idx, 167);
1852
2055
  slotAt(idx, 0, c_expression);
1853
2056
  spanAt(idx, asStart(n), asEnd(n));
2057
+ recordComments(n, idx);
1854
2058
  return idx;
1855
2059
  }
1856
2060
  function enc_jsx_empty_expression(n) {
1857
2061
  const idx = alloc();
1858
2062
  tagAt(idx, 168);
1859
2063
  spanAt(idx, asStart(n), asEnd(n));
2064
+ recordComments(n, idx);
1860
2065
  return idx;
1861
2066
  }
1862
2067
  function enc_jsx_text(n) {
@@ -1865,6 +2070,7 @@ function encode(estree, comments, lineStarts) {
1865
2070
  tagAt(idx, 169);
1866
2071
  slotAt(idx, 0, v.start); slotAt(idx, 1, v.end);
1867
2072
  spanAt(idx, asStart(n), asEnd(n));
2073
+ recordComments(n, idx);
1868
2074
  return idx;
1869
2075
  }
1870
2076
  function enc_jsx_spread_child(n) {
@@ -1873,18 +2079,30 @@ function encode(estree, comments, lineStarts) {
1873
2079
  tagAt(idx, 170);
1874
2080
  slotAt(idx, 0, c_expression);
1875
2081
  spanAt(idx, asStart(n), asEnd(n));
2082
+ recordComments(n, idx);
1876
2083
  return idx;
1877
2084
  }
2085
+ // encoded node index -> its `.comments` array
2086
+ const commentsByIdx = new Map();
1878
2087
  function encNode(n) {
1879
2088
  if (n == null) return NULL;
1880
2089
  switch (n.type) {
1881
- case "Identifier": return enc_identifier_reference(n);
2090
+ case "Identifier": {
2091
+ switch (n.kind) {
2092
+ case "binding": return enc_binding_identifier(n);
2093
+ case "name": return enc_identifier_name(n);
2094
+ case "label": return enc_label_identifier(n);
2095
+ default: return enc_identifier_reference(n);
2096
+ }
2097
+ }
1882
2098
  case "PrivateIdentifier": return enc_private_identifier(n);
1883
2099
  case "Literal": {
1884
2100
  if (n.regex) return enc_regexp_literal(n);
1885
2101
  if (typeof n.bigint === "string") return enc_bigint_literal(n);
1886
2102
  const v = n.value;
1887
- if (v === null) return typeof n.raw === "string" && n.raw !== "null" ? enc_numeric_literal(n) : enc_null_literal(n);
2103
+ if (v === null) return typeof n.raw === "string" && n.raw !== "null"
2104
+ ? enc_numeric_literal(n)
2105
+ : enc_null_literal(n);
1888
2106
  if (typeof v === "boolean") return enc_boolean_literal(n);
1889
2107
  if (typeof v === "string") return enc_string_literal(n);
1890
2108
  if (typeof v === "number") return enc_numeric_literal(n);
@@ -1903,8 +2121,12 @@ function encode(estree, comments, lineStarts) {
1903
2121
  case "AccessorProperty": return enc_property_definition(n, true, false);
1904
2122
  case "TSAbstractAccessorProperty": return enc_property_definition(n, true, true);
1905
2123
  case "RestElement": return enc_binding_rest_element(n);
1906
- case "TSModuleDeclaration": return n.global ? enc_ts_global_declaration(n) : enc_ts_module_declaration(n);
1907
- case "ExpressionStatement": return n.directive != null ? enc_directive(n) : enc_expression_statement(n);
2124
+ case "TSModuleDeclaration": return n.global
2125
+ ? enc_ts_global_declaration(n)
2126
+ : enc_ts_module_declaration(n);
2127
+ case "ExpressionStatement": return n.directive != null
2128
+ ? enc_directive(n)
2129
+ : enc_expression_statement(n);
1908
2130
  case "SequenceExpression": return enc_sequence_expression(n);
1909
2131
  case "ParenthesizedExpression": return enc_parenthesized_expression(n);
1910
2132
  case "ArrowFunctionExpression": return enc_arrow_function_expression(n);
@@ -2054,29 +2276,44 @@ function encode(estree, comments, lineStarts) {
2054
2276
  default: throw new Error("yuku-codegen: unsupported ESTree node type: " + n.type);
2055
2277
  }
2056
2278
  }
2057
- const progIdx = encNode(estree);
2058
- // Comments are encoded after the node walk so string interning lands in the pool first.
2059
- const commentCount = Array.isArray(comments) ? comments.length : 0;
2279
+ const progIdx = encNode(root);
2280
+ const POSITION_INV = { "before": 0, "after": 1, "inside": 2 };
2281
+ // counting-sort comments by host into a prefix-sum offsets table,
2282
+ // then write each comment at its slot in `commentBytes`.
2283
+ const attachComments = commentsByIdx.size > 0;
2284
+ let commentCount = 0;
2285
+ let offsetsBytes = null;
2060
2286
  let commentBytes = null;
2061
- if (commentCount > 0) {
2287
+ if (attachComments) {
2288
+ for (const arr of commentsByIdx.values()) commentCount += arr.length;
2289
+ const offsets = new Uint32Array(nodeCount + 1);
2290
+ for (const [idx, arr] of commentsByIdx) offsets[idx] = arr.length;
2291
+ let sum = 0;
2292
+ for (let i = 0; i < nodeCount; i++) {
2293
+ const c = offsets[i];
2294
+ offsets[i] = sum;
2295
+ sum += c;
2296
+ }
2297
+ offsets[nodeCount] = sum;
2298
+ offsetsBytes = offsets.buffer;
2062
2299
  commentBytes = new ArrayBuffer(commentCount * COMMENT_SIZE);
2063
2300
  const cU8 = new Uint8Array(commentBytes);
2064
2301
  const cDV = new DataView(commentBytes);
2065
- for (let i = 0; i < commentCount; i++) {
2066
- const c = comments[i];
2067
- const v = encStr(typeof c.value === "string" ? c.value : "");
2068
- const kind = typeof c.kind === "string" ? (COMMENT_KINDS_INV[c.kind] ?? 0) : 0;
2069
- let flags = 0;
2070
- if (c.precededByNewline) flags |= 1;
2071
- if (c.followedByNewline) flags |= 2;
2072
- const o = i * COMMENT_SIZE;
2073
- cU8[o + COMMENT_TYPE_OFFSET] = c.type === "Block" ? 1 : 0;
2074
- cU8[o + COMMENT_KIND_OFFSET] = kind;
2075
- cU8[o + COMMENT_FLAGS_OFFSET] = flags;
2076
- cDV.setUint32(o + COMMENT_START_OFFSET, (c.start >>> 0), true);
2077
- cDV.setUint32(o + COMMENT_END_OFFSET, (c.end >>> 0), true);
2078
- cDV.setUint32(o + COMMENT_VALUE_START_OFFSET, v.start, true);
2079
- cDV.setUint32(o + COMMENT_VALUE_END_OFFSET, v.end, true);
2302
+ const cursor = new Uint32Array(nodeCount);
2303
+ for (const [idx, arr] of commentsByIdx) {
2304
+ for (let j = 0; j < arr.length; j++) {
2305
+ const c = arr[j];
2306
+ const slot = offsets[idx] + cursor[idx]; cursor[idx]++;
2307
+ let f = 0;
2308
+ if (c.type === "Block") f |= 1;
2309
+ f |= ((POSITION_INV[c.position] ?? 0) & 3) << 1;
2310
+ if (c.sameLine) f |= 8;
2311
+ const v = encStr(typeof c.value === "string" ? c.value : "");
2312
+ const o = slot * COMMENT_SIZE;
2313
+ cU8[o + COMMENT_FLAGS_OFFSET] = f;
2314
+ cDV.setUint32(o + COMMENT_VALUE_START_OFFSET, v.start, true);
2315
+ cDV.setUint32(o + COMMENT_VALUE_END_OFFSET, v.end, true);
2316
+ }
2080
2317
  }
2081
2318
  }
2082
2319
  const lineStartsCount = Array.isArray(lineStarts) ? lineStarts.length : 0;
@@ -2084,13 +2321,18 @@ function encode(estree, comments, lineStarts) {
2084
2321
  if (lineStartsCount > 0) {
2085
2322
  lineStartsBytes = new ArrayBuffer(lineStartsCount * 4);
2086
2323
  const lsDV = new DataView(lineStartsBytes);
2087
- for (let i = 0; i < lineStartsCount; i++) lsDV.setUint32(i * 4, lineStarts[i] >>> 0, true);
2324
+ for (let i = 0; i < lineStartsCount; i++) {
2325
+ lsDV.setUint32(i * 4, lineStarts[i] >>> 0, true);
2326
+ }
2088
2327
  }
2089
2328
  const totalNodeBytes = nodeCount * NODE_SIZE;
2090
2329
  const totalExtraBytes = extraCount * 4;
2330
+ const totalOffsetsBytes = attachComments ? (nodeCount + 1) * 4 : 0;
2091
2331
  const totalCommentBytes = commentCount * COMMENT_SIZE;
2092
2332
  const totalLineStartsBytes = lineStartsCount * 4;
2093
- const finalSize = HEADER_SIZE + totalNodeBytes + totalExtraBytes + poolLen + totalCommentBytes + totalLineStartsBytes;
2333
+ const finalSize =
2334
+ HEADER_SIZE + totalNodeBytes + totalExtraBytes + poolLen +
2335
+ totalOffsetsBytes + totalCommentBytes + totalLineStartsBytes;
2094
2336
  const out = new ArrayBuffer(finalSize);
2095
2337
  const outU8 = new Uint8Array(out);
2096
2338
  const outU32 = new Uint32Array(out, 0, (finalSize >>> 2));
@@ -2102,16 +2344,18 @@ function encode(estree, comments, lineStarts) {
2102
2344
  outU32[5] = lineStartsCount;
2103
2345
  outU32[6] = 0;
2104
2346
  outU32[7] = progIdx;
2105
- outU32[8] = 0;
2347
+ outU32[8] = attachComments ? FLAG_ATTACH_COMMENTS : 0;
2106
2348
  outU32[9] = 0;
2107
2349
  const nodesOff = HEADER_SIZE;
2108
2350
  const extrasOff = nodesOff + totalNodeBytes;
2109
2351
  const poolOff = extrasOff + totalExtraBytes;
2110
- const commentsOff = poolOff + poolLen;
2352
+ const offsetsOff = poolOff + poolLen;
2353
+ const commentsOff = offsetsOff + totalOffsetsBytes;
2111
2354
  const lineStartsOff = commentsOff + totalCommentBytes;
2112
2355
  outU8.set(new Uint8Array(nodeAB, 0, totalNodeBytes), nodesOff);
2113
2356
  outU8.set(new Uint8Array(extras.buffer, 0, totalExtraBytes), extrasOff);
2114
2357
  outU8.set(pool.subarray(0, poolLen), poolOff);
2358
+ if (offsetsBytes !== null) outU8.set(new Uint8Array(offsetsBytes), offsetsOff);
2115
2359
  if (commentBytes !== null) outU8.set(new Uint8Array(commentBytes), commentsOff);
2116
2360
  if (lineStartsBytes !== null) outU8.set(new Uint8Array(lineStartsBytes), lineStartsOff);
2117
2361
  return out;