UNPKG

maestro-roku-bsc-plugin

Version:

Visual studio plugin for maestro brightscript development

80 lines 3.15 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 func = file.ast.statements[0]; let that = this; 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) { 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 that.shouldParseReflectionFile(file.bscFile); } }).map((n) => n.replace(/\./g, '_')); let codeText = `if false ? "maestro reflection"`; for (let name of classNames) { codeText += `\n else if name = "${name}" return ${name}`; } codeText += '\n end if'; func.func.body.statements[1] = new RawCodeStatement_1.RawCodeStatement(codeText); } } updateXMLCompTypesFunction(file) { let func = file.ast.statements[1]; 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.pathAbsolute]; 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.pathAbsolute, filter)) { return false; } } } return true; } } exports.default = ReflectionUtil; //# sourceMappingURL=ReflectionUtil.js.map