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

UIP-1638: Make transformer output strong mode compliant #81

Merged
merged 6 commits into from Jun 20, 2017

Conversation

jacehensley-wf
Copy link
Contributor

@jacehensley-wf jacehensley-wf commented Jun 19, 2017

Solution for #14

Ultimate problem:

Code outputted by generated code was not strong-mode compliant under certain circumstances (concrete classes with generic parameter for props/state type).

How it was fixed:

  • Add untyped generation of typedPropsFactory and typedStateFactory to get around that.
  • Add warning if consumers are implementing their own typedPropsFactory or typedStateFactory

Testing suggestions:

  • Verify tests pass

Potential areas of regression:

  • Code generation

FYA: @greglittlefield-wf @aaronlademann-wf @clairesarsam-wf @joelleibow-wf

@aviary-wf
Copy link

Raven

Number of Findings: 0

@codecov-io
Copy link

codecov-io commented Jun 19, 2017

Codecov Report

Merging #81 into master will increase coverage by 0.02%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master      #81      +/-   ##
==========================================
+ Coverage   97.57%   97.58%   +0.02%     
==========================================
  Files          29       29              
  Lines        1394     1402       +8     
==========================================
+ Hits         1360     1368       +8     
  Misses         34       34

Copy link
Contributor

@greglittlefield-wf greglittlefield-wf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple things, but looking really good!

@@ -273,6 +277,22 @@ class ImplGenerator {
' extends Object with $componentClassImplMixinName'
);
}

if (new RegExp(r'typed(Props|State)Factory\(.+\)(\s+)?({|=>)').hasMatch(sourceFile.getText(0))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be much more robust to use the AST to detect this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could do something like this:

typedMap.node.members.any((member) => member is MethodDeclaration && !member.isStatic && (
    member.name.name == 'typedPropsFactory' ||
    member.name.name == 'typedStateFactory'
));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I like that a lot better! Thanks

var args = ['--strong']
..addAll(files);

return await Process.run('dartanalyzer', args);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just give dartanalyzer a path:

return await Process.run('dartanalyzer', ['--strong', projectPath]);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It keeps timing out when I do that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, interesting.

I'd try using the project path as the working directory for the command. If that doesn't work, that's fine, but we should have a comment here as to why we're listing out all of the files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed!

test('generates strong mode compliant code', () async {
var testProject = copyProject(strongModeProject);

// Run `pub get` and the bootstrap up-front so that back-to-back runs on the same directory complete faster.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment was relevant to this code being run in setUpAll, and is no longer applicable here.

class GenericStatelessProps extends UiProps {}

@Component()
class GenericStatelessComponent<T extends GenericStatelessProps> extends UiComponent<T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a test fixture for a component with generic state as well, to fully test the generation of typedStateFactory in that scenario.

@jacehensley-wf
Copy link
Contributor Author

@greglittlefield-wf Feedback has been addressed/replied to

@greglittlefield-wf
Copy link
Contributor

  • Code looks good
  • Tests pass

+10

@aaronlademann-wf aaronlademann-wf changed the title UIP-1638: Transformer output strong mode compliant UIP-1638: Make transformer output strong mode compliant Jun 20, 2017
@aaronlademann-wf
Copy link
Contributor

QA +1

  • Testing instruction
    • All tests pass.
    • Tests include new test to verify that transformer output is strong-mode clean.
  • Dev +1 or +10
  • Unit tests created/updated
  • All unit tests pass
  • Rosie ran/Rosie comment displays expected info
  • Dependency Scan Clean

Merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants