From 5a9dd9161be29e6e50d2a392c25d4c598ee92433 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Tue, 22 Jun 2021 15:10:32 -0700 Subject: [PATCH] Fix a variable-assignment bug (#1372) Closes #1250 --- CHANGELOG.md | 8 ++++++++ lib/src/async_environment.dart | 28 +++++++++++++--------------- lib/src/environment.dart | 30 ++++++++++++++---------------- pubspec.yaml | 2 +- 4 files changed, 36 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5808078f..0493238f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## 1.35.2 + +* **Potentially breaking bug fix:** Fixed a bug where certain local variable + declarations nested within multiple `@if` statements would incorrectly + override a global variable. It's unlikely that any real stylesheets were + relying on this bug, but if so they can simply add `!global` to the variable + declaration to preserve the old behavior. + ## 1.35.1 * Fix a bug where the quiet dependency flag didn't silence warnings in some diff --git a/lib/src/async_environment.dart b/lib/src/async_environment.dart index 887a8155..916c46ff 100644 --- a/lib/src/async_environment.dart +++ b/lib/src/async_environment.dart @@ -740,18 +740,20 @@ class AsyncEnvironment { /// executes [callback] and returns its result. Future scope(Future callback(), {bool semiGlobal = false, bool when = true}) async { + // We have to track semi-globalness even if `!when` so that + // + // div { + // @if ... { + // $x: y; + // } + // } + // + // doesn't assign to the global scope. + semiGlobal = semiGlobal && _inSemiGlobalScope; + var wasInSemiGlobalScope = _inSemiGlobalScope; + _inSemiGlobalScope = semiGlobal; + if (!when) { - // We still have to track semi-globalness so that - // - // div { - // @if ... { - // $x: y; - // } - // } - // - // doesn't assign to the global scope. - var wasInSemiGlobalScope = _inSemiGlobalScope; - _inSemiGlobalScope = semiGlobal; try { return await callback(); } finally { @@ -759,10 +761,6 @@ class AsyncEnvironment { } } - semiGlobal = semiGlobal && _inSemiGlobalScope; - var wasInSemiGlobalScope = _inSemiGlobalScope; - _inSemiGlobalScope = semiGlobal; - _variables.add({}); _variableNodes.add({}); _functions.add({}); diff --git a/lib/src/environment.dart b/lib/src/environment.dart index b77e31a6..1602ef34 100644 --- a/lib/src/environment.dart +++ b/lib/src/environment.dart @@ -5,7 +5,7 @@ // DO NOT EDIT. This file was generated from async_environment.dart. // See tool/grind/synchronize.dart for details. // -// Checksum: d5a12dbc383245a91d1e2fee0e2c4aa38939a3d8 +// Checksum: 6e5ee671e0a6e5b1d6ac87beb6aeee1e4b155d74 // // ignore_for_file: unused_import @@ -746,18 +746,20 @@ class Environment { /// If [when] is false, this doesn't create a new scope and instead just /// executes [callback] and returns its result. T scope(T callback(), {bool semiGlobal = false, bool when = true}) { + // We have to track semi-globalness even if `!when` so that + // + // div { + // @if ... { + // $x: y; + // } + // } + // + // doesn't assign to the global scope. + semiGlobal = semiGlobal && _inSemiGlobalScope; + var wasInSemiGlobalScope = _inSemiGlobalScope; + _inSemiGlobalScope = semiGlobal; + if (!when) { - // We still have to track semi-globalness so that - // - // div { - // @if ... { - // $x: y; - // } - // } - // - // doesn't assign to the global scope. - var wasInSemiGlobalScope = _inSemiGlobalScope; - _inSemiGlobalScope = semiGlobal; try { return callback(); } finally { @@ -765,10 +767,6 @@ class Environment { } } - semiGlobal = semiGlobal && _inSemiGlobalScope; - var wasInSemiGlobalScope = _inSemiGlobalScope; - _inSemiGlobalScope = semiGlobal; - _variables.add({}); _variableNodes.add({}); _functions.add({}); diff --git a/pubspec.yaml b/pubspec.yaml index 4a8fd35f..d21991f5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: sass -version: 1.35.1 +version: 1.35.2-dev description: A Sass implementation in Dart. author: Sass Team homepage: https://github.com/sass/dart-sass