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

calc() with escaped strings removes parenthesis #3191

Closed
oBusk opened this issue Mar 21, 2018 · 5 comments
Closed

calc() with escaped strings removes parenthesis #3191

oBusk opened this issue Mar 21, 2018 · 5 comments

Comments

@oBusk
Copy link

oBusk commented Mar 21, 2018

In 3.0 calculations in calc() are now only done on runtime, as stated in changelog.md. Previously, since content of calc() was being calculated, things that wanted to be kept had to be espaced as such:

// input
.a {
  @v: 10px;
  height: calc(~'100%' - ((@v  * 3) + (@v * 2)));
}

// output
.a {
  height: calc(100% - 50px);
}

After upgrading to 3.0 the result is

// input
.a {
  @v: 10px;
  height: calc(~'100%' - ((@v  * 3) + (@v * 2)));
}

// Expected output
.a {
  height: calc(100% - ((10px * 3) + (10px * 2)));
}

// Actual output 
.a {
  height: calc(100% - (10px * 3) + (10px * 2));
}

Workaround

This can currently be fixed by not escaping;

// input
.a {
  @v: 10px;
  height: calc(100% - ((@v  * 3) + (@v * 2)));
}

// output
.a {
  height: calc(100% - ((10px * 3) + (10px * 2)));
}
@matthew-dean
Copy link
Member

Sorry, what is the problem with the output? The removal of the parentheses?

@oBusk
Copy link
Author

oBusk commented Mar 21, 2018

Exactly. The parentheses is removed, causing the calculation to be wrong.

Calc will be evaluated as (A - B) + C instead of A - (B + C)

@matthew-dean
Copy link
Member

@oBusk Okay, got it. Not sure why Less is doing that, other than there's probably logic in there for simplifying expressions that normally works when the calculations are allowed to be evaluated, but doesn't work in this case because the expressions aren't getting evaluated.

Valid bug.

@matthew-dean
Copy link
Member

Elevating to medium just because low is like an edge case that may never happen, and this seems like it may reasonably happen more often.

matthew-dean added a commit to matthew-dean/less.js that referenced this issue Jun 20, 2018
@matthew-dean
Copy link
Member

matthew-dean commented Jun 20, 2018

Fixed! - PR needs review - #3223

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants