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

Fix calc function #506

Merged
merged 4 commits into from
Aug 17, 2024
Merged

Fix calc function #506

merged 4 commits into from
Aug 17, 2024

Conversation

zakybilfagih
Copy link
Collaborator

No description provided.

Copy link

vercel bot commented Aug 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
styled-ppx ⬜️ Ignored (Inspect) Visit Preview Aug 17, 2024 6:32am

@@ -190,7 +189,7 @@ module Length = struct
| `add of calc_value * calc_value
| `sub of calc_value * calc_value
| `mult of calc_value * calc_value
| `div of calc_value * float
| `div of calc_value * calc_value
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heads up, this doesn't seem right. You can't divide by something that isn't a number.

Copy link
Owner

@davesnx davesnx Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it's a bit more complex than this:

Current implementations require that for the * and / operators, one of the operands has to be unitless. For /, the right operand must be unitless. For example font-size: calc(1.25rem / 1.25) is valid but font-size: calc(1.25rem / 125%) is invalid.

https://developer.mozilla.org/en-US/docs/Web/CSS/calc#rules_and_best_practices_while_using_calc

Copy link
Collaborator Author

@zakybilfagih zakybilfagih Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the formal grammar is a bit misleading.

<calc-product> = <calc-value> [ [ '*' |  '/' ] <calc-value>]*

maybe we can have <unitless-calc-value>

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe later, i think float should be sufficient for now

@zakybilfagih zakybilfagih marked this pull request as ready for review August 15, 2024 12:05
@@ -146,5 +146,5 @@ If this test fail means that the module is not in sync with the ppx
CSS.unsafe({js|columnRuleColor|js}, {js|#000000FF|js});
CSS.unsafe({js|columnRuleColor|js}, {js|rebeccapurple|js});

CSS.color(`rgba((0, 0, 0, `num(1.))));
CSS.color(`rgba((0, 0, 0, `calc(`num(1.)))));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct, calc shouldn't leak here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So calc(1) should evaluate to 1?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, I read the diff wrong. I thought calc wasn't on the value.

@davesnx davesnx merged commit 2679b11 into davesnx:main Aug 17, 2024
7 checks passed
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.

2 participants