Compare commits

...

2 Commits

Author SHA1 Message Date
Jill 38038d710b fix comment removal 2021-11-03 10:40:28 +03:00
Jill d95ec10f53 dont put jsonified AST in resulting file 2021-11-03 09:42:23 +03:00
1 changed files with 9 additions and 4 deletions

View File

@ -41,6 +41,13 @@ function transpile(parsed, indent, prefix) {
return '';
}
function removeComments(code) {
// remove /* */ style comments, for now
code = code.replace(/\/\*(.*?)\*\//gs, '');
code = code.split('\n').filter(c => !c.trim().startsWith('//')).join('\n');
return code;
}
/**
* @param {string} code
*/
@ -52,9 +59,7 @@ function parse(code) {
// were gonna end up with an ast of sorts anyways as a result, which we can then use instead of declares
// sanitize stuff
code = code.split('\n').filter(c => !c.trim().startsWith('//')).join('\n');
// remove /* */ style comments, for now
code = code.replace(/\/\*(.*?)(?=\*\/)/gs, '');
code = removeComments(code);
const elements = [];
@ -182,7 +187,7 @@ function parse(code) {
//console.log(inspect(parsed, false, 10));
const luaFilename = f.replace('.d.ts', '.lua');
await fs.writeFile(path.resolve(outPath, luaFilename), '--[[\n' + inspect(parsed, false, null) + '\n]]\n\n' + transpiled);
await fs.writeFile(path.resolve(outPath, luaFilename), transpiled);
console.log(` wrote ${chalk.cyanBright(luaFilename)}`);
}
}