Skip to content

Commit

Permalink
Don't migrate plain CSS min and max (#263)
Browse files Browse the repository at this point in the history
Fixes #262.
  • Loading branch information
jathak authored Oct 23, 2024
1 parent c5f8ac8 commit 8b80d14
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 32 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 2.2.1

### Module Migrator

* Fix a bug where plain CSS `min()` and `max()` functions would incorrectly
be migrated to `math.min()` and `math.max()`.

## 2.2.0

### Module Migrator
Expand Down
27 changes: 1 addition & 26 deletions lib/src/migrator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:meta/meta.dart';
import 'package:path/path.dart' as p;
import 'package:sass_api/sass_api.dart';
import 'package:source_span/source_span.dart';
import 'package:stack_trace/stack_trace.dart';

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

/// This is called whenever a deprecation warning is emitted during parsing.
@protected
void handleDeprecation(String message, FileSpan? span) {}

/// Runs this migrator.
///
/// Each entrypoint is migrated separately. If a stylesheet is migrated more
Expand All @@ -75,8 +70,7 @@ abstract class Migrator extends Command<Map<Uri, String>> {
var importer = FilesystemImporter('.');
var importCache = ImportCache(
importers: [NodeModulesImporter()],
loadPaths: globalResults!['load-path'],
logger: _DeprecationLogger(this));
loadPaths: globalResults!['load-path']);

var entrypoints = [
for (var argument in argResults!.rest)
Expand Down Expand Up @@ -132,22 +126,3 @@ abstract class Migrator extends Command<Map<Uri, String>> {
}
}
}

/// A silent logger that calls [Migrator.handleDeprecation] when it receives a
/// deprecation warning
class _DeprecationLogger implements Logger {
final Migrator migrator;

_DeprecationLogger(this.migrator);

@override
void debug(String message, SourceSpan span) {}

@override
void warn(String message,
{FileSpan? span, Trace? trace, bool deprecation = false}) {
if (deprecation) {
migrator.handleDeprecation(message, span);
}
}
}
6 changes: 3 additions & 3 deletions lib/src/migrators/module/references.dart
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ class _ReferenceVisitor extends ScopedAstVisitor {
bool _isCssCompatibilityOverload(FunctionExpression node) {
var argument = getOnlyArgument(node.arguments);
switch (node.name) {
case 'grayscale':
case 'invert':
case 'opacity':
case 'min' || 'max':
return node.arguments.positional.every((arg) => arg.isCalculationSafe);
case 'grayscale' || 'invert' || 'opacity':
return argument is NumberExpression;
case 'saturate':
return argument != null;
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: sass_migrator
version: 2.2.0
version: 2.2.1
description: A tool for running migrations on Sass files
homepage: https://github.com/sass/migrator

Expand All @@ -17,7 +17,7 @@ dependencies:
node_interop: ^2.0.2
node_io: ^2.3.0
path: ^1.8.0
sass_api: ^12.0.0
sass_api: ^14.1.0
source_span: ^1.8.1
stack_trace: ^1.10.0
string_scanner: ^1.1.0
Expand Down
3 changes: 2 additions & 1 deletion test/cli_dart_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ void main() {

test("an unknown argument", () async {
var migrator = await runMigrator(["--asdf"]);
expect(migrator.stderr, emits('Could not find an option named "asdf".'));
expect(
migrator.stderr, emits('Could not find an option named "--asdf".'));
expect(migrator.stderr,
emitsThrough(contains('for more information about a command.')));
await migrator.shouldExit(64);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ $c: opacity(25%);
$d: saturate(0.5);
$e: alpha(opacity=50);
$f: alpha(g=h, i=j, k=l);
$g: min(var(--test), 5px);
$h: max(1 + 2 * 3, 3 / 4 - 5);

<==> log.txt
Nothing to migrate!
3 changes: 3 additions & 0 deletions test/migrators/module/built_in_functions/namespacing.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ $a: mix(red, blue);
$b: str-length("hello");
$c: scale-color(blue, $lightness: -10%);
$d: call(get-function(mix), red, blue);
$e: min(10 % 2, 4 + 3);

@function fn($args...) {
@return keywords($args);
}

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

@function fn($args...) {
@return meta.keywords($args);
Expand Down

0 comments on commit 8b80d14

Please sign in to comment.