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

Prevents "TypeError: Cannot read property 'name' of undefined" #13

Merged
merged 3 commits into from
Dec 31, 2018

Conversation

Caltor
Copy link
Contributor

@Caltor Caltor commented Nov 29, 2018

At the moment certain files throw the following error.
ERR ..js Transformation error
TypeError: Cannot read property 'name' of undefined
at D:/Git/Fusion/UI/codemod.js:32:57
at Array.some ()

I have done some defensive programming and added prop => prop.key != null && into line 32 to prevent this.

At the moment certain files throw the following error.
ERR ..js Transformation error
TypeError: Cannot read property 'name' of undefined
    at D:/Git/Fusion/UI/codemod.js:32:57
    at Array.some (<anonymous>)

I have done some defensive programming and added `prop => prop.key != null &&` into line 32 to prevent this.
Copy link
Contributor

@snewcomer snewcomer left a comment

Choose a reason for hiding this comment

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

@Caltor Just one comment and we will merge!

lib/codemod.js Outdated
@@ -29,7 +29,7 @@ module.exports = function(file, api, options) {
source
.find(j.ObjectExpression)
.filter(path => {
return path.node.properties.some(prop => prop.key.name === 'i18n');
return path.node.properties.some(prop => prop => prop.key != null && prop.key.name === 'i18n');
Copy link
Contributor

Choose a reason for hiding this comment

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

can we do prop.key && prop.key.name === 'i18n'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good shout! That will catch undefined as well then. I've changed that and committed. Do I need to do anything else now or can you merge?

@snewcomer snewcomer added the bug Something isn't working label Dec 27, 2018
This change should catch undefined as well as null
Somehow an additional `prop =>` had snuck in
@snewcomer snewcomer merged commit 3a6793b into DockYard:master Dec 31, 2018
@Caltor Caltor deleted the patch-1 branch January 2, 2019 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants