@willbooster/web-tree-sitter 15.5.4 → 16.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.
@@ -1577,8 +1577,8 @@ var require_web_tree_sitter = __commonJS({
1577
1577
  if (Module.currentProgressCallback) {
1578
1578
  return Module.currentProgressCallback({
1579
1579
  currentOffset,
1580
- hasError
1581
- });
1580
+ hasError: hasError !== 0
1581
+ }) === true;
1582
1582
  }
1583
1583
  return false;
1584
1584
  }
@@ -1587,7 +1587,7 @@ var require_web_tree_sitter = __commonJS({
1587
1587
  if (Module.currentQueryProgressCallback) {
1588
1588
  return Module.currentQueryProgressCallback({
1589
1589
  currentOffset
1590
- });
1590
+ }) === true;
1591
1591
  }
1592
1592
  return false;
1593
1593
  }
@@ -4273,10 +4273,6 @@ function parsePattern(index, stepType, stepValueId, captureNames, stringValues,
4273
4273
  }
4274
4274
  }
4275
4275
  __name(parsePattern, "parsePattern");
4276
- function indexForByteOffset(source, byteOffset) {
4277
- return new TextEncoder().encodeInto(source, new Uint8Array(byteOffset)).read;
4278
- }
4279
- __name(indexForByteOffset, "indexForByteOffset");
4280
4276
  var finalizer5 = newFinalizer((address) => {
4281
4277
  C._ts_query_delete(address);
4282
4278
  });
