Skip to content

Commit 8b80d14

Browse files
authored
Don't migrate plain CSS min and max (#263)
Fixes #262.
1 parent c5f8ac8 commit 8b80d14

File tree

7 files changed

+20
-32
lines changed

7 files changed

+20
-32
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 2.2.1
2+
3+
### Module Migrator
4+
5+
* Fix a bug where plain CSS `min()` and `max()` functions would incorrectly
6+
be migrated to `math.min()` and `math.max()`.
7+
18
## 2.2.0
29

310
### Module Migrator

lib/src/migrator.dart

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import 'package:meta/meta.dart';
1010
import 'package:path/path.dart' as p;
1111
import 'package:sass_api/sass_api.dart';
1212
import 'package:source_span/source_span.dart';
13-
import 'package:stack_trace/stack_trace.dart';
1413

1514
import 'exception.dart';
1615
import 'io.dart';
@@ -58,10 +57,6 @@ abstract class Migrator extends Command<Map<Uri, String>> {
5857
Map<Uri, String> migrateFile(
5958
ImportCache importCache, Stylesheet stylesheet, Importer importer);
6059

61-
/// This is called whenever a deprecation warning is emitted during parsing.
62-
@protected
63-
void handleDeprecation(String message, FileSpan? span) {}
64-
6560
/// Runs this migrator.
6661
///
6762
/// Each entrypoint is migrated separately. If a stylesheet is migrated more
@@ -75,8 +70,7 @@ abstract class Migrator extends Command<Map<Uri, String>> {
7570
var importer = FilesystemImporter('.');
7671
var importCache = ImportCache(
7772
importers: [NodeModulesImporter()],
78-
loadPaths: globalResults!['load-path'],
79-
logger: _DeprecationLogger(this));
73+
loadPaths: globalResults!['load-path']);
8074

8175
var entrypoints = [
8276
for (var argument in argResults!.rest)
@@ -132,22 +126,3 @@ abstract class Migrator extends Command<Map<Uri, String>> {
132126
}
133127
}
134128
}
135-
136-
/// A silent logger that calls [Migrator.handleDeprecation] when it receives a
137-
/// deprecation warning
138-
class _DeprecationLogger implements Logger {
139-
final Migrator migrator;
140-
141-
_DeprecationLogger(this.migrator);
142-
143-
@override
144-
void debug(String message, SourceSpan span) {}
145-
146-
@override
147-
void warn(String message,
148-
{FileSpan? span, Trace? trace, bool deprecation = false}) {
149-
if (deprecation) {
150-
migrator.handleDeprecation(message, span);
151-
}
152-
}
153-
}

lib/src/migrators/module/references.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,9 @@ class _ReferenceVisitor extends ScopedAstVisitor {
294294
bool _isCssCompatibilityOverload(FunctionExpression node) {
295295
var argument = getOnlyArgument(node.arguments);
296296
switch (node.name) {
297-
case 'grayscale':
298-
case 'invert':
299-
case 'opacity':
297+
case 'min' || 'max':
298+
return node.arguments.positional.every((arg) => arg.isCalculationSafe);
299+
case 'grayscale' || 'invert' || 'opacity':
300300
return argument is NumberExpression;
301301
case 'saturate':
302302
return argument != null;

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: sass_migrator
2-
version: 2.2.0
2+
version: 2.2.1
33
description: A tool for running migrations on Sass files
44
homepage: https://github.com/sass/migrator
55

@@ -17,7 +17,7 @@ dependencies:
1717
node_interop: ^2.0.2
1818
node_io: ^2.3.0
1919
path: ^1.8.0
20-
sass_api: ^12.0.0
20+
sass_api: ^14.1.0
2121
source_span: ^1.8.1
2222
stack_trace: ^1.10.0
2323
string_scanner: ^1.1.0

test/cli_dart_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ void main() {
178178

179179
test("an unknown argument", () async {
180180
var migrator = await runMigrator(["--asdf"]);
181-
expect(migrator.stderr, emits('Could not find an option named "asdf".'));
181+
expect(
182+
migrator.stderr, emits('Could not find an option named "--asdf".'));
182183
expect(migrator.stderr,
183184
emitsThrough(contains('for more information about a command.')));
184185
await migrator.shouldExit(64);

test/migrators/module/built_in_functions/doesnt_namespace_css_overloads.hrx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ $c: opacity(25%);
55
$d: saturate(0.5);
66
$e: alpha(opacity=50);
77
$f: alpha(g=h, i=j, k=l);
8+
$g: min(var(--test), 5px);
9+
$h: max(1 + 2 * 3, 3 / 4 - 5);
810

911
<==> log.txt
1012
Nothing to migrate!

test/migrators/module/built_in_functions/namespacing.hrx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@ $a: mix(red, blue);
33
$b: str-length("hello");
44
$c: scale-color(blue, $lightness: -10%);
55
$d: call(get-function(mix), red, blue);
6+
$e: min(10 % 2, 4 + 3);
67

78
@function fn($args...) {
89
@return keywords($args);
910
}
1011

1112
<==> output/entrypoint.scss
1213
@use "sass:color";
14+
@use "sass:math";
1315
@use "sass:meta";
1416
@use "sass:string";
1517
$a: color.mix(red, blue);
1618
$b: string.length("hello");
1719
$c: color.scale(blue, $lightness: -10%);
1820
$d: meta.call(meta.get-function(mix, $module: "color"), red, blue);
21+
$e: math.min(10 % 2, 4 + 3);
1922

2023
@function fn($args...) {
2124
@return meta.keywords($args);

0 commit comments

Comments
 (0)