-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Spec the @for at-rule #2986
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
Spec the @for at-rule #2986
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing the groundwork here!
spec/variables.md
Outdated
## Syntax | ||
|
||
<x><pre> | ||
**Variable** ::= '$' Identifier | NamespacedVariable | ||
**Variable** ::= VariableName | NamespacedVariable | ||
**VariableName** ::= '$' Identifier |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make the difference clearer, I think this should probably be something like NamespacelessVariable
or LocalVariable
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After writing this, I saw that #2850 (comment) suggested PlainVariable
.
LocalVariable
seems wrong to me, as it could be the name of a global variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will let you decide which name I should use before updating my PR.
|
||
* While `i` is not equal to `to`: | ||
|
||
* Declare a variable with `rule`'s `VariableName` as name and value `i` in the `rule`'s `ForBlock`'s scope | ||
* Let `scope` be a new [scope]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we actually create a new scope at each iteration ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nex3 was there anything wrong with my previous proposal ? According to the spec for variables, the curly braces of the ForBlock
are already introducing a new scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's actually detectable either way right now, but if we do ever add full closure semantics to Sass we'll want a closure to capture the current value of the iteration variable rather than the final value (that is, we'll want it to behave like for
/let
in JS and not like for
/var
). This text makes that explicit.
@nex3 by curiosity, what is this weird |
A |
This represents a non-namespaced variable named (as opposed to Variable which accepts both). Several parts of Sass don't allow namespaced names for the variables they need (loops, argument declaration, etc...)
I updated my markdown-link-check fork but it still failed to fetch GitHub URLs 😕. I'm re-running tests (again) to see if that clears it out. |
Oh, I missed #2994. |
As a basis for the fast-track proposal in #2931, this writes specs for the
@for
at-rule.I intentionally skipped any mention of the unit conversion for
from
andto
, because dart-sass, libsass and ruby-sass have 3 different behaviors for it (which is precisely what #2931 is meant to solve).Implementing strictly the spec as written here would probably produce the libsass behavior (relying on the fact that adding a unitless number to a number with unit is allowed in Sass and produces a number with that unit). Specifying the ruby-sass behavior is a matter of adding a step
Convert `to` to `from`'s unit
before asserting that both values are integers (but currently, dart-sass does the conversion the other way, which is why I prefer keeping this line as part of the proposal instead). Spec'ing the existing dart-sass behavior would make the spec more complex for something that would have to be reverted by the proposal anyway (converting numbers to strip the unit for the loop variable).