Skip to content
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

Handle logical expressions when getting attribute values #1014

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

K-Schaeffer
Copy link

@K-Schaeffer K-Schaeffer commented Jan 16, 2024

I noticed that logical expressions are not being resolved when getting attribute values, and thus simple bindings that should not raise a failed rule are raising, example:

<div role="textbox" :tabindex="disabled || 0" :aria-disabled="disabled"></div>

This should not fail the rule because if disabled is false then it actually has tabindex properly, but it currently fails with the "element should be focusable" rule.

The reason behind this is the fact that the own expression is being returned on all cases except for the Literal, that actually returns the value of the attribute.

  if (node.value.expression.type === "Literal") {
      return node.value.expression.value;
    }

   // 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
   // types of values or just return a special symbol or something else.
   return node.value.expression;

I understand the TODO that was put on the return of the expression on those cases and I think that handling the LogicalExpression as I did on my PR might be a good addition to at least solve this simple case, even though we definitely have more cases that would require to be handled as the comment suggests.

@K-Schaeffer K-Schaeffer marked this pull request as draft January 16, 2024 21:45
@K-Schaeffer K-Schaeffer marked this pull request as ready for review January 17, 2024 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant