mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
Refactor build script to simplify it. No changes to the `.rs` files the script creates, only the script itself.
30 lines
895 B
JavaScript
30 lines
895 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: &TraverseCtx<'a>) {}
|
|
#[inline]
|
|
fn exit_${snakeName}(&mut self, node: &mut ${type.rawName}, ctx: &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}
|
|
}
|
|
`;
|
|
}
|