Merge branch 'master' into patch-1

This commit is contained in:
Leandro Ostera 2020-12-13 00:28:54 +01:00 committed by GitHub
commit da58afb0b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 1 deletions

View file

@ -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)

View file

@ -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",

View file

@ -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",

View file

@ -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) {