-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Rollup Version
4.16.2
Operating System (or Browser)
osx
Node Version (if applicable)
20
Link To Reproduction
https://rollupjs.org/repl/?version=4.16.2&shareable=JTd...
Expected Behaviour
acorn-walk simple visitor methods should be called after compilation.
function simple(node, visitors, baseVisitor) {
if (!baseVisitor) baseVisitor = base
;(function c(node, override) {
let type = override || node.type; // <--
baseVisitor[type](node, c);
if (visitors[type]) visitors[type](node);
})(node);
}In the provided repl, the node of type Identifier should trigger a recursive call to "c" with override = "Expression" and that should if (visitors[type]) visitors[type](node) -> console.log("node found")
If the override parameter is assumed undefined with treeshaking (even "safest" exhibits this issue), then the behavior is broken.
Actual Behaviour
acorn-walk simple visitor methods are not called because "override" is erroneously optimized out.
The simple visitors object is keyed on simpler override keys like Expression, not native es-tree node.type keys like ExpressionStatement, or FunctionExpression), the value of override is provided by the call through baseVisitor which then calls c again with the children of the node possibly classified by the override key for simple visitors[type] usage.
When rollup optimizes this out, then the simple visitor[type] callbacks are not run.
function simple(node, visitors, baseVisitor) {
if (!baseVisitor) baseVisitor = base
;(function c(node, override) {
let type = node.type; // <-- ⚠️
baseVisitor[type](node, c);
if (visitors[type]) visitors[type](node);
})(node);
}