mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
Merge branch 'stable'
# Conflicts: # package-lock.json
This commit is contained in:
commit
9b8474a728
@ -211,6 +211,35 @@ describe("Parser", () => {
|
|||||||
expect(secondSubSub.constructor.name).toEqual("LabelComparisonExp");
|
expect(secondSubSub.constructor.name).toEqual("LabelComparisonExp");
|
||||||
expect(secondSubSub.attributeName).toEqual("third");
|
expect(secondSubSub.attributeName).toEqual("third");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("label sub-expression without explicit operator", () => {
|
||||||
|
const rootExp = parse({
|
||||||
|
fulltextTokens: [],
|
||||||
|
expressionTokens: tokens(["#first", ["#second", "or", "#third"], "#fourth"]),
|
||||||
|
searchContext: new SearchContext()
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(rootExp.constructor.name).toEqual("AndExp");
|
||||||
|
assertIsArchived(rootExp.subExpressions[0]);
|
||||||
|
|
||||||
|
expect(rootExp.subExpressions[1].constructor.name).toEqual("AndExp");
|
||||||
|
const [firstSub, secondSub, thirdSub] = rootExp.subExpressions[1].subExpressions;
|
||||||
|
|
||||||
|
expect(firstSub.constructor.name).toEqual("AttributeExistsExp");
|
||||||
|
expect(firstSub.attributeName).toEqual("first");
|
||||||
|
|
||||||
|
expect(secondSub.constructor.name).toEqual("OrExp");
|
||||||
|
const [firstSubSub, secondSubSub] = secondSub.subExpressions;
|
||||||
|
|
||||||
|
expect(firstSubSub.constructor.name).toEqual("AttributeExistsExp");
|
||||||
|
expect(firstSubSub.attributeName).toEqual("second");
|
||||||
|
|
||||||
|
expect(secondSubSub.constructor.name).toEqual("AttributeExistsExp");
|
||||||
|
expect(secondSubSub.attributeName).toEqual("third");
|
||||||
|
|
||||||
|
expect(thirdSub.constructor.name).toEqual("AttributeExistsExp");
|
||||||
|
expect(thirdSub.attributeName).toEqual("fourth");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Invalid expressions", () => {
|
describe("Invalid expressions", () => {
|
||||||
|
@ -39,8 +39,12 @@ function getFulltext(tokens, searchContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isOperator(str) {
|
function isOperator(token) {
|
||||||
return str.match(/^[!=<>*%]+$/);
|
if (Array.isArray(token)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return token.token.match(/^[!=<>*%]+$/);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getExpression(tokens, searchContext, level = 0) {
|
function getExpression(tokens, searchContext, level = 0) {
|
||||||
@ -129,16 +133,16 @@ function getExpression(tokens, searchContext, level = 0) {
|
|||||||
|
|
||||||
i += 1;
|
i += 1;
|
||||||
|
|
||||||
const operator = tokens[i].token;
|
const operator = tokens[i];
|
||||||
|
|
||||||
if (!isOperator(operator)) {
|
if (!isOperator(operator)) {
|
||||||
searchContext.addError(`After content expected operator, but got "${tokens[i].token}" in ${context(i)}`);
|
searchContext.addError(`After content expected operator, but got "${operator.token}" in ${context(i)}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
return new NoteContentFulltextExp(operator, {tokens: [tokens[i].token], raw });
|
return new NoteContentFulltextExp(operator.token, {tokens: [tokens[i].token], raw });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tokens[i].token === 'parents') {
|
if (tokens[i].token === 'parents') {
|
||||||
@ -228,7 +232,7 @@ function getExpression(tokens, searchContext, level = 0) {
|
|||||||
function parseLabel(labelName) {
|
function parseLabel(labelName) {
|
||||||
searchContext.highlightedTokens.push(labelName);
|
searchContext.highlightedTokens.push(labelName);
|
||||||
|
|
||||||
if (i < tokens.length - 2 && isOperator(tokens[i + 1].token)) {
|
if (i < tokens.length - 2 && isOperator(tokens[i + 1])) {
|
||||||
let operator = tokens[i + 1].token;
|
let operator = tokens[i + 1].token;
|
||||||
|
|
||||||
i += 2;
|
i += 2;
|
||||||
@ -265,7 +269,7 @@ function getExpression(tokens, searchContext, level = 0) {
|
|||||||
|
|
||||||
return new RelationWhereExp(relationName, parseNoteProperty());
|
return new RelationWhereExp(relationName, parseNoteProperty());
|
||||||
}
|
}
|
||||||
else if (i < tokens.length - 2 && isOperator(tokens[i + 1].token)) {
|
else if (i < tokens.length - 2 && isOperator(tokens[i + 1])) {
|
||||||
searchContext.addError(`Relation can be compared only with property, e.g. ~relation.title=hello in ${context(i)}`);
|
searchContext.addError(`Relation can be compared only with property, e.g. ~relation.title=hello in ${context(i)}`);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -384,7 +388,7 @@ function getExpression(tokens, searchContext, level = 0) {
|
|||||||
searchContext.addError('Mixed usage of AND/OR - always use parenthesis to group AND/OR expressions.');
|
searchContext.addError('Mixed usage of AND/OR - always use parenthesis to group AND/OR expressions.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (isOperator(token)) {
|
else if (isOperator({token: token})) {
|
||||||
searchContext.addError(`Misplaced or incomplete expression "${token}"`);
|
searchContext.addError(`Misplaced or incomplete expression "${token}"`);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user