diff --git a/lib/src/migrators/module/references.dart b/lib/src/migrators/module/references.dart index c65d293..23962e2 100644 --- a/lib/src/migrators/module/references.dart +++ b/lib/src/migrators/module/references.dart @@ -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); } @@ -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); } diff --git a/test/migrators/module/references/different_reference_same_function.hrx b/test/migrators/module/references/different_reference_same_function.hrx new file mode 100644 index 0000000..53396a4 --- /dev/null +++ b/test/migrators/module/references/different_reference_same_function.hrx @@ -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!