@@ -356,7 +356,7 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
356
356
if (declaration.isForwarded) return ;
357
357
358
358
var name = declaration.name;
359
- name = _unprefix (name, isReferenced : isPrivate (name) && references.referencedOutsideDeclaringStylesheet (declaration));
359
+ name = _unprefix (name, forcePublic : references.referencedOutsideDeclaringStylesheet (declaration));
360
360
if (name != declaration.name) {
361
361
renamedMembers[declaration] = name;
362
362
if (_upstreamStylesheets.isEmpty) _needsImportOnly = true ;
@@ -1073,7 +1073,7 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
1073
1073
if (declaration is ImportOnlyMemberDeclaration ) {
1074
1074
name = name.substring (declaration.importOnlyPrefix.length);
1075
1075
}
1076
- name = _unprefix (name, isReferenced : true );
1076
+ name = _unprefix (name, forcePublic : true );
1077
1077
if (subprefix.isNotEmpty) name = '$subprefix $name ' ;
1078
1078
if (declaration.member is VariableDeclaration ) name = '\$ $name ' ;
1079
1079
allHidden.add (name);
@@ -1239,22 +1239,29 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
1239
1239
/// longest matching prefix removed.
1240
1240
///
1241
1241
/// Otherwise, returns [name] unaltered.
1242
- String _unprefix (String name, {bool isReferenced = false }) {
1243
- var wasPrivate = isPrivate (name);
1242
+ String _unprefix (String name, {bool forcePublic = false }) {
1244
1243
var unprivateName = _privateToPublic (name);
1245
- var prefix = _prefixFor (unprivateName, unprivatized: true );
1246
- if (prefix == null ) return isReferenced ? unprivateName : name;
1247
-
1248
- var withoutPrefix = unprivateName.substring (prefix.length);
1249
- var withoutPrefixPublic = _privateToPublic (withoutPrefix);
1244
+ var wasPrivate = unprivateName != name;
1245
+ var prefix = _prefixFor (name);
1246
+ var withoutPrefix = '' ;
1250
1247
var privatePrefix = '' ;
1251
- if (wasPrivate) {
1252
- var realPrefix = prefixesToRemove.firstWhere ((pre) => _privateToPublic (pre) == prefix, orElse: () => prefix);
1253
- privatePrefix = ! isPrivate (realPrefix)
1254
- ? name.substring (0 , name.length - unprivateName.length)
1255
- : withoutPrefix.substring (0 , withoutPrefix.length - withoutPrefixPublic.length);
1248
+ if (wasPrivate && prefix == null ) {
1249
+ prefix = _prefixFor (unprivateName);
1250
+ if (prefix != null ) {
1251
+ privatePrefix = name.substring (0 , name.length - unprivateName.length);
1252
+ withoutPrefix = _privateToPublic (unprivateName.substring (prefix.length));
1253
+ }
1254
+ } else if (prefix != null ) {
1255
+ withoutPrefix = name.substring (prefix.length);
1256
+ var withoutPrefixPublic = _privateToPublic (withoutPrefix);
1257
+ if (wasPrivate && withoutPrefixPublic != withoutPrefix) {
1258
+ privatePrefix = withoutPrefix.substring (0 , withoutPrefix.length - withoutPrefixPublic.length);
1259
+ }
1260
+ withoutPrefix = withoutPrefixPublic;
1256
1261
}
1257
- return isReferenced ? withoutPrefixPublic : privatePrefix + withoutPrefixPublic;
1262
+ if (prefix == null ) return forcePublic ? unprivateName : name;
1263
+
1264
+ return forcePublic ? _privateToPublic (withoutPrefix) : privatePrefix + withoutPrefix;
1258
1265
}
1259
1266
1260
1267
/// Returns the namespace that built-in module [module] is loaded under.
@@ -1349,13 +1356,11 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
1349
1356
/// starts with it and the remainder is a valid Sass identifier.
1350
1357
///
1351
1358
/// If there is no such prefix, returns `null` .
1352
- String ? _prefixFor (String identifier, {bool unprivatized = false }) => maxBy (
1353
- prefixesToRemove
1354
- .map ((prefix) => unprivatized ? _privateToPublic (prefix) : prefix)
1355
- .where ((prefix) =>
1356
- prefix.length < identifier.length &&
1357
- identifier.startsWith (prefix) &&
1358
- isIdentifier (identifier.substring (prefix.length))),
1359
+ String ? _prefixFor (String identifier) => maxBy (
1360
+ prefixesToRemove.where ((prefix) =>
1361
+ prefix.length < identifier.length &&
1362
+ identifier.startsWith (prefix) &&
1363
+ isIdentifier (identifier.substring (prefix.length))),
1359
1364
(prefix) => prefix.length);
1360
1365
1361
1366
/// Disallows `@use` after `@at-root` rules.
0 commit comments