@willbooster/web-tree-sitter 2.0.20 → 2.0.22

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.
@@ -808,6 +808,11 @@
808
808
  * if query execution should be cancelled. You can also use this to instrument query execution
809
809
  * and check where the query is at in the document. The progress callback takes a single argument,
810
810
  * which is a {@link QueryState} representing the current state of the query.
811
+ * Return `true` to cancel execution, or `false` or nothing to continue.
812
+ * Capture observers may return incidental values; only `true` cancels capture execution.
813
+ * For matches, legacy WebAssembly conversion can treat incidental numeric returns, such as
814
+ * the length returned by Array.push, as cancellation. Use a block body with no return value
815
+ * when observing progress. Nested queries preserve the outer execution and its callback.
811
816
  */
812
817
  progressCallback?: (state: QueryState) => void;
813
818
  }
@@ -56,6 +56,6 @@
56
56
  null,
57
57
  null
58
58
  ],
59
- "mappings": ";;;;;;kBASiBA,KAAKA;;;;;;;;;;kBAYLC,KAAKA;;;;;;;;;;;;;aAsCVC,aAAaA;;;;aAKbC,gBAAgBA;;;;;;aAOhBC,WAAWA;;kBChENC,iBAAiBA;;;;;;;cCLrBC,IAAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBCgBAC,YAAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAmCZC,UAAUA;;;;;;;;;;;;;;YAuBhBC,gBAAgBA;;;;;YAqBhBC,sBAAsBA;;;;;cAWpBC,MAAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WCrGFC,gBAAgBA;;;;;;;;;cAYpBC,QAAQA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cCiBRC,IAAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cC1BJC,IAAIA;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oBA;;;;;;;;;WAOpBC,mBAAmBA;;;;cAyUvBC,KAAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cC9fLC,iBAAiBA",
60
60
  "ignoreList": []
61
61
  }
@@ -808,6 +808,11 @@
808
808
  * if query execution should be cancelled. You can also use this to instrument query execution
809
809
  * and check where the query is at in the document. The progress callback takes a single argument,
810
810
  * which is a {@link QueryState} representing the current state of the query.
811
+ * Return `true` to cancel execution, or `false` or nothing to continue.
812
+ * Capture observers may return incidental values; only `true` cancels capture execution.
813
+ * For matches, legacy WebAssembly conversion can treat incidental numeric returns, such as
814
+ * the length returned by Array.push, as cancellation. Use a block body with no return value
815
+ * when observing progress. Nested queries preserve the outer execution and its callback.
811
816
  */
812
817
  progressCallback?: (state: QueryState) => void;
813
818
  }
@@ -56,6 +56,6 @@
56
56
  null,
57
57
  null
58
58
  ],
59
- "mappings": ";;;;;;kBASiBA,KAAKA;;;;;;;;;;kBAYLC,KAAKA;;;;;;;;;;;;;aAsCVC,aAAaA;;;;aAKbC,gBAAgBA;;;;;;aAOhBC,WAAWA;;kBChENC,iBAAiBA;;;;;;;cCLrBC,IAAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBCgBAC,YAAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAmCZC,UAAUA;;;;;;;;;;;;;;YAuBhBC,gBAAgBA;;;;;YAqBhBC,sBAAsBA;;;;;cAWpBC,MAAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WCrGFC,gBAAgBA;;;;;;;;;cAYpBC,QAAQA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;cA2BfC,iBAAiBA;;;;;;;;aAAjBA,iBAAiBA;;;;;;;;;;;;aAajBC,aAAaA;;;;;;WAORC,oBAAoBA;;;;;;;;;WAOpBC,mBAAmBA;;;;cAyUvBC,KAAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cC9fLC,iBAAiBA",
60
60
  "ignoreList": []
61
61
  }
