sass / migrator

Tool for migrating stylesheets to new Sass versions
MIT License
84 stars 10 forks source link

Avoid namespace conflicts #78

Closed jathak closed 4 years ago

nex3 commented 4 years ago

WDYT about changing this to use parent directory names for these namespaces, rather than numeric suffixes? So instead of variables and variables2, you'd have a-variables and b-variables.

jathak commented 4 years ago

Yeah, that makes sense. I'll do that.

jathak commented 4 years ago

Hmm. How should this work for extra @use rules, which aren't added until we visit a reference to one of their members?

For the existing @use/@import rules, we can check them all at the beginning for conflicts and then alias both conflicting rules, but for something like @use "color" and @use "sass:color", we won't know that there's a conflict until after we've used the default namespace for the first one.

jathak commented 4 years ago

Okay, I was able to get this working by adding additional logic to References to also track the source of a member being referenced (including both those from imports and those from built-in modules). The main migrator then uses that information to determine most namespaces for a stylesheet before visiting it, allowing conflicts to be resolved more intelligently. Built-in modules now get priority for their default namespaces and the migrator will now try adding additional path segments to namespaces before it falls back to numerical suffixes.