Skip to content

Commit

Permalink
[walker] Fix bug where full and fullAncestor skip nodes with overridd…
Browse files Browse the repository at this point in the history
…en types

Issue #1008
  • Loading branch information
marijnh committed Jan 5, 2021
1 parent c20e05a commit 5468909
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions acorn-walk/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,31 @@ class Found {
// A full walk triggers the callback on each node
export function full(node, callback, baseVisitor, state, override) {
if (!baseVisitor) baseVisitor = base
let last
;(function c(node, st, override) {
let type = override || node.type
baseVisitor[type](node, st, c)
if (!override) callback(node, st, type)
if (last != node) {
callback(node, st, type)
last = node
}
})(node, state, override)
}

// An fullAncestor walk is like an ancestor walk, but triggers
// the callback on each node
export function fullAncestor(node, callback, baseVisitor, state) {
if (!baseVisitor) baseVisitor = base
let ancestors = []
let ancestors = [], last
;(function c(node, st, override) {
let type = override || node.type
let isNew = node !== ancestors[ancestors.length - 1]
if (isNew) ancestors.push(node)
baseVisitor[type](node, st, c)
if (!override) callback(node, st || ancestors, ancestors, type)
if (last != node) {
callback(node, st || ancestors, ancestors, type)
last = node
}
if (isNew) ancestors.pop()
})(node, state)
}
Expand Down

0 comments on commit 5468909

Please sign in to comment.