Closed trueadm closed 1 year ago
I'm looking into it.
I'm unable to reproduce this issue, here is my code
const { parseModule } = require('meriyah')
const astring = require('astring')
const ast = parseModule(`
const x = () => {};
`)
traverse(ast, {
$: { scope: true, validateNodes: true },
ArrowFunctionExpression(path) {
path.get('body').replaceWith(b.updateExpression('++', b.identifier('foo'), false))
}
})
console.log(astring.generate(ast))
// Output: const x = () => foo++;
Can you share your code?
Your arrow function has a BlockStatement
. Try making it an expression instead;
const ast = parseModule(`
let y = 0;
const x = () => y++;
`)
It works on my system, I also ran it on Replit - https://replit.com/@SarsaMurmu/TastyGivingVendors#index.js. It works there too. I'm not sure what is causing this issue.
Ah, I think I know what it might be. It's because my nodes have an additional parent
property and it seems the validation logic must be looking at this property. Maybe the parent
property can be skipped internally to help my use-case?
If I use the builders this is also evident:
const body = b.identifier('test');
body.parent = someOtherNode
b.arrowFunctionExpression(params, body)
Edit: I made the parent
property non-enumerable and that seems to fix it.
Given the below:
This fails and gives me some strange validation error about a circular structure to JSON. I assume the issue is assuming arrow functions must have block statements.