@@ -4291,8 +4287,6 @@ var Query = class {
4291
4287
  exceededMatchLimit;
4292
4288
  /** @internal */
4293
4289
  textPredicates;
4294
- /** @internal */
4295
- source;
4296
4290
  /** The names of the captures used in the query. */
4297
4291
  captureNames;
4298
4292
  /** The quantifiers of the captures used in the query. */
@@ -4432,7 +4426,6 @@ var Query = class {
4432
4426
  this.captureNames = captureNames;
4433
4427
  this.captureQuantifiers = captureQuantifiers;
4434
4428
  this.textPredicates = textPredicates;
4435
- this.source = source;
4436
4429
  this.predicates = predicates;
4437
4430
  this.setProperties = setProperties;
4438
4431
  this.assertedProperties = assertedProperties;
@@ -4459,72 +4452,84 @@ var Query = class {
4459
4452
  * @param {QueryOptions} options - Options for query execution.
4460
4453
  */
4461
4454
  matches(node, options = {}) {
4462
- const {
4463
- startPosition,
4464
- endPosition,
4455
+ const startPosition = options.startPosition ?? ZERO_POINT;
4456
+ const endPosition = options.endPosition ?? ZERO_POINT;
4457
+ const startIndex = options.startIndex ?? 0;
4458
+ const endIndex = options.endIndex ?? 0;
4459
+ const startContainingPosition = options.startContainingPosition ?? ZERO_POINT;
4460
+ const endContainingPosition = options.endContainingPosition ?? ZERO_POINT;
4461
+ const startContainingIndex = options.startContainingIndex ?? 0;
4462
+ const endContainingIndex = options.endContainingIndex ?? 0;
4463
+ const matchLimit = options.matchLimit ?? 4294967295;
4464
+ const maxStartDepth = options.maxStartDepth ?? 4294967295;
4465
+ const progressCallback = options.progressCallback;
4466
+ if (typeof matchLimit !== "number") {
4467
+ throw new Error("Arguments must be numbers");
4468
+ }
4469
+ this.matchLimit = matchLimit;
4470
+ if (endIndex !== 0 && startIndex > endIndex) {
4471
+ throw new Error("`startIndex` cannot be greater than `endIndex`");
4472
+ }
4473
+ if (endPosition !== ZERO_POINT && (startPosition.row > endPosition.row || startPosition.row === endPosition.row && startPosition.column > endPosition.column)) {
4474
+ throw new Error("`startPosition` cannot be greater than `endPosition`");
4475
+ }
4476
+ if (endContainingIndex !== 0 && startContainingIndex > endContainingIndex) {
4477
+ throw new Error("`startContainingIndex` cannot be greater than `endContainingIndex`");
4478
+ }
4479
+ if (endContainingPosition !== ZERO_POINT && (startContainingPosition.row > endContainingPosition.row || startContainingPosition.row === endContainingPosition.row && startContainingPosition.column > endContainingPosition.column)) {
4480
+ throw new Error("`startContainingPosition` cannot be greater than `endContainingPosition`");
4481
+ }
4482
+ if (progressCallback) {
4483
+ C.currentQueryProgressCallback = progressCallback;
4484
+ }
4485
+ marshalNode(node);
4486
+ C._ts_query_matches_wasm(
4487
+ this[0],
4488
+ node.tree[0],
4489
+ startPosition.row,
4490
+ startPosition.column,
4491
+ endPosition.row,
4492
+ endPosition.column,
4465
4493
  startIndex,
4466
4494
  endIndex,
4467
- startContainingPosition,
4468
- endContainingPosition,
4495
+ startContainingPosition.row,
4496
+ startContainingPosition.column,
4497
+ endContainingPosition.row,
4498
+ endContainingPosition.column,
4469
4499
  startContainingIndex,
4470
4500
  endContainingIndex,
4471
4501
  matchLimit,
4472
- maxStartDepth,
4473
- progressCallback
4474
- } = prepareQuery(this, options);
4475
- return executeQuery(
4476
- progressCallback,
4477
- () => {
4478
- marshalNode(node);
4479
- C._ts_query_matches_wasm(
4480
- this[0],
4481
- node.tree[0],
4482
- startPosition.row,
4483
- startPosition.column,
4484
- endPosition.row,
4485
- endPosition.column,
4486
- startIndex,
4487
- endIndex,
4488
- startContainingPosition.row,
4489
- startContainingPosition.column,
4490
- endContainingPosition.row,
4491
- endContainingPosition.column,
4492
- startContainingIndex,
4493
- endContainingIndex,
4494
- matchLimit,
4495
- maxStartDepth
4496
- );
4497
- },
4498
- (exceededMatchLimit) => {
4499
- this.matchLimit = matchLimit;
4500
- this.exceededMatchLimit = exceededMatchLimit;
4501
- },
4502
- (rawCount, startAddress) => {
4503
- const result = new Array(rawCount);
4504
- let filteredCount = 0;
4505
- let address = startAddress;
4506
- for (let i2 = 0; i2 < rawCount; i2++) {
4507
- const patternIndex = C.getValue(address, "i32");
4508
- address += SIZE_OF_INT;
4509
- const captureCount = C.getValue(address, "i32");
4510
- address += SIZE_OF_INT;
4511
- const captures = new Array(captureCount);
4512
- address = unmarshalCaptures(this, node.tree, address, patternIndex, captures);
4513
- if (this.textPredicates[patternIndex].every((p) => p(captures))) {
4514
- result[filteredCount] = { patternIndex, captures };
4515
- const setProperties = this.setProperties[patternIndex];
4516
- result[filteredCount].setProperties = setProperties;
4517
- const assertedProperties = this.assertedProperties[patternIndex];
4518
- result[filteredCount].assertedProperties = assertedProperties;
4519
- const refutedProperties = this.refutedProperties[patternIndex];
4520
- result[filteredCount].refutedProperties = refutedProperties;
4521
- filteredCount++;
4522
- }
4523
- }
4524
- result.length = filteredCount;
4525
- return result;
4526
- }
4502
+ maxStartDepth
4527
4503
  );
4504
+ const rawCount = C.getValue(TRANSFER_BUFFER, "i32");
4505
+ const startAddress = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
4506
+ const didExceedMatchLimit = C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, "i32");
4507
+ const result = new Array(rawCount);
4508
+ this.exceededMatchLimit = Boolean(didExceedMatchLimit);
4509
+ let filteredCount = 0;
4510
+ let address = startAddress;
4511
+ for (let i2 = 0; i2 < rawCount; i2++) {
4512
+ const patternIndex = C.getValue(address, "i32");
4513
+ address += SIZE_OF_INT;
4514
+ const captureCount = C.getValue(address, "i32");
4515
+ address += SIZE_OF_INT;
4516
+ const captures = new Array(captureCount);
4517
+ address = unmarshalCaptures(this, node.tree, address, patternIndex, captures);
4518
+ if (this.textPredicates[patternIndex].every((p) => p(captures))) {
4519
+ result[filteredCount] = { patternIndex, captures };
4520
+ const setProperties = this.setProperties[patternIndex];
4521
+ result[filteredCount].setProperties = setProperties;
4522
+ const assertedProperties = this.assertedProperties[patternIndex];
4523
+ result[filteredCount].assertedProperties = assertedProperties;
4524
+ const refutedProperties = this.refutedProperties[patternIndex];
4525
+ result[filteredCount].refutedProperties = refutedProperties;
4526
+ filteredCount++;
4527
+ }
4528
+ }
4529
+ result.length = filteredCount;
4530
+ C._free(startAddress);
4531
+ C.currentQueryProgressCallback = null;
4532
+ return result;
4528
4533
  }
4529
4534
  /**
4530
4535
  * Iterate over all of the individual captures in the order that they
@@ -4538,71 +4543,85 @@ var Query = class {
4538
4543
  * @param {QueryOptions} options - Options for query execution.
4539
4544
  */
4540
4545
  captures(node, options = {}) {
4541
- const {
4542
- startPosition,
4543
- endPosition,
4546
+ const startPosition = options.startPosition ?? ZERO_POINT;
4547
+ const endPosition = options.endPosition ?? ZERO_POINT;
4548
+ const startIndex = options.startIndex ?? 0;
4549
+ const endIndex = options.endIndex ?? 0;
4550
+ const startContainingPosition = options.startContainingPosition ?? ZERO_POINT;
4551
+ const endContainingPosition = options.endContainingPosition ?? ZERO_POINT;
4552
+ const startContainingIndex = options.startContainingIndex ?? 0;
4553
+ const endContainingIndex = options.endContainingIndex ?? 0;
4554
+ const matchLimit = options.matchLimit ?? 4294967295;
4555
+ const maxStartDepth = options.maxStartDepth ?? 4294967295;
4556
+ const progressCallback = options.progressCallback;
4557
+ if (typeof matchLimit !== "number") {
4558
+ throw new Error("Arguments must be numbers");
4559
+ }
4560
+ this.matchLimit = matchLimit;
4561
+ if (endIndex !== 0 && startIndex > endIndex) {
4562
+ throw new Error("`startIndex` cannot be greater than `endIndex`");
4563
+ }
4564
+ if (endPosition !== ZERO_POINT && (startPosition.row > endPosition.row || startPosition.row === endPosition.row && startPosition.column > endPosition.column)) {
4565
+ throw new Error("`startPosition` cannot be greater than `endPosition`");
4566
+ }
4567
+ if (endContainingIndex !== 0 && startContainingIndex > endContainingIndex) {
4568
+ throw new Error("`startContainingIndex` cannot be greater than `endContainingIndex`");
4569
+ }
4570
+ if (endContainingPosition !== ZERO_POINT && (startContainingPosition.row > endContainingPosition.row || startContainingPosition.row === endContainingPosition.row && startContainingPosition.column > endContainingPosition.column)) {
4571
+ throw new Error("`startContainingPosition` cannot be greater than `endContainingPosition`");
4572
+ }
4573
+ if (progressCallback) {
4574
+ C.currentQueryProgressCallback = progressCallback;
4575
+ }
4576
+ marshalNode(node);
4577
+ C._ts_query_captures_wasm(
4578
+ this[0],
4579
+ node.tree[0],
4580
+ startPosition.row,
4581
+ startPosition.column,
4582
+ endPosition.row,
4583
+ endPosition.column,
4544
4584
  startIndex,
4545
4585
  endIndex,
4546
- startContainingPosition,
4547
- endContainingPosition,
4586
+ startContainingPosition.row,
4587
+ startContainingPosition.column,
4588
+ endContainingPosition.row,
4589
+ endContainingPosition.column,
4548
4590
  startContainingIndex,
4549
4591
  endContainingIndex,
4550
4592
  matchLimit,
4551
- maxStartDepth,
4552
- progressCallback
4553
- } = prepareQuery(this, options);
4554
- const callback = progressCallback;
4555
- return executeQuery(
4556
- callback ? (state) => callback(state) === true : void 0,
4557
- () => {
4558
- marshalNode(node);
4559
- C._ts_query_captures_wasm(
4560
- this[0],
4561
- node.tree[0],
4562
- startPosition.row,
4563
- startPosition.column,
4564
- endPosition.row,
4565
- endPosition.column,
4566
- startIndex,
4567
- endIndex,
4568
- startContainingPosition.row,
4569
- startContainingPosition.column,
4570
- endContainingPosition.row,
4571
- endContainingPosition.column,
4572
- startContainingIndex,
4573
- endContainingIndex,
4574
- matchLimit,
4575
- maxStartDepth
4576
- );
4577
- },
4578
- (exceededMatchLimit) => {
4579
- this.matchLimit = matchLimit;
4580
- this.exceededMatchLimit = exceededMatchLimit;
4581
- },
4582
- (count, startAddress) => {
4583
- const result = new Array();
4584
- const captures = new Array();
4585
- let address = startAddress;
4586
- for (let i2 = 0; i2 < count; i2++) {
4587
- const patternIndex = C.getValue(address, "i32");
4588
- address += SIZE_OF_INT;
4589
- const captureCount = C.getValue(address, "i32");
4590
- address += SIZE_OF_INT;
4591
- const captureIndex = C.getValue(address, "i32");
4592
- address += SIZE_OF_INT;
4593
- captures.length = captureCount;
4594
- address = unmarshalCaptures(this, node.tree, address, patternIndex, captures);
4595
- if (this.textPredicates[patternIndex].every((p) => p(captures))) {
4596
- const capture = captures[captureIndex];
4597
- capture.setProperties = this.setProperties[patternIndex];
4598
- capture.assertedProperties = this.assertedProperties[patternIndex];
4599
- capture.refutedProperties = this.refutedProperties[patternIndex];
4600
- result.push(capture);
4601
- }
4602
- }
4603
- return result;
4604
- }
4593
+ maxStartDepth
4605
4594
  );
4595
+ const count = C.getValue(TRANSFER_BUFFER, "i32");
4596
+ const startAddress = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
4597
+ const didExceedMatchLimit = C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, "i32");
4598
+ const result = new Array();
4599
+ this.exceededMatchLimit = Boolean(didExceedMatchLimit);
4600
+ const captures = new Array();
4601
+ let address = startAddress;
4602
+ for (let i2 = 0; i2 < count; i2++) {
4603
+ const patternIndex = C.getValue(address, "i32");
4604
+ address += SIZE_OF_INT;
4605
+ const captureCount = C.getValue(address, "i32");
4606
+ address += SIZE_OF_INT;
4607
+ const captureIndex = C.getValue(address, "i32");
4608
+ address += SIZE_OF_INT;
4609
+ captures.length = captureCount;
4610
+ address = unmarshalCaptures(this, node.tree, address, patternIndex, captures);
4611
+ if (this.textPredicates[patternIndex].every((p) => p(captures))) {
4612
+ const capture = captures[captureIndex];
4613
+ const setProperties = this.setProperties[patternIndex];
4614
+ capture.setProperties = setProperties;
4615
+ const assertedProperties = this.assertedProperties[patternIndex];
4616
+ capture.assertedProperties = assertedProperties;
4617
+ const refutedProperties = this.refutedProperties[patternIndex];
4618
+ capture.refutedProperties = refutedProperties;
4619
+ result.push(capture);
4620
+ }
4621
+ }
4622
+ C._free(startAddress);
4623
+ C.currentQueryProgressCallback = null;
4624
+ return result;
4606
4625
  }
4607
4626
  /** Get the predicates for a given pattern. */
4608
4627
  predicatesForPattern(patternIndex) {
@@ -4643,25 +4662,23 @@ var Query = class {
4643
4662
  didExceedMatchLimit() {
4644
4663
  return this.exceededMatchLimit;
4645
4664
  }
4646
- /** Get the index where the given pattern starts in the query's source. */
4665
+ /** Get the byte offset where the given pattern starts in the query's source. */
4647
4666
  startIndexForPattern(patternIndex) {
4648
4667
  if (patternIndex >= this.predicates.length) {
4649
4668
  throw new Error(
4650
4669
  `Pattern index is ${patternIndex} but the pattern count is ${this.predicates.length}`
4651
4670
  );
4652
4671
  }
4653
- const byteOffset = C._ts_query_start_byte_for_pattern(this[0], patternIndex);
4654
- return indexForByteOffset(this.source, byteOffset);
4672
+ return C._ts_query_start_byte_for_pattern(this[0], patternIndex);
4655
4673
  }
4656
- /** Get the index where the given pattern ends in the query's source. */
4674
+ /** Get the byte offset where the given pattern ends in the query's source. */
4657
4675
  endIndexForPattern(patternIndex) {
4658
4676
  if (patternIndex >= this.predicates.length) {
4659
4677
  throw new Error(
4660
4678
  `Pattern index is ${patternIndex} but the pattern count is ${this.predicates.length}`
4661
4679
  );
4662
4680
  }
4663
- const byteOffset = C._ts_query_end_byte_for_pattern(this[0], patternIndex);
4664
- return indexForByteOffset(this.source, byteOffset);
4681
+ return C._ts_query_end_byte_for_pattern(this[0], patternIndex);
4665
4682
  }
4666
4683
  /** Get the number of patterns in the query. */
4667
4684
  patternCount() {
@@ -4680,91 +4697,15 @@ var Query = class {
4680
4697
  return C._ts_query_is_pattern_non_local(this[0], patternIndex) === 1;
4681
4698
  }
4682
4699
  /**
4683
- * Check if the step at the given index in the query's source is 'definite'.
4700
+ * Check if a given step in a query is 'definite'.
4684
4701
  *
4685
4702
  * A query step is 'definite' if its parent pattern will be guaranteed to
4686
4703
  * match successfully once it reaches the step.
4687
4704
  */
4688
- isPatternGuaranteedAtStep(index) {
4689
- const byteOffset = C.lengthBytesUTF8(this.source.slice(0, index));
4690
- return C._ts_query_is_pattern_guaranteed_at_step(this[0], byteOffset) === 1;
4705
+ isPatternGuaranteedAtStep(byteIndex) {
4706
+ return C._ts_query_is_pattern_guaranteed_at_step(this[0], byteIndex) === 1;
4691
4707
  }
4692
4708
  };
4693
- function prepareQuery(query, options) {
4694
- const parameters = {
4695
- startPosition: options.startPosition ?? ZERO_POINT,
4696
- endPosition: options.endPosition ?? ZERO_POINT,
4697
- startIndex: options.startIndex ?? 0,
4698
- endIndex: options.endIndex ?? 0,
4699
- startContainingPosition: options.startContainingPosition ?? ZERO_POINT,
4700
- endContainingPosition: options.endContainingPosition ?? ZERO_POINT,
4701
- startContainingIndex: options.startContainingIndex ?? 0,
4702
- endContainingIndex: options.endContainingIndex ?? 0,
4703
- matchLimit: options.matchLimit ?? 4294967295,
4704
- maxStartDepth: options.maxStartDepth ?? 4294967295,
4705
- progressCallback: options.progressCallback
4706
- };
4707
- const {
4708
- startPosition,
4709
- endPosition,
4710
- startIndex,
4711
- endIndex,
4712
- startContainingPosition,
4713
- endContainingPosition,
4714
- startContainingIndex,
4715
- endContainingIndex,
4716
- matchLimit
4717
- } = parameters;
4718
- if (typeof matchLimit !== "number") {
4719
- throw new Error("Arguments must be numbers");
4720
- }
4721
- query.matchLimit = matchLimit;
4722
- if (endIndex !== 0 && startIndex > endIndex) {
4723
- throw new Error("`startIndex` cannot be greater than `endIndex`");
4724
- }
4725
- if (endPosition !== ZERO_POINT && (startPosition.row > endPosition.row || startPosition.row === endPosition.row && startPosition.column > endPosition.column)) {
4726
- throw new Error("`startPosition` cannot be greater than `endPosition`");
4727
- }
4728
- if (endContainingIndex !== 0 && startContainingIndex > endContainingIndex) {
4729
- throw new Error("`startContainingIndex` cannot be greater than `endContainingIndex`");
4730
- }
4731
- if (endContainingPosition !== ZERO_POINT && (startContainingPosition.row > endContainingPosition.row || startContainingPosition.row === endContainingPosition.row && startContainingPosition.column > endContainingPosition.column)) {
4732
- throw new Error("`startContainingPosition` cannot be greater than `endContainingPosition`");
4733
- }
4734
- return parameters;
4735
- }
4736
- __name(prepareQuery, "prepareQuery");
4737
- function executeQuery(progressCallback, execute, updateState, readResult) {
4738
- const previousCallback = C.currentQueryProgressCallback;
4739
- let callbackFailure;
4740
- C.currentQueryProgressCallback = progressCallback ? (state) => {
4741
- try {
4742
- return progressCallback(state);
4743
- } catch (error) {
4744
- callbackFailure = { error };
4745
- return true;
4746
- }
4747
- } : null;
4748
- try {
4749
- execute();
4750
- } finally {
4751
- C.currentQueryProgressCallback = previousCallback;
4752
- }
4753
- const count = C.getValue(TRANSFER_BUFFER, "i32");
4754
- const address = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
4755
- const exceededMatchLimit = Boolean(C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, "i32"));
4756
- try {
4757
- updateState(exceededMatchLimit);
4758
- if (callbackFailure) {
4759
- throw callbackFailure.error;
4760
- }
4761
- return readResult(count, address);
4762
- } finally {
4763
- C._free(address);
4764
- updateState(exceededMatchLimit);
4765
- }
4766
- }
4767
- __name(executeQuery, "executeQuery");
4768
4709
  // Annotate the CommonJS export names for ESM import in node:
4769
4710
  0 && (module.exports = {
4770
4711
  CaptureQuantifier,