transpile argument comments
This commit is contained in:
parent
63f283b350
commit
3f4af8f9a9
14
index.js
14
index.js
|
@ -104,7 +104,7 @@ function transpile(parsed, indent, prefix, gl) {
|
|||
return `${comments}---@class ${d.name}${d.extends ? ' : ' + d.extends : ''}${n}${contents.filter(e => e[0] === 'const').map(c => `---@field public ${c[1].name} ${transpileType(c[1].type)}${n}`).join('')}${global ? '' : '__class_'}${d.name} = {}${n}${contents.filter(e => e[0] !== 'const').map(c => transpile(c, indent, `${global ? '' : '__class_'}${d.name}`, global)).join(n)}\n`;
|
||||
case 'function':
|
||||
if (d.arguments[0] && d.arguments[0].type === 'void') d.arguments = d.arguments.slice(1);
|
||||
return `${comments}${d.arguments.map(p => `---@param ${p.name.replace('?', '')} ${transpileType(p.type)}${n}`).join('')}---@return ${transpileType(d.returns)}${n}function ${prefix ? prefix + (gl ? '.' : ':') : ''}${d.name}(${d.arguments.map(a => a.name.replace('?', '')).join(', ')}) end`;
|
||||
return `${comments}${d.arguments.map(p => `---@param ${p.name.replace('?', '')} ${transpileType(p.type)}${p.comment ? ' @' + p.comment : ''}${n}`).join('')}---@return ${transpileType(d.returns)}${n}function ${prefix ? prefix + (gl ? '.' : ':') : ''}${d.name}(${d.arguments.map(a => a.name.replace('?', '')).join(', ')}) end`;
|
||||
case 'const':
|
||||
return `${comments}---@type ${transpileType(d.type)}${n}${prefix ? prefix + '.' : ''}${d.name} = nil`;
|
||||
case 'enum':
|
||||
|
@ -184,6 +184,18 @@ function parse(code, originalCode) {
|
|||
const c = comments.pop();
|
||||
//if (c) c[0] += 'isaac-lua-definitions debug: comment distance = ' + (origIndex - c[1]).toString();
|
||||
|
||||
// add parameter comments
|
||||
if (c) {
|
||||
c[0].split('\n').map(l => l.trim()).filter(l => l.startsWith('* @param ')).forEach(p => {
|
||||
p = p.slice('* @param '.length);
|
||||
let indx = arguments.findIndex(arg => arg.name.replace('?', '').trim() === p.split(' ')[0]);
|
||||
if (p.split(' ')[1] && indx !== -1) {
|
||||
let comment = p.split(' ').slice(1).join(' ');
|
||||
arguments[indx].comment = comment;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
elements.push(['function', {name: match[2], arguments: arguments, returns: match[5], comment: (c || [null])[0]}]);
|
||||
}
|
||||
code = functionFreeCode;
|
||||
|
|
Loading…
Reference in New Issue