swc/crates/swc_estree_visit
Donny/강동윤 790a262c07
refactor(es/estree): Rename: babel => estree (#2846)
swc_babel_ast:
 - Rename as `swc_estree_ast`.

swc_babel_compat:
 - Rename as `swc_estree_compat`.

swc_babel_visit:
 - Rename as `swc_estree_visit`.
2021-11-24 05:34:41 +09:00
..
src refactor(es/estree): Rename: babel => estree (#2846) 2021-11-24 05:34:41 +09:00
Cargo.toml refactor(es/estree): Rename: babel => estree (#2846) 2021-11-24 05:34:41 +09:00
README.md refactor(es/estree): Rename: babel => estree (#2846) 2021-11-24 05:34:41 +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);