mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 20:32:10 +00:00
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.
30 lines
903 B
JavaScript
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}
|
|
}
|
|
`;
|
|
}
|