eslint-plugin-obsidian
Version:
ESLint rules for Obsidian
27 lines • 1.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClassAdapter = void 0;
const ts_morph_extensions_1 = require("ts-morph-extensions");
const ts_morph_1 = require("ts-morph");
class ClassAdapter {
constructor(projectRegistry) {
this.projectRegistry = projectRegistry;
}
classToGraph(node, filePath) {
var _a, _b;
if (!((_a = node.id) === null || _a === void 0 ? void 0 : _a.name))
return;
const sourceFile = this.projectRegistry.getSourceFile(filePath);
let clazz = (_b = this.topLevelClass(sourceFile, node.id.name)) !== null && _b !== void 0 ? _b : this.nestedClass(sourceFile, node.id.name);
return clazz && new ts_morph_extensions_1.Graph(clazz);
}
topLevelClass(sourceFile, className) {
return sourceFile === null || sourceFile === void 0 ? void 0 : sourceFile.getClass(className);
}
nestedClass(sourceFile, className) {
const allClasses = sourceFile === null || sourceFile === void 0 ? void 0 : sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.ClassDeclaration);
return allClasses === null || allClasses === void 0 ? void 0 : allClasses.find(c => c.getName() === className);
}
}
exports.ClassAdapter = ClassAdapter;
//# sourceMappingURL=classAdapter.js.map