lezer-tree
Advanced tools
Comparing version 0.7.0 to 0.7.1
@@ -0,1 +1,8 @@ | ||
## 0.7.1 (2020-01-23) | ||
### Bug fixes | ||
In `applyChanges`, make sure the tree is collapsed all the way to the | ||
nearest non-error node next to the change. | ||
## 0.7.0 (2020-01-20) | ||
@@ -2,0 +9,0 @@ |
@@ -353,12 +353,13 @@ "use strict"; | ||
function cutAt(tree, pos, side) { | ||
var sub = tree.resolve(pos); | ||
for (var cur = pos;;) { | ||
var sibling = side < 0 ? sub.childBefore(cur) : sub.childAfter(cur); | ||
if (sibling) | ||
return side < 0 ? sibling.end - 1 : sibling.start + 1; | ||
if (!sub.parent) | ||
return side < 0 ? 0 : 1e9; | ||
cur = side < 0 ? sub.start : sub.end; | ||
sub = sub.parent; | ||
} | ||
var found = -1; | ||
tree.iterate({ | ||
from: pos, | ||
to: side < 0 ? 0 : tree.length, | ||
enter: function () { return found < 0 ? undefined : false; }, | ||
leave: function (type, start, end) { | ||
if (found < 0 && !type.prop(NodeProp.error)) | ||
found = side < 0 ? Math.min(pos, end - 1) : Math.max(pos, start + 1); | ||
} | ||
}); | ||
return found > -1 ? found : side < 0 ? 0 : tree.length; | ||
} | ||
@@ -365,0 +366,0 @@ var off = 0; |
{ | ||
"name": "lezer-tree", | ||
"version": "0.7.0", | ||
"version": "0.7.1", | ||
"description": "Syntax tree data structure for the lezer parser", | ||
@@ -5,0 +5,0 @@ "main": "dist/tree.js", |
@@ -368,10 +368,13 @@ /// The default maximum length of a `TreeBuffer` node. | ||
function cutAt(tree: Tree, pos: number, side: -1 | 1) { | ||
let sub = tree.resolve(pos) | ||
for (let cur = pos;;) { | ||
let sibling = side < 0 ? sub.childBefore(cur) : sub.childAfter(cur) | ||
if (sibling) return side < 0 ? sibling.end - 1 : sibling.start + 1 | ||
if (!sub.parent) return side < 0 ? 0 : 1e9 | ||
cur = side < 0 ? sub.start : sub.end | ||
sub = sub.parent! | ||
} | ||
let found = -1 | ||
tree.iterate({ | ||
from: pos, | ||
to: side < 0 ? 0 : tree.length, | ||
enter() { return found < 0 ? undefined : false }, | ||
leave(type, start, end) { | ||
if (found < 0 && !type.prop(NodeProp.error)) | ||
found = side < 0 ? Math.min(pos, end - 1) : Math.max(pos, start + 1) | ||
} | ||
}) | ||
return found > -1 ? found : side < 0 ? 0 : tree.length | ||
} | ||
@@ -378,0 +381,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
120019
11
1979