Now, I'll use estree-toolkit to traverse the AST, with the following:
import { traverse } from "estree-toolkit";
traverse(ast, {
$: { scope: true }, // When I disable this (: false), the error goes away... but I need path.scope !
MemberExpression (path) {
if (!path.node) return;
if (path.node.object.type === "Identifier") {
// do stuff with path.scope ...
// that part of the code is not important, it already threw anyway.
}
}
});
Here is the full trace I get
758 | // From -
759 | // const { a, b: [c, { d }], e: f = 0, ...g } = x;
760 | // Returns paths to
761 | // - a, c, d, f, g
762 | const findVisiblePathsInPattern = (path, result) => {
763 | switch (path.node.type) {
^
TypeError: null is not an object (evaluating 'path.node.type')
at findVisiblePathsInPattern (/home/vexcited/Projects/.../node_modules/estree-toolkit/dist-es/scope.mjs:763:12)
at registerBindingFromPattern (/home/vexcited/Projects/.../node_modules/estree-toolkit/dist-es/scope.mjs:834:4)
at CatchClause (/home/vexcited/Projects/.../node_modules/estree-toolkit/dist-es/scope.mjs:975:8)
at crawl (/home/vexcited/Projects/.../node_modules/estree-toolkit/dist-es/scope.mjs:1108:16)
at init (/home/vexcited/Projects/.../node_modules/estree-toolkit/dist-es/scope.mjs:1052:8)
at init (/home/vexcited/Projects/.../node_modules/estree-toolkit/dist-es/nodepath.mjs:112:16)
at crawl (/home/vexcited/Projects/.../node_modules/estree-toolkit/dist-es/scope.mjs:1165:12)
at init (/home/vexcited/Projects/.../node_modules/estree-toolkit/dist-es/scope.mjs:1052:8)
at init (/home/vexcited/Projects/.../node_modules/estree-toolkit/dist-es/nodepath.mjs:112:16)
at crawl (/home/vexcited/Projects/.../node_modules/estree-toolkit/dist-es/scope.mjs:1165:12)
Also, I should mention that I use Bun to run this piece of code. I don't know if that changes anything though.
Hi! I'm currently using a combo of librairies to rewrite an identifier from scripts that can be found while browsing the web.
I use
meriyah
to parse the code using the following:Now, I'll use
estree-toolkit
to traverse the AST, with the following:Here is the full trace I get
Also, I should mention that I use Bun to run this piece of code. I don't know if that changes anything though.