current position:Home>@Babel / traverse official example running error: typeerror: traverse is not a function

@Babel / traverse official example running error: typeerror: traverse is not a function

2022-04-29 07:01:13CSDN Q & A

import * as parser from "@babel/parser";import traverse from "@babel/traverse";const code = `function square(n) {  return n * n;}`;const ast = parser.parse(code);traverse(ast, {  enter(path) {    if (path.isIdentifier({ name: "n" })) {      path.node.name = "x";    }  },});

img

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/112/202204221451028690.html

Random recommended