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
Increase strictness about whitespace around minus sign #1912
Comments
ooof! That's pretty not-fun to have to track down in production code. Does that happen in compressed mode, or just standard, like you show in your example? |
If you add parentheses, it doesn't do that: $value: 10px;
.my-class {
margin: 0 auto (-$value);
} Note that you should be doing this to prevent the expression from being evaluated as subtraction rather than negation. Without parentheses$value: 10px;
.my-class {
margin: 0 -$value;
} Output: .my-class {
margin: -10px;
} With parentheses
Output: .my-class {
margin: 0 -10px;
} |
@cimmanon Yes, but that's counter-intuitive - you shouldn't need to add parentheses. These should all produce the same result: $value : 12px;
$neg-value: -$value;
.my-class {
margin: 0 auto -$value;
margin: 0 auto (-$value);
margin: 0 auto $neg-value;
margin: 0 auto -12px;
} |
@hcatlin : it happens in standard, just like I showed. :( @cimmanon : thx! that does work as well. However, I still consider it a bug because Sass is not treating |
@cimmanon and I was just about to point out what @Darvishzadeh just wrote about the counter-intuitive-ness of it. Syntactically, I don't think you should need the parenthesis. |
@akaScooter, I think you meant @davidkpiano |
The fact that there is no space between the minus operator and the variable is irrelevant to the Sass parser. whitespace is optional except where the dash would be interpreted as part of the identifier. So Sass sees Very early in Sass's development we went out of our way to define all binary operators for all types of operands even where the implementation is a bit of a stretch (This is why we have color math. E.g.
Seen another way, what if So we were left with the following choices:
Forcing infix operators to be surrounded by a space is not how any other language works (that I'm aware of) in their expression syntax so the 3rd choice here seemed very wrong early on, but we may have been wrong about that, given the peculiarities of CSS. This is a common issue that trips people up, but changing the way expressions are parsed is not something we take lightly. The benefit at this point would need to be extremely clear and there would need to be a way to silence all deprecation warnings by adjusting the source which would mean we may need to force unambiguous syntax via parens (around intended subtraction) during the deprecation period -- which would certainly be frustrating for a lot of people. TL;DR spaces are a really terrible delimiter for values in a data structure because it is a delimiter in expressions. This pattern in CSS has other negative consequences in Sass -- for instance, it is not possible to define a space-delimited list containing a single value syntactically which is one of the reasons all of our list functions have an optional delimiter argument and must treat single values as lists of one element wherever a list is expected. |
@nex3 Thoughts on changing the parsing of binary operators to require a surrounding space and forcing unary operands to never allow a space at 4.0? We can have sass-convert take care of the expressions and re-parenthesize them during the upgrade process. |
@chriseppstein That sounds good if we can come up with a close-to-bulletproof strategy for deprecation warnings. Can you work on that? |
@nex3 I can take a swing at it, I'm still learning my way around the nitty gritty aspects of the script parser code. |
If you work on a prose description of the deprecation first, that shouldn't require too much parser delving (although probably non-zero). That may also make it easier to code later on, too. |
We have a proposal out for this now. I'll give it a full month for feedback, since it is a breaking change, then mark it as accepted if there are no substantive changes or challenges. |
This is blocked on @jathak having time to implement the migrator plugin for it. |
Plenty of time has passed and the migrator plugin has landed so I'm going to mark this accepted and get to work on the implementation. |
This is now just waiting on Dart Sass 2.0.0 |
Deprecation
Removal
The following code:
results in the following CSS output:
with no space between the
auto
and the-12px
values. My browser (Firefox v42.0) doesn't recognizeauto-12px
as a valid value and ignores the rule.Is this an issue where Sass's rules for compressing the output aren't taking the combination of
auto
(or any keyword string value) with a numeric value into account?(The following is an example of the work-around I am using in these instances, but there should really be a space left between those values)
[Sass 3.4.19 (Selective Steve)]
The text was updated successfully, but these errors were encountered: