Skip to content

Commit

Permalink
Make visitors keep their "this" context
Browse files Browse the repository at this point in the history
FIX: Visitor functions are now called in such a way that their
`this` refers to the object they are part of.

Closes #1261
  • Loading branch information
VanillaMaster authored and marijnh committed Nov 11, 2023
1 parent 494ecc8 commit 5906be3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions acorn-walk/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
export function simple(node, visitors, baseVisitor, state, override) {
if (!baseVisitor) baseVisitor = base
;(function c(node, st, override) {
let type = override || node.type, found = visitors[type]
let type = override || node.type
baseVisitor[type](node, st, c)
if (found) found(node, st)
if (visitors[type]) visitors[type](node, st)
})(node, state, override)
}

Expand All @@ -32,11 +32,11 @@ export function ancestor(node, visitors, baseVisitor, state, override) {
let ancestors = []
if (!baseVisitor) baseVisitor = base
;(function c(node, st, override) {
let type = override || node.type, found = visitors[type]
let type = override || node.type
let isNew = node !== ancestors[ancestors.length - 1]
if (isNew) ancestors.push(node)
baseVisitor[type](node, st, c)
if (found) found(node, st || ancestors, ancestors)
if (visitors[type]) visitors[type](node, st || ancestors, ancestors)
if (isNew) ancestors.pop()
})(node, state, override)
}
Expand Down

0 comments on commit 5906be3

Please sign in to comment.