@jqassistant/ts-lce
Version:
Tool to extract language concepts from a TypeScript codebase and export them to a JSON file.
46 lines (45 loc) • 1.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAndDeleteChildConcepts = getAndDeleteChildConcepts;
exports.getAndDeleteAllValueChildConcepts = getAndDeleteAllValueChildConcepts;
exports.getChildConcepts = getChildConcepts;
exports.getParentPropName = getParentPropName;
exports.getParentPropIndex = getParentPropIndex;
const value_concept_1 = require("../concepts/value.concept");
const context_keys_1 = require("../context.keys");
function getAndDeleteChildConcepts(propName, conceptId, childConcepts) {
const propConcepts = childConcepts.get(propName);
if (!propConcepts)
return [];
const result = propConcepts.get(conceptId) ?? [];
propConcepts.delete(conceptId);
if (propConcepts.size == 0)
childConcepts.delete(propName);
return result;
}
function getAndDeleteAllValueChildConcepts(propName, childConcepts) {
const values = [];
for (const conceptId of value_concept_1.valueConceptIds) {
values.push(...getAndDeleteChildConcepts(propName, conceptId, childConcepts));
}
return values;
}
function getChildConcepts(propName, conceptId, childConcepts) {
const propConcepts = childConcepts.get(propName);
if (!propConcepts)
return [];
const result = propConcepts.get(conceptId) ?? [];
return result;
}
function getParentPropName(localContexts) {
const traverserContext = localContexts.currentContexts.get(context_keys_1.CoreContextKeys.TRAVERSER_CONTEXT);
if (!traverserContext)
throw new Error("No traverser context found");
return traverserContext.parentPropName;
}
function getParentPropIndex(localContexts) {
const traverserContext = localContexts.currentContexts.get(context_keys_1.CoreContextKeys.TRAVERSER_CONTEXT);
if (!traverserContext)
throw new Error("No traverser context found");
return traverserContext.parentPropIndex;
}