oxc/crates/oxc_traverse/scripts/lib/traverse.mjs
DonIsaac d5cf1f823b chore(traverse): add JSDoc type hints to JS codegen scripts (#6375)
Use JSDoc comments in `build.mjs` and related scripts to provide type hints and better intellisense. I was having a hard time knowing what fields are available in different methods, and I found this quite helpful. I'm sure other newcomers to this part of our codegen infrastructure will find it helpful as well.
2024-10-08 21:00:34 +00:00

33 lines
877 B
JavaScript

import { camelToSnake } from './utils.mjs';
/**
* @param {import('./parse.mjs').Types} types
*/
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}
}
`;
}