Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function tryParseTypeScript(text, jsx) {
const parser = require("@typescript-eslint/typescript-estree");
return parser.parse(text, {
loc: true,
range: true,
tokens: true,
comment: true,
useJSXTextNode: true,
jsx
});
}
function runTSESTree(directory, files) {
for (const file of files) {
const result = tsEstree.parse(
fs.readFileSync(path.join(__dirname, file), 'utf8'),
{
comment: true,
tokens: true
}
);
if (result.type !== 'Program') {
throw new Error('something went wrong');
}
}
}
function collectClass(filePath) {
var fileContent = fs.readFileSync(filePath, 'utf-8');
var parsed = parser.parse(fileContent);
astMap[filePath] = parsed;
tc.collect(parsed);
}
function doTranslateFile(filePath) {
function translate(tsCode, option) {
processOption(option);
var parsed = parser.parse(tsCode);
tc.collect(parsed);
lm.setClassMap(tc.classMap, tc.moduleMap, tc.enumMap);
var luaCode = lm.toLuaBySource(parsed);
collectUnknowRegex();
return luaCode;
}
exports.translate = translate;
parseTypescriptEstree(content) {
let data = typescriptEstreeParser.parse(content, {
loc: true,
range: true,
tokens: true,
errorOnUnknownASTType: true,
useJSXTextNode: true,
ecmaFeatures: {
jsx: true,
modules: true
}
});
data.astParser = this.esLintESTreeAst;
data.Scope = {}; //new Scope(data);
data.Scope.resolveVarValue = (astNode) => astNode.arguments[0];
data.Scope.updateFunctionScope = () => {};
return data;