@@ -356,13 +356,10 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
356
356
if (declaration.isForwarded) return ;
357
357
358
358
var name = declaration.name;
359
- if (_isPrivate (name) &&
360
- references.referencedOutsideDeclaringStylesheet (declaration)) {
359
+ name = _unprefix (name,
361
360
// Private members can't be accessed outside the module they're declared
362
361
// in.
363
- name = _privateToPublic (name);
364
- }
365
- name = _unprefix (name);
362
+ forcePublic: references.referencedOutsideDeclaringStylesheet (declaration));
366
363
if (name != declaration.name) {
367
364
renamedMembers[declaration] = name;
368
365
if (_upstreamStylesheets.isEmpty) _needsImportOnly = true ;
@@ -1100,8 +1097,7 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
1100
1097
if (declaration is ImportOnlyMemberDeclaration ) {
1101
1098
name = name.substring (declaration.importOnlyPrefix.length);
1102
1099
}
1103
- if (_isPrivate (name)) name = _privateToPublic (name);
1104
- name = _unprefix (name);
1100
+ name = _unprefix (name, forcePublic: true );
1105
1101
if (subprefix.isNotEmpty) name = '$subprefix $name ' ;
1106
1102
if (declaration.member is VariableDeclaration ) name = '\$ $name ' ;
1107
1103
allHidden.add (name);
@@ -1251,17 +1247,32 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
1251
1247
/// longest matching prefix removed.
1252
1248
///
1253
1249
/// Otherwise, returns [name] unaltered.
1254
- String _unprefix (String name) {
1255
- var isPrivate = _isPrivate (name);
1256
- var unprivateName = isPrivate ? _privateToPublic (name) : name;
1257
- var prefix = _prefixFor (unprivateName);
1258
- if (prefix == null ) return name;
1250
+ ///
1251
+ /// If [forcePublic] is true, this will ensure that the name is always a
1252
+ /// public identifier.
1253
+ String _unprefix (String name, {bool forcePublic= false }) {
1254
+ bool isPrivate;
1255
+ String withoutPrefix;
1256
+
1257
+ // Allow users to pass prefixes that either do or do not include leading
1258
+ // dashes/underscores. As usual, the longest prefix wins, so we check for
1259
+ // ones that do include them first.
1260
+ var prefix = _prefixFor (name);
1261
+ if (prefix != null ) {
1262
+ isPrivate = false ;
1263
+ withoutPrefix = name.substring (prefix.length);
1264
+ } else {
1265
+ isPrivate = _isPrivate (name);
1266
+ var unprivateName = isPrivate ? _privateToPublic (name) : name;
1267
+ prefix = _prefixFor (unprivateName);
1268
+ if (prefix == null ) return isPrivate && forcePublic ? unprivateName : name;
1269
+ withoutPrefix = unprivateName.substring (prefix.length);
1270
+ }
1259
1271
1260
- var withoutPrefix = unprivateName.substring (prefix.length);
1261
1272
if (_isPrivate (withoutPrefix)) {
1262
1273
withoutPrefix = _privateToPublic (withoutPrefix);
1263
1274
}
1264
- return (isPrivate ? '-' : '' ) + withoutPrefix;
1275
+ return (isPrivate && ! forcePublic ? '-' : '' ) + withoutPrefix;
1265
1276
}
1266
1277
1267
1278
/// Returns the namespace that built-in module [module] is loaded under.
0 commit comments