Skip to content

Commit 6574ec8

Browse files
committed
Fix issue where leaving visitor could return false, it should behave as similarly to visitor enter as possible
1 parent 2c6fa95 commit 6574ec8

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/language/visitor.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export const BREAK = {};
6666
* leave(node, key, parent, path, ancestors) {
6767
* // @return
6868
* // undefined: no action
69+
* // false: no action
6970
* // visitor.BREAK: stop visiting altogether
7071
* // null: delete this node
7172
* // any value: replace this node with the returned value
@@ -203,12 +204,12 @@ export function visit(root, visitor) {
203204
break;
204205
}
205206

206-
if (!isLeaving && result === false) {
207-
path.pop();
208-
continue;
209-
}
210-
211-
if (result !== undefined) {
207+
if (result === false) {
208+
if (!isLeaving) {
209+
path.pop();
210+
continue;
211+
}
212+
} else if (result !== undefined) {
212213
edits.push([key, result]);
213214
if (!isLeaving) {
214215
if (isNode(result)) {

src/validator/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function visitUsingRules(
165165
instances[i] = null;
166166
} else if (isError(result)) {
167167
append(errors, result);
168-
} else if (result !== undefined) {
168+
} else if (result !== undefined && result !== false) {
169169
throw new Error('Validator cannot edit document.');
170170
}
171171
}

0 commit comments

Comments
 (0)