diff --git a/lib/src/migrators/module/references.dart b/lib/src/migrators/module/references.dart index c65d293..d3e3733 100644 --- a/lib/src/migrators/module/references.dart +++ b/lib/src/migrators/module/references.dart @@ -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); } @@ -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); } diff --git a/test/migrators/calc_interpolation/calc_remove_interpolation.hrx b/test/migrators/calc_interpolation/calc_remove_interpolation.hrx index 0e0767b..ce2d6f9 100644 --- a/test/migrators/calc_interpolation/calc_remove_interpolation.hrx +++ b/test/migrators/calc_interpolation/calc_remove_interpolation.hrx @@ -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 @@ -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 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! diff --git a/test/migrators/module/references/different_reference_same_mixin.hrx b/test/migrators/module/references/different_reference_same_mixin.hrx new file mode 100644 index 0000000..2fb04a8 --- /dev/null +++ b/test/migrators/module/references/different_reference_same_mixin.hrx @@ -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!