Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants