@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.
- package/debug/web-tree-sitter.cjs +194 -145
- package/debug/web-tree-sitter.cjs.map +2 -2
- package/debug/web-tree-sitter.js +194 -145
- package/debug/web-tree-sitter.js.map +2 -2
- package/debug/web-tree-sitter.wasm +0 -0
- package/debug/web-tree-sitter.wasm.map +2 -2
- package/package.json +1 -1
- package/web-tree-sitter.cjs +194 -145
- package/web-tree-sitter.cjs.map +2 -2
- package/web-tree-sitter.d.cts +5 -0
- package/web-tree-sitter.d.cts.map +1 -1
- package/web-tree-sitter.d.ts +5 -0
- package/web-tree-sitter.d.ts.map +1 -1
- package/web-tree-sitter.js +194 -145
- package/web-tree-sitter.js.map +2 -2
- package/web-tree-sitter.wasm +0 -0
- package/web-tree-sitter.wasm.map +2 -2
- package/web-tree-sitter.web.js +194 -145
- package/web-tree-sitter.web.js.map +2 -2
package/web-tree-sitter.web.js
CHANGED
|
@@ -3861,84 +3861,72 @@ var Query = class {
|
|
|
3861
3861
|
* @param {QueryOptions} options - Options for query execution.
|
|
3862
3862
|
*/
|
|
3863
3863
|
matches(node, options = {}) {
|
|
3864
|
-
const
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
const endIndex = options.endIndex ?? 0;
|
|
3868
|
-
const startContainingPosition = options.startContainingPosition ?? ZERO_POINT;
|
|
3869
|
-
const endContainingPosition = options.endContainingPosition ?? ZERO_POINT;
|
|
3870
|
-
const startContainingIndex = options.startContainingIndex ?? 0;
|
|
3871
|
-
const endContainingIndex = options.endContainingIndex ?? 0;
|
|
3872
|
-
const matchLimit = options.matchLimit ?? 4294967295;
|
|
3873
|
-
const maxStartDepth = options.maxStartDepth ?? 4294967295;
|
|
3874
|
-
const progressCallback = options.progressCallback;
|
|
3875
|
-
if (typeof matchLimit !== "number") {
|
|
3876
|
-
throw new Error("Arguments must be numbers");
|
|
3877
|
-
}
|
|
3878
|
-
this.matchLimit = matchLimit;
|
|
3879
|
-
if (endIndex !== 0 && startIndex > endIndex) {
|
|
3880
|
-
throw new Error("`startIndex` cannot be greater than `endIndex`");
|
|
3881
|
-
}
|
|
3882
|
-
if (endPosition !== ZERO_POINT && (startPosition.row > endPosition.row || startPosition.row === endPosition.row && startPosition.column > endPosition.column)) {
|
|
3883
|
-
throw new Error("`startPosition` cannot be greater than `endPosition`");
|
|
3884
|
-
}
|
|
3885
|
-
if (endContainingIndex !== 0 && startContainingIndex > endContainingIndex) {
|
|
3886
|
-
throw new Error("`startContainingIndex` cannot be greater than `endContainingIndex`");
|
|
3887
|
-
}
|
|
3888
|
-
if (endContainingPosition !== ZERO_POINT && (startContainingPosition.row > endContainingPosition.row || startContainingPosition.row === endContainingPosition.row && startContainingPosition.column > endContainingPosition.column)) {
|
|
3889
|
-
throw new Error("`startContainingPosition` cannot be greater than `endContainingPosition`");
|
|
3890
|
-
}
|
|
3891
|
-
if (progressCallback) {
|
|
3892
|
-
C.currentQueryProgressCallback = progressCallback;
|
|
3893
|
-
}
|
|
3894
|
-
marshalNode(node);
|
|
3895
|
-
C._ts_query_matches_wasm(
|
|
3896
|
-
this[0],
|
|
3897
|
-
node.tree[0],
|
|
3898
|
-
startPosition.row,
|
|
3899
|
-
startPosition.column,
|
|
3900
|
-
endPosition.row,
|
|
3901
|
-
endPosition.column,
|
|
3864
|
+
const {
|
|
3865
|
+
startPosition,
|
|
3866
|
+
endPosition,
|
|
3902
3867
|
startIndex,
|
|
3903
3868
|
endIndex,
|
|
3904
|
-
startContainingPosition
|
|
3905
|
-
|
|
3906
|
-
endContainingPosition.row,
|
|
3907
|
-
endContainingPosition.column,
|
|
3869
|
+
startContainingPosition,
|
|
3870
|
+
endContainingPosition,
|
|
3908
3871
|
startContainingIndex,
|
|
3909
3872
|
endContainingIndex,
|
|
3910
3873
|
matchLimit,
|
|
3911
|
-
maxStartDepth
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3874
|
+
maxStartDepth,
|
|
3875
|
+
progressCallback
|
|
3876
|
+
} = prepareQuery(this, options);
|
|
3877
|
+
return executeQuery(
|
|
3878
|
+
progressCallback,
|
|
3879
|
+
() => {
|
|
3880
|
+
marshalNode(node);
|
|
3881
|
+
C._ts_query_matches_wasm(
|
|
3882
|
+
this[0],
|
|
3883
|
+
node.tree[0],
|
|
3884
|
+
startPosition.row,
|
|
3885
|
+
startPosition.column,
|
|
3886
|
+
endPosition.row,
|
|
3887
|
+
endPosition.column,
|
|
3888
|
+
startIndex,
|
|
3889
|
+
endIndex,
|
|
3890
|
+
startContainingPosition.row,
|
|
3891
|
+
startContainingPosition.column,
|
|
3892
|
+
endContainingPosition.row,
|
|
3893
|
+
endContainingPosition.column,
|
|
3894
|
+
startContainingIndex,
|
|
3895
|
+
endContainingIndex,
|
|
3896
|
+
matchLimit,
|
|
3897
|
+
maxStartDepth
|
|
3898
|
+
);
|
|
3899
|
+
},
|
|
3900
|
+
(exceededMatchLimit) => {
|
|
3901
|
+
this.matchLimit = matchLimit;
|
|
3902
|
+
this.exceededMatchLimit = exceededMatchLimit;
|
|
3903
|
+
},
|
|
3904
|
+
(rawCount, startAddress) => {
|
|
3905
|
+
const result = new Array(rawCount);
|
|
3906
|
+
let filteredCount = 0;
|
|
3907
|
+
let address = startAddress;
|
|
3908
|
+
for (let i2 = 0; i2 < rawCount; i2++) {
|
|
3909
|
+
const patternIndex = C.getValue(address, "i32");
|
|
3910
|
+
address += SIZE_OF_INT;
|
|
3911
|
+
const captureCount = C.getValue(address, "i32");
|
|
3912
|
+
address += SIZE_OF_INT;
|
|
3913
|
+
const captures = new Array(captureCount);
|
|
3914
|
+
address = unmarshalCaptures(this, node.tree, address, patternIndex, captures);
|
|
3915
|
+
if (this.textPredicates[patternIndex].every((p) => p(captures))) {
|
|
3916
|
+
result[filteredCount] = { patternIndex, captures };
|
|
3917
|
+
const setProperties = this.setProperties[patternIndex];
|
|
3918
|
+
result[filteredCount].setProperties = setProperties;
|
|
3919
|
+
const assertedProperties = this.assertedProperties[patternIndex];
|
|
3920
|
+
result[filteredCount].assertedProperties = assertedProperties;
|
|
3921
|
+
const refutedProperties = this.refutedProperties[patternIndex];
|
|
3922
|
+
result[filteredCount].refutedProperties = refutedProperties;
|
|
3923
|
+
filteredCount++;
|
|
3924
|
+
}
|
|
3925
|
+
}
|
|
3926
|
+
result.length = filteredCount;
|
|
3927
|
+
return result;
|
|
3936
3928
|
}
|
|
3937
|
-
|
|
3938
|
-
result.length = filteredCount;
|
|
3939
|
-
C._free(startAddress);
|
|
3940
|
-
C.currentQueryProgressCallback = null;
|
|
3941
|
-
return result;
|
|
3929
|
+
);
|
|
3942
3930
|
}
|
|
3943
3931
|
/**
|
|
3944
3932
|
* Iterate over all of the individual captures in the order that they
|
|
@@ -3952,85 +3940,71 @@ var Query = class {
|
|
|
3952
3940
|
* @param {QueryOptions} options - Options for query execution.
|
|
3953
3941
|
*/
|
|
3954
3942
|
captures(node, options = {}) {
|
|
3955
|
-
const
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
const endIndex = options.endIndex ?? 0;
|
|
3959
|
-
const startContainingPosition = options.startContainingPosition ?? ZERO_POINT;
|
|
3960
|
-
const endContainingPosition = options.endContainingPosition ?? ZERO_POINT;
|
|
3961
|
-
const startContainingIndex = options.startContainingIndex ?? 0;
|
|
3962
|
-
const endContainingIndex = options.endContainingIndex ?? 0;
|
|
3963
|
-
const matchLimit = options.matchLimit ?? 4294967295;
|
|
3964
|
-
const maxStartDepth = options.maxStartDepth ?? 4294967295;
|
|
3965
|
-
const progressCallback = options.progressCallback;
|
|
3966
|
-
if (typeof matchLimit !== "number") {
|
|
3967
|
-
throw new Error("Arguments must be numbers");
|
|
3968
|
-
}
|
|
3969
|
-
this.matchLimit = matchLimit;
|
|
3970
|
-
if (endIndex !== 0 && startIndex > endIndex) {
|
|
3971
|
-
throw new Error("`startIndex` cannot be greater than `endIndex`");
|
|
3972
|
-
}
|
|
3973
|
-
if (endPosition !== ZERO_POINT && (startPosition.row > endPosition.row || startPosition.row === endPosition.row && startPosition.column > endPosition.column)) {
|
|
3974
|
-
throw new Error("`startPosition` cannot be greater than `endPosition`");
|
|
3975
|
-
}
|
|
3976
|
-
if (endContainingIndex !== 0 && startContainingIndex > endContainingIndex) {
|
|
3977
|
-
throw new Error("`startContainingIndex` cannot be greater than `endContainingIndex`");
|
|
3978
|
-
}
|
|
3979
|
-
if (endContainingPosition !== ZERO_POINT && (startContainingPosition.row > endContainingPosition.row || startContainingPosition.row === endContainingPosition.row && startContainingPosition.column > endContainingPosition.column)) {
|
|
3980
|
-
throw new Error("`startContainingPosition` cannot be greater than `endContainingPosition`");
|
|
3981
|
-
}
|
|
3982
|
-
if (progressCallback) {
|
|
3983
|
-
C.currentQueryProgressCallback = progressCallback;
|
|
3984
|
-
}
|
|
3985
|
-
marshalNode(node);
|
|
3986
|
-
C._ts_query_captures_wasm(
|
|
3987
|
-
this[0],
|
|
3988
|
-
node.tree[0],
|
|
3989
|
-
startPosition.row,
|
|
3990
|
-
startPosition.column,
|
|
3991
|
-
endPosition.row,
|
|
3992
|
-
endPosition.column,
|
|
3943
|
+
const {
|
|
3944
|
+
startPosition,
|
|
3945
|
+
endPosition,
|
|
3993
3946
|
startIndex,
|
|
3994
3947
|
endIndex,
|
|
3995
|
-
startContainingPosition
|
|
3996
|
-
|
|
3997
|
-
endContainingPosition.row,
|
|
3998
|
-
endContainingPosition.column,
|
|
3948
|
+
startContainingPosition,
|
|
3949
|
+
endContainingPosition,
|
|
3999
3950
|
startContainingIndex,
|
|
4000
3951
|
endContainingIndex,
|
|
4001
3952
|
matchLimit,
|
|
4002
|
-
maxStartDepth
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
const
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
3953
|
+
maxStartDepth,
|
|
3954
|
+
progressCallback
|
|
3955
|
+
} = prepareQuery(this, options);
|
|
3956
|
+
const callback = progressCallback;
|
|
3957
|
+
return executeQuery(
|
|
3958
|
+
callback ? (state) => callback(state) === true : void 0,
|
|
3959
|
+
() => {
|
|
3960
|
+
marshalNode(node);
|
|
3961
|
+
C._ts_query_captures_wasm(
|
|
3962
|
+
this[0],
|
|
3963
|
+
node.tree[0],
|
|
3964
|
+
startPosition.row,
|
|
3965
|
+
startPosition.column,
|
|
3966
|
+
endPosition.row,
|
|
3967
|
+
endPosition.column,
|
|
3968
|
+
startIndex,
|
|
3969
|
+
endIndex,
|
|
3970
|
+
startContainingPosition.row,
|
|
3971
|
+
startContainingPosition.column,
|
|
3972
|
+
endContainingPosition.row,
|
|
3973
|
+
endContainingPosition.column,
|
|
3974
|
+
startContainingIndex,
|
|
3975
|
+
endContainingIndex,
|
|
3976
|
+
matchLimit,
|
|
3977
|
+
maxStartDepth
|
|
3978
|
+
);
|
|
3979
|
+
},
|
|
3980
|
+
(exceededMatchLimit) => {
|
|
3981
|
+
this.matchLimit = matchLimit;
|
|
3982
|
+
this.exceededMatchLimit = exceededMatchLimit;
|
|
3983
|
+
},
|
|
3984
|
+
(count, startAddress) => {
|
|
3985
|
+
const result = new Array();
|
|
3986
|
+
const captures = new Array();
|
|
3987
|
+
let address = startAddress;
|
|
3988
|
+
for (let i2 = 0; i2 < count; i2++) {
|
|
3989
|
+
const patternIndex = C.getValue(address, "i32");
|
|
3990
|
+
address += SIZE_OF_INT;
|
|
3991
|
+
const captureCount = C.getValue(address, "i32");
|
|
3992
|
+
address += SIZE_OF_INT;
|
|
3993
|
+
const captureIndex = C.getValue(address, "i32");
|
|
3994
|
+
address += SIZE_OF_INT;
|
|
3995
|
+
captures.length = captureCount;
|
|
3996
|
+
address = unmarshalCaptures(this, node.tree, address, patternIndex, captures);
|
|
3997
|
+
if (this.textPredicates[patternIndex].every((p) => p(captures))) {
|
|
3998
|
+
const capture = captures[captureIndex];
|
|
3999
|
+
capture.setProperties = this.setProperties[patternIndex];
|
|
4000
|
+
capture.assertedProperties = this.assertedProperties[patternIndex];
|
|
4001
|
+
capture.refutedProperties = this.refutedProperties[patternIndex];
|
|
4002
|
+
result.push(capture);
|
|
4003
|
+
}
|
|
4004
|
+
}
|
|
4005
|
+
return result;
|
|
4029
4006
|
}
|
|
4030
|
-
|
|
4031
|
-
C._free(startAddress);
|
|
4032
|
-
C.currentQueryProgressCallback = null;
|
|
4033
|
-
return result;
|
|
4007
|
+
);
|
|
4034
4008
|
}
|
|
4035
4009
|
/** Get the predicates for a given pattern. */
|
|
4036
4010
|
predicatesForPattern(patternIndex) {
|
|
@@ -4115,6 +4089,81 @@ var Query = class {
|
|
|
4115
4089
|
return C._ts_query_is_pattern_guaranteed_at_step(this[0], byteIndex) === 1;
|
|
4116
4090
|
}
|
|
4117
4091
|
};
|
|
4092
|
+
function prepareQuery(query, options) {
|
|
4093
|
+
const parameters = {
|
|
4094
|
+
startPosition: options.startPosition ?? ZERO_POINT,
|
|
4095
|
+
endPosition: options.endPosition ?? ZERO_POINT,
|
|
4096
|
+
startIndex: options.startIndex ?? 0,
|
|
4097
|
+
endIndex: options.endIndex ?? 0,
|
|
4098
|
+
startContainingPosition: options.startContainingPosition ?? ZERO_POINT,
|
|
4099
|
+
endContainingPosition: options.endContainingPosition ?? ZERO_POINT,
|
|
4100
|
+
startContainingIndex: options.startContainingIndex ?? 0,
|
|
4101
|
+
endContainingIndex: options.endContainingIndex ?? 0,
|
|
4102
|
+
matchLimit: options.matchLimit ?? 4294967295,
|
|
4103
|
+
maxStartDepth: options.maxStartDepth ?? 4294967295,
|
|
4104
|
+
progressCallback: options.progressCallback
|
|
4105
|
+
};
|
|
4106
|
+
const {
|
|
4107
|
+
startPosition,
|
|
4108
|
+
endPosition,
|
|
4109
|
+
startIndex,
|
|
4110
|
+
endIndex,
|
|
4111
|
+
startContainingPosition,
|
|
4112
|
+
endContainingPosition,
|
|
4113
|
+
startContainingIndex,
|
|
4114
|
+
endContainingIndex,
|
|
4115
|
+
matchLimit
|
|
4116
|
+
} = parameters;
|
|
4117
|
+
if (typeof matchLimit !== "number") {
|
|
4118
|
+
throw new Error("Arguments must be numbers");
|
|
4119
|
+
}
|
|
4120
|
+
query.matchLimit = matchLimit;
|
|
4121
|
+
if (endIndex !== 0 && startIndex > endIndex) {
|
|
4122
|
+
throw new Error("`startIndex` cannot be greater than `endIndex`");
|
|
4123
|
+
}
|
|
4124
|
+
if (endPosition !== ZERO_POINT && (startPosition.row > endPosition.row || startPosition.row === endPosition.row && startPosition.column > endPosition.column)) {
|
|
4125
|
+
throw new Error("`startPosition` cannot be greater than `endPosition`");
|
|
4126
|
+
}
|
|
4127
|
+
if (endContainingIndex !== 0 && startContainingIndex > endContainingIndex) {
|
|
4128
|
+
throw new Error("`startContainingIndex` cannot be greater than `endContainingIndex`");
|
|
4129
|
+
}
|
|
4130
|
+
if (endContainingPosition !== ZERO_POINT && (startContainingPosition.row > endContainingPosition.row || startContainingPosition.row === endContainingPosition.row && startContainingPosition.column > endContainingPosition.column)) {
|
|
4131
|
+
throw new Error("`startContainingPosition` cannot be greater than `endContainingPosition`");
|
|
4132
|
+
}
|
|
4133
|
+
return parameters;
|
|
4134
|
+
}
|
|
4135
|
+
__name(prepareQuery, "prepareQuery");
|
|
4136
|
+
function executeQuery(progressCallback, execute, updateState, readResult) {
|
|
4137
|
+
const previousCallback = C.currentQueryProgressCallback;
|
|
4138
|
+
let callbackFailure;
|
|
4139
|
+
C.currentQueryProgressCallback = progressCallback ? (state) => {
|
|
4140
|
+
try {
|
|
4141
|
+
return progressCallback(state);
|
|
4142
|
+
} catch (error) {
|
|
4143
|
+
callbackFailure = { error };
|
|
4144
|
+
return true;
|
|
4145
|
+
}
|
|
4146
|
+
} : null;
|
|
4147
|
+
try {
|
|
4148
|
+
execute();
|
|
4149
|
+
} finally {
|
|
4150
|
+
C.currentQueryProgressCallback = previousCallback;
|
|
4151
|
+
}
|
|
4152
|
+
const count = C.getValue(TRANSFER_BUFFER, "i32");
|
|
4153
|
+
const address = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
|
|
4154
|
+
const exceededMatchLimit = Boolean(C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, "i32"));
|
|
4155
|
+
try {
|
|
4156
|
+
updateState(exceededMatchLimit);
|
|
4157
|
+
if (callbackFailure) {
|
|
4158
|
+
throw callbackFailure.error;
|
|
4159
|
+
}
|
|
4160
|
+
return readResult(count, address);
|
|
4161
|
+
} finally {
|
|
4162
|
+
C._free(address);
|
|
4163
|
+
updateState(exceededMatchLimit);
|
|
4164
|
+
}
|
|
4165
|
+
}
|
|
4166
|
+
__name(executeQuery, "executeQuery");
|
|
4118
4167
|
export {
|
|
4119
4168
|
CaptureQuantifier,
|
|
4120
4169
|
Edit,
|