UNPKG

maestro-roku-bsc-plugin

Version:

Visual studio plugin for maestro brightscript development

98 lines 3.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const RawCodeStatement_1 = require("../utils/RawCodeStatement"); const minimatch = require("minimatch"); /* Crude brighterscript class processor */ class ReflectionUtil { constructor(fileMap, program, maestroConfig) { this.fileMap = fileMap; this.program = program; this.maestroConfig = maestroConfig; } updateRuntimeFile() { let runtimeFile = this.program.getFile('source/roku_modules/maestro/reflection/Reflection.brs'); if (runtimeFile) { runtimeFile.needsTranspiled = true; this.updateClassLookupFunction(runtimeFile); this.updateXMLCompTypesFunction(runtimeFile); // eslint-disable-next-line @typescript-eslint/dot-notation runtimeFile['diagnostics'] = []; } } updateClassLookupFunction(file) { var _a, _b; let classNames = this.fileMap.classNames.filter((n) => { let file = this.fileMap.getFileForClass(n); if (!file) { console.log('MISSING FILE for class:', n); return false; } else { return this.shouldParseReflectionFile(file.bscFile); } }).map((n) => n.replace(/\./g, '_')); let funcIndex = 0; const maxFuncs = 4; for (let i = 0; i < Math.min(classNames.length, maxFuncs * 250); i += 250) { let chunk = classNames.slice(i, i + 250); let isLastFunction = (i + 250) >= classNames.length; let codeText = this.generateFunctionBody(chunk, isLastFunction, funcIndex); let func = file.ast.statements[funcIndex]; if (((_b = (_a = func === null || func === void 0 ? void 0 : func.func) === null || _a === void 0 ? void 0 : _a.body) === null || _b === void 0 ? void 0 : _b.statements.length) > 0) { func.func.body.statements[funcIndex === 0 ? 1 : 0] = new RawCodeStatement_1.RawCodeStatement(codeText); } else { console.error(`Function at index ${funcIndex} does not have the expected structure.`); } funcIndex++; } } generateFunctionBody(classNames, isLastFunction, index) { let codeText = `if false\n ? "maestro reflection"`; for (let name of classNames) { codeText += `\nelse if name = "${name}"\n return ${name}`; } if (!isLastFunction) { let nextFunctionName = `mr_getClass${index + 2}`; codeText += `\nelse\n return ${nextFunctionName}(name)`; } else { codeText += `\nelse\n return false`; } codeText += `\nend if`; return codeText; } updateXMLCompTypesFunction(file) { let func = file.ast.statements[4]; if (func) { let text = '{\n'; let compNames = this.fileMap.XMLComponentNames; for (let name of compNames) { text += ` "${name}": true \n`; } text += '}'; func.func.body.statements.push(new RawCodeStatement_1.RawCodeStatement(`return ${text}`)); } } addFile(file) { let mFile = this.fileMap.allFiles[file.srcPath]; this.fileMap.removeFileClasses(mFile); for (let cs of file.parser.references.classStatements) { this.fileMap.addClass(cs, mFile); } } shouldParseReflectionFile(file) { if (this.maestroConfig.reflection.excludeFilters) { for (let filter of [...this.maestroConfig.reflection.excludeFilters, '**/components/maestro/generated/*']) { if (minimatch(file.srcPath, filter)) { return false; } } } return true; } } exports.default = ReflectionUtil; //# sourceMappingURL=ReflectionUtil.js.map