Skip to content

Commit 5a9dd91

Browse files
authored
Fix a variable-assignment bug (#1372)
Closes #1250
1 parent 0f68d7a commit 5a9dd91

File tree

4 files changed

+36
-32
lines changed

4 files changed

+36
-32
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 1.35.2
2+
3+
* **Potentially breaking bug fix:** Fixed a bug where certain local variable
4+
declarations nested within multiple `@if` statements would incorrectly
5+
override a global variable. It's unlikely that any real stylesheets were
6+
relying on this bug, but if so they can simply add `!global` to the variable
7+
declaration to preserve the old behavior.
8+
19
## 1.35.1
210

311
* Fix a bug where the quiet dependency flag didn't silence warnings in some

lib/src/async_environment.dart

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -740,29 +740,27 @@ class AsyncEnvironment {
740740
/// executes [callback] and returns its result.
741741
Future<T> scope<T>(Future<T> callback(),
742742
{bool semiGlobal = false, bool when = true}) async {
743+
// We have to track semi-globalness even if `!when` so that
744+
//
745+
// div {
746+
// @if ... {
747+
// $x: y;
748+
// }
749+
// }
750+
//
751+
// doesn't assign to the global scope.
752+
semiGlobal = semiGlobal && _inSemiGlobalScope;
753+
var wasInSemiGlobalScope = _inSemiGlobalScope;
754+
_inSemiGlobalScope = semiGlobal;
755+
743756
if (!when) {
744-
// We still have to track semi-globalness so that
745-
//
746-
// div {
747-
// @if ... {
748-
// $x: y;
749-
// }
750-
// }
751-
//
752-
// doesn't assign to the global scope.
753-
var wasInSemiGlobalScope = _inSemiGlobalScope;
754-
_inSemiGlobalScope = semiGlobal;
755757
try {
756758
return await callback();
757759
} finally {
758760
_inSemiGlobalScope = wasInSemiGlobalScope;
759761
}
760762
}
761763

762-
semiGlobal = semiGlobal && _inSemiGlobalScope;
763-
var wasInSemiGlobalScope = _inSemiGlobalScope;
764-
_inSemiGlobalScope = semiGlobal;
765-
766764
_variables.add({});
767765
_variableNodes.add({});
768766
_functions.add({});

lib/src/environment.dart

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// DO NOT EDIT. This file was generated from async_environment.dart.
66
// See tool/grind/synchronize.dart for details.
77
//
8-
// Checksum: d5a12dbc383245a91d1e2fee0e2c4aa38939a3d8
8+
// Checksum: 6e5ee671e0a6e5b1d6ac87beb6aeee1e4b155d74
99
//
1010
// ignore_for_file: unused_import
1111

@@ -746,29 +746,27 @@ class Environment {
746746
/// If [when] is false, this doesn't create a new scope and instead just
747747
/// executes [callback] and returns its result.
748748
T scope<T>(T callback(), {bool semiGlobal = false, bool when = true}) {
749+
// We have to track semi-globalness even if `!when` so that
750+
//
751+
// div {
752+
// @if ... {
753+
// $x: y;
754+
// }
755+
// }
756+
//
757+
// doesn't assign to the global scope.
758+
semiGlobal = semiGlobal && _inSemiGlobalScope;
759+
var wasInSemiGlobalScope = _inSemiGlobalScope;
760+
_inSemiGlobalScope = semiGlobal;
761+
749762
if (!when) {
750-
// We still have to track semi-globalness so that
751-
//
752-
// div {
753-
// @if ... {
754-
// $x: y;
755-
// }
756-
// }
757-
//
758-
// doesn't assign to the global scope.
759-
var wasInSemiGlobalScope = _inSemiGlobalScope;
760-
_inSemiGlobalScope = semiGlobal;
761763
try {
762764
return callback();
763765
} finally {
764766
_inSemiGlobalScope = wasInSemiGlobalScope;
765767
}
766768
}
767769

768-
semiGlobal = semiGlobal && _inSemiGlobalScope;
769-
var wasInSemiGlobalScope = _inSemiGlobalScope;
770-
_inSemiGlobalScope = semiGlobal;
771-
772770
_variables.add({});
773771
_variableNodes.add({});
774772
_functions.add({});

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: sass
2-
version: 1.35.1
2+
version: 1.35.2-dev
33
description: A Sass implementation in Dart.
44
author: Sass Team
55
homepage: https://github.com/sass/dart-sass

0 commit comments

Comments
 (0)