mirror of
https://github.com/danbulant/oxc
synced 2026-05-22 05:38:54 +00:00
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.
43 lines
1,007 B
JavaScript
43 lines
1,007 B
JavaScript
/**
|
|
* @param {string} name
|
|
*/
|
|
export function typeAndWrappers(name) {
|
|
const wrappers = [];
|
|
while (true) {
|
|
const match = name.match(/^(.+?)<(.+)>$/);
|
|
if (!match) break;
|
|
wrappers.push(match[1]);
|
|
name = match[2];
|
|
}
|
|
return { name, wrappers };
|
|
}
|
|
|
|
/**
|
|
* @param {string} name
|
|
*/
|
|
export function camelToSnake(name) {
|
|
let prefixLen = 1;
|
|
for (const prefix of ['TS', 'JSX', 'JS']) {
|
|
if (name.startsWith(prefix)) {
|
|
prefixLen = prefix.length;
|
|
break;
|
|
}
|
|
}
|
|
return name.slice(0, prefixLen).toLowerCase() +
|
|
name.slice(prefixLen).replace(/[A-Z]/g, c => `_${c.toLowerCase()}`);
|
|
}
|
|
|
|
/**
|
|
* @param {string} name
|
|
*/
|
|
export function snakeToCamel(name) {
|
|
let prefixLen = 0;
|
|
for (const prefix of ['TS', 'JSX', 'JS']) {
|
|
if (name.startsWith(`${prefix.toLowerCase()}_`)) {
|
|
prefixLen = prefix.length + 1;
|
|
break;
|
|
}
|
|
}
|
|
return name.slice(0, prefixLen + 1).toUpperCase() +
|
|
name.slice(prefixLen + 1).replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
|
}
|