oxc/crates/oxc_traverse/scripts/lib/traverse.mjs
overlookmotel 421107aa82 feat(traverse): pass &mut TraverseCtx to visitors (#3312)
Pass `&mut TraverseCtx` to `Traverse::enter_*` and `Traverse::exit_*` visitor methods. Previously was immutable `&TraverseCtx`.

This is a step towards exposing mutable scope tree + symbol table to visitors.
2024-05-16 16:21:23 +00:00

30 lines
903 B
JavaScript

import {camelToSnake} from './utils.mjs';
export default function generateTraverseTraitCode(types) {
const typesArr = Object.values(types);
typesArr.push({name: 'Statements', rawName: "Vec<'a, Statement<'a>>"});
let traverseMethods = '';
for (const type of typesArr) {
const snakeName = camelToSnake(type.name);
traverseMethods += `
#[inline]
fn enter_${snakeName}(&mut self, node: &mut ${type.rawName}, ctx: &mut TraverseCtx<'a>) {}
#[inline]
fn exit_${snakeName}(&mut self, node: &mut ${type.rawName}, ctx: &mut TraverseCtx<'a>) {}
`;
}
return `
use oxc_allocator::Vec;
#[allow(clippy::wildcard_imports)]
use oxc_ast::ast::*;
use crate::TraverseCtx;
#[allow(unused_variables)]
pub trait Traverse<'a> {
${traverseMethods}
}
`;
}