Skip to content

Commit

Permalink
Update other suggestors
Browse files Browse the repository at this point in the history
  • Loading branch information
sydneyjodon-wk committed Oct 24, 2024
1 parent 29f0f00 commit 84d8dce
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ class CallbackRefHintSuggestor extends RecursiveAstVisitor<void>
'Could not get resolved result for "${context.relativePath}"');
}
result = r;
// Don't make any updates if the file is already null safe.
if (result.libraryElement.isNonNullableByDefault) {
return;
}

result.unit.visitChildren(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ class StateMixinSuggestor extends RecursiveAstVisitor<void>
throw Exception(
'Could not get resolved result for "${context.relativePath}"');
}

// Don't make any updates if the file is already null safe.
if (r.libraryElement.isNonNullableByDefault) {
return;
}
r.unit.accept(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import 'package:test/test.dart';
import '../../mui_suggestors/components/shared.dart';
import '../../resolved_file_context.dart';
import '../../util.dart';
import '../../util/component_usage_migrator_test.dart';

void main() {
final resolvedContext = SharedAnalysisContext.wsd;
Expand Down Expand Up @@ -280,5 +281,64 @@ void main() {
'''),
);
});

group('makes no update if file is already on a null safe Dart version', () {
final resolvedContext = SharedAnalysisContext.overReactNullSafe;

// Warm up analysis in a setUpAll so that if getting the resolved AST times out
// (which is more common for the WSD context), it fails here instead of failing the first test.
setUpAll(resolvedContext.warmUpAnalysis);

late SuggestorTester nullSafeTestSuggestor;

setUp(() {
nullSafeTestSuggestor = getSuggestorTester(
CallbackRefHintSuggestor(),
resolvedContext: resolvedContext,
);
});

test('', () async {
await nullSafeTestSuggestor(
expectedPatchCount: 0,
input: withOverReactImport(/*language=dart*/ '''
import 'dart:html';
content() {
var ref;
(Dom.div()..ref = (ButtonElement r) { ref = r; })();
ref;
}
'''),
);
});

test('unless there is a lang version comment', () async {
await nullSafeTestSuggestor(
input: withOverReactImport(/*language=dart*/ '''
import 'dart:html';
content() {
var ref;
(Dom.div()..ref = (ButtonElement r) { ref = r; })();
ref;
}
''', filePrefix: '// @dart=2.11\n'),
expectedOutput: withOverReactImport(/*language=dart*/ '''
import 'dart:html';
content() {
var ref;
(Dom.div()..ref = (ButtonElement /*?*/ r) { ref = r; })();
ref;
}
''', filePrefix: '// @dart=2.11\n'),
// Ignore error on language version comment.
isExpectedError: (error) =>
error.errorCode.name.toLowerCase() ==
'illegal_language_version_override',
);
});
});
}, tags: 'wsd');
}
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ void main() {
''', filePrefix: '// @dart=2.11\n'),
// Ignore error on language version comment.
isExpectedError: (error) =>
error.errorCode.name.toLowerCase() ==
error.errorCode.name.toLowerCase() ==
'illegal_language_version_override',
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,104 @@ void main() {
'''),
);
});

group('makes no update if file is already on a null safe Dart version', () {
final resolvedContext = SharedAnalysisContext.overReactNullSafe;

// Warm up analysis in a setUpAll so that if getting the resolved AST times out
// (which is more common for the WSD context), it fails here instead of failing the first test.
setUpAll(resolvedContext.warmUpAnalysis);

late SuggestorTester nullSafeTestSuggestor;

setUp(() {
nullSafeTestSuggestor = getSuggestorTester(
StateMixinSuggestor(),
resolvedContext: resolvedContext,
);
});

test('', () async {
await nullSafeTestSuggestor(
expectedPatchCount: 0,
input: withOverReactImport(/*language=dart*/ r'''
// ignore: undefined_identifier
UiFactory<FooProps> Foo = castUiFactory(_$Foo);
mixin FooProps on UiProps {
String? prop1;
}
mixin FooStateMixin on UiState {
String? state1;
late num state2;
}
mixin SomeOtherStateMixin on UiState {
String? state3;
}
class FooState = UiState with FooStateMixin, SomeOtherStateMixin;
class FooComponent extends UiStatefulComponent2<FooProps, FooState> {
@override
render() => null;
}
'''),
);
});

test('unless there is a lang version comment', () async {
await nullSafeTestSuggestor(
input: withOverReactImport(/*language=dart*/ r'''
// ignore: undefined_identifier
UiFactory<FooProps> Foo = castUiFactory(_$Foo);
mixin FooProps on UiProps {
String prop1;
}
mixin FooStateMixin on UiState {
String state1;
num state2;
/// This is a doc comment
/*late*/ String/*!*/ alreadyPatched;
/*late*/ String/*?*/ alreadyPatchedButNoDocComment;
String/*?*/ alreadyPatchedOptional;
}
mixin SomeOtherStateMixin on UiState {
String state3;
String/*?*/ alreadyPatchedOptional2;
}
class FooState = UiState with FooStateMixin, SomeOtherStateMixin;
class FooComponent extends UiStatefulComponent2<FooProps, FooState> {
@override
render() => null;
}
''', filePrefix: '// @dart=2.11\n'),
expectedOutput: withOverReactImport(/*language=dart*/ r'''
// ignore: undefined_identifier
UiFactory<FooProps> Foo = castUiFactory(_$Foo);
mixin FooProps on UiProps {
String prop1;
}
mixin FooStateMixin on UiState {
String/*?*/ state1;
num/*?*/ state2;
/// This is a doc comment
/*late*/ String/*!*/ alreadyPatched;
/*late*/ String/*?*/ alreadyPatchedButNoDocComment;
String/*?*/ alreadyPatchedOptional;
}
mixin SomeOtherStateMixin on UiState {
String/*?*/ state3;
String/*?*/ alreadyPatchedOptional2;
}
class FooState = UiState with FooStateMixin, SomeOtherStateMixin;
class FooComponent extends UiStatefulComponent2<FooProps, FooState> {
@override
render() => null;
}
''', filePrefix: '// @dart=2.11\n'),
// Ignore error on language version comment.
isExpectedError: (error) =>
error.errorCode.name.toLowerCase() ==
'illegal_language_version_override',
);
});
});
});
}

0 comments on commit 84d8dce

Please sign in to comment.