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