Skip to content

Handle logical expressions when getting attribute values #1014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: handle LogicalExpressions on getAttributeValue
  • Loading branch information
K-Schaeffer committed Jan 16, 2024
commit fa42255e933f534cf8e7aacc0160f71cb2464345
10 changes: 10 additions & 0 deletions src/utils/getAttributeValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ function getAttributeValue(node: AST.VAttribute | AST.VDirective) {
return node.value.expression.value;
}

if (node.value.expression.type === 'LogicalExpression') {
const operator = node.value.expression.operator;
// @ts-ignore
const leftSideOfOperation = node.value.expression.left.value;
// @ts-ignore
const rightSideOfOperation = node.value.expression.right.value;

return eval(`${leftSideOfOperation} ${operator} ${rightSideOfOperation}`);
}

// TODO we're effectively using this as just a placeholder to let rules know
// that a value has been passed in for this attribute. We should replace
// this with a stronger API to either explicitly handle all of the different
Expand Down