Skip to content

Commit 402e6f5

Browse files
Error if function reference that refers to other function over time
1 parent dce67db commit 402e6f5

File tree

4 files changed

+68
-4
lines changed

4 files changed

+68
-4
lines changed

Diff for: lib/src/migrators/module/references.dart

+18
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,15 @@ class _ReferenceVisitor extends ScopedAstVisitor {
630630
super.visitMixinRule(node);
631631
var member = MemberDeclaration(node);
632632
_declarationSources[member] = CurrentSource(_currentUrl);
633+
_mixins.forEach((declaredMixins, reference) {
634+
if (declaredMixins.name == node.name &&
635+
reference.sourceUrl != _currentUrl) {
636+
throw new MigrationException(
637+
'Mixin `${node.name}` has been previously declared' +
638+
' in ${reference.sourceUrl.pathSegments.last} and is' +
639+
' later on defined in ${_currentUrl.pathSegments.last}.');
640+
}
641+
});
633642
_registerLibraryUrl(member);
634643
}
635644

@@ -660,6 +669,15 @@ class _ReferenceVisitor extends ScopedAstVisitor {
660669
super.visitFunctionRule(node);
661670
var member = MemberDeclaration(node);
662671
_declarationSources[member] = CurrentSource(_currentUrl);
672+
_functions.forEach((declaredFunction, reference) {
673+
if (declaredFunction.name == node.name &&
674+
reference.sourceUrl != _currentUrl) {
675+
throw new MigrationException(
676+
'Function `${node.name}` has been previously declared' +
677+
' in ${reference.sourceUrl.pathSegments.last} and is' +
678+
' later on defined in ${_currentUrl.pathSegments.last}.');
679+
}
680+
});
663681
_registerLibraryUrl(member);
664682
}
665683

Diff for: test/migrators/calc_interpolation/calc_remove_interpolation.hrx

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ $d: 5;
99

1010
// More than one interpolations
1111
.a {
12-
.b: calc($b - #{$c + 1} + #{$d});
13-
.c: calc(100% - #{$TABLE_TITLE + 2px});
12+
.b: calc($b - #{$c + 1} + #{$d});
1413
}
1514

1615
// Nested
@@ -36,8 +35,7 @@ $d: 5;
3635

3736
// More than one interpolations
3837
.a {
39-
.b: calc($b - ($c + 1) + $d);
40-
.c: calc(100% - ($TABLE-TITLE + 2px));
38+
.b: calc($b - ($c + 1) + $d);
4139
}
4240

4341
// Nested
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<==> input/entrypoint.scss
2+
@import "definition1";
3+
@import "upstream";
4+
@import "direct";
5+
6+
<==> input/_direct.scss
7+
@import "definition2";
8+
@import "upstream";
9+
10+
<==> input/definition1.scss
11+
@function fn() {@return 1}
12+
13+
<==> input/definition2.scss
14+
@function fn() {@return 2}
15+
16+
<==> input/upstream.scss
17+
a { b: fn() }
18+
19+
<==> error.txt
20+
Error: Function `fn` has been previously declared in definition1.scss and is later on defined in definition2.scss.
21+
Migration failed!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<==> input/entrypoint.scss
2+
@import "definition1";
3+
@import "upstream";
4+
@import "direct";
5+
6+
<==> input/_direct.scss
7+
@import "definition2";
8+
@import "upstream";
9+
10+
<==> input/definition1.scss
11+
@mixin fn {
12+
margin: 0;
13+
padding: 0;
14+
list-style: none;
15+
}
16+
17+
<==> input/definition2.scss
18+
@mixin fn {
19+
color: blue;
20+
}
21+
22+
<==> input/upstream.scss
23+
@include fn;
24+
25+
<==> error.txt
26+
Error: Mixin `fn` has been previously declared in definition1.scss and is later on defined in definition2.scss.
27+
Migration failed!

0 commit comments

Comments
 (0)