question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Operator precedence is not preserved

See original GitHub issue

Source:

:root {
    --fluid-min-width: 320;
    --fluid-max-width: 1140;
    --fluid-screen: 100vw;
    --fluid-bp: calc(
        (var(--fluid-screen) - ((var(--fluid-min-width) / 16) * 1rem)) /
        ((var(--fluid-max-width) / 16) - (var(--fluid-min-width) / 16))
    );
}

7.0.4 outputs:

:root {
    --fluid-min-width: 320;
    --fluid-max-width: 1140;
    --fluid-screen: 100vw;
    --fluid-bp: calc(
        (var(--fluid-screen) - var(--fluid-min-width) / 16 * 1rem) / 
        (var(--fluid-max-width) - var(--fluid-min-width)) / 16
    );
}

The output should instead be:

:root {
    --fluid-min-width: 320;
    --fluid-max-width: 1140;
    --fluid-screen: 100vw;
    --fluid-bp: calc(
        (var(--fluid-screen) - (var(--fluid-min-width) / 16) * 1rem)) / 
        ((var(--fluid-max-width) - var(--fluid-min-width)) / 16
    );
}

postcss-calc is removing the necessary parentheses and affecting the operator precedence.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
bashercommented, Sep 21, 2020

I have same issue with 7.0.4 which comes with parcel@2.0.0-nightly.400.

I only spotted this today on production sites with our responsive iframe containers, where we set an inline HTML style attribute with correct iframe aspect ratio, and pass that to Sass to evaluate padding-top as per this CSS Tricks article:

<div class="responsive-media" style="--aspectRatio: 560/315;">
    <iframe width="560" height="315" ...></iframe>
</div>
.responsive-media {
    padding-top: calc(100% / (var(--aspectRatio)));
}

Output in DEV mode with Parcel start:

padding-top: calc(100% / (var(--aspectRatio)));

Output in PROD mode after with Parcel build:

padding-top: calc(100% / var(--aspectRatio));
1reaction
bashercommented, Feb 19, 2021

I’ve given up waiting for a fix for this.

I’m now using the new standard CSS aspect-ratio property in supported browsers, and a hardcoded padding-top hack without calc() for older browsers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Operator Precedence Considered Harmful - Wiki
The problem with operator precedence is that it's yet another thing a programmer has to memorize about the language he's using. And since...
Read more >
Ambiguous operator precedence, please explain why ...
Precedence is not the same as order of evaluation. Precedence simply determines what operands and operators belong together.
Read more >
Operator precedence - Microsoft Learn
Operations within parentheses are always performed before those outside. Within parentheses, however, operator precedence is maintained.
Read more >
Ask Hackaday: Is There A Legit Use For Operator Precedence?
APL is a programming language that doesn't have operator precedence. Simply because that language has so many operators that no one would be ......
Read more >
Operator Precedence and Associativity in C - GeeksforGeeks
// Associativity is not used in the below program. // Output is compiler dependent. ... This is necessary, otherwise, there won't be any...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found