From 0f492e4254aab125d5828ed95a506ddb684c9201 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 11 Dec 2020 13:47:20 -0800 Subject: [PATCH] Include ts_tree_copy in wasm build Fixes #846 --- lib/binding_web/exports.json | 1 + lib/binding_web/test/tree-test.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) 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/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) {