2020-05-23 10:36:49 +02:00
|
|
|
"use strict";
|
|
|
|
|
2024-07-18 21:35:17 +03:00
|
|
|
import Expression from "./expression.js";
|
|
|
|
import NoteSet from "../note_set.js";
|
|
|
|
import SearchContext from "../search_context.js";
|
2020-05-23 10:36:49 +02:00
|
|
|
|
|
|
|
class ParentOfExp extends Expression {
|
2024-02-18 01:18:20 +02:00
|
|
|
private subExpression: Expression;
|
|
|
|
|
|
|
|
constructor(subExpression: Expression) {
|
2020-05-23 10:36:49 +02:00
|
|
|
super();
|
|
|
|
|
|
|
|
this.subExpression = subExpression;
|
|
|
|
}
|
|
|
|
|
2024-02-18 01:18:20 +02:00
|
|
|
execute(inputNoteSet: NoteSet, executionContext: {}, searchContext: SearchContext) {
|
2020-05-23 10:36:49 +02:00
|
|
|
const subInputNoteSet = new NoteSet();
|
|
|
|
|
|
|
|
for (const note of inputNoteSet.notes) {
|
|
|
|
subInputNoteSet.addAll(note.children);
|
|
|
|
}
|
|
|
|
|
2022-12-17 13:07:42 +01:00
|
|
|
const subResNoteSet = this.subExpression.execute(subInputNoteSet, executionContext, searchContext);
|
2020-05-23 10:36:49 +02:00
|
|
|
|
|
|
|
const resNoteSet = new NoteSet();
|
|
|
|
|
|
|
|
for (const childNote of subResNoteSet.notes) {
|
|
|
|
for (const parentNote of childNote.parents) {
|
|
|
|
if (inputNoteSet.hasNote(parentNote)) {
|
|
|
|
resNoteSet.add(parentNote);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return resNoteSet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-18 01:18:20 +02:00
|
|
|
export = ParentOfExp;
|