* Iterate over all of the individual captures in the order that they * appear. * * This is useful if you don't care about which pattern matched, and just * want a single, ordered sequence of captures. * * @param {Node} node - The node to execute the query on. * * @param {Quer
(node, options = {})
| 3828 | * @param {QueryOptions} options - Options for query execution. |
| 3829 | */ |
| 3830 | captures(node, options = {}) { |
| 3831 | const startPosition = options.startPosition ?? ZERO_POINT; |
| 3832 | const endPosition = options.endPosition ?? ZERO_POINT; |
| 3833 | const startIndex = options.startIndex ?? 0; |
| 3834 | const endIndex = options.endIndex ?? 0; |
| 3835 | const startContainingPosition = options.startContainingPosition ?? ZERO_POINT; |
| 3836 | const endContainingPosition = options.endContainingPosition ?? ZERO_POINT; |
| 3837 | const startContainingIndex = options.startContainingIndex ?? 0; |
| 3838 | const endContainingIndex = options.endContainingIndex ?? 0; |
| 3839 | const matchLimit = options.matchLimit ?? 4294967295; |
| 3840 | const maxStartDepth = options.maxStartDepth ?? 4294967295; |
| 3841 | const progressCallback = options.progressCallback; |
| 3842 | if (typeof matchLimit !== "number") { |
| 3843 | throw new Error("Arguments must be numbers"); |
| 3844 | } |
| 3845 | this.matchLimit = matchLimit; |
| 3846 | if (endIndex !== 0 && startIndex > endIndex) { |
| 3847 | throw new Error("`startIndex` cannot be greater than `endIndex`"); |
| 3848 | } |
| 3849 | if (endPosition !== ZERO_POINT && (startPosition.row > endPosition.row || startPosition.row === endPosition.row && startPosition.column > endPosition.column)) { |
| 3850 | throw new Error("`startPosition` cannot be greater than `endPosition`"); |
| 3851 | } |
| 3852 | if (endContainingIndex !== 0 && startContainingIndex > endContainingIndex) { |
| 3853 | throw new Error("`startContainingIndex` cannot be greater than `endContainingIndex`"); |
| 3854 | } |
| 3855 | if (endContainingPosition !== ZERO_POINT && (startContainingPosition.row > endContainingPosition.row || startContainingPosition.row === endContainingPosition.row && startContainingPosition.column > endContainingPosition.column)) { |
| 3856 | throw new Error("`startContainingPosition` cannot be greater than `endContainingPosition`"); |
| 3857 | } |
| 3858 | if (progressCallback) { |
| 3859 | C.currentQueryProgressCallback = progressCallback; |
| 3860 | } |
| 3861 | marshalNode(node); |
| 3862 | C._ts_query_captures_wasm( |
| 3863 | this[0], |
| 3864 | node.tree[0], |
| 3865 | startPosition.row, |
| 3866 | startPosition.column, |
| 3867 | endPosition.row, |
| 3868 | endPosition.column, |
| 3869 | startIndex, |
| 3870 | endIndex, |
| 3871 | startContainingPosition.row, |
| 3872 | startContainingPosition.column, |
| 3873 | endContainingPosition.row, |
| 3874 | endContainingPosition.column, |
| 3875 | startContainingIndex, |
| 3876 | endContainingIndex, |
| 3877 | matchLimit, |
| 3878 | maxStartDepth |
| 3879 | ); |
| 3880 | const count = C.getValue(TRANSFER_BUFFER, "i32"); |
| 3881 | const startAddress = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32"); |
| 3882 | const didExceedMatchLimit = C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, "i32"); |
| 3883 | const result = new Array(); |
| 3884 | this.exceededMatchLimit = Boolean(didExceedMatchLimit); |
| 3885 | const captures = new Array(); |
| 3886 | let address = startAddress; |
| 3887 | for (let i2 = 0; i2 < count; i2++) { |
no test coverage detected