From d38888705543cb29e5467424f19a9f0487d4ac2e Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Tue, 2 Sep 2025 10:33:57 -0700 Subject: [PATCH] Forbid multiple !global or !default flags on the same variable Closes #604 --- CHANGELOG.md | 3 +++ lib/src/deprecation.dart | 3 ++- lib/src/parse/stylesheet.dart | 18 ++++-------------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4dd248f4..f79402c24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ parsing associated with it. It is now parsed like any other unknown plain CSS at-rule, where Sass features are only allowed within `#{}` interpolation. +* **Breaking change:** A variable definition may now only have a single + `!global` flag or `!default` flag, or one of each. + ### Bogus Combinators * **Breaking change:** Selectors with more than one combinator in a row, such as diff --git a/lib/src/deprecation.dart b/lib/src/deprecation.dart index 56c468234..6b8fdd4b0 100644 --- a/lib/src/deprecation.dart +++ b/lib/src/deprecation.dart @@ -15,7 +15,7 @@ enum Deprecation { // DO NOT EDIT. This section was generated from the language repo. // See tool/grind/generate_deprecations.dart for details. // - // Checksum: f9088047deb7019c0d619480b54cea07a65abbb4 + // Checksum: d1c9c01ca8d2b69e39b7371d774c9c86349efdef /// Deprecation for passing a string directly to meta.call(). callString('call-string', @@ -70,6 +70,7 @@ enum Deprecation { /// Deprecation for using !default or !global multiple times for one variable. duplicateVarFlags('duplicate-var-flags', deprecatedIn: '1.62.0', + obsoleteIn: '2.0.0', description: 'Using !default or !global multiple times for one variable.'), diff --git a/lib/src/parse/stylesheet.dart b/lib/src/parse/stylesheet.dart index 7a9e1307e..df9104310 100644 --- a/lib/src/parse/stylesheet.dart +++ b/lib/src/parse/stylesheet.dart @@ -255,13 +255,8 @@ abstract class StylesheetParser extends Parser { switch (identifier()) { case 'default': if (guarded) { - warnings.add(( - deprecation: Deprecation.duplicateVarFlags, - message: - '!default should only be written once for each variable.\n' - 'This will be an error in Dart Sass 2.0.0.', - span: scanner.spanFrom(flagStart), - )); + error('Only one !default is allowed per declaration.', + scanner.spanFrom(flagStart)); } guarded = true; @@ -272,13 +267,8 @@ abstract class StylesheetParser extends Parser { scanner.spanFrom(flagStart), ); } else if (global) { - warnings.add(( - deprecation: Deprecation.duplicateVarFlags, - message: - '!global should only be written once for each variable.\n' - 'This will be an error in Dart Sass 2.0.0.', - span: scanner.spanFrom(flagStart), - )); + error('Only one !global is allowed per declaration.', + scanner.spanFrom(flagStart)); } global = true;