Skip to content

Commit

Permalink
Fix show / hide import updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sydneyjodon-wk committed Oct 30, 2023
1 parent e1ff537 commit 80a9c4d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
8 changes: 7 additions & 1 deletion lib/src/unify_package_rename_suggestors/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
/// Info on a unify_ui import.
class UnifyImportInfo {
UnifyImportInfo(this.uri,
{this.rmuiUri, this.namespace, this.possibleMuiNamespaces});
{this.rmuiUri,
this.namespace,
this.possibleMuiNamespaces,
this.showHideInfo});

/// Unify import URI.
String uri;
Expand All @@ -28,6 +31,9 @@ class UnifyImportInfo {

/// Previous RMUI import URI (if it's different from the unify_ui path).
String? rmuiUri;

/// Additional show / hide information used in [importRenamerSuggestorBuilder] to add to updated imports.
String? showHideInfo;
}

/// A list of the standard imports for unify_ui that should be updated.
Expand Down
10 changes: 7 additions & 3 deletions lib/src/unify_package_rename_suggestors/import_renamer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@ Suggestor importRenamerSuggestorBuilder({

if (newImportUri != null) {
// Collect info on new imports to add.
newImportsInfo
.add(UnifyImportInfo(newImportUri, namespace: newNamespace));
newImportsInfo.add(UnifyImportInfo(newImportUri,
namespace: newNamespace,
showHideInfo: import.combinators
.map((c) => c.toSource())
.toList()
.join(' ')));
}

final prevTokenEnd = import.beginToken.previous?.end;
Expand All @@ -96,7 +100,7 @@ Suggestor importRenamerSuggestorBuilder({
mainLibraryUnitResult.unit, mainLibraryUnitResult.lineInfo);
yield Patch(
insertInfo.leadingNewlines +
"import '${importInfo.uri}'${importInfo.namespace != null ? ' as ${importInfo.namespace}' : ''};" +
"import '${importInfo.uri}'${importInfo.namespace != null ? ' as ${importInfo.namespace}' : ''}${importInfo.showHideInfo != null ? ' ${importInfo.showHideInfo}' : ''};" +
insertInfo.trailingNewlines,
insertInfo.offset,
insertInfo.offset);
Expand Down
32 changes: 30 additions & 2 deletions test/unify_package_rename_suggestors/import_renamer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void main() {
import 'package:over_react/over_react.dart' as mui;
import 'package:react_material_ui/components/badge.dart' as mui;
import 'package:react_material_ui/components/alert.dart' as something_else;
import 'package:react_material_ui/styles/theme_provider.dart' as mui_theme;
import 'package:react_material_ui/styles/theme_provider.dart' as mui_theme show UnifyThemeProvider;
content() => Dom.div()();
''',
Expand All @@ -143,7 +143,7 @@ void main() {
import 'package:'''
'''unify_ui/components/badge.dart' as unify;
import 'package:'''
'''unify_ui/styles/theme_provider.dart' as unify_theme;
'''unify_ui/styles/theme_provider.dart' as unify_theme show UnifyThemeProvider;
import 'package:'''
'''unify_ui/unify_ui.dart' as unify;
import 'package:'''
Expand All @@ -156,6 +156,34 @@ void main() {
);
});

test('with show / hide', () async {
await testSuggestor(
input: '''
import 'package:react_material_ui/react_material_ui.dart' hide Alert;
import 'package:react_material_ui/z_alpha_may_break_at_runtime_do_not_release_to_customers.dart' as mui_alpha hide Alert show LinearProgress;
import 'package:react_material_ui/components/badge.dart' show Badge hide BadgeColor;
import 'package:react_material_ui/components/alert.dart' as something_else show Alert;
import 'package:react_material_ui/styles/theme_provider.dart' as mui_theme show UnifyThemeProvider;
content() => Dom.div()();
''',
expectedOutput: '''
import 'package:'''
'''unify_ui/components/alert.dart' as something_else show Alert;
import 'package:'''
'''unify_ui/components/badge.dart' show Badge hide BadgeColor;
import 'package:'''
'''unify_ui/styles/theme_provider.dart' as unify_theme show UnifyThemeProvider;
import 'package:'''
'''unify_ui/unify_ui.dart' hide Alert;
import 'package:'''
'''unify_ui/z_alpha_may_break_at_runtime_do_not_release_to_customers.dart' as alpha_unify hide Alert show LinearProgress;
content() => Dom.div()();
''',
);
});

test('unless the imports are already updated to the new name', () async {
await testSuggestor(
input: '''
Expand Down

0 comments on commit 80a9c4d

Please sign in to comment.