Skip to content

Commit

Permalink
Add support for covariant props / state fields
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronlademann-wf committed Jun 13, 2017
1 parent 9c17956 commit 036a2db
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: dart
dart:
- "1.21.1"
- "1.23.0"
with_content_shell: true
before_install:
- export DISPLAY=:99.0
Expand Down
9 changes: 6 additions & 3 deletions lib/src/transformer/impl_generation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import 'package:transformer_utils/transformer_utils.dart';
///
/// Generates implementations for:
///
/// * A component commprised of a `@Factory()`, `@Component()`, `@Props()`, and optionally a `@State()`
/// * A component comprised of a `@Factory()`, `@Component()`, `@Props()`, and optionally a `@State()`
///
/// * Generates:
///
Expand Down Expand Up @@ -296,7 +296,7 @@ class ImplGenerator {
!member.isSynthetic &&
member.isAbstract &&
member.name.name == name &&
member.returnType?.name?.name == type
member.returnType == type
);
});
}
Expand Down Expand Up @@ -484,10 +484,13 @@ class ImplGenerator {

TypeName type = field.fields.type;
String typeString = type == null ? '' : '$type ';
String setterTypeString = field.covariantKeyword == null
? typeString
: '${field.covariantKeyword} $typeString';

String generatedAccessor =
'${typeString}get $accessorName => $proxiedMapName[$keyConstantName]; '
'set $accessorName(${typeString}value) => $proxiedMapName[$keyConstantName] = value;';
'set $accessorName(${setterTypeString}value) => $proxiedMapName[$keyConstantName] = value;';

transformedFile.replace(
sourceFile.span(variable.firstTokenAfterCommentAndMetadata.offset, variable.name.end),
Expand Down
9 changes: 5 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@ homepage: https://github.com/Workiva/over_react/
authors:
- Workiva UI Platform Team <uip@workiva.com>
environment:
sdk: ">=1.21.1"
sdk: ">=1.23.0"
dependencies:
analyzer: ">=0.26.1+3 <0.31.0"
analyzer: ">=0.30.0 <0.31.0"
barback: "^0.15.0"
js: "^0.6.0"
meta: "^1.0.4"
path: "^1.4.1"
react: "^3.1.0"
source_span: "^1.2.0"
transformer_utils: "^0.1.1"
w_flux: "^2.5.0"
w_flux: "^2.7.1"
platform_detect: "^1.1.1"
quiver: ">=0.21.4 <0.25.0"
dev_dependencies:
browser_detect: "^1.0.4"
matcher: ">=0.11.0 <0.13.0"
coverage: "^0.7.2"
dart_dev: "^1.0.5"
dart_dev: "^1.7.6"
dart_style: ">=1.0.6 <2.0.0"
mockito: "^0.11.0"
test: "^0.12.6+2"

Expand Down
4 changes: 2 additions & 2 deletions smithy.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
project: dart
language: dart

# dart 1.21.1, built from https://github.com/Workiva/smithy-runner-dart/tree/0.0.4
runner_image: drydock-prod.workiva.net/workiva/smithy-runner-dart:119662
# dart 1.23.0
runner_image: drydock-prod.workiva.net/workiva/smithy-runner-generator:153818

script:
- pub get
Expand Down
13 changes: 13 additions & 0 deletions test/vm_tests/transformer/impl_generation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,19 @@ main() {
''');
});

test('covariant keyword', () {
preservedLineNumbersTest('''
@AbstractProps()
class AbstractFooProps {
covariant String foo;
}
''');

expect(transformedFile.getTransformedText(), contains('String get foo => props[_\$key__foo];'));
expect(transformedFile.getTransformedText(),
contains('set foo(covariant String value) => props[_\$key__foo] = value;'));
});

group('accessors', () {
test('that are absent', () {
preservedLineNumbersTest('''
Expand Down

0 comments on commit 036a2db

Please sign in to comment.