diff --git a/docs/index.md b/docs/index.md index 414dd9f9..d671bdaf 100644 --- a/docs/index.md +++ b/docs/index.md @@ -46,6 +46,7 @@ Parsers for these languages are fairly complete: * [Python](https://github.com/tree-sitter/tree-sitter-python) * [Ruby](https://github.com/tree-sitter/tree-sitter-ruby) * [Rust](https://github.com/tree-sitter/tree-sitter-rust) +* [R](https://github.com/r-lib/tree-sitter-r) * [S-expressions](https://github.com/AbstractMachinesLab/tree-sitter-sexp) * [SystemRDL](https://github.com/SystemRDL/tree-sitter-systemrdl) * [TOML](https://github.com/ikatyang/tree-sitter-toml) diff --git a/lib/binding_web/exports.json b/lib/binding_web/exports.json index 72105158..d0173f3a 100644 --- a/lib/binding_web/exports.json +++ b/lib/binding_web/exports.json @@ -79,6 +79,7 @@ "_ts_query_predicates_for_pattern", "_ts_query_string_count", "_ts_query_string_value_for_id", + "_ts_tree_copy", "_ts_tree_cursor_current_field_id_wasm", "_ts_tree_cursor_current_node_id_wasm", "_ts_tree_cursor_current_node_is_missing_wasm", diff --git a/lib/binding_web/package.json b/lib/binding_web/package.json index 8c61cf75..25aeb862 100644 --- a/lib/binding_web/package.json +++ b/lib/binding_web/package.json @@ -1,6 +1,6 @@ { "name": "web-tree-sitter", - "version": "0.17.1", + "version": "0.18.0", "description": "Tree-sitter bindings for the web", "main": "tree-sitter.js", "types": "tree-sitter-web.d.ts", diff --git a/lib/binding_web/test/tree-test.js b/lib/binding_web/test/tree-test.js index ccb7a830..8c04e63e 100644 --- a/lib/binding_web/test/tree-test.js +++ b/lib/binding_web/test/tree-test.js @@ -323,6 +323,31 @@ describe("Tree", () => { assert(!cursor.gotoParent()); }) }); + + describe(".copy", () => { + it("creates another tree that remains stable if the original tree is edited", () => { + input = 'abc + cde'; + tree = parser.parse(input); + assert.equal( + tree.rootNode.toString(), + "(program (expression_statement (binary_expression left: (identifier) right: (identifier))))" + ); + + const tree2 = tree.copy(); + ([input, edit] = spliceInput(input, 3, 0, '123')); + assert.equal(input, 'abc123 + cde'); + tree.edit(edit); + + const leftNode = tree.rootNode.firstChild.firstChild.firstChild; + const leftNode2 = tree2.rootNode.firstChild.firstChild.firstChild; + const rightNode = tree.rootNode.firstChild.firstChild.lastChild; + const rightNode2 = tree2.rootNode.firstChild.firstChild.lastChild; + assert.equal(leftNode.endIndex, 6) + assert.equal(leftNode2.endIndex, 3) + assert.equal(rightNode.startIndex, 9) + assert.equal(rightNode2.startIndex, 6) + }); + }); }); function spliceInput(input, startIndex, lengthRemoved, newText) {