diff --git a/mobx_codegen/CHANGELOG.md b/mobx_codegen/CHANGELOG.md index bfa7313c..e1fcfd20 100644 --- a/mobx_codegen/CHANGELOG.md +++ b/mobx_codegen/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.6.2 + +- Fixes [error with code generation when file has unnamed extension](https://github.com/mobxjs/mobx.dart/issues/1010) by [@amondnet](https://github.com/amondnet) in [#1020](https://github.com/mobxjs/mobx.dart/pull/1020) + ## 2.6.1 - Upgrading packages and sdk diff --git a/mobx_codegen/lib/src/template/method_override.dart b/mobx_codegen/lib/src/template/method_override.dart index d07e45ca..1a31e6f2 100644 --- a/mobx_codegen/lib/src/template/method_override.dart +++ b/mobx_codegen/lib/src/template/method_override.dart @@ -43,7 +43,7 @@ class MethodOverrideTemplate { late String name; late String returnType; - late SurroundedCommaList returnTypeArgs; + late SurroundedCommaList returnTypeArgs; late SurroundedCommaList _typeParams; late SurroundedCommaList _typeArgs; diff --git a/mobx_codegen/lib/src/type_names.dart b/mobx_codegen/lib/src/type_names.dart index 4992928c..f5211651 100644 --- a/mobx_codegen/lib/src/type_names.dart +++ b/mobx_codegen/lib/src/type_names.dart @@ -22,14 +22,14 @@ class LibraryScopedNameFinder { final LibraryElement library; - final Map _namesByElement = {}; + final Map _namesByElement = {}; - Map get namesByElement { + Map get namesByElement { // Add all of this library's type-defining elements to the name map final libraryElements = library.topLevelElements.whereType(); for (final element in libraryElements) { - _namesByElement[element] = element.name!; + _namesByElement[element] = element.name; } // Reverse each import's export namespace so we can map elements to their @@ -58,14 +58,14 @@ class LibraryScopedNameFinder { String findReturnTypeName(FunctionTypedElement executable) => _getDartTypeName(executable.returnType); - List findReturnTypeArgumentTypeNames(ExecutableElement executable) { + List findReturnTypeArgumentTypeNames(ExecutableElement executable) { final returnType = executable.returnType; return returnType is ParameterizedType ? returnType.typeArguments.map(_getDartTypeName).toList() : []; } - String findTypeParameterBoundsTypeName(TypeParameterElement typeParameter) { + String? findTypeParameterBoundsTypeName(TypeParameterElement typeParameter) { assert(typeParameter.bound != null); return _getDartTypeName(typeParameter.bound!); } @@ -88,7 +88,6 @@ class LibraryScopedNameFinder { typeElement == null || // This is a bare type param, like "T" type is TypeParameterType) { - // ignore: deprecated_member_use_from_same_package return type.getDisplayString(); } diff --git a/mobx_codegen/lib/version.dart b/mobx_codegen/lib/version.dart index 2bae6d5c..99454540 100644 --- a/mobx_codegen/lib/version.dart +++ b/mobx_codegen/lib/version.dart @@ -1,4 +1,4 @@ // Generated via set_version.dart. !!!DO NOT MODIFY BY HAND!!! /// The current version as per `pubspec.yaml`. -const version = '2.6.1'; +const version = '2.6.2'; diff --git a/mobx_codegen/pubspec.yaml b/mobx_codegen/pubspec.yaml index a1dc4479..c673423b 100644 --- a/mobx_codegen/pubspec.yaml +++ b/mobx_codegen/pubspec.yaml @@ -1,6 +1,6 @@ name: mobx_codegen description: Code generator for MobX that adds support for annotating your code with @observable, @computed, @action and also creating Store classes. -version: 2.6.1 +version: 2.6.2 repository: https://github.com/mobxjs/mobx.dart issue_tracker: https://github.com/mobxjs/mobx.dart/issues diff --git a/mobx_codegen/test/data/with_extension_input.dart b/mobx_codegen/test/data/with_extension_input.dart new file mode 100644 index 00000000..5618a8ee --- /dev/null +++ b/mobx_codegen/test/data/with_extension_input.dart @@ -0,0 +1,15 @@ +library generator_sample; + +import 'package:mobx/mobx.dart'; + +part 'store_with_extension.g.dart'; + +// ignore: library_private_types_in_public_api +class Foo = _Foo with _$Foo; + +abstract class _Foo with Store { + @observable + late String name; +} + +extension on int {} \ No newline at end of file diff --git a/mobx_codegen/test/data/with_extension_output.dart b/mobx_codegen/test/data/with_extension_output.dart new file mode 100644 index 00000000..573e5ba0 --- /dev/null +++ b/mobx_codegen/test/data/with_extension_output.dart @@ -0,0 +1,36 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'store_with_extension.dart'; + +// ************************************************************************** +// StoreGenerator +// ************************************************************************** + +// ignore_for_file: non_constant_identifier_names, unnecessary_brace_in_string_interps, unnecessary_lambdas, prefer_expression_function_bodies, lines_longer_than_80_chars, avoid_as, avoid_annotating_with_dynamic, no_leading_underscores_for_local_identifiers + +mixin _$Foo on _Foo, Store { + late final _$nameAtom = Atom(name: '_Foo.name', context: context); + + @override + String get name { + _$nameAtom.reportRead(); + return super.name; + } + + bool _nameIsInitialized = false; + + @override + set name(String value) { + _$nameAtom.reportWrite(value, _nameIsInitialized ? super.name : null, () { + super.name = value; + _nameIsInitialized = true; + }); + } + + @override + String toString() { + return ''' +name: ${name} + '''; + } +} \ No newline at end of file diff --git a/mobx_codegen/test/mobx_codegen_test.dart b/mobx_codegen/test/mobx_codegen_test.dart index 87222fcf..6e351629 100644 --- a/mobx_codegen/test/mobx_codegen_test.dart +++ b/mobx_codegen/test/mobx_codegen_test.dart @@ -59,6 +59,11 @@ void main() { './data/valid_keep_alive_computed_output.dart'); }); + test('generates for a class with extension', () async { + await compareFiles('./data/with_extension_input.dart', + './data/with_extension_output.dart'); + }); + createTests([ const TestInfo( description: 'invalid output is handled',