8000 Spec the @for at-rule by stof · Pull Request #2986 · sass/sass · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 4 commits into from
Jan 8, 2021
Merged

Spec the @for at-rule #2986

merged 4 commits into from
Jan 8, 2021

Conversation

stof
Copy link
Contributor
@stof stof commented Jan 4, 2021

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 and to, 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).

Copy link
Contributor
@nex3 nex3 left a 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!

## Syntax

<x><pre>
**Variable** ::= '$' Identifier | NamespacedVariable
**Variable** ::= VariableName | NamespacedVariable
**VariableName** ::= '$' Identifier
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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].
Copy link
Contributor Author

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 ?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@stof
Copy link
8000
Contributor Author
stof commented Jan 6, 2021

@nex3 by curiosity, what is this weird <x> tag around <pre> blocks ?

@nex3
Copy link
Contributor
nex3 commented Jan 6, 2021

@nex3 by curiosity, what is this weird <x> tag around <pre> blocks ?

A <pre> block on its own puts the Markdown parser into a state where inline Markdown is treated as plain text, but only if the <pre> isn't in another HTML element. So in order to use Markdown links and emphasis and so on in a <pre> context we have to wrap it in some other HTML tag. We use <x> as a short option that will get stripped before rendering.

stof and others added 3 commits January 8, 2021 11:14
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...)
@nex3
Copy link
Contributor
nex3 commented Jan 8, 2021

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.

@nex3
Copy link
Contributor
nex3 commented Jan 8, 2021

Oh, I missed #2994.

@nex3 nex3 merged commit 601fbad into sass:master Jan 8, 2021
@stof stof deleted the spec_for branch January 11, 2021 09:40
mirisuzanne pushed a commit that referenced this pull request Feb 10, 2022
Co-authored-by: Natalie Weizenbaum <nweiz@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0