fix type transliteration

This commit is contained in:
Jill 2021-11-03 12:19:28 +03:00
parent a43df3e28b
commit 84320e5aab
1 changed files with 8 additions and 2 deletions

View File

@ -14,6 +14,7 @@ let tsToLuaTypes = {
}
function transpileType(type) {
if (!type) return 'what';
type = type.trim();
if (type.startsWith('(') && type.endsWith(')')) type = type.slice(1, -1);
@ -30,10 +31,14 @@ function transpileType(type) {
return type.split('|').map(t => transpileType(t)).join(' | ');
}
if (type.startsWith('Record<')) {
if (type.startsWith('"')) {
return 'string';
}
if (type.startsWith('Record<') && type.endsWith('>')) {
return 'table<' + transpileType(type.split(',')[0].replace('Record<','')) + ', ' + transpileType(type.split(',')[1].replace('>','')) + '>';
}
if (type.startsWith('LuaTable<')) {
if (type.startsWith('LuaTable<') && type.endsWith('>')) {
return 'table<' + transpileType(type.split(',')[0].replace('LuaTable<','')) + ', ' + transpileType(type.split(',')[1].replace('>','')) + '>';
}
@ -236,6 +241,7 @@ async function recursiveReaddir(rpath, p, fileNames) {
errorReason[f] = err;
if (errored.length > files.length - i) {
console.error(`${chalk.redBright('!')} failed resolving extends!`);
errored = [...new Set(errored)];
console.error(`${chalk.redBright('!')} abandoned ${chalk.magentaBright(errored.length)} files:`);
let longest = errored.reduce((a, b) => Math.max(a.length || a || 0, b.length));
errored.forEach(e => console.error(` - ${chalk.cyanBright(e)}${' '.repeat(longest - e.length + 2)}${chalk.gray(' → ' + errorReason[e].message.replace('Class not found in class storage: ', ''))}`));