@willbooster/web-tree-sitter 18.0.2 → 19.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.
- package/debug/web-tree-sitter.cjs +11 -738
- package/debug/web-tree-sitter.cjs.map +4 -4
- package/debug/web-tree-sitter.js +11 -736
- package/debug/web-tree-sitter.js.map +4 -4
- package/debug/web-tree-sitter.wasm +0 -0
- package/debug/web-tree-sitter.wasm.map +4 -8
- package/package.json +5 -5
- package/web-tree-sitter.cjs +3 -4
- package/web-tree-sitter.cjs.map +4 -4
- package/web-tree-sitter.d.cts +0 -252
- package/web-tree-sitter.d.cts.map +1 -14
- package/web-tree-sitter.d.ts +0 -252
- package/web-tree-sitter.d.ts.map +1 -14
- package/web-tree-sitter.js +3 -4
- package/web-tree-sitter.js.map +4 -4
- package/web-tree-sitter.wasm +0 -0
- package/web-tree-sitter.wasm.map +4 -8
- package/web-tree-sitter.web.js +3 -4
- package/web-tree-sitter.web.js.map +4 -4
package/debug/web-tree-sitter.js
CHANGED
|
@@ -1178,17 +1178,6 @@ var Node = class {
|
|
|
1178
1178
|
};
|
|
1179
1179
|
|
|
1180
1180
|
// src/marshal.ts
|
|
1181
|
-
function unmarshalCaptures(query, tree, address, patternIndex, result) {
|
|
1182
|
-
for (let i2 = 0, n = result.length; i2 < n; i2++) {
|
|
1183
|
-
const captureIndex = C.getValue(address, "i32");
|
|
1184
|
-
address += SIZE_OF_INT;
|
|
1185
|
-
const node = unmarshalNode(tree, address);
|
|
1186
|
-
address += SIZE_OF_NODE;
|
|
1187
|
-
result[i2] = { patternIndex, name: query.captureNames[captureIndex], node };
|
|
1188
|
-
}
|
|
1189
|
-
return address;
|
|
1190
|
-
}
|
|
1191
|
-
__name(unmarshalCaptures, "unmarshalCaptures");
|
|
1192
1181
|
function marshalNode(node, index = 0) {
|
|
1193
1182
|
let address = TRANSFER_BUFFER + index * SIZE_OF_NODE;
|
|
1194
1183
|
C.setValue(address, node.id, "i32");
|
|
@@ -1551,7 +1540,6 @@ async function Module2(moduleArg = {}) {
|
|
|
1551
1540
|
const { createRequire } = await import("module");
|
|
1552
1541
|
var require = createRequire(import.meta.url);
|
|
1553
1542
|
}
|
|
1554
|
-
Module.currentQueryProgressCallback = null;
|
|
1555
1543
|
Module.currentProgressCallback = null;
|
|
1556
1544
|
Module.currentLogCallback = null;
|
|
1557
1545
|
Module.currentParseCallback = null;
|
|
@@ -2344,7 +2332,7 @@ async function Module2(moduleArg = {}) {
|
|
|
2344
2332
|
newDSO("__main__", 0, wasmImports);
|
|
2345
2333
|
}
|
|
2346
2334
|
};
|
|
2347
|
-
var ___heap_base =
|
|
2335
|
+
var ___heap_base = 82464;
|
|
2348
2336
|
var alignMemory = /* @__PURE__ */ __name((size, alignment) => {
|
|
2349
2337
|
assert(alignment, "alignment argument is required");
|
|
2350
2338
|
return Math.ceil(size / alignment) * alignment;
|
|
@@ -2439,7 +2427,7 @@ async function Module2(moduleArg = {}) {
|
|
|
2439
2427
|
}, "convertJsFunctionToWasm");
|
|
2440
2428
|
var wasmTableMirror = [];
|
|
2441
2429
|
var wasmTable = new WebAssembly.Table({
|
|
2442
|
-
"initial":
|
|
2430
|
+
"initial": 55,
|
|
2443
2431
|
"element": "anyfunc"
|
|
2444
2432
|
});
|
|
2445
2433
|
var getWasmTableEntry = /* @__PURE__ */ __name((funcPtr) => {
|
|
@@ -2975,12 +2963,12 @@ async function Module2(moduleArg = {}) {
|
|
|
2975
2963
|
"value": "i32",
|
|
2976
2964
|
"mutable": false
|
|
2977
2965
|
}, 1024);
|
|
2978
|
-
var ___stack_high =
|
|
2979
|
-
var ___stack_low =
|
|
2966
|
+
var ___stack_high = 82464;
|
|
2967
|
+
var ___stack_low = 16928;
|
|
2980
2968
|
var ___stack_pointer = new WebAssembly.Global({
|
|
2981
2969
|
"value": "i32",
|
|
2982
2970
|
"mutable": true
|
|
2983
|
-
},
|
|
2971
|
+
}, 82464);
|
|
2984
2972
|
var ___table_base = new WebAssembly.Global({
|
|
2985
2973
|
"value": "i32",
|
|
2986
2974
|
"mutable": false
|
|
@@ -3113,15 +3101,6 @@ async function Module2(moduleArg = {}) {
|
|
|
3113
3101
|
return false;
|
|
3114
3102
|
}
|
|
3115
3103
|
__name(_tree_sitter_progress_callback, "_tree_sitter_progress_callback");
|
|
3116
|
-
function _tree_sitter_query_progress_callback(currentOffset) {
|
|
3117
|
-
if (Module.currentQueryProgressCallback) {
|
|
3118
|
-
return Module.currentQueryProgressCallback({
|
|
3119
|
-
currentOffset
|
|
3120
|
-
}) === true;
|
|
3121
|
-
}
|
|
3122
|
-
return false;
|
|
3123
|
-
}
|
|
3124
|
-
__name(_tree_sitter_query_progress_callback, "_tree_sitter_query_progress_callback");
|
|
3125
3104
|
var runtimeKeepaliveCounter = 0;
|
|
3126
3105
|
var keepRuntimeAlive = /* @__PURE__ */ __name(() => noExitRuntime || runtimeKeepaliveCounter > 0, "keepRuntimeAlive");
|
|
3127
3106
|
var _proc_exit = /* @__PURE__ */ __name((code) => {
|
|
@@ -3333,28 +3312,9 @@ async function Module2(moduleArg = {}) {
|
|
|
3333
3312
|
var _ts_parser_set_language = Module["_ts_parser_set_language"] = makeInvalidEarlyAccess("_ts_parser_set_language");
|
|
3334
3313
|
var _ts_parser_reset = Module["_ts_parser_reset"] = makeInvalidEarlyAccess("_ts_parser_reset");
|
|
3335
3314
|
var _ts_parser_set_included_ranges = Module["_ts_parser_set_included_ranges"] = makeInvalidEarlyAccess("_ts_parser_set_included_ranges");
|
|
3336
|
-
var _ts_query_new = Module["_ts_query_new"] = makeInvalidEarlyAccess("_ts_query_new");
|
|
3337
|
-
var _ts_query_delete = Module["_ts_query_delete"] = makeInvalidEarlyAccess("_ts_query_delete");
|
|
3338
|
-
var _iswspace = Module["_iswspace"] = makeInvalidEarlyAccess("_iswspace");
|
|
3339
|
-
var _ts_query_copy = Module["_ts_query_copy"] = makeInvalidEarlyAccess("_ts_query_copy");
|
|
3340
|
-
var _ts_query_pattern_count = Module["_ts_query_pattern_count"] = makeInvalidEarlyAccess("_ts_query_pattern_count");
|
|
3341
|
-
var _ts_query_capture_count = Module["_ts_query_capture_count"] = makeInvalidEarlyAccess("_ts_query_capture_count");
|
|
3342
|
-
var _ts_query_string_count = Module["_ts_query_string_count"] = makeInvalidEarlyAccess("_ts_query_string_count");
|
|
3343
|
-
var _ts_query_capture_name_for_id = Module["_ts_query_capture_name_for_id"] = makeInvalidEarlyAccess("_ts_query_capture_name_for_id");
|
|
3344
|
-
var _ts_query_capture_quantifier_for_id = Module["_ts_query_capture_quantifier_for_id"] = makeInvalidEarlyAccess("_ts_query_capture_quantifier_for_id");
|
|
3345
|
-
var _ts_query_string_value_for_id = Module["_ts_query_string_value_for_id"] = makeInvalidEarlyAccess("_ts_query_string_value_for_id");
|
|
3346
|
-
var _ts_query_predicates_for_pattern = Module["_ts_query_predicates_for_pattern"] = makeInvalidEarlyAccess("_ts_query_predicates_for_pattern");
|
|
3347
|
-
var _ts_query_start_byte_for_pattern = Module["_ts_query_start_byte_for_pattern"] = makeInvalidEarlyAccess("_ts_query_start_byte_for_pattern");
|
|
3348
|
-
var _ts_query_end_byte_for_pattern = Module["_ts_query_end_byte_for_pattern"] = makeInvalidEarlyAccess("_ts_query_end_byte_for_pattern");
|
|
3349
|
-
var _ts_query_is_pattern_rooted = Module["_ts_query_is_pattern_rooted"] = makeInvalidEarlyAccess("_ts_query_is_pattern_rooted");
|
|
3350
|
-
var _ts_query_is_pattern_non_local = Module["_ts_query_is_pattern_non_local"] = makeInvalidEarlyAccess("_ts_query_is_pattern_non_local");
|
|
3351
|
-
var _ts_query_is_pattern_guaranteed_at_step = Module["_ts_query_is_pattern_guaranteed_at_step"] = makeInvalidEarlyAccess("_ts_query_is_pattern_guaranteed_at_step");
|
|
3352
|
-
var _ts_query_disable_capture = Module["_ts_query_disable_capture"] = makeInvalidEarlyAccess("_ts_query_disable_capture");
|
|
3353
|
-
var _ts_query_disable_pattern = Module["_ts_query_disable_pattern"] = makeInvalidEarlyAccess("_ts_query_disable_pattern");
|
|
3354
3315
|
var _memcmp = Module["_memcmp"] = makeInvalidEarlyAccess("_memcmp");
|
|
3355
3316
|
var _ts_tree_copy = Module["_ts_tree_copy"] = makeInvalidEarlyAccess("_ts_tree_copy");
|
|
3356
3317
|
var _ts_tree_delete = Module["_ts_tree_delete"] = makeInvalidEarlyAccess("_ts_tree_delete");
|
|
3357
|
-
var _iswalnum = Module["_iswalnum"] = makeInvalidEarlyAccess("_iswalnum");
|
|
3358
3318
|
var _ts_init = Module["_ts_init"] = makeInvalidEarlyAccess("_ts_init");
|
|
3359
3319
|
var _ts_free_wasm = Module["_ts_free_wasm"] = makeInvalidEarlyAccess("_ts_free_wasm");
|
|
3360
3320
|
var _ts_scanner_malloc_wasm = Module["_ts_scanner_malloc_wasm"] = makeInvalidEarlyAccess("_ts_scanner_malloc_wasm");
|
|
@@ -3441,18 +3401,18 @@ async function Module2(moduleArg = {}) {
|
|
|
3441
3401
|
var _ts_node_is_extra_wasm = Module["_ts_node_is_extra_wasm"] = makeInvalidEarlyAccess("_ts_node_is_extra_wasm");
|
|
3442
3402
|
var _ts_node_parse_state_wasm = Module["_ts_node_parse_state_wasm"] = makeInvalidEarlyAccess("_ts_node_parse_state_wasm");
|
|
3443
3403
|
var _ts_node_next_parse_state_wasm = Module["_ts_node_next_parse_state_wasm"] = makeInvalidEarlyAccess("_ts_node_next_parse_state_wasm");
|
|
3444
|
-
var _ts_query_matches_wasm = Module["_ts_query_matches_wasm"] = makeInvalidEarlyAccess("_ts_query_matches_wasm");
|
|
3445
|
-
var _ts_query_captures_wasm = Module["_ts_query_captures_wasm"] = makeInvalidEarlyAccess("_ts_query_captures_wasm");
|
|
3446
3404
|
var _memset = Module["_memset"] = makeInvalidEarlyAccess("_memset");
|
|
3447
3405
|
var _memcpy = Module["_memcpy"] = makeInvalidEarlyAccess("_memcpy");
|
|
3448
3406
|
var _memmove = Module["_memmove"] = makeInvalidEarlyAccess("_memmove");
|
|
3449
3407
|
var _fflush = makeInvalidEarlyAccess("_fflush");
|
|
3450
3408
|
var _strlen = Module["_strlen"] = makeInvalidEarlyAccess("_strlen");
|
|
3409
|
+
var _iswalnum = Module["_iswalnum"] = makeInvalidEarlyAccess("_iswalnum");
|
|
3451
3410
|
var _iswalpha = Module["_iswalpha"] = makeInvalidEarlyAccess("_iswalpha");
|
|
3452
3411
|
var _iswblank = Module["_iswblank"] = makeInvalidEarlyAccess("_iswblank");
|
|
3453
3412
|
var _iswdigit = Module["_iswdigit"] = makeInvalidEarlyAccess("_iswdigit");
|
|
3454
3413
|
var _iswlower = Module["_iswlower"] = makeInvalidEarlyAccess("_iswlower");
|
|
3455
3414
|
var _iswpunct = Module["_iswpunct"] = makeInvalidEarlyAccess("_iswpunct");
|
|
3415
|
+
var _iswspace = Module["_iswspace"] = makeInvalidEarlyAccess("_iswspace");
|
|
3456
3416
|
var _iswupper = Module["_iswupper"] = makeInvalidEarlyAccess("_iswupper");
|
|
3457
3417
|
var _iswxdigit = Module["_iswxdigit"] = makeInvalidEarlyAccess("_iswxdigit");
|
|
3458
3418
|
var _memchr = Module["_memchr"] = makeInvalidEarlyAccess("_memchr");
|
|
@@ -3500,28 +3460,9 @@ async function Module2(moduleArg = {}) {
|
|
|
3500
3460
|
Module["_ts_parser_set_language"] = _ts_parser_set_language = createExportWrapper("ts_parser_set_language", 2);
|
|
3501
3461
|
Module["_ts_parser_reset"] = _ts_parser_reset = createExportWrapper("ts_parser_reset", 1);
|
|
3502
3462
|
Module["_ts_parser_set_included_ranges"] = _ts_parser_set_included_ranges = createExportWrapper("ts_parser_set_included_ranges", 3);
|
|
3503
|
-
Module["_ts_query_new"] = _ts_query_new = createExportWrapper("ts_query_new", 5);
|
|
3504
|
-
Module["_ts_query_delete"] = _ts_query_delete = createExportWrapper("ts_query_delete", 1);
|
|
3505
|
-
Module["_iswspace"] = _iswspace = createExportWrapper("iswspace", 1);
|
|
3506
|
-
Module["_ts_query_copy"] = _ts_query_copy = createExportWrapper("ts_query_copy", 1);
|
|
3507
|
-
Module["_ts_query_pattern_count"] = _ts_query_pattern_count = createExportWrapper("ts_query_pattern_count", 1);
|
|
3508
|
-
Module["_ts_query_capture_count"] = _ts_query_capture_count = createExportWrapper("ts_query_capture_count", 1);
|
|
3509
|
-
Module["_ts_query_string_count"] = _ts_query_string_count = createExportWrapper("ts_query_string_count", 1);
|
|
3510
|
-
Module["_ts_query_capture_name_for_id"] = _ts_query_capture_name_for_id = createExportWrapper("ts_query_capture_name_for_id", 3);
|
|
3511
|
-
Module["_ts_query_capture_quantifier_for_id"] = _ts_query_capture_quantifier_for_id = createExportWrapper("ts_query_capture_quantifier_for_id", 3);
|
|
3512
|
-
Module["_ts_query_string_value_for_id"] = _ts_query_string_value_for_id = createExportWrapper("ts_query_string_value_for_id", 3);
|
|
3513
|
-
Module["_ts_query_predicates_for_pattern"] = _ts_query_predicates_for_pattern = createExportWrapper("ts_query_predicates_for_pattern", 3);
|
|
3514
|
-
Module["_ts_query_start_byte_for_pattern"] = _ts_query_start_byte_for_pattern = createExportWrapper("ts_query_start_byte_for_pattern", 2);
|
|
3515
|
-
Module["_ts_query_end_byte_for_pattern"] = _ts_query_end_byte_for_pattern = createExportWrapper("ts_query_end_byte_for_pattern", 2);
|
|
3516
|
-
Module["_ts_query_is_pattern_rooted"] = _ts_query_is_pattern_rooted = createExportWrapper("ts_query_is_pattern_rooted", 2);
|
|
3517
|
-
Module["_ts_query_is_pattern_non_local"] = _ts_query_is_pattern_non_local = createExportWrapper("ts_query_is_pattern_non_local", 2);
|
|
3518
|
-
Module["_ts_query_is_pattern_guaranteed_at_step"] = _ts_query_is_pattern_guaranteed_at_step = createExportWrapper("ts_query_is_pattern_guaranteed_at_step", 2);
|
|
3519
|
-
Module["_ts_query_disable_capture"] = _ts_query_disable_capture = createExportWrapper("ts_query_disable_capture", 3);
|
|
3520
|
-
Module["_ts_query_disable_pattern"] = _ts_query_disable_pattern = createExportWrapper("ts_query_disable_pattern", 2);
|
|
3521
3463
|
Module["_memcmp"] = _memcmp = createExportWrapper("memcmp", 3);
|
|
3522
3464
|
Module["_ts_tree_copy"] = _ts_tree_copy = createExportWrapper("ts_tree_copy", 1);
|
|
3523
3465
|
Module["_ts_tree_delete"] = _ts_tree_delete = createExportWrapper("ts_tree_delete", 1);
|
|
3524
|
-
Module["_iswalnum"] = _iswalnum = createExportWrapper("iswalnum", 1);
|
|
3525
3466
|
Module["_ts_init"] = _ts_init = createExportWrapper("ts_init", 0);
|
|
3526
3467
|
Module["_ts_free_wasm"] = _ts_free_wasm = createExportWrapper("ts_free_wasm", 1);
|
|
3527
3468
|
Module["_ts_scanner_malloc_wasm"] = _ts_scanner_malloc_wasm = createExportWrapper("ts_scanner_malloc_wasm", 1);
|
|
@@ -3608,18 +3549,18 @@ async function Module2(moduleArg = {}) {
|
|
|
3608
3549
|
Module["_ts_node_is_extra_wasm"] = _ts_node_is_extra_wasm = createExportWrapper("ts_node_is_extra_wasm", 1);
|
|
3609
3550
|
Module["_ts_node_parse_state_wasm"] = _ts_node_parse_state_wasm = createExportWrapper("ts_node_parse_state_wasm", 1);
|
|
3610
3551
|
Module["_ts_node_next_parse_state_wasm"] = _ts_node_next_parse_state_wasm = createExportWrapper("ts_node_next_parse_state_wasm", 1);
|
|
3611
|
-
Module["_ts_query_matches_wasm"] = _ts_query_matches_wasm = createExportWrapper("ts_query_matches_wasm", 16);
|
|
3612
|
-
Module["_ts_query_captures_wasm"] = _ts_query_captures_wasm = createExportWrapper("ts_query_captures_wasm", 16);
|
|
3613
3552
|
Module["_memset"] = _memset = createExportWrapper("memset", 3);
|
|
3614
3553
|
Module["_memcpy"] = _memcpy = createExportWrapper("memcpy", 3);
|
|
3615
3554
|
Module["_memmove"] = _memmove = createExportWrapper("memmove", 3);
|
|
3616
3555
|
_fflush = createExportWrapper("fflush", 1);
|
|
3617
3556
|
Module["_strlen"] = _strlen = createExportWrapper("strlen", 1);
|
|
3557
|
+
Module["_iswalnum"] = _iswalnum = createExportWrapper("iswalnum", 1);
|
|
3618
3558
|
Module["_iswalpha"] = _iswalpha = createExportWrapper("iswalpha", 1);
|
|
3619
3559
|
Module["_iswblank"] = _iswblank = createExportWrapper("iswblank", 1);
|
|
3620
3560
|
Module["_iswdigit"] = _iswdigit = createExportWrapper("iswdigit", 1);
|
|
3621
3561
|
Module["_iswlower"] = _iswlower = createExportWrapper("iswlower", 1);
|
|
3622
3562
|
Module["_iswpunct"] = _iswpunct = createExportWrapper("iswpunct", 1);
|
|
3563
|
+
Module["_iswspace"] = _iswspace = createExportWrapper("iswspace", 1);
|
|
3623
3564
|
Module["_iswupper"] = _iswupper = createExportWrapper("iswupper", 1);
|
|
3624
3565
|
Module["_iswxdigit"] = _iswxdigit = createExportWrapper("iswxdigit", 1);
|
|
3625
3566
|
Module["_memchr"] = _memchr = createExportWrapper("memchr", 3);
|
|
@@ -3693,9 +3634,7 @@ async function Module2(moduleArg = {}) {
|
|
|
3693
3634
|
/** @export */
|
|
3694
3635
|
tree_sitter_parse_callback: _tree_sitter_parse_callback,
|
|
3695
3636
|
/** @export */
|
|
3696
|
-
tree_sitter_progress_callback: _tree_sitter_progress_callback
|
|
3697
|
-
/** @export */
|
|
3698
|
-
tree_sitter_query_progress_callback: _tree_sitter_query_progress_callback
|
|
3637
|
+
tree_sitter_progress_callback: _tree_sitter_progress_callback
|
|
3699
3638
|
};
|
|
3700
3639
|
function invoke_vi(index, a1) {
|
|
3701
3640
|
var sp = stackSave();
|
|
@@ -3803,7 +3742,7 @@ async function Module2(moduleArg = {}) {
|
|
|
3803
3742
|
}
|
|
3804
3743
|
__name(callMain, "callMain");
|
|
3805
3744
|
function stackCheckInit() {
|
|
3806
|
-
_emscripten_stack_set_limits(
|
|
3745
|
+
_emscripten_stack_set_limits(82464, 16928);
|
|
3807
3746
|
writeStackCookie();
|
|
3808
3747
|
}
|
|
3809
3748
|
__name(stackCheckInit, "stackCheckInit");
|
|
@@ -4145,670 +4084,7 @@ function clearCallbacks() {
|
|
|
4145
4084
|
C.currentProgressCallback = null;
|
|
4146
4085
|
}
|
|
4147
4086
|
__name(clearCallbacks, "clearCallbacks");
|
|
4148
|
-
|
|
4149
|
-
// src/query.ts
|
|
4150
|
-
var PREDICATE_STEP_TYPE_CAPTURE = 1;
|
|
4151
|
-
var PREDICATE_STEP_TYPE_STRING = 2;
|
|
4152
|
-
var QUERY_WORD_REGEX = /[\w-]+/g;
|
|
4153
|
-
var CaptureQuantifier = {
|
|
4154
|
-
Zero: 0,
|
|
4155
|
-
ZeroOrOne: 1,
|
|
4156
|
-
ZeroOrMore: 2,
|
|
4157
|
-
One: 3,
|
|
4158
|
-
OneOrMore: 4
|
|
4159
|
-
};
|
|
4160
|
-
var isCaptureStep = /* @__PURE__ */ __name((step) => step.type === "capture", "isCaptureStep");
|
|
4161
|
-
var isStringStep = /* @__PURE__ */ __name((step) => step.type === "string", "isStringStep");
|
|
4162
|
-
var QueryErrorKind = {
|
|
4163
|
-
Syntax: 1,
|
|
4164
|
-
NodeName: 2,
|
|
4165
|
-
FieldName: 3,
|
|
4166
|
-
CaptureName: 4,
|
|
4167
|
-
PatternStructure: 5
|
|
4168
|
-
};
|
|
4169
|
-
var QueryError = class _QueryError extends Error {
|
|
4170
|
-
constructor(kind, info2, index, length) {
|
|
4171
|
-
super(_QueryError.formatMessage(kind, info2));
|
|
4172
|
-
this.kind = kind;
|
|
4173
|
-
this.info = info2;
|
|
4174
|
-
this.index = index;
|
|
4175
|
-
this.length = length;
|
|
4176
|
-
this.name = "QueryError";
|
|
4177
|
-
}
|
|
4178
|
-
kind;
|
|
4179
|
-
info;
|
|
4180
|
-
index;
|
|
4181
|
-
length;
|
|
4182
|
-
static {
|
|
4183
|
-
__name(this, "QueryError");
|
|
4184
|
-
}
|
|
4185
|
-
/** Formats an error message based on the error kind and info */
|
|
4186
|
-
static formatMessage(kind, info2) {
|
|
4187
|
-
switch (kind) {
|
|
4188
|
-
case QueryErrorKind.NodeName:
|
|
4189
|
-
return `Bad node name '${info2.word}'`;
|
|
4190
|
-
case QueryErrorKind.FieldName:
|
|
4191
|
-
return `Bad field name '${info2.word}'`;
|
|
4192
|
-
case QueryErrorKind.CaptureName:
|
|
4193
|
-
return `Bad capture name @${info2.word}`;
|
|
4194
|
-
case QueryErrorKind.PatternStructure:
|
|
4195
|
-
return `Bad pattern structure at offset ${info2.suffix}`;
|
|
4196
|
-
case QueryErrorKind.Syntax:
|
|
4197
|
-
return `Bad syntax at offset ${info2.suffix}`;
|
|
4198
|
-
}
|
|
4199
|
-
}
|
|
4200
|
-
};
|
|
4201
|
-
function parseAnyPredicate(steps, index, operator, textPredicates) {
|
|
4202
|
-
if (steps.length !== 3) {
|
|
4203
|
-
throw new Error(
|
|
4204
|
-
`Wrong number of arguments to \`#${operator}\` predicate. Expected 2, got ${steps.length - 1}`
|
|
4205
|
-
);
|
|
4206
|
-
}
|
|
4207
|
-
if (!isCaptureStep(steps[1])) {
|
|
4208
|
-
throw new Error(
|
|
4209
|
-
`First argument of \`#${operator}\` predicate must be a capture. Got "${steps[1].value}"`
|
|
4210
|
-
);
|
|
4211
|
-
}
|
|
4212
|
-
const isPositive = operator === "eq?" || operator === "any-eq?";
|
|
4213
|
-
const matchAll = !operator.startsWith("any-");
|
|
4214
|
-
if (isCaptureStep(steps[2])) {
|
|
4215
|
-
const captureName1 = steps[1].name;
|
|
4216
|
-
const captureName2 = steps[2].name;
|
|
4217
|
-
textPredicates[index].push((captures) => {
|
|
4218
|
-
const nodes1 = [];
|
|
4219
|
-
const nodes2 = [];
|
|
4220
|
-
for (const c of captures) {
|
|
4221
|
-
if (c.name === captureName1) nodes1.push(c.node);
|
|
4222
|
-
if (c.name === captureName2) nodes2.push(c.node);
|
|
4223
|
-
}
|
|
4224
|
-
const compare = /* @__PURE__ */ __name((n1, n2, positive) => {
|
|
4225
|
-
return positive ? n1.text === n2.text : n1.text !== n2.text;
|
|
4226
|
-
}, "compare");
|
|
4227
|
-
return matchAll ? nodes1.every((n1) => nodes2.some((n2) => compare(n1, n2, isPositive))) : nodes1.some((n1) => nodes2.some((n2) => compare(n1, n2, isPositive)));
|
|
4228
|
-
});
|
|
4229
|
-
} else {
|
|
4230
|
-
const captureName = steps[1].name;
|
|
4231
|
-
const stringValue = steps[2].value;
|
|
4232
|
-
const matches = /* @__PURE__ */ __name((n) => n.text === stringValue, "matches");
|
|
4233
|
-
const doesNotMatch = /* @__PURE__ */ __name((n) => n.text !== stringValue, "doesNotMatch");
|
|
4234
|
-
textPredicates[index].push((captures) => {
|
|
4235
|
-
const nodes = [];
|
|
4236
|
-
for (const c of captures) {
|
|
4237
|
-
if (c.name === captureName) nodes.push(c.node);
|
|
4238
|
-
}
|
|
4239
|
-
const test = isPositive ? matches : doesNotMatch;
|
|
4240
|
-
return matchAll ? nodes.every(test) : nodes.some(test);
|
|
4241
|
-
});
|
|
4242
|
-
}
|
|
4243
|
-
}
|
|
4244
|
-
__name(parseAnyPredicate, "parseAnyPredicate");
|
|
4245
|
-
function parseMatchPredicate(steps, index, operator, textPredicates) {
|
|
4246
|
-
if (steps.length !== 3) {
|
|
4247
|
-
throw new Error(
|
|
4248
|
-
`Wrong number of arguments to \`#${operator}\` predicate. Expected 2, got ${steps.length - 1}.`
|
|
4249
|
-
);
|
|
4250
|
-
}
|
|
4251
|
-
if (steps[1].type !== "capture") {
|
|
4252
|
-
throw new Error(
|
|
4253
|
-
`First argument of \`#${operator}\` predicate must be a capture. Got "${steps[1].value}".`
|
|
4254
|
-
);
|
|
4255
|
-
}
|
|
4256
|
-
if (steps[2].type !== "string") {
|
|
4257
|
-
throw new Error(
|
|
4258
|
-
`Second argument of \`#${operator}\` predicate must be a string. Got @${steps[2].name}.`
|
|
4259
|
-
);
|
|
4260
|
-
}
|
|
4261
|
-
const isPositive = operator === "match?" || operator === "any-match?";
|
|
4262
|
-
const matchAll = !operator.startsWith("any-");
|
|
4263
|
-
const captureName = steps[1].name;
|
|
4264
|
-
const regex = new RegExp(steps[2].value);
|
|
4265
|
-
textPredicates[index].push((captures) => {
|
|
4266
|
-
const nodes = [];
|
|
4267
|
-
for (const c of captures) {
|
|
4268
|
-
if (c.name === captureName) nodes.push(c.node.text);
|
|
4269
|
-
}
|
|
4270
|
-
const test = /* @__PURE__ */ __name((text, positive) => {
|
|
4271
|
-
return positive ? regex.test(text) : !regex.test(text);
|
|
4272
|
-
}, "test");
|
|
4273
|
-
if (nodes.length === 0) return !isPositive;
|
|
4274
|
-
return matchAll ? nodes.every((text) => test(text, isPositive)) : nodes.some((text) => test(text, isPositive));
|
|
4275
|
-
});
|
|
4276
|
-
}
|
|
4277
|
-
__name(parseMatchPredicate, "parseMatchPredicate");
|
|
4278
|
-
function parseAnyOfPredicate(steps, index, operator, textPredicates) {
|
|
4279
|
-
if (steps.length < 2) {
|
|
4280
|
-
throw new Error(
|
|
4281
|
-
`Wrong number of arguments to \`#${operator}\` predicate. Expected at least 1. Got ${steps.length - 1}.`
|
|
4282
|
-
);
|
|
4283
|
-
}
|
|
4284
|
-
if (steps[1].type !== "capture") {
|
|
4285
|
-
throw new Error(
|
|
4286
|
-
`First argument of \`#${operator}\` predicate must be a capture. Got "${steps[1].value}".`
|
|
4287
|
-
);
|
|
4288
|
-
}
|
|
4289
|
-
const isPositive = operator === "any-of?";
|
|
4290
|
-
const captureName = steps[1].name;
|
|
4291
|
-
const stringSteps = steps.slice(2);
|
|
4292
|
-
if (!stringSteps.every(isStringStep)) {
|
|
4293
|
-
throw new Error(
|
|
4294
|
-
`Arguments to \`#${operator}\` predicate must be strings.".`
|
|
4295
|
-
);
|
|
4296
|
-
}
|
|
4297
|
-
const values = stringSteps.map((s) => s.value);
|
|
4298
|
-
textPredicates[index].push((captures) => {
|
|
4299
|
-
const nodes = [];
|
|
4300
|
-
for (const c of captures) {
|
|
4301
|
-
if (c.name === captureName) nodes.push(c.node.text);
|
|
4302
|
-
}
|
|
4303
|
-
if (nodes.length === 0) return !isPositive;
|
|
4304
|
-
return nodes.every((text) => values.includes(text)) === isPositive;
|
|
4305
|
-
});
|
|
4306
|
-
}
|
|
4307
|
-
__name(parseAnyOfPredicate, "parseAnyOfPredicate");
|
|
4308
|
-
function parseIsPredicate(steps, index, operator, assertedProperties, refutedProperties) {
|
|
4309
|
-
if (steps.length < 2 || steps.length > 3) {
|
|
4310
|
-
throw new Error(
|
|
4311
|
-
`Wrong number of arguments to \`#${operator}\` predicate. Expected 1 or 2. Got ${steps.length - 1}.`
|
|
4312
|
-
);
|
|
4313
|
-
}
|
|
4314
|
-
if (!steps.every(isStringStep)) {
|
|
4315
|
-
throw new Error(
|
|
4316
|
-
`Arguments to \`#${operator}\` predicate must be strings.".`
|
|
4317
|
-
);
|
|
4318
|
-
}
|
|
4319
|
-
const properties = operator === "is?" ? assertedProperties : refutedProperties;
|
|
4320
|
-
if (!properties[index]) properties[index] = {};
|
|
4321
|
-
properties[index][steps[1].value] = steps[2]?.value ?? null;
|
|
4322
|
-
}
|
|
4323
|
-
__name(parseIsPredicate, "parseIsPredicate");
|
|
4324
|
-
function parseSetDirective(steps, index, setProperties) {
|
|
4325
|
-
if (steps.length < 2 || steps.length > 3) {
|
|
4326
|
-
throw new Error(`Wrong number of arguments to \`#set!\` predicate. Expected 1 or 2. Got ${steps.length - 1}.`);
|
|
4327
|
-
}
|
|
4328
|
-
if (!steps.every(isStringStep)) {
|
|
4329
|
-
throw new Error(`Arguments to \`#set!\` predicate must be strings.".`);
|
|
4330
|
-
}
|
|
4331
|
-
if (!setProperties[index]) setProperties[index] = {};
|
|
4332
|
-
setProperties[index][steps[1].value] = steps[2]?.value ?? null;
|
|
4333
|
-
}
|
|
4334
|
-
__name(parseSetDirective, "parseSetDirective");
|
|
4335
|
-
function parsePattern(index, stepType, stepValueId, captureNames, stringValues, steps, textPredicates, predicates, setProperties, assertedProperties, refutedProperties) {
|
|
4336
|
-
if (stepType === PREDICATE_STEP_TYPE_CAPTURE) {
|
|
4337
|
-
const name2 = captureNames[stepValueId];
|
|
4338
|
-
steps.push({ type: "capture", name: name2 });
|
|
4339
|
-
} else if (stepType === PREDICATE_STEP_TYPE_STRING) {
|
|
4340
|
-
steps.push({ type: "string", value: stringValues[stepValueId] });
|
|
4341
|
-
} else if (steps.length > 0) {
|
|
4342
|
-
if (steps[0].type !== "string") {
|
|
4343
|
-
throw new Error("Predicates must begin with a literal value");
|
|
4344
|
-
}
|
|
4345
|
-
const operator = steps[0].value;
|
|
4346
|
-
switch (operator) {
|
|
4347
|
-
case "any-not-eq?":
|
|
4348
|
-
case "not-eq?":
|
|
4349
|
-
case "any-eq?":
|
|
4350
|
-
case "eq?":
|
|
4351
|
-
parseAnyPredicate(steps, index, operator, textPredicates);
|
|
4352
|
-
break;
|
|
4353
|
-
case "any-not-match?":
|
|
4354
|
-
case "not-match?":
|
|
4355
|
-
case "any-match?":
|
|
4356
|
-
case "match?":
|
|
4357
|
-
parseMatchPredicate(steps, index, operator, textPredicates);
|
|
4358
|
-
break;
|
|
4359
|
-
case "not-any-of?":
|
|
4360
|
-
case "any-of?":
|
|
4361
|
-
parseAnyOfPredicate(steps, index, operator, textPredicates);
|
|
4362
|
-
break;
|
|
4363
|
-
case "is?":
|
|
4364
|
-
case "is-not?":
|
|
4365
|
-
parseIsPredicate(steps, index, operator, assertedProperties, refutedProperties);
|
|
4366
|
-
break;
|
|
4367
|
-
case "set!":
|
|
4368
|
-
parseSetDirective(steps, index, setProperties);
|
|
4369
|
-
break;
|
|
4370
|
-
default:
|
|
4371
|
-
predicates[index].push({ operator, operands: steps.slice(1) });
|
|
4372
|
-
}
|
|
4373
|
-
steps.length = 0;
|
|
4374
|
-
}
|
|
4375
|
-
}
|
|
4376
|
-
__name(parsePattern, "parsePattern");
|
|
4377
|
-
var finalizer5 = newFinalizer((address) => {
|
|
4378
|
-
C._ts_query_delete(address);
|
|
4379
|
-
});
|
|
4380
|
-
var Query = class {
|
|
4381
|
-
static {
|
|
4382
|
-
__name(this, "Query");
|
|
4383
|
-
}
|
|
4384
|
-
/** @internal */
|
|
4385
|
-
[0] = 0;
|
|
4386
|
-
// Internal handle for Wasm
|
|
4387
|
-
/** @internal */
|
|
4388
|
-
exceededMatchLimit;
|
|
4389
|
-
/** @internal */
|
|
4390
|
-
textPredicates;
|
|
4391
|
-
/** The names of the captures used in the query. */
|
|
4392
|
-
captureNames;
|
|
4393
|
-
/** The quantifiers of the captures used in the query. */
|
|
4394
|
-
captureQuantifiers;
|
|
4395
|
-
/**
|
|
4396
|
-
* The other user-defined predicates associated with the given index.
|
|
4397
|
-
*
|
|
4398
|
-
* This includes predicates with operators other than:
|
|
4399
|
-
* - `match?`
|
|
4400
|
-
* - `eq?` and `not-eq?`
|
|
4401
|
-
* - `any-of?` and `not-any-of?`
|
|
4402
|
-
* - `is?` and `is-not?`
|
|
4403
|
-
* - `set!`
|
|
4404
|
-
*/
|
|
4405
|
-
predicates;
|
|
4406
|
-
/** The properties for predicates with the operator `set!`. */
|
|
4407
|
-
setProperties;
|
|
4408
|
-
/** The properties for predicates with the operator `is?`. */
|
|
4409
|
-
assertedProperties;
|
|
4410
|
-
/** The properties for predicates with the operator `is-not?`. */
|
|
4411
|
-
refutedProperties;
|
|
4412
|
-
/** The maximum number of in-progress matches for this cursor. */
|
|
4413
|
-
matchLimit;
|
|
4414
|
-
/**
|
|
4415
|
-
* Create a new query from a string containing one or more S-expression
|
|
4416
|
-
* patterns.
|
|
4417
|
-
*
|
|
4418
|
-
* The query is associated with a particular language, and can only be run
|
|
4419
|
-
* on syntax nodes parsed with that language. References to Queries can be
|
|
4420
|
-
* shared between multiple threads.
|
|
4421
|
-
*
|
|
4422
|
-
* @link {@see https://tree-sitter.github.io/tree-sitter/using-parsers/queries}
|
|
4423
|
-
*/
|
|
4424
|
-
constructor(language, source) {
|
|
4425
|
-
assertSupportedLanguage(language);
|
|
4426
|
-
const sourceLength = C.lengthBytesUTF8(source);
|
|
4427
|
-
const sourceAddress = C._malloc(sourceLength + 1);
|
|
4428
|
-
C.stringToUTF8(source, sourceAddress, sourceLength + 1);
|
|
4429
|
-
const address = C._ts_query_new(
|
|
4430
|
-
language[0],
|
|
4431
|
-
sourceAddress,
|
|
4432
|
-
sourceLength,
|
|
4433
|
-
TRANSFER_BUFFER,
|
|
4434
|
-
TRANSFER_BUFFER + SIZE_OF_INT
|
|
4435
|
-
);
|
|
4436
|
-
if (!address) {
|
|
4437
|
-
const errorId = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
|
|
4438
|
-
const errorByte = C.getValue(TRANSFER_BUFFER, "i32");
|
|
4439
|
-
const errorIndex = C.UTF8ToString(sourceAddress, errorByte).length;
|
|
4440
|
-
const suffix = source.slice(errorIndex, errorIndex + 100).split("\n")[0];
|
|
4441
|
-
const word = suffix.match(QUERY_WORD_REGEX)?.[0] ?? "";
|
|
4442
|
-
C._free(sourceAddress);
|
|
4443
|
-
switch (errorId) {
|
|
4444
|
-
case QueryErrorKind.Syntax:
|
|
4445
|
-
throw new QueryError(QueryErrorKind.Syntax, { suffix: `${errorIndex}: '${suffix}'...` }, errorIndex, 0);
|
|
4446
|
-
case QueryErrorKind.NodeName:
|
|
4447
|
-
throw new QueryError(errorId, { word }, errorIndex, word.length);
|
|
4448
|
-
case QueryErrorKind.FieldName:
|
|
4449
|
-
throw new QueryError(errorId, { word }, errorIndex, word.length);
|
|
4450
|
-
case QueryErrorKind.CaptureName:
|
|
4451
|
-
throw new QueryError(errorId, { word }, errorIndex, word.length);
|
|
4452
|
-
case QueryErrorKind.PatternStructure:
|
|
4453
|
-
throw new QueryError(errorId, { suffix: `${errorIndex}: '${suffix}'...` }, errorIndex, 0);
|
|
4454
|
-
}
|
|
4455
|
-
}
|
|
4456
|
-
const stringCount = C._ts_query_string_count(address);
|
|
4457
|
-
const captureCount = C._ts_query_capture_count(address);
|
|
4458
|
-
const patternCount = C._ts_query_pattern_count(address);
|
|
4459
|
-
const captureNames = new Array(captureCount);
|
|
4460
|
-
const captureQuantifiers = new Array(patternCount);
|
|
4461
|
-
const stringValues = new Array(stringCount);
|
|
4462
|
-
for (let i2 = 0; i2 < captureCount; i2++) {
|
|
4463
|
-
const nameAddress = C._ts_query_capture_name_for_id(
|
|
4464
|
-
address,
|
|
4465
|
-
i2,
|
|
4466
|
-
TRANSFER_BUFFER
|
|
4467
|
-
);
|
|
4468
|
-
const nameLength = C.getValue(TRANSFER_BUFFER, "i32");
|
|
4469
|
-
captureNames[i2] = C.UTF8ToString(nameAddress, nameLength);
|
|
4470
|
-
}
|
|
4471
|
-
for (let i2 = 0; i2 < patternCount; i2++) {
|
|
4472
|
-
const captureQuantifiersArray = new Array(captureCount);
|
|
4473
|
-
for (let j = 0; j < captureCount; j++) {
|
|
4474
|
-
const quantifier = C._ts_query_capture_quantifier_for_id(address, i2, j);
|
|
4475
|
-
captureQuantifiersArray[j] = quantifier;
|
|
4476
|
-
}
|
|
4477
|
-
captureQuantifiers[i2] = captureQuantifiersArray;
|
|
4478
|
-
}
|
|
4479
|
-
for (let i2 = 0; i2 < stringCount; i2++) {
|
|
4480
|
-
const valueAddress = C._ts_query_string_value_for_id(
|
|
4481
|
-
address,
|
|
4482
|
-
i2,
|
|
4483
|
-
TRANSFER_BUFFER
|
|
4484
|
-
);
|
|
4485
|
-
const nameLength = C.getValue(TRANSFER_BUFFER, "i32");
|
|
4486
|
-
stringValues[i2] = C.UTF8ToString(valueAddress, nameLength);
|
|
4487
|
-
}
|
|
4488
|
-
const setProperties = new Array(patternCount);
|
|
4489
|
-
const assertedProperties = new Array(patternCount);
|
|
4490
|
-
const refutedProperties = new Array(patternCount);
|
|
4491
|
-
const predicates = new Array(patternCount);
|
|
4492
|
-
const textPredicates = new Array(patternCount);
|
|
4493
|
-
for (let i2 = 0; i2 < patternCount; i2++) {
|
|
4494
|
-
const predicatesAddress = C._ts_query_predicates_for_pattern(address, i2, TRANSFER_BUFFER);
|
|
4495
|
-
const stepCount = C.getValue(TRANSFER_BUFFER, "i32");
|
|
4496
|
-
predicates[i2] = [];
|
|
4497
|
-
textPredicates[i2] = [];
|
|
4498
|
-
const steps = new Array();
|
|
4499
|
-
let stepAddress = predicatesAddress;
|
|
4500
|
-
for (let j = 0; j < stepCount; j++) {
|
|
4501
|
-
const stepType = C.getValue(stepAddress, "i32");
|
|
4502
|
-
stepAddress += SIZE_OF_INT;
|
|
4503
|
-
const stepValueId = C.getValue(stepAddress, "i32");
|
|
4504
|
-
stepAddress += SIZE_OF_INT;
|
|
4505
|
-
parsePattern(
|
|
4506
|
-
i2,
|
|
4507
|
-
stepType,
|
|
4508
|
-
stepValueId,
|
|
4509
|
-
captureNames,
|
|
4510
|
-
stringValues,
|
|
4511
|
-
steps,
|
|
4512
|
-
textPredicates,
|
|
4513
|
-
predicates,
|
|
4514
|
-
setProperties,
|
|
4515
|
-
assertedProperties,
|
|
4516
|
-
refutedProperties
|
|
4517
|
-
);
|
|
4518
|
-
}
|
|
4519
|
-
Object.freeze(textPredicates[i2]);
|
|
4520
|
-
Object.freeze(predicates[i2]);
|
|
4521
|
-
Object.freeze(setProperties[i2]);
|
|
4522
|
-
Object.freeze(assertedProperties[i2]);
|
|
4523
|
-
Object.freeze(refutedProperties[i2]);
|
|
4524
|
-
}
|
|
4525
|
-
C._free(sourceAddress);
|
|
4526
|
-
this[0] = address;
|
|
4527
|
-
this.captureNames = captureNames;
|
|
4528
|
-
this.captureQuantifiers = captureQuantifiers;
|
|
4529
|
-
this.textPredicates = textPredicates;
|
|
4530
|
-
this.predicates = predicates;
|
|
4531
|
-
this.setProperties = setProperties;
|
|
4532
|
-
this.assertedProperties = assertedProperties;
|
|
4533
|
-
this.refutedProperties = refutedProperties;
|
|
4534
|
-
this.exceededMatchLimit = false;
|
|
4535
|
-
finalizer5?.register(this, address, this);
|
|
4536
|
-
}
|
|
4537
|
-
/** Delete the query, freeing its resources. */
|
|
4538
|
-
delete() {
|
|
4539
|
-
finalizer5?.unregister(this);
|
|
4540
|
-
C._ts_query_delete(this[0]);
|
|
4541
|
-
this[0] = 0;
|
|
4542
|
-
}
|
|
4543
|
-
/**
|
|
4544
|
-
* Iterate over all of the matches in the order that they were found.
|
|
4545
|
-
*
|
|
4546
|
-
* Each match contains the index of the pattern that matched, and a list of
|
|
4547
|
-
* captures. Because multiple patterns can match the same set of nodes,
|
|
4548
|
-
* one match may contain captures that appear *before* some of the
|
|
4549
|
-
* captures from a previous match.
|
|
4550
|
-
*
|
|
4551
|
-
* @param {Node} node - The node to execute the query on.
|
|
4552
|
-
*
|
|
4553
|
-
* @param {QueryOptions} options - Options for query execution.
|
|
4554
|
-
*/
|
|
4555
|
-
matches(node, options = {}) {
|
|
4556
|
-
const startPosition = options.startPosition ?? ZERO_POINT;
|
|
4557
|
-
const endPosition = options.endPosition ?? ZERO_POINT;
|
|
4558
|
-
const startIndex = options.startIndex ?? 0;
|
|
4559
|
-
const endIndex = options.endIndex ?? 0;
|
|
4560
|
-
const startContainingPosition = options.startContainingPosition ?? ZERO_POINT;
|
|
4561
|
-
const endContainingPosition = options.endContainingPosition ?? ZERO_POINT;
|
|
4562
|
-
const startContainingIndex = options.startContainingIndex ?? 0;
|
|
4563
|
-
const endContainingIndex = options.endContainingIndex ?? 0;
|
|
4564
|
-
const matchLimit = options.matchLimit ?? 4294967295;
|
|
4565
|
-
const maxStartDepth = options.maxStartDepth ?? 4294967295;
|
|
4566
|
-
const progressCallback = options.progressCallback;
|
|
4567
|
-
if (typeof matchLimit !== "number") {
|
|
4568
|
-
throw new Error("Arguments must be numbers");
|
|
4569
|
-
}
|
|
4570
|
-
this.matchLimit = matchLimit;
|
|
4571
|
-
if (endIndex !== 0 && startIndex > endIndex) {
|
|
4572
|
-
throw new Error("`startIndex` cannot be greater than `endIndex`");
|
|
4573
|
-
}
|
|
4574
|
-
if (endPosition !== ZERO_POINT && (startPosition.row > endPosition.row || startPosition.row === endPosition.row && startPosition.column > endPosition.column)) {
|
|
4575
|
-
throw new Error("`startPosition` cannot be greater than `endPosition`");
|
|
4576
|
-
}
|
|
4577
|
-
if (endContainingIndex !== 0 && startContainingIndex > endContainingIndex) {
|
|
4578
|
-
throw new Error("`startContainingIndex` cannot be greater than `endContainingIndex`");
|
|
4579
|
-
}
|
|
4580
|
-
if (endContainingPosition !== ZERO_POINT && (startContainingPosition.row > endContainingPosition.row || startContainingPosition.row === endContainingPosition.row && startContainingPosition.column > endContainingPosition.column)) {
|
|
4581
|
-
throw new Error("`startContainingPosition` cannot be greater than `endContainingPosition`");
|
|
4582
|
-
}
|
|
4583
|
-
if (progressCallback) {
|
|
4584
|
-
C.currentQueryProgressCallback = progressCallback;
|
|
4585
|
-
}
|
|
4586
|
-
marshalNode(node);
|
|
4587
|
-
C._ts_query_matches_wasm(
|
|
4588
|
-
this[0],
|
|
4589
|
-
node.tree[0],
|
|
4590
|
-
startPosition.row,
|
|
4591
|
-
startPosition.column,
|
|
4592
|
-
endPosition.row,
|
|
4593
|
-
endPosition.column,
|
|
4594
|
-
startIndex,
|
|
4595
|
-
endIndex,
|
|
4596
|
-
startContainingPosition.row,
|
|
4597
|
-
startContainingPosition.column,
|
|
4598
|
-
endContainingPosition.row,
|
|
4599
|
-
endContainingPosition.column,
|
|
4600
|
-
startContainingIndex,
|
|
4601
|
-
endContainingIndex,
|
|
4602
|
-
matchLimit,
|
|
4603
|
-
maxStartDepth
|
|
4604
|
-
);
|
|
4605
|
-
const rawCount = C.getValue(TRANSFER_BUFFER, "i32");
|
|
4606
|
-
const startAddress = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
|
|
4607
|
-
const didExceedMatchLimit = C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, "i32");
|
|
4608
|
-
const result = new Array(rawCount);
|
|
4609
|
-
this.exceededMatchLimit = Boolean(didExceedMatchLimit);
|
|
4610
|
-
let filteredCount = 0;
|
|
4611
|
-
let address = startAddress;
|
|
4612
|
-
for (let i2 = 0; i2 < rawCount; i2++) {
|
|
4613
|
-
const patternIndex = C.getValue(address, "i32");
|
|
4614
|
-
address += SIZE_OF_INT;
|
|
4615
|
-
const captureCount = C.getValue(address, "i32");
|
|
4616
|
-
address += SIZE_OF_INT;
|
|
4617
|
-
const captures = new Array(captureCount);
|
|
4618
|
-
address = unmarshalCaptures(this, node.tree, address, patternIndex, captures);
|
|
4619
|
-
if (this.textPredicates[patternIndex].every((p) => p(captures))) {
|
|
4620
|
-
result[filteredCount] = { patternIndex, captures };
|
|
4621
|
-
const setProperties = this.setProperties[patternIndex];
|
|
4622
|
-
result[filteredCount].setProperties = setProperties;
|
|
4623
|
-
const assertedProperties = this.assertedProperties[patternIndex];
|
|
4624
|
-
result[filteredCount].assertedProperties = assertedProperties;
|
|
4625
|
-
const refutedProperties = this.refutedProperties[patternIndex];
|
|
4626
|
-
result[filteredCount].refutedProperties = refutedProperties;
|
|
4627
|
-
filteredCount++;
|
|
4628
|
-
}
|
|
4629
|
-
}
|
|
4630
|
-
result.length = filteredCount;
|
|
4631
|
-
C._ts_free_wasm(startAddress);
|
|
4632
|
-
C.currentQueryProgressCallback = null;
|
|
4633
|
-
return result;
|
|
4634
|
-
}
|
|
4635
|
-
/**
|
|
4636
|
-
* Iterate over all of the individual captures in the order that they
|
|
4637
|
-
* appear.
|
|
4638
|
-
*
|
|
4639
|
-
* This is useful if you don't care about which pattern matched, and just
|
|
4640
|
-
* want a single, ordered sequence of captures.
|
|
4641
|
-
*
|
|
4642
|
-
* @param {Node} node - The node to execute the query on.
|
|
4643
|
-
*
|
|
4644
|
-
* @param {QueryOptions} options - Options for query execution.
|
|
4645
|
-
*/
|
|
4646
|
-
captures(node, options = {}) {
|
|
4647
|
-
const startPosition = options.startPosition ?? ZERO_POINT;
|
|
4648
|
-
const endPosition = options.endPosition ?? ZERO_POINT;
|
|
4649
|
-
const startIndex = options.startIndex ?? 0;
|
|
4650
|
-
const endIndex = options.endIndex ?? 0;
|
|
4651
|
-
const startContainingPosition = options.startContainingPosition ?? ZERO_POINT;
|
|
4652
|
-
const endContainingPosition = options.endContainingPosition ?? ZERO_POINT;
|
|
4653
|
-
const startContainingIndex = options.startContainingIndex ?? 0;
|
|
4654
|
-
const endContainingIndex = options.endContainingIndex ?? 0;
|
|
4655
|
-
const matchLimit = options.matchLimit ?? 4294967295;
|
|
4656
|
-
const maxStartDepth = options.maxStartDepth ?? 4294967295;
|
|
4657
|
-
const progressCallback = options.progressCallback;
|
|
4658
|
-
if (typeof matchLimit !== "number") {
|
|
4659
|
-
throw new Error("Arguments must be numbers");
|
|
4660
|
-
}
|
|
4661
|
-
this.matchLimit = matchLimit;
|
|
4662
|
-
if (endIndex !== 0 && startIndex > endIndex) {
|
|
4663
|
-
throw new Error("`startIndex` cannot be greater than `endIndex`");
|
|
4664
|
-
}
|
|
4665
|
-
if (endPosition !== ZERO_POINT && (startPosition.row > endPosition.row || startPosition.row === endPosition.row && startPosition.column > endPosition.column)) {
|
|
4666
|
-
throw new Error("`startPosition` cannot be greater than `endPosition`");
|
|
4667
|
-
}
|
|
4668
|
-
if (endContainingIndex !== 0 && startContainingIndex > endContainingIndex) {
|
|
4669
|
-
throw new Error("`startContainingIndex` cannot be greater than `endContainingIndex`");
|
|
4670
|
-
}
|
|
4671
|
-
if (endContainingPosition !== ZERO_POINT && (startContainingPosition.row > endContainingPosition.row || startContainingPosition.row === endContainingPosition.row && startContainingPosition.column > endContainingPosition.column)) {
|
|
4672
|
-
throw new Error("`startContainingPosition` cannot be greater than `endContainingPosition`");
|
|
4673
|
-
}
|
|
4674
|
-
if (progressCallback) {
|
|
4675
|
-
C.currentQueryProgressCallback = progressCallback;
|
|
4676
|
-
}
|
|
4677
|
-
marshalNode(node);
|
|
4678
|
-
C._ts_query_captures_wasm(
|
|
4679
|
-
this[0],
|
|
4680
|
-
node.tree[0],
|
|
4681
|
-
startPosition.row,
|
|
4682
|
-
startPosition.column,
|
|
4683
|
-
endPosition.row,
|
|
4684
|
-
endPosition.column,
|
|
4685
|
-
startIndex,
|
|
4686
|
-
endIndex,
|
|
4687
|
-
startContainingPosition.row,
|
|
4688
|
-
startContainingPosition.column,
|
|
4689
|
-
endContainingPosition.row,
|
|
4690
|
-
endContainingPosition.column,
|
|
4691
|
-
startContainingIndex,
|
|
4692
|
-
endContainingIndex,
|
|
4693
|
-
matchLimit,
|
|
4694
|
-
maxStartDepth
|
|
4695
|
-
);
|
|
4696
|
-
const count = C.getValue(TRANSFER_BUFFER, "i32");
|
|
4697
|
-
const startAddress = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
|
|
4698
|
-
const didExceedMatchLimit = C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, "i32");
|
|
4699
|
-
const result = new Array();
|
|
4700
|
-
this.exceededMatchLimit = Boolean(didExceedMatchLimit);
|
|
4701
|
-
const captures = new Array();
|
|
4702
|
-
let address = startAddress;
|
|
4703
|
-
for (let i2 = 0; i2 < count; i2++) {
|
|
4704
|
-
const patternIndex = C.getValue(address, "i32");
|
|
4705
|
-
address += SIZE_OF_INT;
|
|
4706
|
-
const captureCount = C.getValue(address, "i32");
|
|
4707
|
-
address += SIZE_OF_INT;
|
|
4708
|
-
const captureIndex = C.getValue(address, "i32");
|
|
4709
|
-
address += SIZE_OF_INT;
|
|
4710
|
-
captures.length = captureCount;
|
|
4711
|
-
address = unmarshalCaptures(this, node.tree, address, patternIndex, captures);
|
|
4712
|
-
if (this.textPredicates[patternIndex].every((p) => p(captures))) {
|
|
4713
|
-
const capture = captures[captureIndex];
|
|
4714
|
-
const setProperties = this.setProperties[patternIndex];
|
|
4715
|
-
capture.setProperties = setProperties;
|
|
4716
|
-
const assertedProperties = this.assertedProperties[patternIndex];
|
|
4717
|
-
capture.assertedProperties = assertedProperties;
|
|
4718
|
-
const refutedProperties = this.refutedProperties[patternIndex];
|
|
4719
|
-
capture.refutedProperties = refutedProperties;
|
|
4720
|
-
result.push(capture);
|
|
4721
|
-
}
|
|
4722
|
-
}
|
|
4723
|
-
C._ts_free_wasm(startAddress);
|
|
4724
|
-
C.currentQueryProgressCallback = null;
|
|
4725
|
-
return result;
|
|
4726
|
-
}
|
|
4727
|
-
/** Get the predicates for a given pattern. */
|
|
4728
|
-
predicatesForPattern(patternIndex) {
|
|
4729
|
-
return this.predicates[patternIndex];
|
|
4730
|
-
}
|
|
4731
|
-
/**
|
|
4732
|
-
* Disable a certain capture within a query.
|
|
4733
|
-
*
|
|
4734
|
-
* This prevents the capture from being returned in matches, and also
|
|
4735
|
-
* avoids any resource usage associated with recording the capture.
|
|
4736
|
-
*/
|
|
4737
|
-
disableCapture(captureName) {
|
|
4738
|
-
const captureNameLength = C.lengthBytesUTF8(captureName);
|
|
4739
|
-
const captureNameAddress = C._malloc(captureNameLength + 1);
|
|
4740
|
-
C.stringToUTF8(captureName, captureNameAddress, captureNameLength + 1);
|
|
4741
|
-
C._ts_query_disable_capture(this[0], captureNameAddress, captureNameLength);
|
|
4742
|
-
C._free(captureNameAddress);
|
|
4743
|
-
}
|
|
4744
|
-
/**
|
|
4745
|
-
* Disable a certain pattern within a query.
|
|
4746
|
-
*
|
|
4747
|
-
* This prevents the pattern from matching, and also avoids any resource
|
|
4748
|
-
* usage associated with the pattern. This throws an error if the pattern
|
|
4749
|
-
* index is out of bounds.
|
|
4750
|
-
*/
|
|
4751
|
-
disablePattern(patternIndex) {
|
|
4752
|
-
if (patternIndex >= this.predicates.length) {
|
|
4753
|
-
throw new Error(
|
|
4754
|
-
`Pattern index is ${patternIndex} but the pattern count is ${this.predicates.length}`
|
|
4755
|
-
);
|
|
4756
|
-
}
|
|
4757
|
-
C._ts_query_disable_pattern(this[0], patternIndex);
|
|
4758
|
-
}
|
|
4759
|
-
/**
|
|
4760
|
-
* Check if, on its last execution, this cursor exceeded its maximum number
|
|
4761
|
-
* of in-progress matches.
|
|
4762
|
-
*/
|
|
4763
|
-
didExceedMatchLimit() {
|
|
4764
|
-
return this.exceededMatchLimit;
|
|
4765
|
-
}
|
|
4766
|
-
/** Get the byte offset where the given pattern starts in the query's source. */
|
|
4767
|
-
startIndexForPattern(patternIndex) {
|
|
4768
|
-
if (patternIndex >= this.predicates.length) {
|
|
4769
|
-
throw new Error(
|
|
4770
|
-
`Pattern index is ${patternIndex} but the pattern count is ${this.predicates.length}`
|
|
4771
|
-
);
|
|
4772
|
-
}
|
|
4773
|
-
return C._ts_query_start_byte_for_pattern(this[0], patternIndex);
|
|
4774
|
-
}
|
|
4775
|
-
/** Get the byte offset where the given pattern ends in the query's source. */
|
|
4776
|
-
endIndexForPattern(patternIndex) {
|
|
4777
|
-
if (patternIndex >= this.predicates.length) {
|
|
4778
|
-
throw new Error(
|
|
4779
|
-
`Pattern index is ${patternIndex} but the pattern count is ${this.predicates.length}`
|
|
4780
|
-
);
|
|
4781
|
-
}
|
|
4782
|
-
return C._ts_query_end_byte_for_pattern(this[0], patternIndex);
|
|
4783
|
-
}
|
|
4784
|
-
/** Get the number of patterns in the query. */
|
|
4785
|
-
patternCount() {
|
|
4786
|
-
return C._ts_query_pattern_count(this[0]);
|
|
4787
|
-
}
|
|
4788
|
-
/** Get the index for a given capture name. */
|
|
4789
|
-
captureIndexForName(captureName) {
|
|
4790
|
-
return this.captureNames.indexOf(captureName);
|
|
4791
|
-
}
|
|
4792
|
-
/** Check if a given pattern within a query has a single root node. */
|
|
4793
|
-
isPatternRooted(patternIndex) {
|
|
4794
|
-
return C._ts_query_is_pattern_rooted(this[0], patternIndex) === 1;
|
|
4795
|
-
}
|
|
4796
|
-
/** Check if a given pattern within a query has a single root node. */
|
|
4797
|
-
isPatternNonLocal(patternIndex) {
|
|
4798
|
-
return C._ts_query_is_pattern_non_local(this[0], patternIndex) === 1;
|
|
4799
|
-
}
|
|
4800
|
-
/**
|
|
4801
|
-
* Check if a given step in a query is 'definite'.
|
|
4802
|
-
*
|
|
4803
|
-
* A query step is 'definite' if its parent pattern will be guaranteed to
|
|
4804
|
-
* match successfully once it reaches the step.
|
|
4805
|
-
*/
|
|
4806
|
-
isPatternGuaranteedAtStep(byteIndex) {
|
|
4807
|
-
return C._ts_query_is_pattern_guaranteed_at_step(this[0], byteIndex) === 1;
|
|
4808
|
-
}
|
|
4809
|
-
};
|
|
4810
4087
|
export {
|
|
4811
|
-
CaptureQuantifier,
|
|
4812
4088
|
Edit,
|
|
4813
4089
|
LANGUAGE_VERSION,
|
|
4814
4090
|
Language,
|
|
@@ -4816,7 +4092,6 @@ export {
|
|
|
4816
4092
|
MIN_COMPATIBLE_VERSION,
|
|
4817
4093
|
Node,
|
|
4818
4094
|
Parser,
|
|
4819
|
-
Query,
|
|
4820
4095
|
Tree,
|
|
4821
4096
|
TreeCursor
|
|
4822
4097
|
};
|