Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AF-3085: Transformer is aware of Dart 2 builder compatible boilerplate for Factories #205

Merged
merged 2 commits into from
Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/src/transformer/impl_generation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ class ImplGenerator {
}

declarations.factory.node.variables.variables.forEach((variable) {
if (variable.initializer != null) {
if (variable.initializer != null && !(variable.initializer.toString() == '\$$factoryName')) {
logger.error(
'Factory variables are stubs for the generated factories, and should not have initializers.',
'Factory variables are stubs for the generated factories, and should not have initializers '
'unless initialized with \$$factoryName for Dart 2 builder compatibility.',
span: getSpan(sourceFile, variable.initializer)
);
}
Expand Down
37 changes: 36 additions & 1 deletion test/vm_tests/transformer/impl_generation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,28 @@ main() {
reason: 'should preserve existing inheritance');
});

test('with an initialized UiFactory with \$<UiFactory>', () {
final originalUiFactoryLine = 'UiFactory<FooProps> Foo = \$Foo;';
final transformedUiFactoryLine = 'UiFactory<FooProps> Foo = ([Map backingProps]) => new _\$FooPropsImpl(backingProps);';

preservedLineNumbersTest('''
@Factory()
UiFactory<FooProps> Foo = \$Foo;

@Props()
class FooProps {}

@Component()
class FooComponent {
render() => null;
}
''');

var transformedSource = transformedFile.getTransformedText();
expect(transformedSource, isNot(contains(originalUiFactoryLine)));
expect(transformedSource, contains(transformedUiFactoryLine));
});

test('with static PropsMeta and StateMeta declaration', () {
final originalPropsMetaLine = 'static const PropsMeta meta = \$metaForFooProps;';
final originalStateMetaLine = 'static const StateMeta meta = \$metaForFooState;';
Expand Down Expand Up @@ -661,7 +683,20 @@ main() {
$restOfComponent
''');

verify(logger.error('Factory variables are stubs for the generated factories, and should not have initializers.', span: any));
verify(logger.error('Factory variables are stubs for the generated factories, and should not have initializers'
' unless initialized with \$Foo for Dart 2 builder compatibility.', span: any));
});

test('declared with an \$ prefixed initializer matching the factory name', () {
setUpAndGenerate('''
@Factory()
UiFactory<FooProps> Foo = \$Foo;

$restOfComponent
''');

verifyNever(logger.error('Factory variables are stubs for the generated factories, and should not have initializers'
' unless initialized with \$Foo for Dart 2 builder compatibility.', span: any));
});
});

Expand Down