swc/ecmascript/babel/visit
2021-10-22 13:32:34 +09:00
..
src feat(es/babel): Support babelify of static blocks (#2504) 2021-10-22 13:32:34 +09:00
Cargo.toml fix(es/codegen): Fix codegen of ~ (#2104) 2021-08-19 17:21:08 +09:00
README.md fix(es/codegen): Fix codegen of ~ (#2104) 2021-08-19 17:21:08 +09:00

Visitor pattern implementation for Babel AST.

Example

// Visit all Identifier nodes in the Babel AST and change the optional field to 
// Some(true) for each of them.

use swc_babel_visit::{VisitMut, VisitMutWith};
use swc_babel_ast::{Identifier, File};

struct Visitor;

impl VisitMut for Visitor {
    fn visit_mut_identifier(&mut self, node: &mut Identifier) {
        node.optional = Some(true);
    }
}

let ast: File = get_babel_ast();
let mut v = Visitor {};
ast.visit_mut_with(&mut v);