-
Notifications
You must be signed in to change notification settings - Fork 262
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
Conversation
There was a problem hiding this 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') { |
There was a problem hiding this comment.
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
}
test/__snapshots__/index.js.snap
Outdated
@@ -81,6 +81,47 @@ export default class { | |||
}" | |||
`; | |||
|
|||
exports[`works with complex spread props (class) 1`] = ` |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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 => { |
There was a problem hiding this comment.
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
test/__snapshots__/index.js.snap
Outdated
@@ -81,6 +81,47 @@ export default class { | |||
}" | |||
`; | |||
|
|||
exports[`works with complex spread props (class) 1`] = ` |
There was a problem hiding this comment.
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') | ||
) | ||
} |
There was a problem hiding this comment.
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')
)
I think I got it all, but if there is anything else I can change, just let me know :) |
@pudility awesome, thank you again for contributing! |
@giuseppeg No problem, thanks for all the mentoring. |
Fixing issue #329.
TODO:
this.props.foo
MemberExpression
s