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

cannot assign variable again inside if statement #88

Open
mitsuru793 opened this issue Nov 27, 2016 · 1 comment
Open

cannot assign variable again inside if statement #88

mitsuru793 opened this issue Nov 27, 2016 · 1 comment

Comments

@mitsuru793
Copy link

mitsuru793 commented Nov 27, 2016

Can't precss assign variable inside if statement?
I use the following plugin. I can use calc at to assign variable.
https://github.com/postcss/postcss-calc

input code

$max: 3;
@for $i from 0 to $max {
  $next: -1;
  @if $i < $max {
    $next: calc($i + 1);
    #id_inside-$next {}
  }
  @else {
    $next: 0;
    #id_inside-$next {}
  }
  #id_$next {}
}

output code

#id_inside-1 {}
#id_-1 {}
#id_inside-2 {}
#id_-1 {}
#id_inside-3 {}
#id_-1 {}
#id_inside-0 {}
#id_-1 {}
@keithjgrant
Copy link

The problem is the way block scoping works on these variables. If you assign the variable inside an @if, that value is only applied inside that block… it doesn’t persist after the closing brace.

I don’t know if @if/@else should have different scoping rules, or if there should be a way to indicate you want a value to be applied up a scope, but I would like a way to accomplish this as well.

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

No branches or pull requests

2 participants