Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import util = require('util');
import path = require('path');
import { TsClassInfo, TsEnumInfo, TsModuleInfo } from './TsCollector';
import { TranslateOption } from './TranslateOption';
import { stringify } from 'querystring';
export class LuaMaker {
private readonly noBraceTypes = [AST_NODE_TYPES.MemberExpression, AST_NODE_TYPES.ThisExpression, AST_NODE_TYPES.Identifier, AST_NODE_TYPES.CallExpression, AST_NODE_TYPES.TSAsExpression, AST_NODE_TYPES.TSTypeAssertion, AST_NODE_TYPES.Super];
// TODO: Typeof's return value may be different between ts and lua
private readonly tsType2luaType = {
'undefined': 'nil',
'object': 'table'
};
private readonly ignoreExpressionType = [AST_NODE_TYPES.MemberExpression, AST_NODE_TYPES.Identifier];
private readonly luaKeyWords = ['and', 'break', 'do', 'else', 'elseif', 'end', 'false', 'for', 'function', 'if', 'in', 'local', 'nil', 'not', 'or', 'repeat', 'return', 'then', 'true', 'until', 'while'];
private pv = 0;
private readonly operatorPriorityMap: { [opt: string]: number } = {};
constructor() {
this.setPriority(['( … )'], this.pv++);
this.setPriority(['… . …', '… [ … ]', 'new … ( … )', '… ( … )'], this.pv++);
this.setPriority(['new …'], this.pv++);
this.setPriority(['… ++', '… --'], this.pv++);
this.setPriority(['! …', '~ …', '+ …', '- …', '++ …', '-- …', 'typeof …', 'void …', 'delete …', 'await …'], this.pv++);
this.setPriority(['… ** …'], this.pv++);
this.setPriority(['… * …', '… / …', '… % …'], this.pv++);
this.setPriority(['… + …', '… - …'], this.pv++);
this.setPriority(['… << …', '… >> …', '… >>> …'], this.pv++);
case AST_NODE_TYPES.AssignmentExpression:
{
let ae = ast as AssignmentExpression;
ast.__calPriority = this.getPriority('… ' + ae.operator + ' …');
}
break;
case AST_NODE_TYPES.LogicalExpression:
{
let le = ast as LogicalExpression;
ast.__calPriority = this.getPriority('… ' + le.operator + ' …');
}
break;
case AST_NODE_TYPES.MemberExpression:
{
let me = ast as MemberExpression;
ast.__calPriority = this.getPriority(me.computed ? '… [ … ]' : '… . …');
}
break;
case AST_NODE_TYPES.ConditionalExpression:
{
ast.__calPriority = this.getPriority('… ? … : …');
}
break;
case AST_NODE_TYPES.CallExpression:
{
ast.__calPriority = this.getPriority('… ( … )');
}