@willbooster/web-tree-sitter 10.0.4 → 11.0.0

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.
@@ -363,29 +363,17 @@ var Tree = class _Tree {
363
363
  };
364
364
 
365
365
  // src/tree_cursor.ts
366
- var finalizer3 = newFinalizer((address) => {
367
- C._ts_tree_cursor_delete_wasm(address);
366
+ var finalizer3 = newFinalizer((handles) => {
367
+ marshalTreeCursor({ handles });
368
+ C._ts_tree_cursor_delete_wasm(0);
368
369
  });
369
370
  var TreeCursor = class _TreeCursor {
370
371
  static {
371
372
  __name(this, "TreeCursor");
372
373
  }
373
374
  /** @internal */
374
- // @ts-expect-error: never read
375
- [0] = 0;
376
- // Internal handle for Wasm
377
- /** @internal */
378
- // @ts-expect-error: never read
379
- [1] = 0;
380
- // Internal handle for Wasm
381
- /** @internal */
382
- // @ts-expect-error: never read
383
- [2] = 0;
384
- // Internal handle for Wasm
385
- /** @internal */
386
- // @ts-expect-error: never read
387
- [3] = 0;
388
- // Internal handle for Wasm
375
+ handles = [0, 0, 0, 0];
376
+ // Internal handles for Wasm, shared with the finalizer.
389
377
  /** @internal */
390
378
  tree;
391
379
  /** @internal */
@@ -393,22 +381,20 @@ var TreeCursor = class _TreeCursor {
393
381
  assertInternal(internal);
394
382
  this.tree = tree;
395
383
  unmarshalTreeCursor(this);
396
- finalizer3?.register(this, this.tree[0], this);
384
+ finalizer3?.register(this, this.handles, this);
397
385
  }
398
386
  /** Creates a deep copy of the tree cursor. This allocates new memory. */
399
387
  copy() {
400
388
  marshalTreeCursor(this);
401
- const copy = new _TreeCursor(INTERNAL, this.tree);
402
389
  C._ts_tree_cursor_copy_wasm(this.tree[0]);
403
- unmarshalTreeCursor(copy);
404
- return copy;
390
+ return new _TreeCursor(INTERNAL, this.tree);
405
391
  }
406
392
  /** Delete the tree cursor, freeing its resources. */
407
393
  delete() {
408
394
  finalizer3?.unregister(this);
409
395
  marshalTreeCursor(this);
410
396
  C._ts_tree_cursor_delete_wasm(this.tree[0]);
411
- this[0] = this[1] = this[2] = 0;
397
+ this.handles.fill(0);
412
398
  }
413
399
  /** Get the tree cursor's current {@link Node}. */
414
400
  get currentNode() {
@@ -605,7 +591,7 @@ var TreeCursor = class _TreeCursor {
605
591
  }
606
592
  /**
607
593
  * Move this cursor to the first child of its current node that contains or
608
- * starts after the given byte offset.
594
+ * starts after the given index.
609
595
  *
610
596
  * This returns `true` if the cursor successfully moved to a child node, and returns
611
597
  * `false` if no such child was found.
@@ -619,10 +605,10 @@ var TreeCursor = class _TreeCursor {
619
605
  }
620
606
  /**
621
607
  * Move this cursor to the first child of its current node that contains or
622
- * starts after the given byte offset.
608
+ * starts after the given position.
623
609
  *
624
- * This returns the index of the child node if one was found, and returns
625
- * `null` if no such child was found.
610
+ * This returns `true` if the cursor successfully moved to a child node, and returns
611
+ * `false` if no such child was found.
626
612
  */
627
613
  gotoFirstChildForPosition(goalPosition) {
628
614
  marshalTreeCursor(this);
@@ -638,8 +624,9 @@ var TreeCursor = class _TreeCursor {
638
624
  reset(node) {
639
625
  marshalNode(node);
640
626
  marshalTreeCursor(this, TRANSFER_BUFFER + SIZE_OF_NODE);
641
- C._ts_tree_cursor_reset_wasm(this.tree[0]);
627
+ C._ts_tree_cursor_reset_wasm(node.tree[0]);
642
628
  unmarshalTreeCursor(this);
629
+ this.tree = node.tree;
643
630
  }
644
631
  /**
645
632
  * Re-initialize a tree cursor to the same position as another cursor.
@@ -652,6 +639,7 @@ var TreeCursor = class _TreeCursor {
652
639
  marshalTreeCursor(cursor, TRANSFER_BUFFER + SIZE_OF_CURSOR);
653
640
  C._ts_tree_cursor_reset_to_wasm(this.tree[0], cursor.tree[0]);
654
641
  unmarshalTreeCursor(this);
642
+ this.tree = cursor.tree;
655
643
  }
656
644
  };
657
645
 
@@ -1012,16 +1000,14 @@ var Node = class {
1012
1000
  if (!Array.isArray(types)) types = [types];
1013
1001
  const symbols = [];
1014
1002
  const typesBySymbol = this.tree.language.types;
1015
- for (const node_type of types) {
1016
- if (node_type == "ERROR") {
1017
- symbols.push(65535);
1018
- }
1019
- }
1020
1003
  for (let i2 = 0, n = typesBySymbol.length; i2 < n; i2++) {
1021
1004
  if (types.includes(typesBySymbol[i2])) {
1022
1005
  symbols.push(i2);
1023
1006
  }
1024
1007
  }
1008
+ if (types.includes("ERROR")) {
1009
+ symbols.push(65535);
1010
+ }
1025
1011
  const symbolsAddress = C._malloc(SIZE_OF_INT * symbols.length);
1026
1012
  for (let i2 = 0, n = symbols.length; i2 < n; i2++) {
1027
1013
  C.setValue(symbolsAddress + i2 * SIZE_OF_INT, symbols[i2], "i32");
@@ -1177,31 +1163,9 @@ var Node = class {
1177
1163
  * you want to keep and continue to use after an edit.
1178
1164
  */
1179
1165
  edit(edit) {
1180
- if (this.startIndex >= edit.oldEndIndex) {
1181
- this.startIndex = edit.newEndIndex + (this.startIndex - edit.oldEndIndex);
1182
- let subbedPointRow;
1183
- let subbedPointColumn;
1184
- if (this.startPosition.row > edit.oldEndPosition.row) {
1185
- subbedPointRow = this.startPosition.row - edit.oldEndPosition.row;
1186
- subbedPointColumn = this.startPosition.column;
1187
- } else {
1188
- subbedPointRow = 0;
1189
- subbedPointColumn = this.startPosition.column;
1190
- if (this.startPosition.column >= edit.oldEndPosition.column) {
1191
- subbedPointColumn = this.startPosition.column - edit.oldEndPosition.column;
1192
- }
1193
- }
1194
- if (subbedPointRow > 0) {
1195
- this.startPosition.row += subbedPointRow;
1196
- this.startPosition.column = subbedPointColumn;
1197
- } else {
1198
- this.startPosition.column += subbedPointColumn;
1199
- }
1200
- } else if (this.startIndex > edit.startIndex) {
1201
- this.startIndex = edit.newEndIndex;
1202
- this.startPosition.row = edit.newEndPosition.row;
1203
- this.startPosition.column = edit.newEndPosition.column;
1204
- }
1166
+ const { point, index } = edit.editPoint(this.startPosition, this.startIndex);
1167
+ this.startPosition = point;
1168
+ this.startIndex = index;
1205
1169
  }
1206
1170
  /** Get the S-expression representation of this node. */
1207
1171
  toString() {
@@ -1259,18 +1223,18 @@ function unmarshalNode(tree, address = TRANSFER_BUFFER) {
1259
1223
  return result;
1260
1224
  }
1261
1225
  __name(unmarshalNode, "unmarshalNode");
1262
- function marshalTreeCursor(cursor, address = TRANSFER_BUFFER) {
1263
- C.setValue(address + 0 * SIZE_OF_INT, cursor[0], "i32");
1264
- C.setValue(address + 1 * SIZE_OF_INT, cursor[1], "i32");
1265
- C.setValue(address + 2 * SIZE_OF_INT, cursor[2], "i32");
1266
- C.setValue(address + 3 * SIZE_OF_INT, cursor[3], "i32");
1226
+ function marshalTreeCursor({ handles }, address = TRANSFER_BUFFER) {
1227
+ C.setValue(address + 0 * SIZE_OF_INT, handles[0], "i32");
1228
+ C.setValue(address + 1 * SIZE_OF_INT, handles[1], "i32");
1229
+ C.setValue(address + 2 * SIZE_OF_INT, handles[2], "i32");
1230
+ C.setValue(address + 3 * SIZE_OF_INT, handles[3], "i32");
1267
1231
  }
1268
1232
  __name(marshalTreeCursor, "marshalTreeCursor");
1269
- function unmarshalTreeCursor(cursor) {
1270
- cursor[0] = C.getValue(TRANSFER_BUFFER + 0 * SIZE_OF_INT, "i32");
1271
- cursor[1] = C.getValue(TRANSFER_BUFFER + 1 * SIZE_OF_INT, "i32");
1272
- cursor[2] = C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, "i32");
1273
- cursor[3] = C.getValue(TRANSFER_BUFFER + 3 * SIZE_OF_INT, "i32");
1233
+ function unmarshalTreeCursor({ handles }) {
1234
+ handles[0] = C.getValue(TRANSFER_BUFFER + 0 * SIZE_OF_INT, "i32");
1235
+ handles[1] = C.getValue(TRANSFER_BUFFER + 1 * SIZE_OF_INT, "i32");
1236
+ handles[2] = C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, "i32");
1237
+ handles[3] = C.getValue(TRANSFER_BUFFER + 3 * SIZE_OF_INT, "i32");
1274
1238
  }
1275
1239
  __name(unmarshalTreeCursor, "unmarshalTreeCursor");
1276
1240
  function marshalPoint(address, point) {
@@ -2358,7 +2322,7 @@ async function Module2(moduleArg = {}) {
2358
2322
  newDSO("__main__", 0, wasmImports);
2359
2323
  }
2360
2324
  };
2361
- var ___heap_base = 82352;
2325
+ var ___heap_base = 82384;
2362
2326
  var alignMemory = /* @__PURE__ */ __name((size, alignment) => {
2363
2327
  assert(alignment, "alignment argument is required");
2364
2328
  return Math.ceil(size / alignment) * alignment;
@@ -2989,12 +2953,12 @@ async function Module2(moduleArg = {}) {
2989
2953
  "value": "i32",
2990
2954
  "mutable": false
2991
2955
  }, 1024);
2992
- var ___stack_high = 82352;
2993
- var ___stack_low = 16816;
2956
+ var ___stack_high = 82384;
2957
+ var ___stack_low = 16848;
2994
2958
  var ___stack_pointer = new WebAssembly.Global({
2995
2959
  "value": "i32",
2996
2960
  "mutable": true
2997
- }, 82352);
2961
+ }, 82384);
2998
2962
  var ___table_base = new WebAssembly.Global({
2999
2963
  "value": "i32",
3000
2964
  "mutable": false
@@ -3708,7 +3672,7 @@ async function Module2(moduleArg = {}) {
3708
3672
  }
3709
3673
  __name(callMain, "callMain");
3710
3674
  function stackCheckInit() {
3711
- _emscripten_stack_set_limits(82352, 16816);
3675
+ _emscripten_stack_set_limits(82384, 16848);
3712
3676
  writeStackCookie();
3713
3677
  }
3714
3678
  __name(stackCheckInit, "stackCheckInit");
@@ -4251,6 +4215,10 @@ function parsePattern(index, stepType, stepValueId, captureNames, stringValues,
4251
4215
  }
4252
4216
  }
4253
4217
  __name(parsePattern, "parsePattern");
4218
+ function indexForByteOffset(source, byteOffset) {
4219
+ return new TextEncoder().encodeInto(source, new Uint8Array(byteOffset)).read;
4220
+ }
4221
+ __name(indexForByteOffset, "indexForByteOffset");
4254
4222
  var finalizer5 = newFinalizer((address) => {
4255
4223
  C._ts_query_delete(address);
4256
4224
  });
@@ -4265,6 +4233,8 @@ var Query = class {
4265
4233
  exceededMatchLimit;
4266
4234
  /** @internal */
4267
4235
  textPredicates;
4236
+ /** @internal */
4237
+ source;
4268
4238
  /** The names of the captures used in the query. */
4269
4239
  captureNames;
4270
4240
  /** The quantifiers of the captures used in the query. */
@@ -4404,6 +4374,7 @@ var Query = class {
4404
4374
  this.captureNames = captureNames;
4405
4375
  this.captureQuantifiers = captureQuantifiers;
4406
4376
  this.textPredicates = textPredicates;
4377
+ this.source = source;
4407
4378
  this.predicates = predicates;
4408
4379
  this.setProperties = setProperties;
4409
4380
  this.assertedProperties = assertedProperties;
@@ -4614,23 +4585,25 @@ var Query = class {
4614
4585
  didExceedMatchLimit() {
4615
4586
  return this.exceededMatchLimit;
4616
4587
  }
4617
- /** Get the byte offset where the given pattern starts in the query's source. */
4588
+ /** Get the index where the given pattern starts in the query's source. */
4618
4589
  startIndexForPattern(patternIndex) {
4619
4590
  if (patternIndex >= this.predicates.length) {
4620
4591
  throw new Error(
4621
4592
  `Pattern index is ${patternIndex} but the pattern count is ${this.predicates.length}`
4622
4593
  );
4623
4594
  }
4624
- return C._ts_query_start_byte_for_pattern(this[0], patternIndex);
4595
+ const byteOffset = C._ts_query_start_byte_for_pattern(this[0], patternIndex);
4596
+ return indexForByteOffset(this.source, byteOffset);
4625
4597
  }
4626
- /** Get the byte offset where the given pattern ends in the query's source. */
4598
+ /** Get the index where the given pattern ends in the query's source. */
4627
4599
  endIndexForPattern(patternIndex) {
4628
4600
  if (patternIndex >= this.predicates.length) {
4629
4601
  throw new Error(
4630
4602
  `Pattern index is ${patternIndex} but the pattern count is ${this.predicates.length}`
4631
4603
  );
4632
4604
  }
4633
- return C._ts_query_end_byte_for_pattern(this[0], patternIndex);
4605
+ const byteOffset = C._ts_query_end_byte_for_pattern(this[0], patternIndex);
4606
+ return indexForByteOffset(this.source, byteOffset);
4634
4607
  }
4635
4608
  /** Get the number of patterns in the query. */
4636
4609
  patternCount() {
@@ -4649,13 +4622,14 @@ var Query = class {
4649
4622
  return C._ts_query_is_pattern_non_local(this[0], patternIndex) === 1;
4650
4623
  }
4651
4624
  /**
4652
- * Check if a given step in a query is 'definite'.
4625
+ * Check if the step at the given index in the query's source is 'definite'.
4653
4626
  *
4654
4627
  * A query step is 'definite' if its parent pattern will be guaranteed to
4655
4628
  * match successfully once it reaches the step.
4656
4629
  */
4657
- isPatternGuaranteedAtStep(byteIndex) {
4658
- return C._ts_query_is_pattern_guaranteed_at_step(this[0], byteIndex) === 1;
4630
+ isPatternGuaranteedAtStep(index) {
4631
+ const byteOffset = C.lengthBytesUTF8(this.source.slice(0, index));
4632
+ return C._ts_query_is_pattern_guaranteed_at_step(this[0], byteOffset) === 1;
4659
4633
  }
4660
4634
  };
4661
4635
  function prepareQuery(query, options) {