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

Fix complex spread props breaking (#329) #356

Merged
merged 9 commits into from
Nov 28, 2017
Merged

Conversation

zoecarver
Copy link

@zoecarver zoecarver commented Nov 27, 2017

Fixing issue #329.

TODO:

  • Add test cases for this.props.foo
  • Unlimited length MemberExpressions

@zoecarver zoecarver requested a review from giuseppeg as a code owner November 27, 2017 15:32
Copy link
Collaborator

@giuseppeg giuseppeg left a comment

Choose a reason for hiding this comment

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

Awesome thank you @pudility! The branch looks good.

You can add the new test cases to the existing fixture test/fixtures/attribute-generation-classname-rewriting.js

Somewhere in that component, I would add the following:

<div className="test" {...test.test} />
<div className="test" {...test.test.test} />
<div className="test" {...this.test.test} />

And then you can run npm test -- -u to update the snapshots. Remember to commit them obviously.

src/_utils.js Outdated
t.identifier(name),
t.identifier('className')
)

if (node.argument.type === 'MemberExpression') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

here you can do the following:

let attrNameDotClassName

if (t.isMemberExpression(node.argument)) {
   attrNameDotClassName = // with nested member expression
} else {
   attrNameDotClassName = // with simple identifier
}

@@ -81,6 +81,47 @@ export default class {
}"
`;

exports[`works with complex spread props (class) 1`] = `
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you revert the changes to this file? It seems that you removed the fixture and the test from test/index.js but the snapshot is still here in the diff :)

Copy link
Author

Choose a reason for hiding this comment

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

I added back the tests in test/index.js, is that what you where looking for? If not I am not sure I understand what you are asking, sorry.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry I didn't remember correctly the tests for this feature are in test/attribute.js.
Can you do the following:

  • remove the test from test/index.js
  • regenerate the snapshot for test/index.js like so:
rm test/__snapshots__/index.js.snap
npm test -- -u

Copy link
Collaborator

@giuseppeg giuseppeg left a comment

Choose a reason for hiding this comment

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

👌 last round of feedbacks I swear :) Thank you for your patience

test/index.js Outdated
@@ -20,6 +20,13 @@ test('works with stateless', async t => {
t.snapshot(code)
})

test('works with spread', async t => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

we don't need this test here since it is already in test/attribute.js

@@ -81,6 +81,47 @@ export default class {
}"
`;

exports[`works with complex spread props (class) 1`] = `
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry I didn't remember correctly the tests for this feature are in test/attribute.js.
Can you do the following:

  • remove the test from test/index.js
  • regenerate the snapshot for test/index.js like so:
rm test/__snapshots__/index.js.snap
npm test -- -u

src/_utils.js Outdated
t.identifier(name),
t.identifier('className')
)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpick: I just realized that this could be:

const attrNameDotClassName = t.memberExpression(
  t.isMemberExpression(node.argument) ? node.argument : t.identifier(name),
  t.identifier('className')
)

@zoecarver
Copy link
Author

I think I got it all, but if there is anything else I can change, just let me know :)

@giuseppeg giuseppeg merged commit aa4537f into vercel:master Nov 28, 2017
@giuseppeg
Copy link
Collaborator

@pudility awesome, thank you again for contributing!

@zoecarver
Copy link
Author

@giuseppeg No problem, thanks for all the mentoring.

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

Successfully merging this pull request may close these issues.

2 participants