@@ -3829,84 +3829,72 @@ var Query = class {
3829
3829
  * @param {QueryOptions} options - Options for query execution.
3830
3830
  */
3831
3831
  matches(node, options = {}) {
3832
- const startPosition = options.startPosition ?? ZERO_POINT;
3833
- const endPosition = options.endPosition ?? ZERO_POINT;
3834
- const startIndex = options.startIndex ?? 0;
3835
- const endIndex = options.endIndex ?? 0;
3836
- const startContainingPosition = options.startContainingPosition ?? ZERO_POINT;
3837
- const endContainingPosition = options.endContainingPosition ?? ZERO_POINT;
3838
- const startContainingIndex = options.startContainingIndex ?? 0;
3839
- const endContainingIndex = options.endContainingIndex ?? 0;
3840
- const matchLimit = options.matchLimit ?? 4294967295;
3841
- const maxStartDepth = options.maxStartDepth ?? 4294967295;
3842
- const progressCallback = options.progressCallback;
3843
- if (typeof matchLimit !== "number") {
3844
- throw new Error("Arguments must be numbers");
3845
- }
3846
- this.matchLimit = matchLimit;
3847
- if (endIndex !== 0 && startIndex > endIndex) {
3848
- throw new Error("`startIndex` cannot be greater than `endIndex`");
3849
- }
3850
- if (endPosition !== ZERO_POINT && (startPosition.row > endPosition.row || startPosition.row === endPosition.row && startPosition.column > endPosition.column)) {
3851
- throw new Error("`startPosition` cannot be greater than `endPosition`");
3852
- }
3853
- if (endContainingIndex !== 0 && startContainingIndex > endContainingIndex) {
3854
- throw new Error("`startContainingIndex` cannot be greater than `endContainingIndex`");
3855
- }
3856
- if (endContainingPosition !== ZERO_POINT && (startContainingPosition.row > endContainingPosition.row || startContainingPosition.row === endContainingPosition.row && startContainingPosition.column > endContainingPosition.column)) {
3857
- throw new Error("`startContainingPosition` cannot be greater than `endContainingPosition`");
3858
- }
3859
- if (progressCallback) {
3860
- C.currentQueryProgressCallback = progressCallback;
3861
- }
3862
- marshalNode(node);
3863
- C._ts_query_matches_wasm(
3864
- this[0],
3865
- node.tree[0],
3866
- startPosition.row,
3867
- startPosition.column,
3868
- endPosition.row,
3869
- endPosition.column,
3832
+ const {
3833
+ startPosition,
3834
+ endPosition,
3870
3835
  startIndex,
3871
3836
  endIndex,
3872
- startContainingPosition.row,
3873
- startContainingPosition.column,
3874
- endContainingPosition.row,
3875
- endContainingPosition.column,
3837
+ startContainingPosition,
3838
+ endContainingPosition,
3876
3839
  startContainingIndex,
3877
3840
  endContainingIndex,
3878
3841
  matchLimit,
3879
- maxStartDepth
3880
- );
3881
- const rawCount = C.getValue(TRANSFER_BUFFER, "i32");
3882
- const startAddress = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
3883
- const didExceedMatchLimit = C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, "i32");
3884
- const result = new Array(rawCount);
3885
- this.exceededMatchLimit = Boolean(didExceedMatchLimit);
3886
- let filteredCount = 0;
3887
- let address = startAddress;
3888
- for (let i2 = 0; i2 < rawCount; i2++) {
3889
- const patternIndex = C.getValue(address, "i32");
3890
- address += SIZE_OF_INT;
3891
- const captureCount = C.getValue(address, "i32");
3892
- address += SIZE_OF_INT;
3893
- const captures = new Array(captureCount);
3894
- address = unmarshalCaptures(this, node.tree, address, patternIndex, captures);
3895
- if (this.textPredicates[patternIndex].every((p) => p(captures))) {
3896
- result[filteredCount] = { patternIndex, captures };
3897
- const setProperties = this.setProperties[patternIndex];
3898
- result[filteredCount].setProperties = setProperties;
3899
- const assertedProperties = this.assertedProperties[patternIndex];
3900
- result[filteredCount].assertedProperties = assertedProperties;
3901
- const refutedProperties = this.refutedProperties[patternIndex];
3902
- result[filteredCount].refutedProperties = refutedProperties;
3903
- filteredCount++;
3842
+ maxStartDepth,
3843
+ progressCallback
3844
+ } = prepareQuery(this, options);
3845
+ return executeQuery(
3846
+ progressCallback,
3847
+ () => {
3848
+ marshalNode(node);
3849
+ C._ts_query_matches_wasm(
3850
+ this[0],
3851
+ node.tree[0],
3852
+ startPosition.row,
3853
+ startPosition.column,
3854
+ endPosition.row,
3855
+ endPosition.column,
3856
+ startIndex,
3857
+ endIndex,
3858
+ startContainingPosition.row,
3859
+ startContainingPosition.column,
3860
+ endContainingPosition.row,
3861
+ endContainingPosition.column,
3862
+ startContainingIndex,
3863
+ endContainingIndex,
3864
+ matchLimit,
3865
+ maxStartDepth
3866
+ );
3867
+ },
3868
+ (exceededMatchLimit) => {
3869
+ this.matchLimit = matchLimit;
3870
+ this.exceededMatchLimit = exceededMatchLimit;
3871
+ },
3872
+ (rawCount, startAddress) => {
3873
+ const result = new Array(rawCount);
3874
+ let filteredCount = 0;
3875
+ let address = startAddress;
3876
+ for (let i2 = 0; i2 < rawCount; i2++) {
3877
+ const patternIndex = C.getValue(address, "i32");
3878
+ address += SIZE_OF_INT;
3879
+ const captureCount = C.getValue(address, "i32");
3880
+ address += SIZE_OF_INT;
3881
+ const captures = new Array(captureCount);
3882
+ address = unmarshalCaptures(this, node.tree, address, patternIndex, captures);
3883
+ if (this.textPredicates[patternIndex].every((p) => p(captures))) {
3884
+ result[filteredCount] = { patternIndex, captures };
3885
+ const setProperties = this.setProperties[patternIndex];
3886
+ result[filteredCount].setProperties = setProperties;
3887
+ const assertedProperties = this.assertedProperties[patternIndex];
3888
+ result[filteredCount].assertedProperties = assertedProperties;
3889
+ const refutedProperties = this.refutedProperties[patternIndex];
3890
+ result[filteredCount].refutedProperties = refutedProperties;
3891
+ filteredCount++;
3892
+ }
3893
+ }
3894
+ result.length = filteredCount;
3895
+ return result;
3904
3896
  }
3905
- }
3906
- result.length = filteredCount;
3907
- C._free(startAddress);
3908
- C.currentQueryProgressCallback = null;
3909
- return result;
3897
+ );
3910
3898
  }
3911
3899
  /**
3912
3900
  * Iterate over all of the individual captures in the order that they
@@ -3920,85 +3908,71 @@ var Query = class {
3920
3908
  * @param {QueryOptions} options - Options for query execution.
3921
3909
  */
3922
3910
  captures(node, options = {}) {
3923
- const startPosition = options.startPosition ?? ZERO_POINT;
3924
- const endPosition = options.endPosition ?? ZERO_POINT;
3925
- const startIndex = options.startIndex ?? 0;
3926
- const endIndex = options.endIndex ?? 0;
3927
- const startContainingPosition = options.startContainingPosition ?? ZERO_POINT;
3928
- const endContainingPosition = options.endContainingPosition ?? ZERO_POINT;
3929
- const startContainingIndex = options.startContainingIndex ?? 0;
3930
- const endContainingIndex = options.endContainingIndex ?? 0;
3931
- const matchLimit = options.matchLimit ?? 4294967295;
3932
- const maxStartDepth = options.maxStartDepth ?? 4294967295;
3933
- const progressCallback = options.progressCallback;
3934
- if (typeof matchLimit !== "number") {
3935
- throw new Error("Arguments must be numbers");
3936
- }
3937
- this.matchLimit = matchLimit;
3938
- if (endIndex !== 0 && startIndex > endIndex) {
3939
- throw new Error("`startIndex` cannot be greater than `endIndex`");
3940
- }
3941
- if (endPosition !== ZERO_POINT && (startPosition.row > endPosition.row || startPosition.row === endPosition.row && startPosition.column > endPosition.column)) {
3942
- throw new Error("`startPosition` cannot be greater than `endPosition`");
3943
- }
3944
- if (endContainingIndex !== 0 && startContainingIndex > endContainingIndex) {
3945
- throw new Error("`startContainingIndex` cannot be greater than `endContainingIndex`");
3946
- }
3947
- if (endContainingPosition !== ZERO_POINT && (startContainingPosition.row > endContainingPosition.row || startContainingPosition.row === endContainingPosition.row && startContainingPosition.column > endContainingPosition.column)) {
3948
- throw new Error("`startContainingPosition` cannot be greater than `endContainingPosition`");
3949
- }
3950
- if (progressCallback) {
3951
- C.currentQueryProgressCallback = progressCallback;
3952
- }
3953
- marshalNode(node);
3954
- C._ts_query_captures_wasm(
3955
- this[0],
3956
- node.tree[0],
3957
- startPosition.row,
3958
- startPosition.column,
3959
- endPosition.row,
3960
- endPosition.column,
3911
+ const {
3912
+ startPosition,
3913
+ endPosition,
3961
3914
  startIndex,
3962
3915
  endIndex,
3963
- startContainingPosition.row,
3964
- startContainingPosition.column,
3965
- endContainingPosition.row,
3966
- endContainingPosition.column,
3916
+ startContainingPosition,
3917
+ endContainingPosition,
3967
3918
  startContainingIndex,
3968
3919
  endContainingIndex,
3969
3920
  matchLimit,
3970
- maxStartDepth
3971
- );
3972
- const count = C.getValue(TRANSFER_BUFFER, "i32");
3973
- const startAddress = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
3974
- const didExceedMatchLimit = C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, "i32");
3975
- const result = new Array();
3976
- this.exceededMatchLimit = Boolean(didExceedMatchLimit);
3977
- const captures = new Array();
3978
- let address = startAddress;
3979
- for (let i2 = 0; i2 < count; i2++) {
3980
- const patternIndex = C.getValue(address, "i32");
3981
- address += SIZE_OF_INT;
3982
- const captureCount = C.getValue(address, "i32");
3983
- address += SIZE_OF_INT;
3984
- const captureIndex = C.getValue(address, "i32");
3985
- address += SIZE_OF_INT;
3986
- captures.length = captureCount;
3987
- address = unmarshalCaptures(this, node.tree, address, patternIndex, captures);
3988
- if (this.textPredicates[patternIndex].every((p) => p(captures))) {
3989
- const capture = captures[captureIndex];
3990
- const setProperties = this.setProperties[patternIndex];
3991
- capture.setProperties = setProperties;
3992
- const assertedProperties = this.assertedProperties[patternIndex];
3993
- capture.assertedProperties = assertedProperties;
3994
- const refutedProperties = this.refutedProperties[patternIndex];
3995
- capture.refutedProperties = refutedProperties;
3996
- result.push(capture);
3921
+ maxStartDepth,
3922
+ progressCallback
3923
+ } = prepareQuery(this, options);
3924
+ const callback = progressCallback;
3925
+ return executeQuery(
3926
+ callback ? (state) => callback(state) === true : void 0,
3927
+ () => {
3928
+ marshalNode(node);
3929
+ C._ts_query_captures_wasm(
3930
+ this[0],
3931
+ node.tree[0],
3932
+ startPosition.row,
3933
+ startPosition.column,
3934
+ endPosition.row,
3935
+ endPosition.column,
3936
+ startIndex,
3937
+ endIndex,
3938
+ startContainingPosition.row,
3939
+ startContainingPosition.column,
3940
+ endContainingPosition.row,
3941
+ endContainingPosition.column,
3942
+ startContainingIndex,
3943
+ endContainingIndex,
3944
+ matchLimit,
3945
+ maxStartDepth
3946
+ );
3947
+ },
3948
+ (exceededMatchLimit) => {
3949
+ this.matchLimit = matchLimit;
3950
+ this.exceededMatchLimit = exceededMatchLimit;
3951
+ },
3952
+ (count, startAddress) => {
3953
+ const result = new Array();
3954
+ const captures = new Array();
3955
+ let address = startAddress;
3956
+ for (let i2 = 0; i2 < count; i2++) {
3957
+ const patternIndex = C.getValue(address, "i32");
3958
+ address += SIZE_OF_INT;
3959
+ const captureCount = C.getValue(address, "i32");
3960
+ address += SIZE_OF_INT;
3961
+ const captureIndex = C.getValue(address, "i32");
3962
+ address += SIZE_OF_INT;
3963
+ captures.length = captureCount;
3964
+ address = unmarshalCaptures(this, node.tree, address, patternIndex, captures);
3965
+ if (this.textPredicates[patternIndex].every((p) => p(captures))) {
3966
+ const capture = captures[captureIndex];
3967
+ capture.setProperties = this.setProperties[patternIndex];
3968
+ capture.assertedProperties = this.assertedProperties[patternIndex];
3969
+ capture.refutedProperties = this.refutedProperties[patternIndex];
3970
+ result.push(capture);
3971
+ }
3972
+ }
3973
+ return result;
3997
3974
  }
3998
- }
3999
- C._free(startAddress);
4000
- C.currentQueryProgressCallback = null;
4001
- return result;
3975
+ );
4002
3976
  }
4003
3977
  /** Get the predicates for a given pattern. */
4004
3978
  predicatesForPattern(patternIndex) {
@@ -4083,6 +4057,81 @@ var Query = class {
4083
4057
  return C._ts_query_is_pattern_guaranteed_at_step(this[0], byteIndex) === 1;
4084
4058
  }
4085
4059
  };
4060
+ function prepareQuery(query, options) {
4061
+ const parameters = {
4062
+ startPosition: options.startPosition ?? ZERO_POINT,
4063
+ endPosition: options.endPosition ?? ZERO_POINT,
4064
+ startIndex: options.startIndex ?? 0,
4065
+ endIndex: options.endIndex ?? 0,
4066
+ startContainingPosition: options.startContainingPosition ?? ZERO_POINT,
4067
+ endContainingPosition: options.endContainingPosition ?? ZERO_POINT,
4068
+ startContainingIndex: options.startContainingIndex ?? 0,
4069
+ endContainingIndex: options.endContainingIndex ?? 0,
4070
+ matchLimit: options.matchLimit ?? 4294967295,
4071
+ maxStartDepth: options.maxStartDepth ?? 4294967295,
4072
+ progressCallback: options.progressCallback
4073
+ };
4074
+ const {
4075
+ startPosition,
4076
+ endPosition,
4077
+ startIndex,
4078
+ endIndex,
4079
+ startContainingPosition,
4080
+ endContainingPosition,
4081
+ startContainingIndex,
4082
+ endContainingIndex,
4083
+ matchLimit
4084
+ } = parameters;
4085
+ if (typeof matchLimit !== "number") {
4086
+ throw new Error("Arguments must be numbers");
4087
+ }
4088
+ query.matchLimit = matchLimit;
4089
+ if (endIndex !== 0 && startIndex > endIndex) {
4090
+ throw new Error("`startIndex` cannot be greater than `endIndex`");
4091
+ }
4092
+ if (endPosition !== ZERO_POINT && (startPosition.row > endPosition.row || startPosition.row === endPosition.row && startPosition.column > endPosition.column)) {
4093
+ throw new Error("`startPosition` cannot be greater than `endPosition`");
4094
+ }
4095
+ if (endContainingIndex !== 0 && startContainingIndex > endContainingIndex) {
4096
+ throw new Error("`startContainingIndex` cannot be greater than `endContainingIndex`");
4097
+ }
4098
+ if (endContainingPosition !== ZERO_POINT && (startContainingPosition.row > endContainingPosition.row || startContainingPosition.row === endContainingPosition.row && startContainingPosition.column > endContainingPosition.column)) {
4099
+ throw new Error("`startContainingPosition` cannot be greater than `endContainingPosition`");
4100
+ }
4101
+ return parameters;
4102
+ }
4103
+ __name(prepareQuery, "prepareQuery");
4104
+ function executeQuery(progressCallback, execute, updateState, readResult) {
4105
+ const previousCallback = C.currentQueryProgressCallback;
4106
+ let callbackFailure;
4107
+ C.currentQueryProgressCallback = progressCallback ? (state) => {
4108
+ try {
4109
+ return progressCallback(state);
4110
+ } catch (error) {
4111
+ callbackFailure = { error };
4112
+ return true;
4113
+ }
4114
+ } : null;
4115
+ try {
4116
+ execute();
4117
+ } finally {
4118
+ C.currentQueryProgressCallback = previousCallback;
4119
+ }
4120
+ const count = C.getValue(TRANSFER_BUFFER, "i32");
4121
+ const address = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
4122
+ const exceededMatchLimit = Boolean(C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, "i32"));
4123
+ try {
4124
+ updateState(exceededMatchLimit);
4125
+ if (callbackFailure) {
4126
+ throw callbackFailure.error;
4127
+ }
4128
+ return readResult(count, address);
4129
+ } finally {
4130
+ C._free(address);
4131
+ updateState(exceededMatchLimit);
4132
+ }
4133
+ }
4134
+ __name(executeQuery, "executeQuery");
4086
4135
  export {
4087
4136
  CaptureQuantifier,
4088
4137
  Edit,