Skip to content

fix: private variable detection to not match multiple dashes #274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions lib/src/migrators/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
var forwardsByUrl = <Uri, Map<String, Set<MemberDeclaration>>>{};
var hiddenByUrl = <Uri, Set<MemberDeclaration>>{};
for (var declaration in references.globalDeclarations) {
var private = declaration.name.startsWith('-');
var private = _isPrivate(declaration.name);

// Whether this member will be exposed by the regular entrypoint.
var visibleAtEntrypoint = !private &&
Expand Down Expand Up @@ -352,7 +352,7 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
if (declaration.isForwarded) return;

var name = declaration.name;
if (name.startsWith('-') &&
if (_isPrivate(name)
references.referencedOutsideDeclaringStylesheet(declaration)) {
// Remove leading `-` since private members can't be accessed outside
// the module they're declared in.
Expand All @@ -365,6 +365,10 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
}
}

bool _isPrivate(String name) {
return name.startsWith('-') && !name.startsWith('--');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic isn't accurate. Names that start with multiple dashes are still private.

}

/// Returns whether the member named [name] should be forwarded in the
/// entrypoint.
///
Expand Down Expand Up @@ -1026,7 +1030,7 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
}

if (_shouldForward(declaration.name) &&
!declaration.name.startsWith('-')) {
!_isPrivate(declaration.name)) {
var subprefix = "";
if (importOnlyPrefix != null) {
var prefix = _prefixFor(declaration.name);
Expand All @@ -1036,7 +1040,7 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
}
if (declaration.name != newName) _needsImportOnly = true;
shownByPrefix.putIfAbsent(subprefix, () => {}).add(declaration);
} else if (!newName.startsWith('-')) {
} else if (!_isPrivate(newName)) {
hidden.add(declaration);
}
}
Expand Down Expand Up @@ -1076,7 +1080,7 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
if (declaration is ImportOnlyMemberDeclaration) {
name = name.substring(declaration.importOnlyPrefix.length);
}
if (name.startsWith('-')) name = name.substring(1);
if (_isPrivate(name)) name = name.substring(1);
name = _unprefix(name);
if (subprefix.isNotEmpty) name = '$subprefix$name';
if (declaration.member is VariableDeclaration) name = '\$$name';
Expand Down Expand Up @@ -1205,7 +1209,7 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
void _renameReference(FileSpan span, MemberDeclaration declaration) {
var newName = renamedMembers[declaration];
if (newName != null) {
if (newName.startsWith('-') &&
if (_isPrivate(newName) &&
declaration.name.endsWith(newName.substring(1))) {
addPatch(patchDelete(span,
start: 1, end: declaration.name.length - newName.length + 1));
Expand All @@ -1228,7 +1232,7 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
///
/// Otherwise, returns [name] unaltered.
String _unprefix(String name) {
var isPrivate = name.startsWith('-');
var isPrivate = _isPrivate(name);
var unprivateName = isPrivate ? name.substring(1) : name;
var prefix = _prefixFor(unprivateName);
if (prefix == null) return name;
Expand Down