Skip to content

Commit fed7ddb

Browse files
Allow generics in Map type for @convertJsMapProp props
1 parent 4be5042 commit fed7ddb

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/src/builder/codegen/accessors_generator.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,15 +469,22 @@ PropConversionConfig? parseConversionConfig({
469469
final convertJsRefProp =
470470
getConstantAnnotation(field, 'convertJsRefProp', annotations.convertJsRefProp);
471471
if (convertJsMapProp != null) {
472+
const allowedConvertedTypes = {
473+
'Map?',
474+
'Map<dynamic, dynamic>?',
475+
};
472476
conversionConfig = PropConversionConfig(
473477
rawType: 'JsMap?',
474478
convertedType: 'Map?',
475479
setter: 'jsifyMapProp',
476480
getter: 'unjsifyMapProp',
477481
);
478-
if (conversionConfig.convertedType != typeSource) {
482+
assert(allowedConvertedTypes.contains(conversionConfig.convertedType));
483+
if (!allowedConvertedTypes.contains(typeSource)) {
479484
handleAnnotationError(
480-
'A prop annotated with `@convertJsMapProp` should be typed as `Map?`.', field);
485+
'A prop annotated with `@convertJsMapProp` must be typed as one of: '
486+
'${allowedConvertedTypes.map((t) => '`$t`').join(', ')}',
487+
field);
481488
return null;
482489
}
483490
} else if (convertJsRefProp != null) {
@@ -489,7 +496,7 @@ PropConversionConfig? parseConversionConfig({
489496
);
490497
if (conversionConfig.convertedType != typeSource) {
491498
handleAnnotationError(
492-
'A prop annotated with `@convertJsRefProp` should be typed as `dynamic`.', field);
499+
'A prop annotated with `@convertJsRefProp` must be typed as `dynamic`.', field);
493500
return null;
494501
}
495502
}

test/vm_tests/builder/codegen_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ main() {
12001200
late String foo;''';
12011201

12021202
setUpAndGenerate(OverReactSrc.abstractProps(backwardsCompatible: false, body: body).source);
1203-
verify(() => logger.severe(contains('Unsupported prop annotation combination for prop \'foo\': A prop annotated with `@convertJsMapProp` should be typed as `Map?`.')));
1203+
verify(() => logger.severe(contains('Unsupported prop annotation combination for prop \'foo\': A prop annotated with `@convertJsMapProp` must be typed as one of: `Map?`, `Map<dynamic, dynamic>?`')));
12041204
});
12051205

12061206
test('@convertJsRefProp of the wrong prop type', () {
@@ -1209,7 +1209,7 @@ main() {
12091209
Map? foo;''';
12101210

12111211
setUpAndGenerate(OverReactSrc.abstractProps(backwardsCompatible: false, body: body).source);
1212-
verify(() => logger.severe(contains('Unsupported prop annotation combination for prop \'foo\': A prop annotated with `@convertJsRefProp` should be typed as `dynamic`.')));
1212+
verify(() => logger.severe(contains('Unsupported prop annotation combination for prop \'foo\': A prop annotated with `@convertJsRefProp` must be typed as `dynamic`.')));
12131213
});
12141214
});
12151215
});

0 commit comments

Comments
 (0)