-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
139 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2022 Google LLC | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
import 'package:sass_api/sass_api.dart'; | ||
|
||
import '../migration_visitor.dart'; | ||
import '../migrator.dart'; | ||
import '../patch.dart'; | ||
|
||
/// Migrates deprecated `$a -$b` construct to unambiguous `$a - $b`. | ||
class StrictUnaryMigrator extends Migrator { | ||
final name = "strict-unary"; | ||
final description = r"Migrates deprecated `$a -$b` syntax (and similar) to " | ||
r"unambiguous `$a - $b`"; | ||
|
||
@override | ||
Map<Uri, String> migrateFile( | ||
ImportCache importCache, Stylesheet stylesheet, Importer importer) { | ||
var visitor = _UnaryMigrationVisitor(importCache, migrateDependencies); | ||
var result = visitor.run(stylesheet, importer); | ||
missingDependencies.addAll(visitor.missingDependencies); | ||
return result; | ||
} | ||
} | ||
|
||
class _UnaryMigrationVisitor extends MigrationVisitor { | ||
_UnaryMigrationVisitor(ImportCache importCache, bool migrateDependencies) | ||
: super(importCache, migrateDependencies); | ||
|
||
@override | ||
void visitBinaryOperationExpression(BinaryOperationExpression node) { | ||
if (node.operator == BinaryOperator.plus || | ||
node.operator == BinaryOperator.minus) { | ||
var betweenOperands = node.span.file | ||
.span(node.left.span.end.offset, node.right.span.start.offset) | ||
.text; | ||
if (betweenOperands.startsWith(RegExp(r'\s')) && | ||
betweenOperands.endsWith(node.operator.operator)) { | ||
addPatch(Patch.insert(node.right.span.start, ' ')); | ||
} | ||
} | ||
super.visitBinaryOperationExpression(node); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,5 @@ import '../utils.dart'; | |
|
||
main() { | ||
runNodeTests = true; | ||
testMigrator("division"); | ||
testMigrator("namespace"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<==> input/entrypoint.scss | ||
$x: 1; | ||
$y: 2; | ||
|
||
plus { | ||
a: $x +$y; | ||
b: ($x) +($y); | ||
c: $x +$y +$y; | ||
} | ||
|
||
minus { | ||
a: $x -$y; | ||
b: ($x) -($y); | ||
c: $x -$y -$y; | ||
} | ||
|
||
<==> output/entrypoint.scss | ||
$x: 1; | ||
$y: 2; | ||
|
||
plus { | ||
a: $x + $y; | ||
b: ($x) + ($y); | ||
c: $x + $y + $y; | ||
} | ||
|
||
minus { | ||
a: $x - $y; | ||
b: ($x) - ($y); | ||
c: $x - $y - $y; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<==> input/entrypoint.scss | ||
$x: 1; | ||
$y: 2; | ||
|
||
plus { | ||
a: $x+$y; | ||
b: $x + $y; | ||
c: $x (+$y); | ||
d: $x+ $y; | ||
} | ||
|
||
minus { | ||
a: ($x)-$y; | ||
b: $x - $y; | ||
c: $x (-$y); | ||
d: ($x)- $y; | ||
} | ||
|
||
<==> log.txt | ||
Nothing to migrate! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright 2022 Google LLC | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
import '../utils.dart'; | ||
|
||
main() { | ||
testMigrator("strict_unary"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2022 Google LLC | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
@Tags(["node"]) | ||
|
||
import 'package:test/test.dart'; | ||
|
||
import '../utils.dart'; | ||
|
||
main() { | ||
runNodeTests = true; | ||
testMigrator("strict_unary"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters