Recast expression bug

node v18.11.0
version: 3.0.0
endpointsharetweet
const recast = require('recast') const types = recast.types const builders = recast.types.builders const scope = builders.identifier('scope') const expression = `( () => { update({ message: "test" }); } )` const ast = recast.parse(expression, { sourceFileName: 'test.js', }) // replace the scope of the identifiers found types.visit(ast, { visitIdentifier(path) { path.replace(builders.memberExpression( scope, path.node, false )) return false } }) // crate a function const result = builders.functionExpression( null, [scope], builders.blockStatement([builders.returnStatement( ast.program.body[0].expression )]) ) // generate the output const output = recast.print(result, { sourceMapName: `source.map` }) return output
Loading…

no comments

    sign in to comment