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 961b748
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/src/migrators/module/references.dart
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,16 @@ 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 +670,16 @@ 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
@@ -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!

0 comments on commit 961b748

Please sign in to comment.