Skip to content

Commit

Permalink
Error if function reference that refers to other function over time
Browse files Browse the repository at this point in the history
  • Loading branch information
pamelalozano16 committed Jun 26, 2024
1 parent dce67db commit 402e6f5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
18 changes: 18 additions & 0 deletions lib/src/migrators/module/references.dart
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,15 @@ class _ReferenceVisitor extends ScopedAstVisitor {
super.visitMixinRule(node);
var member = MemberDeclaration(node);
_declarationSources[member] = CurrentSource(_currentUrl);
_mixins.forEach((declaredMixins, reference) {
if (declaredMixins.name == node.name &&
reference.sourceUrl != _currentUrl) {
throw new MigrationException(
'Mixin `${node.name}` has been previously declared' +
' in ${reference.sourceUrl.pathSegments.last} and is' +
' later on defined in ${_currentUrl.pathSegments.last}.');
}
});
_registerLibraryUrl(member);
}

Expand Down Expand Up @@ -660,6 +669,15 @@ class _ReferenceVisitor extends ScopedAstVisitor {
super.visitFunctionRule(node);
var member = MemberDeclaration(node);
_declarationSources[member] = CurrentSource(_currentUrl);
_functions.forEach((declaredFunction, reference) {
if (declaredFunction.name == node.name &&
reference.sourceUrl != _currentUrl) {
throw new MigrationException(
'Function `${node.name}` has been previously declared' +
' in ${reference.sourceUrl.pathSegments.last} and is' +
' later on defined in ${_currentUrl.pathSegments.last}.');
}
});
_registerLibraryUrl(member);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ $d: 5;

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

// Nested
Expand All @@ -36,8 +35,7 @@ $d: 5;

// More than one interpolations
.a {
.b: calc($b - ($c + 1) + $d);
.c: calc(100% - ($TABLE-TITLE + 2px));
.b: calc($b - ($c + 1) + $d);
}

// Nested
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<==> input/entrypoint.scss
@import "definition1";
@import "upstream";
@import "direct";

<==> input/_direct.scss
@import "definition2";
@import "upstream";

<==> input/definition1.scss
@function fn() {@return 1}

<==> input/definition2.scss
@function fn() {@return 2}

<==> input/upstream.scss
a { b: fn() }

<==> error.txt
Error: Function `fn` has been previously declared in definition1.scss and is later on defined in definition2.scss.
Migration failed!
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<==> input/entrypoint.scss
@import "definition1";
@import "upstream";
@import "direct";

<==> input/_direct.scss
@import "definition2";
@import "upstream";

<==> input/definition1.scss
@mixin fn {
margin: 0;
padding: 0;
list-style: none;
}

<==> input/definition2.scss
@mixin fn {
color: blue;
}

<==> input/upstream.scss
@include fn;

<==> error.txt
Error: Mixin `fn` has been previously declared in definition1.scss and is later on defined in definition2.scss.
Migration failed!

0 comments on commit 402e6f5

Please sign in to comment.