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
Negating variable value causes variable to not be recognized #980
Comments
|
I wonder it's a bit late to disallow usage of dashes, but when we'd get to the next major release, like 1.0, we could do this (along with a lot of other things that could potentially break everything for someone). Now we should update the docs mentioning this issue I think. |
we consider everything to be an identifier, don't we ? If we disallow it, |
Ah, true, my bad. Then, it's just a matter of mentioning this in Docs. |
Beyond mentioning it in the docs, could we be smarter about this? If we see something like -my-val and -my-val is not defined but my-val is, can we emit an appropriate warning that points out to people the error of their ways. |
It may also be possible to come up with an alternative syntax for negation that would be unambiguous but better than (- my-val). Not sure if there really is a better syntax but it my be worth brainstorming over. This would be in addition to the warning because you still need to account for the people who are going to try to do the the obvious but wrong thing. |
I remembered what I thought when I said we could make it in 1.0. One of the most ambiguous thing in Stylus that gives a lot of problems are variables — one of the ideas for 1.0 was to leave only the Also, I think we could make it work this way in the current versions of Stylus, because there are no idents containing |
I like the idea of requiring the |
I approve for $. |
Would |
Only for variables imho. |
Yes, it should be only for variables. |
Another alternative to achieve negative values is -(var) I would definitely opt for stylus to recognise dashes as the minus operator when used on a number variable. Although I'm not too sure how difficult this would be to implement to the parser ? |
What's the progress on this? The only solutions right now is to do:
or
Both are ugly. Why not just allow for "-(var)"? Or is there a negative() function? |
|
|
that's jade related. not the correct error message |
I have this issue in the latest version (0.43.1) My code
|
var = 50px
body {
width var;
margin-left -(var)
} |
@Panya actually, this method also buggy. I got next problem margin gallery_gap 0 gallery_gap -(gallery_gap) produces me margin: 45px 0 0px; |
@fetis this is an edge case, you can write: margin gallery_gap 0 gallery_gap (-(gallery_gap)) |
what about to exclude '-' from variables identifiers? |
In 1.0, sure. |
but this'll be not very soon, will it? |
It's not matter of time, this will be a breaking change, and following semver it should be in the major release. But if you want the estimates, we'll release 1.0 in this year :) |
Requiring a space when negating variables (e.g. Also since you can wrap the whole negation in parenthesis (i.e. Much rather than introducing weird inconsistencies in how math with variables works, or unnecessary breaking changes. |
Found in 0.32.0. An example says it all:
renders as:
workaround, separating the operator from the variable works:
renders as expected:
The workaround is more complicated when dealing with a list of values:
renders as:
Oops, unintended math! Instead the following slightly uglier workaround works:
In the end, this looks like an issue with preceding dashes being interpreted as part of the variable name (just a guess?) I did not see anything in the stylus docs about legal variable names but they probably shouldn't be allowed to start with dashes.
The text was updated successfully, but these errors were encountered: